// NewStorageAPIV3 returns a new storage v3 API facade.
355649
func NewStorageAPIV3(context facade.Context) (*StorageAPIv3, error) {
	storageAPI, err := NewStorageAPIV4(context)
	if err != nil {
		return nil, err
	}
	return &StorageAPIv3{
		StorageAPIv4: *storageAPI,
	}, nil
}
1086517
func NewStrategy(typer runtime.ObjectTyper) rest.RESTCreateUpdateStrategy {
	return apiServerStrategy{typer, names.SimpleNameGenerator}
}
990935
func NewStateFirewallerAPIV3(context facade.Context) (*FirewallerAPIV3, error) {
	st := context.State()

	m, err := st.Model()
	if err != nil {
		return nil, errors.Trace(err)
	}

	cloudSpecAPI := cloudspec.NewCloudSpec(
		context.Resources(),
		cloudspec.MakeCloudSpecGetterForModel(st),
		cloudspec.MakeCloudSpecWatcherForModel(st),
		common.AuthFuncForTag(m.ModelTag()),
	)
	return NewFirewallerAPI(stateShim{st: st, State: firewall.StateShim(st, m)}, context.Resources(), context.Auth(), cloudSpecAPI)
}
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
}
939743
func NewStoreBucketTypePropsCommandBuilder() *StoreBucketTypePropsCommandBuilder {
	props := &rpbRiak.RpbBucketProps{}
	protobuf := &rpbRiak.RpbSetBucketTypeReq{
		Props: props,
	}
	builder := &StoreBucketTypePropsCommandBuilder{protobuf: protobuf, props: props}
	return builder
}
416120
func NewSerializer(meta MetaFactory, creater runtime.ObjectCreater, typer runtime.ObjectTyper, pretty bool) *Serializer {
	return NewSerializerWithOptions(meta, creater, typer, SerializerOptions{false, pretty, false})
}
1025247
func NewS3Provider(domain, key, secret, bucket string) StorageProvider {
	return &S3Provider{
		AccessKeyID:     key,
		SecretAccessKey: secret,
		BucketName:      bucket,
		S3Domain:        domain,
	}
}
569189
func NewStorage() *Storage {
	return &Storage{
		ReferenceStorage: make(ReferenceStorage),
		ConfigStorage:    ConfigStorage{},
		ShallowStorage:   ShallowStorage{},
		ObjectStorage: ObjectStorage{
			Objects: make(map[plumbing.Hash]plumbing.EncodedObject),
			Commits: make(map[plumbing.Hash]plumbing.EncodedObject),
			Trees:   make(map[plumbing.Hash]plumbing.EncodedObject),
			Blobs:   make(map[plumbing.Hash]plumbing.EncodedObject),
			Tags:    make(map[plumbing.Hash]plumbing.EncodedObject),
		},
		ModuleStorage: make(ModuleStorage),
	}
}
1076269
func NewStorageDriver(name string) (types.StorageDriver, error) {

	var ok bool
	var ctor types.NewStorageDriver

	func() {
		storDriverCtorsRWL.RLock()
		defer storDriverCtorsRWL.RUnlock()
		ctor, ok = storDriverCtors[strings.ToLower(name)]
	}()

	if !ok {
		return nil, goof.WithField("driver", name, "invalid driver name")
	}

	return ctor(), nil
}
895657
func NewStorageProvisionerAPIv3(
	st Backend,
	sb StorageBackend,
	resources facade.Resources,
	authorizer facade.Authorizer,
	registry storage.ProviderRegistry,
	poolManager poolmanager.PoolManager,
) (*StorageProvisionerAPIv3, error) {
	if !authorizer.AuthMachineAgent() {
		return nil, common.ErrPerm
	}
	canAccessStorageMachine := func(tag names.Tag, allowController bool) bool {
		authEntityTag := authorizer.GetAuthTag()
		if tag == authEntityTag {
			// Machine agents can access volumes
			// scoped to their own machine.
			return true
		}
		parentId := state.ParentId(tag.Id())
		if parentId == "" {
			return allowController && authorizer.AuthController()
		}
		// All containers with the authenticated
		// machine as a parent are accessible by it.
		return names.NewMachineTag(parentId) == authEntityTag
	}
	getScopeAuthFunc := func() (common.AuthFunc, error) {
		return func(tag names.Tag) bool {
			switch tag := tag.(type) {
			case names.ModelTag:
				// Controllers can access all volumes
				// and filesystems scoped to the environment.
				isModelManager := authorizer.AuthController()
				return isModelManager && tag == st.ModelTag()
			case names.MachineTag:
				return canAccessStorageMachine(tag, false)
			case names.ApplicationTag:
				return authorizer.AuthController()
			default:
				return false
			}
		}, nil
	}
	canAccessStorageEntity := func(tag names.Tag, allowMachines bool) bool {
		switch tag := tag.(type) {
		case names.VolumeTag:
			machineTag, ok := names.VolumeMachine(tag)
			if ok {
				return canAccessStorageMachine(machineTag, false)
			}
			return authorizer.AuthController()
		case names.FilesystemTag:
			machineTag, ok := names.FilesystemMachine(tag)
			if ok {
				return canAccessStorageMachine(machineTag, false)
			}
			_, ok = names.FilesystemUnit(tag)
			if ok {
				return authorizer.AuthController()
			}
			f, err := sb.Filesystem(tag)
			if err != nil {
				return false
			}
			volumeTag, err := f.Volume()
			if err == nil {
				// The filesystem has a backing volume. If the
				// authenticated agent has access to any of the
				// machines that the volume is attached to, then
				// it may access the filesystem too.
				volumeAttachments, err := sb.VolumeAttachments(volumeTag)
				if err != nil {
					return false
				}
				for _, a := range volumeAttachments {
					if canAccessStorageMachine(a.Host(), false) {
						return true
					}
				}
			} else if err != state.ErrNoBackingVolume {
				return false
			}
			return authorizer.AuthController()
		case names.MachineTag:
			return allowMachines && canAccessStorageMachine(tag, true)
		case names.ApplicationTag:
			return authorizer.AuthController()
		default:
			return false
		}
	}
	getStorageEntityAuthFunc := func() (common.AuthFunc, error) {
		return func(tag names.Tag) bool {
			return canAccessStorageEntity(tag, false)
		}, nil
	}
	getLifeAuthFunc := func() (common.AuthFunc, error) {
		return func(tag names.Tag) bool {
			return canAccessStorageEntity(tag, true)
		}, nil
	}
	getAttachmentAuthFunc := func() (func(names.Tag, names.Tag) bool, error) {
		// getAttachmentAuthFunc returns a function that validates
		// access by the authenticated user to an attachment.
		return func(hostTag names.Tag, attachmentTag names.Tag) bool {
			if hostTag.Kind() == names.UnitTagKind {
				return authorizer.AuthController()
			}

			// Machine agents can access their own machine, and
			// machines contained. Controllers can access
			// top-level machines.
			machineAccessOk := canAccessStorageMachine(hostTag, true)

			if !machineAccessOk {
				return false
			}

			// Controllers can access model-scoped
			// volumes and volumes scoped to their own machines.
			// Other machine agents can access volumes regardless
			// of their scope.
			if !authorizer.AuthController() {
				return true
			}
			var machineScope names.MachineTag
			var hasMachineScope bool
			switch attachmentTag := attachmentTag.(type) {
			case names.VolumeTag:
				machineScope, hasMachineScope = names.VolumeMachine(attachmentTag)
			case names.FilesystemTag:
				machineScope, hasMachineScope = names.FilesystemMachine(attachmentTag)
			}
			return !hasMachineScope || machineScope == authorizer.GetAuthTag()
		}, nil
	}
	getMachineAuthFunc := func() (common.AuthFunc, error) {
		return func(tag names.Tag) bool {
			if tag, ok := tag.(names.MachineTag); ok {
				return canAccessStorageMachine(tag, true)
			}
			return false
		}, nil
	}
	getBlockDevicesAuthFunc := func() (common.AuthFunc, error) {
		return func(tag names.Tag) bool {
			if tag, ok := tag.(names.MachineTag); ok {
				return canAccessStorageMachine(tag, false)
			}
			return false
		}, nil
	}
	return &StorageProvisionerAPIv3{
		LifeGetter:       common.NewLifeGetter(st, getLifeAuthFunc),
		DeadEnsurer:      common.NewDeadEnsurer(st, getStorageEntityAuthFunc),
		InstanceIdGetter: common.NewInstanceIdGetter(st, getMachineAuthFunc),
		StatusSetter:     common.NewStatusSetter(st, getStorageEntityAuthFunc),

		st:                       st,
		sb:                       sb,
		resources:                resources,
		authorizer:               authorizer,
		registry:                 registry,
		poolManager:              poolManager,
		getScopeAuthFunc:         getScopeAuthFunc,
		getStorageEntityAuthFunc: getStorageEntityAuthFunc,
		getAttachmentAuthFunc:    getAttachmentAuthFunc,
		getMachineAuthFunc:       getMachineAuthFunc,
		getBlockDevicesAuthFunc:  getBlockDevicesAuthFunc,
	}, nil
}
313047
func NewSubnetAPI(client *Client) *SubnetAPI {
	return &SubnetAPI{
		&baseAPI{
			client: client,
			FuncGetResourceURL: func() string {
				return "subnet"
			},
		},
	}
}
595890
func NewStoreFromOptions(options StoreOptions) (Store, error) {
	driver, err := graphdriver.New(options.GraphDriver, options.PluginGetter, graphdriver.Options{
		Root:                options.Root,
		DriverOptions:       options.GraphDriverOptions,
		UIDMaps:             options.IDMapping.UIDs(),
		GIDMaps:             options.IDMapping.GIDs(),
		ExperimentalEnabled: options.ExperimentalEnabled,
	})
	if err != nil {
		return nil, fmt.Errorf("error initializing graphdriver: %v", err)
	}
	logrus.Debugf("Initialized graph driver %s", driver)

	root := fmt.Sprintf(options.MetadataStorePathTemplate, driver)

	return newStoreFromGraphDriver(root, driver, options.OS)
}
914820
func NewStorage(fs billy.Filesystem, cache cache.Object) *Storage {
	return NewStorageWithOptions(fs, cache, Options{})
}
88013
func NewAPIStore(conf *cloudstorage.Config) (*APIStore, error) {
	googleClient, err := NewGoogleClient(conf)
	if err != nil {
		return nil, err
	}
	service, err := storage.New(googleClient.Client())
	if err != nil {
		return nil, err
	}
	return &APIStore{service: service, project: conf.Project}, nil
}
328281
func parseEventsStoragePolicy() StoragePolicy {
	policy := DefaultStoragePolicy()

	// Parse max age.
	parts := strings.Split(eventStorageAgeLimit, ",")
	for _, part := range parts {
		items := strings.Split(part, "=")
		if len(items) != 2 {
			log.Warningf("Unknown event storage policy %q when parsing max age", part)
			continue
		}
		dur, err := time.ParseDuration(items[1])
		if err != nil {
			log.Warningf("Unable to parse event max age duration %q: %v", items[1], err)
			continue
		}
		if items[0] == "default" {
			policy.DefaultMaxAge = dur
			continue
		}
		policy.PerTypeMaxAge[EventType(items[0])] = dur
	}

	// Parse max number.
	parts = strings.Split(eventStorageEventLimit, ",")
	for _, part := range parts {
		items := strings.Split(part, "=")
		if len(items) != 2 {
			log.Warningf("Unknown event storage policy %q when parsing max event limit", part)
			continue
		}
		val, err := strconv.Atoi(items[1])
		if err != nil {
			log.Warningf("Unable to parse integer from %q: %v", items[1], err)
			continue
		}
		if items[0] == "default" {
			policy.DefaultMaxNumEvents = val
			continue
		}
		policy.PerTypeMaxNumEvents[EventType(items[0])] = val
	}

	return policy
}
35042
func NewControllerAPIv3(ctx facade.Context) (*ControllerAPIv3, error) {
	v4, err := NewControllerAPIv4(ctx)
	if err != nil {
		return nil, errors.Trace(err)
	}
	return &ControllerAPIv3{v4}, nil
}
269881
func NewS3Uploader(bucket, permission string, quiet bool) (*S3Uploader, error) {
	u := &url.URL{
		Scheme: scheme,
		Host:   fmt.Sprintf("%s.%s", bucket, S3_URL),
	}

	permission = strings.ToLower(permission)
	if err := validatePermission(permission); err != nil {
		return nil, err
	}

	uploader := &S3Uploader{
		s3url:      u,
		bucketName: bucket,
		permission: permission,
		out:        os.Stdout,
	}
	if quiet {
		uploader.out = ioutil.Discard
	}
	return uploader, nil
}