コード例 #1
0
ファイル: context.go プロジェクト: harshalhshah/rack
// StoreCredentials caches the users auth credentials if available and the `no-cache`
// flag was not provided.
func (ctx *Context) storeCredentials() {
	// if serviceClient is nil, the HTTP request for the command didn't get sent.
	// don't set cache if the `no-cache` flag is provided
	if ctx.ServiceClient != nil && !ctx.GlobalOptions.noCache {
		newCacheValue := &auth.CacheItem{
			TokenID:         ctx.ServiceClient.TokenID,
			ServiceEndpoint: ctx.ServiceClient.Endpoint,
		}
		// get auth credentials
		credsResult, err := auth.Credentials(ctx.CLIContext, nil)
		ao := credsResult.AuthOpts
		region := credsResult.Region
		if err == nil {
			urlType := gophercloud.AvailabilityPublic
			if ctx.GlobalOptions.useServiceNet {
				urlType = gophercloud.AvailabilityInternal
			}
			// form the cache key
			cacheKey := auth.CacheKey(*ao, region, ctx.ServiceClientType, urlType)
			// initialize the cache
			cache := &auth.Cache{}
			// set the cache value to the current values
			_ = cache.SetValue(cacheKey, newCacheValue)
		}
	}
}
コード例 #2
0
ファイル: context.go プロジェクト: mrhillsman/rack
// StoreCredentials caches the users auth credentials if available and the `no-cache`
// flag was not provided.
func (ctx *Context) StoreCredentials() {
	// if serviceClient is nil, the HTTP request for the command didn't get sent.
	// don't set cache if the `no-cache` flag is provided
	if ctx.ServiceClient != nil && !ctx.CLIContext.GlobalIsSet("no-cache") && !ctx.CLIContext.IsSet("no-cache") {
		newCacheValue := &auth.CacheItem{
			TokenID:         ctx.ServiceClient.TokenID,
			ServiceEndpoint: ctx.ServiceClient.Endpoint,
		}
		// get auth credentials
		ao, region, err := auth.Credentials(ctx.CLIContext)
		if err == nil {
			// form the cache key
			cacheKey := auth.CacheKey(*ao, region, ctx.ServiceClientType)
			// initialize the cache
			cache := &auth.Cache{}
			// set the cache value to the current values
			_ = cache.SetValue(cacheKey, newCacheValue)
		}
	}
}