// getAPI returns the API that supplies methods
// required to execute this command.
764380
func (c *branchCommand) getAPI() (BranchCommandAPI, error) {
	if c.api != nil {
		return c.api, nil
	}
	api, err := c.NewAPIRoot()
	if err != nil {
		return nil, errors.Annotate(err, "opening API connection")
	}
	client := modelgeneration.NewClient(api)
	return client, nil
}
141935
func ReadAPI(fn string, m map[string][]string) error {
	f, err := os.Open(fn)
	if err != nil {
		return err
	}
	defer f.Close()

	scnr := bufio.NewScanner(f)
	var key string
	for scnr.Scan() {
		if s := scnr.Text(); strings.Contains(s, "//") {
			continue
		} else if strings.Contains(s, "\t") {
			m[key] = append(m[key], strings.Replace(s, "\t", "", -1))
			continue
		} else {
			m[s] = make([]string, 0)
			key = s
		}
	}
	return scnr.Err()
}
1069198
func getAPIError(code APIErrorCode) APIError {
	if apiErr, ok := errorCodes[code]; ok {
		return apiErr
	}
	return errorCodes.ToAPIErr(ErrInternalError)
}
533363
func (kr *PortRuleKafka) GetAPIVersion() (int16, bool) {
	if kr.apiVersionInt == nil {
		return 0, true
	}

	return *kr.apiVersionInt, false
}
165838
func NewAPI(ctx facade.Context) (*API, error) {
	leadership, err := common.NewLeadershipPinningFacade(ctx)
	if err != nil {
		if errors.IsNotImplemented(errors.Cause(err)) {
			leadership = disabledLeadershipPinningFacade{}
		} else {
			return nil, errors.Trace(err)
		}
	}
	return NewUpgradeSeriesAPI(common.UpgradeSeriesState{St: ctx.State()}, ctx.Resources(), ctx.Auth(), leadership)
}
268720
func (m *MWApi) API(values ...map[string]string) ([]byte, error) {
	query := m.url.Query()
	for _, valuemap := range values {
		for key, value := range valuemap {
			query.Set(key, value)
		}
	}
	query.Set("format", m.format)
	body, err := m.postForm(query)
	if err != nil {
		return nil, err
	}
	return body, nil
}
1368665
func HostApi(apiType HostApiType) (*HostApiInfo, error) {
	hosts, err := HostApis()
	if err != nil {
		return nil, err
	}
	i := C.Pa_HostApiTypeIdToHostApiIndex(C.PaHostApiTypeId(apiType))
	if i < 0 {
		return nil, newError(C.PaError(i))
	}
	return hosts[i], nil
}
354010
func NewAPI(ctx facade.Context, getEnviron stateenvirons.NewEnvironFunc, getCAASBroker stateenvirons.NewCAASBrokerFunc, callCtx context.ProviderCallContext) (*API, error) {
	auth := ctx.Auth()
	st := ctx.State()
	if err := checkAuth(auth, st); err != nil {
		return nil, errors.Trace(err)
	}
	return &API{
		state:         st,
		pool:          ctx.StatePool(),
		authorizer:    auth,
		resources:     ctx.Resources(),
		presence:      ctx.Presence(),
		getClaimer:    ctx.LeadershipClaimer,
		getEnviron:    getEnviron,
		getCAASBroker: getCAASBroker,
		callContext:   callCtx,
	}, nil
}
760633
func (c *diffCommand) getAPI() (DiffCommandAPI, error) {
	if c.api != nil {
		return c.api, nil
	}
	api, err := c.NewAPIRoot()
	if err != nil {
		return nil, errors.Annotate(err, "opening API connection")
	}
	client := modelgeneration.NewClient(api)
	return client, nil
}
165243
func getBlockAPI(c newAPIRoot) (*apiblock.Client, error) {
	root, err := c.NewAPIRoot()
	if err != nil {
		return nil, err
	}
	return apiblock.NewClient(root), nil
}
953765
func NewAPI(
	backend Backend,
	precheckBackend migration.PrecheckBackend,
	pool migration.Pool,
	resources facade.Resources,
	authorizer facade.Authorizer,
	presence facade.Presence,
) (*API, error) {
	if !authorizer.AuthController() {
		return nil, common.ErrPerm
	}
	return &API{
		backend:         backend,
		precheckBackend: precheckBackend,
		pool:            pool,
		authorizer:      authorizer,
		resources:       resources,
		presence:        presence,
	}, nil
}
682633
func NewAPI(master master.ClientInterface, agent *agent.Client, docker *dockerclient.Client, dao dao.ControlPlane) API {
	return &api{master: master, agent: agent, docker: docker, dao: dao}
}
934466
func setApi(api uint) error {
	if retCode := C.seccomp_api_set(C.uint(api)); retCode != 0 {
		if syscall.Errno(-1*retCode) == syscall.EOPNOTSUPP {
			return fmt.Errorf("API level operations are not supported")
		}

		return fmt.Errorf("could not set API level: %v", retCode)
	}

	return nil
}
468887
func NewAPI(rawurl, key, secret string) (*API, error) {
	client := oauth.NewConsumer(key, secret, oauth.ServiceProvider{})
	token := &oauth.AccessToken{}

	parsed, err := url.Parse(rawurl)
	if err != nil {
		return nil, err
	}

	return &API{
		url:    parsed,
		client: client,
		token:  token,
	}, nil
}
130818
func NewAPI(fileStore *storage.FileStore, dns Resolver, feedHandler *feed.Handler, pk *ecdsa.PrivateKey) (self *API) {
	self = &API{
		fileStore: fileStore,
		dns:       dns,
		feed:      feedHandler,
		Decryptor: func(ctx context.Context, credentials string) DecryptFunc {
			return self.doDecrypt(ctx, credentials, pk)
		},
	}
	return
}
289320
func getAPIClient(ctx context.Context, repoPath, apiAddrStr string) (http.Client, error) {
	var apiErrorFmt string
	switch {
	case osh.IsUnix():
		apiErrorFmt = apiFileErrorFmt + checkIPFSUnixFmt
	case osh.IsWindows():
		apiErrorFmt = apiFileErrorFmt + checkIPFSWinFmt
	default:
		apiErrorFmt = apiFileErrorFmt
	}

	var addr ma.Multiaddr
	var err error
	if len(apiAddrStr) != 0 {
		addr, err = ma.NewMultiaddr(apiAddrStr)
		if err != nil {
			return nil, err
		}
		if len(addr.Protocols()) == 0 {
			return nil, fmt.Errorf("multiaddr doesn't provide any protocols")
		}
	} else {
		addr, err = fsrepo.APIAddr(repoPath)
		if err == repo.ErrApiNotRunning {
			return nil, err
		}

		if err != nil {
			return nil, fmt.Errorf(apiErrorFmt, repoPath, err.Error())
		}
	}
	if len(addr.Protocols()) == 0 {
		return nil, fmt.Errorf(apiErrorFmt, repoPath, "multiaddr doesn't provide any protocols")
	}
	return apiClientForAddr(ctx, addr)
}
510731
func (c *Context) GetAPI() (coreiface.CoreAPI, error) {
	if c.api == nil {
		n, err := c.GetNode()
		if err != nil {
			return nil, err
		}
		fetchBlocks := true
		if c.Gateway {
			cfg, err := c.GetConfig()
			if err != nil {
				return nil, err
			}
			fetchBlocks = !cfg.Gateway.NoFetch
		}

		c.api, err = coreapi.NewCoreAPI(n, options.Api.FetchBlocks(fetchBlocks))
		if err != nil {
			return nil, err
		}
	}
	return c.api, nil
}