// CloudProviders returns the name of all registered cloud providers in a
// string slice
507629
func CloudProviders() []string {
	names := []string{}
	providersMutex.Lock()
	defer providersMutex.Unlock()
	for name := range providers {
		names = append(names, name)
	}
	return names
}
642565
func (r ChainedProviderRegistry) StorageProvider(t ProviderType) (Provider, error) {
	for _, r := range r {
		p, err := r.StorageProvider(t)
		if err == nil {
			return p, nil
		}
		if errors.IsNotFound(err) {
			continue
		}
		return nil, errors.Annotatef(err, "getting storage provider %q", t)
	}
	return nil, errors.NotFoundf("storage provider %q", t)
}
832753
func (c *Client) CreateProvider(provider *ct.Provider) error {
	return c.Post("/providers", provider, provider)
}
461609
func (pm *ProviderManager) AddProvider(ctx context.Context, k cid.Cid, val peer.ID) {
	prov := &addProv{
		k:   k,
		val: val,
	}
	select {
	case pm.newprovs <- prov:
	case <-ctx.Done():
	}
}
1047348
func (p *TerraformProvider) TerraformProvider() string {
	return fmt.Sprintf("%s/%s", p.RawNamespace, p.RawName)
}
1053456
func (c *InitCommand) getProviders(earlyConfig *earlyconfig.Config, state *states.State, upgrade bool) (output bool, diags tfdiags.Diagnostics) {
	var available discovery.PluginMetaSet
	if upgrade {
		// If we're in upgrade mode, we ignore any auto-installed plugins
		// in "available", causing us to reinstall and possibly upgrade them.
		available = c.providerPluginManuallyInstalledSet()
	} else {
		available = c.providerPluginSet()
	}

	configDeps, depsDiags := earlyConfig.ProviderDependencies()
	diags = diags.Append(depsDiags)
	if depsDiags.HasErrors() {
		return false, diags
	}

	configReqs := configDeps.AllPluginRequirements()
	// FIXME: This is weird because ConfigTreeDependencies was written before
	// we switched over to using earlyConfig as the main source of dependencies.
	// In future we should clean this up to be a more reasoable API.
	stateReqs := terraform.ConfigTreeDependencies(nil, state).AllPluginRequirements()

	requirements := configReqs.Merge(stateReqs)
	if len(requirements) == 0 {
		// nothing to initialize
		return false, nil
	}

	c.Ui.Output(c.Colorize().Color(
		"\n[reset][bold]Initializing provider plugins...",
	))

	missing := c.missingPlugins(available, requirements)

	if c.getPlugins {
		if len(missing) > 0 {
			c.Ui.Output("- Checking for available provider plugins...")
		}

		for provider, reqd := range missing {
			_, providerDiags, err := c.providerInstaller.Get(provider, reqd.Versions)
			diags = diags.Append(providerDiags)

			if err != nil {
				constraint := reqd.Versions.String()
				if constraint == "" {
					constraint = "(any version)"
				}

				switch {
				case err == discovery.ErrorServiceUnreachable, err == discovery.ErrorPublicRegistryUnreachable:
					c.Ui.Error(errDiscoveryServiceUnreachable)
				case err == discovery.ErrorNoSuchProvider:
					c.Ui.Error(fmt.Sprintf(errProviderNotFound, provider, DefaultPluginVendorDir))
				case err == discovery.ErrorNoSuitableVersion:
					if reqd.Versions.Unconstrained() {
						// This should never happen, but might crop up if we catch
						// the releases server in a weird state where the provider's
						// directory is present but does not yet contain any
						// versions. We'll treat it like ErrorNoSuchProvider, then.
						c.Ui.Error(fmt.Sprintf(errProviderNotFound, provider, DefaultPluginVendorDir))
					} else {
						c.Ui.Error(fmt.Sprintf(errProviderVersionsUnsuitable, provider, reqd.Versions))
					}
				case errwrap.Contains(err, discovery.ErrorVersionIncompatible.Error()):
					// Attempt to fetch nested error to display to the user which versions
					// we considered and which versions might be compatible. Otherwise,
					// we'll just display a generic version incompatible msg
					incompatErr := errwrap.GetType(err, fmt.Errorf(""))
					if incompatErr != nil {
						c.Ui.Error(incompatErr.Error())
					} else {
						// Generic version incompatible msg
						c.Ui.Error(fmt.Sprintf(errProviderIncompatible, provider, constraint))
					}
					// Reset nested errors
					err = discovery.ErrorVersionIncompatible
				case err == discovery.ErrorNoVersionCompatible:
					// Generic version incompatible msg
					c.Ui.Error(fmt.Sprintf(errProviderIncompatible, provider, constraint))
				case err == discovery.ErrorSignatureVerification:
					c.Ui.Error(fmt.Sprintf(errSignatureVerification, provider))
				case err == discovery.ErrorChecksumVerification,
					err == discovery.ErrorMissingChecksumVerification:
					c.Ui.Error(fmt.Sprintf(errChecksumVerification, provider))
				default:
					c.Ui.Error(fmt.Sprintf(errProviderInstallError, provider, err.Error(), DefaultPluginVendorDir))
				}

				diags = diags.Append(err)
			}
		}

		if diags.HasErrors() {
			return true, diags
		}
	} else if len(missing) > 0 {
		// we have missing providers, but aren't going to try and download them
		var lines []string
		for provider, reqd := range missing {
			if reqd.Versions.Unconstrained() {
				lines = append(lines, fmt.Sprintf("* %s (any version)\n", provider))
			} else {
				lines = append(lines, fmt.Sprintf("* %s (%s)\n", provider, reqd.Versions))
			}
			diags = diags.Append(fmt.Errorf("missing provider %q", provider))
		}
		sort.Strings(lines)
		c.Ui.Error(fmt.Sprintf(errMissingProvidersNoInstall, strings.Join(lines, ""), DefaultPluginVendorDir))
		return true, diags
	}

	// With all the providers downloaded, we'll generate our lock file
	// that ensures the provider binaries remain unchanged until we init
	// again. If anything changes, other commands that use providers will
	// fail with an error instructing the user to re-run this command.
	available = c.providerPluginSet() // re-discover to see newly-installed plugins

	// internal providers were already filtered out, since we don't need to get them.
	chosen := choosePlugins(available, nil, requirements)

	digests := map[string][]byte{}
	for name, meta := range chosen {
		digest, err := meta.SHA256()
		if err != nil {
			diags = diags.Append(fmt.Errorf("Failed to read provider plugin %s: %s", meta.Path, err))
			return true, diags
		}
		digests[name] = digest
		if c.ignorePluginChecksum {
			digests[name] = nil
		}
	}
	err := c.providerPluginsLock().Write(digests)
	if err != nil {
		diags = diags.Append(fmt.Errorf("failed to save provider manifest: %s", err))
		return true, diags
	}

	{
		// Purge any auto-installed plugins that aren't being used.
		purged, err := c.providerInstaller.PurgeUnused(chosen)
		if err != nil {
			// Failure to purge old plugins is not a fatal error
			c.Ui.Warn(fmt.Sprintf("failed to purge unused plugins: %s", err))
		}
		if purged != nil {
			for meta := range purged {
				log.Printf("[DEBUG] Purged unused %s plugin %s", meta.Name, meta.Path)
			}
		}
	}

	// If any providers have "floating" versions (completely unconstrained)
	// we'll suggest the user constrain with a pessimistic constraint to
	// avoid implicitly adopting a later major release.
	constraintSuggestions := make(map[string]discovery.ConstraintStr)
	for name, meta := range chosen {
		req := requirements[name]
		if req == nil {
			// should never happen, but we don't want to crash here, so we'll
			// be cautious.
			continue
		}

		if req.Versions.Unconstrained() && meta.Version != discovery.VersionZero {
			// meta.Version.MustParse is safe here because our "chosen" metas
			// were already filtered for validity of versions.
			constraintSuggestions[name] = meta.Version.MustParse().MinorUpgradeConstraintStr()
		}
	}
	if len(constraintSuggestions) != 0 {
		names := make([]string, 0, len(constraintSuggestions))
		for name := range constraintSuggestions {
			names = append(names, name)
		}
		sort.Strings(names)

		c.Ui.Output(outputInitProvidersUnconstrained)
		for _, name := range names {
			c.Ui.Output(fmt.Sprintf("* provider.%s: version = %q", name, constraintSuggestions[name]))
		}
	}

	return true, diags
}
337680
func RegisterCloudProvider(name string, cloud Factory) {
	providersMutex.Lock()
	defer providersMutex.Unlock()
	if _, found := providers[name]; found {
		klog.Fatalf("Cloud provider %q was registered twice", name)
	}
	klog.V(1).Infof("Registered cloud provider %q", name)
	providers[name] = cloud
}
72122
func (az *Cloud) NodeAddressesByProviderID(ctx context.Context, providerID string) ([]v1.NodeAddress, error) {
	// Returns nil for unmanaged nodes because azure cloud provider couldn't fetch information for them.
	if az.IsNodeUnmanagedByProviderID(providerID) {
		klog.V(4).Infof("NodeAddressesByProviderID: omitting unmanaged node %q", providerID)
		return nil, nil
	}

	name, err := az.vmSet.GetNodeNameByProviderID(providerID)
	if err != nil {
		return nil, err
	}

	return az.NodeAddresses(ctx, name)
}
128119
func (r StaticProviderRegistry) StorageProvider(t ProviderType) (Provider, error) {
	p, ok := r.Providers[t]
	if ok {
		return p, nil
	}
	return nil, errors.NotFoundf("storage provider %q", t)
}
859368
func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
	if config == nil {
		return nil, errors.New("ClouDNS: the configuration of the DNS provider is nil")
	}

	client, err := internal.NewClient(config.AuthID, config.AuthPassword)
	if err != nil {
		return nil, fmt.Errorf("ClouDNS: %v", err)
	}

	client.HTTPClient = config.HTTPClient

	return &DNSProvider{client: client, config: config}, nil
}
668134
func WithProviders(providers ...common.Provider) *ProviderList {
	GetSecurityKey()
	list := &ProviderList{providers}
	SharedProviderList = list
	return list
}
699600
func (env *Environ) StorageProvider(t storage.ProviderType) (storage.Provider, error) {
	if t != CinderProviderType {
		return nil, errors.NotFoundf("storage provider %q", t)
	}
	return env.cinderProvider()
}
1215828
func (l *Client) GetProviders() ([]Provider, error) {
	res := ApiResp{}
	data := []Provider{}

	// make the request
	err := l.Get(providerListEndpoint, nil, nil, &res, &data)
	if err != nil {
		return data, err
	}

	return data, nil
}
619046
func InitCloudProvider(name string, configFilePath string) (Interface, error) {
	var cloud Interface
	var err error

	if name == "" {
		klog.Info("No cloud provider specified.")
		return nil, nil
	}

	if IsExternal(name) {
		klog.Info("External cloud provider specified")
		return nil, nil
	}

	for _, provider := range deprecatedCloudProviders {
		if provider.name == name {
			detail := provider.detail
			if provider.external {
				detail = fmt.Sprintf("Please use 'external' cloud provider for %s: %s", name, provider.detail)
			}
			klog.Warningf("WARNING: %s built-in cloud provider is now deprecated. %s", name, detail)

			break
		}
	}

	if configFilePath != "" {
		var config *os.File
		config, err = os.Open(configFilePath)
		if err != nil {
			klog.Fatalf("Couldn't open cloud provider configuration %s: %#v",
				configFilePath, err)
		}

		defer config.Close()
		cloud, err = GetCloudProvider(name, config)
	} else {
		// Pass explicit nil so plugins can actually check for nil. See
		// "Why is my nil error value not equal to nil?" in golang.org/doc/faq.
		cloud, err = GetCloudProvider(name, nil)
	}

	if err != nil {
		return nil, fmt.Errorf("could not init cloud provider %q: %v", name, err)
	}
	if cloud == nil {
		return nil, fmt.Errorf("unknown cloud provider %q", name)
	}

	return cloud, nil
}
39138
func getAzureCloudProvider(cloudProvider cloudprovider.Interface) (azureCloudProvider, error) {
	azureCloudProvider, ok := cloudProvider.(*azure.Cloud)
	if !ok || azureCloudProvider == nil {
		return nil, fmt.Errorf("Failed to get Azure Cloud Provider. GetCloudProvider returned %v instead", cloudProvider)
	}

	return azureCloudProvider, nil
}
1309615
func NewDNSProvider() (*DNSProvider, error) {
	values, err := env.Get("PDNS_API_KEY", "PDNS_API_URL")
	if err != nil {
		return nil, fmt.Errorf("pdns: %v", err)
	}

	hostURL, err := url.Parse(values["PDNS_API_URL"])
	if err != nil {
		return nil, fmt.Errorf("pdns: %v", err)
	}

	config := NewDefaultConfig()
	config.Host = hostURL
	config.APIKey = values["PDNS_API_KEY"]

	return NewDNSProviderConfig(config)
}
115800
func (st *State) CloudsForUser(user names.UserTag, all bool) ([]CloudInfo, error) {
	// We only treat the user as a superuser if they pass --all
	isControllerSuperuser := false
	if all {
		var err error
		isControllerSuperuser, err = st.isUserSuperuser(user)
		if err != nil {
			return nil, errors.Trace(err)
		}
	}

	clouds, closer := st.db().GetCollection(cloudsC)
	defer closer()

	var cloudQuery mongo.Query
	if isControllerSuperuser {
		// Fast path, we just get all the clouds.
		cloudQuery = clouds.Find(nil)
	} else {
		cloudNames, err := st.cloudNamesForUser(user)
		if err != nil {
			return nil, errors.Trace(err)
		}
		cloudQuery = clouds.Find(bson.M{
			"_id": bson.M{"$in": cloudNames},
		})
	}
	cloudQuery = cloudQuery.Sort("name")

	var cloudDocs []cloudDoc
	if err := cloudQuery.All(&cloudDocs); err != nil {
		return nil, errors.Trace(err)
	}
	result := make([]CloudInfo, len(cloudDocs))
	for i, c := range cloudDocs {
		result[i] = CloudInfo{
			Cloud: c.toCloud(),
		}
	}
	if err := st.fillInCloudUserAccess(user, result); err != nil {
		return nil, errors.Trace(err)
	}
	return result, nil
}