// DetectCredentials is part of the environs.ProviderCredentials interface.
760253
func (c OpenstackCredentials) DetectCredentials() (*cloud.CloudCredential, error) {
	result := cloud.CloudCredential{
		AuthCredentials: make(map[string]cloud.Credential),
	}

	// Try just using environment variables
	creds, user, region, err := c.detectCredential()
	if err == nil {
		result.DefaultRegion = region
		result.AuthCredentials[user] = *creds
	}

	// Now look for .novarc file in home dir.
	novarc := filepath.Join(utils.Home(), ".novarc")
	novaInfo, err := ini.LooseLoad(novarc)
	if err != nil {
		return nil, errors.Annotate(err, "loading novarc file")
	}
	stripExport := regexp.MustCompile(`(?i)^\s*export\s*`)
	keyValues := novaInfo.Section(ini.DEFAULT_SECTION).KeysHash()
	if len(keyValues) > 0 {
		for k, v := range keyValues {
			k = stripExport.ReplaceAllString(k, "")
			os.Setenv(k, v)
		}
		creds, user, region, err := c.detectCredential()
		if err == nil {
			result.DefaultRegion = region
			result.AuthCredentials[user] = *creds
		}
	}
	if len(result.AuthCredentials) == 0 {
		return nil, errors.NotFoundf("openstack credentials")
	}
	return &result, nil
}
488331
func (s *AssumeRoleWithWebIdentityOutput) SetCredentials(v *Credentials) *AssumeRoleWithWebIdentityOutput {
	s.Credentials = v
	return s
}
918049
func (settings EnvironmentSettings) GetClientCredentials() (ClientCredentialsConfig, error) {
	secret := settings.Values[ClientSecret]
	if secret == "" {
		return ClientCredentialsConfig{}, errors.New("missing client secret")
	}
	clientID, tenantID := settings.getClientAndTenant()
	config := NewClientCredentialsConfig(clientID, secret, tenantID)
	config.AADEndpoint = settings.Environment.ActiveDirectoryEndpoint
	config.Resource = settings.Values[Resource]
	return config, nil
}
99244
func (c *Client) UserCredentials(user names.UserTag, cloud names.CloudTag) ([]names.CloudCredentialTag, error) {
	var results params.StringsResults
	args := params.UserClouds{[]params.UserCloud{
		{UserTag: user.String(), CloudTag: cloud.String()},
	}}
	if err := c.facade.FacadeCall("UserCredentials", args, &results); err != nil {
		return nil, errors.Trace(err)
	}
	if len(results.Results) != 1 {
		return nil, errors.Errorf("expected 1 result, got %d", len(results.Results))
	}
	if results.Results[0].Error != nil {
		return nil, results.Results[0].Error
	}
	tags := make([]names.CloudCredentialTag, len(results.Results[0].Result))
	for i, s := range results.Results[0].Result {
		tag, err := names.ParseCloudCredentialTag(s)
		if err != nil {
			return nil, errors.Trace(err)
		}
		tags[i] = tag
	}
	return tags, nil
}
606701
func GetCredential(accessKeyID, location string, t time.Time) string {
	scope := getScope(location, t)
	return accessKeyID + "/" + scope
}
954518
func (e EnvironProvider) FinalizeCredential(
	cfx environs.FinalizeCredentialContext,
	params environs.FinalizeCredentialParams,
) (*cloud.Credential, error) {

	return &params.Credential, nil
}
1288320
func (c *nativeStore) listCredentialsInStore() (map[string]string, error) {
	return client.List(c.programFunc)
}
726609
func (u *User) ProviderCredentials() map[string]*common.Credentials {
	return u.Data().Get(common.UserKeyProviderCredentials).Data().(map[string]*common.Credentials)
}
171863
func NewCredentialsClient(cfg aws.Config, handlers request.Handlers, endpoint string, options ...func(*Provider)) *credentials.Credentials {
	return credentials.NewCredentials(NewProviderClient(cfg, handlers, endpoint, options...))
}
950274
func InboundCredentials(creds credentials.TransportCredentials) InboundOption {
	return func(inboundOptions *inboundOptions) {
		inboundOptions.creds = creds
	}
}
350804
func (c *Core) enableCredential(ctx context.Context, entry *MountEntry) error {
	return c.enableCredentialInternal(ctx, entry, MountTableUpdateStorage)
}
1220379
func (s *IPCredentialList) GetAllCredentials() ([]IPCredential, error) {
	credentials := s.Credentials
	t := s

	for t.HasNextPage() {
		var err error
		t, err = t.NextPage()
		if err != nil {
			return nil, err
		}
		credentials = append(credentials, t.Credentials...)
	}
	return credentials, nil
}
451990
func NewApplicationCredentials(filename string) *Credentials {
	return NewCredentials(&ApplicationCredentialsProvider{
		Filename:  filename,
		retrieved: false,
	})
}
1034628
func GetFileCredentials(name string) (uid int, gid int, err error) {
	stat, err := os.Lstat(name)
	if err != nil {
		return 0, 0, err
	}

	nativeStat := stat.Sys().(*syscall.Stat_t)
	return int(nativeStat.Uid), int(nativeStat.Gid), nil
}
263452
func (context *ElasticRuntime) ReadAllUserCredentials() (err error) {
	configParser := cfbackup.NewConfigurationParser(context.JSONFile)
	installationSettings := configParser.InstallationSettings
	err = context.assignCredentialsAndInstallationName(installationSettings)
	return
}
1274323
func (e *Engine) AppendCredentials(ctx context.Context, notifier *observer.Notifier,
	creds []*PlaintextCredentialEnvelope) ([]*PlaintextCredentialEnvelope, error) {

	if len(creds) == 0 {
		return creds, nil
	}

	n := notifier.Notifier(3 + uint(len(creds)))
	cred := creds[0]

	// Ensure all creds have matching pathexp
	for _, c := range creds {
		if !cred.Body.PathExp.Equal(c.Body.PathExp) {
			return nil, &apitypes.Error{
				Type: apitypes.BadRequestError,
				Err:  []string{"All credential PathExp must match"},
			}
		}
	}

	// Ensure we have an existing keyring for this credential's pathexp
	graphs, err := e.client.CredentialGraph.List(ctx, "", cred.Body.PathExp,
		e.session.AuthID(), nil)
	if err != nil {
		log.Printf("Error retrieving credential graphs: %s", err)
		return nil, err
	}

	n.Notify(observer.Progress, "Credentials retrieved", true)

	keypairs, err := e.client.KeyPairs.List(ctx, cred.Body.OrgID)
	if err != nil {
		log.Printf("Error fetching keypairs: %s", err)
		return nil, err
	}

	claimtree, err := e.client.ClaimTree.Get(ctx, cred.Body.OrgID, nil)
	if err != nil {
		log.Printf("Error fetching claimtree for org[%s]: %s", cred.Body.OrgID, err)
		return nil, err
	}

	sigID, encID, kp, err := fetchKeyPairs(keypairs, cred.Body.OrgID)
	if err != nil {
		log.Printf("Error fetching keypairs: %s", err)
		return nil, err
	}

	n.Notify(observer.Progress, "Keypairs retrieved", true)

	cgs := newCredentialGraphSet()
	err = cgs.Add(graphs...)
	if err != nil {
		return nil, err
	}

	// Find the credentialgraph/keyring that we should store our credential in
	graph, err := cgs.Head(cred.Body.PathExp)
	if err != nil {
		return nil, err
	}

	var newGraph *registry.CredentialGraphV2
	// No matching CredentialGraph/KeyRing for this credential.
	// We'll make a new one now.
	if graph == nil || graph.HasRevocations() {
		newGraph, err = createCredentialGraph(ctx, cred.Body, graph,
			sigID, encID, kp, claimtree, e.client, e.crypto, e.guard)
		if err != nil {
			log.Printf("error creating credential graph: %s", err)
			return nil, err
		}
		cgs.Add(newGraph)
		graph = newGraph
	}

	krm, mekshare, err := graph.FindMember(e.session.AuthID())
	if err != nil {
		log.Printf("Error finding keyring membership: %s", err)
		return nil, err
	}

	encKeySegment, err := claimtree.Find(krm.EncryptingKeyID, true)
	if err != nil {
		log.Printf("Error finding encrypting key[%s]: %s", krm.EncryptingKeyID, err)
		return nil, err
	}
	encryptingKey := encKeySegment.PublicKey.Body

	n.Notify(observer.Progress, "Encrypting key retrieved", true)

	toCreate := []envelope.CredentialInf{}
	for _, c := range creds {
		// Find the  most recent version of this credential to act as our previous.
		previousCred, err := cgs.HeadCredential(c.Body.PathExp, c.Body.Name)
		if err != nil {
			log.Printf("error finding credentials to match: %s", err)
			return nil, err
		}

		// Construct an encrypted and signed version of the credential
		credBody := primitive.Credential{
			State: c.Body.State,
			BaseCredential: primitive.BaseCredential{
				Name:      c.Body.Name,
				PathExp:   c.Body.PathExp,
				KeyringID: graph.GetKeyring().GetID(),
				ProjectID: c.Body.ProjectID,
				OrgID:     c.Body.OrgID,
				Credential: &primitive.CredentialValue{
					Algorithm: crypto.SecretBox,
				},
			},
		}

		if previousCred == nil {
			log.Printf("no previous")
			credBody.Previous = nil
			credBody.CredentialVersion = 1
		} else {
			credBody.Previous = previousCred.GetID()
			credBody.CredentialVersion = previousCred.CredentialVersion() + 1
		}

		// Derive a key for the credential using the keyring master key
		// and use the derived key to encrypt the credential
		cekNonce, ctNonce, ct, err := e.crypto.BoxCredential(
			ctx, []byte(c.Body.Value), *mekshare.Key.Value, *mekshare.Key.Nonce,
			&kp.Encryption, *encryptingKey.Key.Value)
		if err != nil {
			log.Printf("Error encrypting credential: %s", err)
			return nil, err
		}

		credBody.Nonce = base64.New(cekNonce)

		credBody.Credential.Nonce = base64.New(ctNonce)
		credBody.Credential.Value = base64.New(ct)

		signed, err := e.crypto.SignedCredential(ctx, &credBody, sigID, &kp.Signature)
		if err != nil {
			log.Printf("Error signing credential body: %s", err)
			return nil, err
		}

		toCreate = append(toCreate, signed)
		n.Notify(observer.Progress, "Credential encrypted", true)
	}

	// XXX: At the end do this stuff (support multi!)
	if newGraph != nil {
		newGraph.Credentials = toCreate
		_, err = e.client.CredentialGraph.Post(ctx, &graph)
	} else {
		_, err = e.client.Credentials.Create(ctx, toCreate)
	}

	if err != nil {
		log.Printf("error creating credential: %s", err)
		return nil, err
	}

	return creds, nil
}
26269
func OAuth2ClientCredentials(clientID, clientSecret, tokenURL string) registry.Option {
	return func(o *registry.Options) {
		c := clientcredentials.Config{
			ClientID:     clientID,
			ClientSecret: clientSecret,
			TokenURL:     tokenURL,
		}

		o.Context = context.WithValue(o.Context, contextHttpClient{}, newOAuthClient(c))
	}
}