// NewActionAPIV3 returns an initialized ActionAPI for version 3.
192211
func NewActionAPIV3(ctx facade.Context) (*APIv3, error) {
	api, err := newActionAPI(ctx.State(), ctx.Resources(), ctx.Auth())
	if err != nil {
		return nil, errors.Trace(err)
	}
	return &APIv3{api}, nil
}
128744
func NewRegionAPI(client *Client) *RegionAPI {
	return &RegionAPI{
		&baseAPI{
			client: client,
			FuncGetResourceURL: func() string {
				return "region"
			},
		},
	}
}
826518
func (f *factory) NewFailAction(actionId string) (Operation, error) {
	if !names.IsValidAction(actionId) {
		return nil, errors.Errorf("invalid action id %q", actionId)
	}
	return &failAction{
		actionId:  actionId,
		callbacks: f.config.Callbacks,
	}, nil
}
563397
func NewFacadeV3(ctx facade.Context) (*ModelManagerAPIV3, error) {
	v4, err := NewFacadeV4(ctx)
	if err != nil {
		return nil, err
	}
	return &ModelManagerAPIV3{v4}, nil
}
1067454
func (f *factory) NewAction(actionId string) (Operation, error) {
	if !names.IsValidAction(actionId) {
		return nil, errors.Errorf("invalid action id %q", actionId)
	}
	return &runAction{
		actionId:      actionId,
		callbacks:     f.config.Callbacks,
		runnerFactory: f.config.RunnerFactory,
	}, nil
}
881531
func NewAPI(caller base.APICallCloser) *API {
	if caller == nil {
		panic("caller is nil")
	}
	clientFacade, facadeCaller := base.NewClientFacade(caller, subnetsFacade)
	return &API{
		ClientFacade: clientFacade,
		facade:       facadeCaller,
	}
}
257527
func NewActionBlock(blockID string, elements ...BlockElement) *ActionBlock {
	return &ActionBlock{
		Type:     mbtAction,
		BlockID:  blockID,
		Elements: elements,
	}
}
960584
func (s *Action) JSONAPI(ctx context.Context, c *cli.Context) error {
	api := jsonapi.API{Store: s.Store, Reader: stdin, Writer: stdout, Version: s.version}
	if err := api.ReadAndRespond(ctx); err != nil {
		return api.RespondError(err)
	}
	return nil
}
219828
func (u *Unit) AddAction(name string, payload map[string]interface{}) (Action, error) {
	if len(name) == 0 {
		return nil, errors.New("no action name given")
	}

	// If the action is predefined inside juju, get spec from map
	spec, ok := actions.PredefinedActionsSpec[name]
	if !ok {
		specs, err := u.ActionSpecs()
		if err != nil {
			return nil, err
		}
		spec, ok = specs[name]
		if !ok {
			return nil, errors.Errorf("action %q not defined on unit %q", name, u.Name())
		}
	}
	// Reject bad payloads before attempting to insert defaults.
	err := spec.ValidateParams(payload)
	if err != nil {
		return nil, err
	}
	payloadWithDefaults, err := spec.InsertDefaults(payload)
	if err != nil {
		return nil, err
	}

	m, err := u.st.Model()
	if err != nil {
		return nil, errors.Trace(err)
	}
	return m.EnqueueAction(u.Tag(), name, payloadWithDefaults)
}
1064780
func NewCustomAction(f func(manager Manager, filters ...Filter) error, filters ...Filter) Action {
	return &action{action: CustomAction, filters: filters, f: f}
}
1115805
func OpenAPIv3(api *discovery.Document) (*openapi3.Document, error) {
	d := &openapi3.Document{}
	d.Openapi = "3.0"
	d.Info = &openapi3.Info{
		Title:       api.Title,
		Version:     api.Version,
		Description: api.Description,
	}
	d.Servers = make([]*openapi3.Server, 0)

	url, _ := url.Parse(api.RootUrl)
	host := url.Host
	basePath := api.BasePath
	if basePath == "" {
		basePath = "/"
	}
	d.Servers = append(d.Servers, &openapi3.Server{Url: "https://" + host + basePath})

	hasDataWrapper := false
	for _, feature := range api.Features {
		if feature == "dataWrapper" {
			hasDataWrapper = true
		}
	}

	d.Components = &openapi3.Components{}
	d.Components.Schemas = &openapi3.SchemasOrReferences{}
	for _, pair := range api.Schemas.AdditionalProperties {
		addOpenAPI3SchemaForSchema(d, pair.Name, pair.Value)
	}

	d.Paths = &openapi3.Paths{}
	if api.Methods != nil {
		for _, pair := range api.Methods.AdditionalProperties {
			addOpenAPI3PathsForMethod(d, pair.Name, pair.Value, hasDataWrapper)
		}
	}
	for _, pair := range api.Resources.AdditionalProperties {
		addOpenAPI3PathsForResource(d, pair.Value, hasDataWrapper)
	}

	return d, 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
}
234869
func newAPI(prefix string, resolver URLResolver, router routing.Routeable) *API {
	// Add initial and trailing slash to prefix
	prefixSlashes := strings.Trim(prefix, "/")
	if len(prefixSlashes) > 0 {
		prefixSlashes = "/" + prefixSlashes + "/"
	} else {
		prefixSlashes = "/"
	}

	info := information{prefix: prefix, resolver: resolver}

	api := &API{
		ContentType:      defaultContentTypHeader,
		router:           router,
		info:             info,
		middlewares:      make([]HandlerFunc, 0),
		contextAllocator: nil,
	}

	api.contextPool.New = func() interface{} {
		if api.contextAllocator != nil {
			return api.contextAllocator(api)
		}
		return api.allocateDefaultContext()
	}

	return api
}
746650
func (c *SubnetCommandBase) NewAPI() (SubnetAPI, error) {
	if c.api != nil {
		// Already created.
		return c.api, nil
	}
	root, err := c.NewAPIRoot()
	if err != nil {
		return nil, errors.Trace(err)
	}

	// This is tested with a feature test.
	shim := &mvpAPIShim{
		apiState: root,
		facade:   subnets.NewAPI(root),
	}
	return shim, nil
}
973710
func NewDeleteAction(filters ...Filter) Action {
	return &action{action: deleteAction, filters: filters, f: deleteActionFunc}
}
1341957
func NewAPI(
	backend Backend,
	authorizer facade.Authorizer,
	blockChecker BlockChecker,
) (*API, error) {
	if !authorizer.AuthClient() {
		return nil, common.ErrPerm
	}
	return &API{
		backend:    backend,
		authorizer: authorizer,
		check:      blockChecker,
	}, nil
}
1361810
func (f *factory) NewActionRunner(actionId string) (Runner, error) {
	ch, err := getCharm(f.paths.GetCharmDir())
	if err != nil {
		return nil, errors.Trace(err)
	}

	ok := names.IsValidAction(actionId)
	if !ok {
		return nil, charmrunner.NewBadActionError(actionId, "not valid actionId")
	}
	tag := names.NewActionTag(actionId)
	action, err := f.state.Action(tag)
	if params.IsCodeNotFoundOrCodeUnauthorized(err) {
		return nil, charmrunner.ErrActionNotAvailable
	} else if params.IsCodeActionNotAvailable(err) {
		return nil, charmrunner.ErrActionNotAvailable
	} else if err != nil {
		return nil, errors.Trace(err)
	}

	name := action.Name()

	spec, ok := actions.PredefinedActionsSpec[name]
	if !ok {
		var ok bool
		spec, ok = ch.Actions().ActionSpecs[name]
		if !ok {
			return nil, charmrunner.NewBadActionError(name, "not defined")
		}
	}

	params := action.Params()
	if err := spec.ValidateParams(params); err != nil {
		return nil, charmrunner.NewBadActionError(name, err.Error())
	}

	actionData := context.NewActionData(name, &tag, params)
	ctx, err := f.contextFactory.ActionContext(actionData)
	runner := NewRunner(ctx, f.paths)
	return runner, nil
}