// appsEnsureRepo will set the repo if it's not set.
338173
func appsEnsureRepo(db *gorm.DB, app *App, repo string) error {
	if app.Repo != nil {
		return nil
	}

	app.Repo = &repo

	return appsUpdate(db, app)
}
174513
func (c *client) RepoList() ([]*Repo, error) {
	var out []*Repo
	uri := fmt.Sprintf(pathRepos, c.addr)
	err := c.get(uri, &out)
	return out, err
}
100352
func (c *Client) SetAppRelease(appID, releaseID string) error {
	return c.Put(fmt.Sprintf("/apps/%s/release", appID), &ct.Release{ID: releaseID}, nil)
}
1219411
func (m *MockService) SubscriptionRepo() repo.Subscription {
	ret := m.ctrl.Call(m, "SubscriptionRepo")
	ret0, _ := ret[0].(repo.Subscription)
	return ret0
}
74639
func (c *Client) UnsetApplicationConfig(branchName, application string, options []string) error {
	if c.BestAPIVersion() < 6 {
		return errors.NotSupportedf("UnsetApplicationConfig not supported by this version of Juju")
	}
	args := params.ApplicationConfigUnsetArgs{
		Args: []params.ApplicationUnset{{
			ApplicationName: application,
			BranchName:      branchName,
			Options:         options,
		}},
	}
	var results params.ErrorResults
	err := c.facade.FacadeCall("UnsetApplicationsConfig", args, &results)
	if err != nil {
		return errors.Trace(err)
	}
	return results.OneError()
}
415777
func (d *Downloader) DeduceRemoteRepo(path string, insecure bool) (vendor.RemoteRepo, string, error) {
	cache := d.repos
	if insecure {
		cache = d.reposI
	}

	d.reposMu.RLock()
	for p, repo := range cache {
		if path == p || strings.HasPrefix(path, p+"/") {
			d.reposMu.RUnlock()
			extra := strings.Trim(strings.TrimPrefix(path, p), "/")
			return repo, extra, nil
		}
	}
	d.reposMu.RUnlock()

	repo, extra, err := vendor.DeduceRemoteRepo(path, insecure)
	if err != nil {
		return repo, extra, err
	}

	if !strings.HasSuffix(path, extra) {
		// Shouldn't happen, but in case just bypass the cache
		return repo, extra, err
	}
	basePath := strings.Trim(strings.TrimSuffix(path, extra), "/")
	d.reposMu.Lock()
	cache[basePath] = repo
	d.reposMu.Unlock()

	return repo, extra, err
}
110267
func (s *AppsService) ListRepos(ctx context.Context, opt *ListOptions) ([]*Repository, *Response, error) {
	u, err := addOptions("installation/repositories", opt)
	if err != nil {
		return nil, nil, err
	}

	req, err := s.client.NewRequest("GET", u, nil)
	if err != nil {
		return nil, nil, err
	}

	// TODO: remove custom Accept header when this API fully launches.
	req.Header.Set("Accept", mediaTypeIntegrationPreview)

	var r struct {
		Repositories []*Repository `json:"repositories"`
	}
	resp, err := s.client.Do(ctx, req, &r)
	if err != nil {
		return nil, resp, err
	}

	return r.Repositories, resp, nil
}
1368016
func (c ProvisionUiClient) ProvisioneeSuccess(ctx context.Context, __arg ProvisioneeSuccessArg) (err error) {
	err = c.Cli.Call(ctx, "keybase.1.provisionUi.ProvisioneeSuccess", []interface{}{__arg}, nil)
	return
}
271200
func (u *UniterAPI) CloudAPIVersion() (params.StringResult, error) {
	result := params.StringResult{}

	configGetter := stateenvirons.EnvironConfigGetter{State: u.st, Model: u.m, NewContainerBroker: u.containerBrokerFunc}
	spec, err := configGetter.CloudSpec()
	if err != nil {
		return result, common.ServerError(err)
	}
	apiVersion, err := configGetter.CloudAPIVersion(spec)
	if err != nil {
		return result, common.ServerError(err)
	}
	result.Result = apiVersion
	return result, err
}
1298671
func appNameFromRepo(repo string) string {
	p := strings.Split(repo, "/")
	return p[len(p)-1]
}
830390
func SetAppEUI(ctx ttnlog.Interface, appEUI types.AppEUI) {
	err := setData(appFilename, euiKey, appEUI.String())
	if err != nil {
		ctx.WithError(err).Fatal("Could not save app EUI")
	}
}
1261893
func (c *Client) SetAppInfo(appName string, appVersion string) {
	// if app name and version not set, we do not set a new user agent.
	if appName != "" && appVersion != "" {
		c.appInfo = struct {
			appName    string
			appVersion string
		}{}
		c.appInfo.appName = appName
		c.appInfo.appVersion = appVersion
	}
}
1254457
func LoadTUFRepo(options TUFLoadOptions) (*tuf.Repo, *tuf.Repo, error) {
	// set some sane defaults, so nothing has to be provided necessarily
	if options.RemoteStore == nil {
		options.RemoteStore = store.OfflineStore{}
	}
	if options.Cache == nil {
		options.Cache = store.NewMemoryStore(nil)
	}
	if options.CryptoService == nil {
		options.CryptoService = cryptoservice.EmptyService
	}

	c, err := bootstrapClient(options)
	if err != nil {
		if _, ok := err.(store.ErrMetaNotFound); ok {
			return nil, nil, ErrRepositoryNotExist{
				remote: options.RemoteStore.Location(),
				gun:    options.GUN,
			}
		}
		return nil, nil, err
	}
	repo, invalid, err := c.Update()
	if err != nil {
		// notFound.Resource may include a version or checksum so when the role is root,
		// it will be root, <version>.root or root.<checksum>.
		notFound, ok := err.(store.ErrMetaNotFound)
		isRoot, _ := regexp.MatchString(`\.?`+data.CanonicalRootRole.String()+`\.?`, notFound.Resource)
		if ok && isRoot {
			return nil, nil, ErrRepositoryNotExist{
				remote: options.RemoteStore.Location(),
				gun:    options.GUN,
			}
		}
		return nil, nil, err
	}
	warnRolesNearExpiry(repo)
	return repo, invalid, nil
}
1285522
func (c *Client) GetRepo(owner, reponame string) (*Repository, error) {
	repo := new(Repository)
	return repo, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s", owner, reponame), nil, nil, repo)
}
866447
func (rh *RPCHandler) DeleteRepo(
	ctx context.Context, arg keybase1.DeleteRepoArg) (err error) {
	rh.log.CDebugf(ctx, "Deleting repo %s from folder %s/%s",
		arg.Name, arg.Folder.FolderType, arg.Folder.Name)
	defer func() {
		rh.log.CDebugf(ctx, "Done deleting repo: %+v", err)
	}()

	ctx, cancel := context.WithCancel(ctx)
	defer cancel()
	ctx, gitConfig, tlfHandle, tempDir, err := rh.getHandleAndConfig(
		ctx, arg.Folder)
	if err != nil {
		return err
	}
	defer func() {
		rmErr := os.RemoveAll(tempDir)
		if rmErr != nil {
			rh.log.CDebugf(
				ctx, "Error cleaning storage dir %s: %+v\n", tempDir, rmErr)
		}
	}()
	defer gitConfig.Shutdown(ctx)

	err = DeleteRepo(ctx, gitConfig, tlfHandle, string(arg.Name))
	if err != nil {
		return err
	}

	err = rh.waitForJournal(ctx, gitConfig, tlfHandle)
	if err != nil {
		return err
	}

	rh.scheduleCleaning(arg.Folder)
	return nil
}
943785
func (r *FSRepo) SetConfigKey(key string, value interface{}) error {
	packageLock.Lock()
	defer packageLock.Unlock()

	if r.closed {
		return errors.New("repo is closed")
	}

	filename, err := config.Filename(r.path)
	if err != nil {
		return err
	}
	var mapconf map[string]interface{}
	if err := serialize.ReadConfigFile(filename, &mapconf); err != nil {
		return err
	}

	// Load private key to guard against it being overwritten.
	// NOTE: this is a temporary measure to secure this field until we move
	// keys out of the config file.
	pkval, err := common.MapGetKV(mapconf, config.PrivKeySelector)
	if err != nil {
		return err
	}

	// Get the type of the value associated with the key
	oldValue, err := common.MapGetKV(mapconf, key)
	ok := true
	if err != nil {
		// key-value does not exist yet
		switch v := value.(type) {
		case string:
			value, err = strconv.ParseBool(v)
			if err != nil {
				value, err = strconv.Atoi(v)
				if err != nil {
					value, err = strconv.ParseFloat(v, 32)
					if err != nil {
						value = v
					}
				}
			}
		default:
		}
	} else {
		switch oldValue.(type) {
		case bool:
			value, ok = value.(bool)
		case int:
			value, ok = value.(int)
		case float32:
			value, ok = value.(float32)
		case string:
			value, ok = value.(string)
		default:
		}
		if !ok {
			return fmt.Errorf("wrong config type, expected %T", oldValue)
		}
	}

	if err := common.MapSetKV(mapconf, key, value); err != nil {
		return err
	}

	// replace private key, in case it was overwritten.
	if err := common.MapSetKV(mapconf, config.PrivKeySelector, pkval); err != nil {
		return err
	}

	// This step doubles as to validate the map against the struct
	// before serialization
	conf, err := config.FromMap(mapconf)
	if err != nil {
		return err
	}
	if err := serialize.WriteConfigFile(filename, mapconf); err != nil {
		return err
	}
	return r.setConfigUnsynced(conf) // TODO roll this into this method
}
1316051
func (c *client) RepoEnable(owner, name string) (*Repo, error) {
	out := new(Repo)
	uri := fmt.Sprintf(pathRepo, c.addr, owner, name)
	err := c.post(uri, nil, out)
	return out, err
}