* * Copyright 2018 gRPC authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http:www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *
Package google defines credentials for google cloud services.
package google

import (
	
	
	

	
	
	
	
	
)

const tokenRequestTimeout = 30 * time.Second

var logger = grpclog.Component("credentials")
NewDefaultCredentials returns a credentials bundle that is configured to work with google services. This API is experimental.
func () credentials.Bundle {
	 := &creds{
		newPerRPCCreds: func() credentials.PerRPCCredentials {
			,  := context.WithTimeout(context.Background(), tokenRequestTimeout)
			defer ()
			,  := oauth.NewApplicationDefault()
			if  != nil {
				logger.Warningf("google default creds: failed to create application oauth: %v", )
			}
			return 
		},
	}
	,  := .NewWithMode(internal.CredsBundleModeFallback)
	if  != nil {
		logger.Warningf("google default creds: failed to create new creds: %v", )
	}
	return 
}
NewComputeEngineCredentials returns a credentials bundle that is configured to work with google services. This API must only be used when running on GCE. Authentication configured by this API represents the GCE VM's default service account. This API is experimental.
func () credentials.Bundle {
	 := &creds{
		newPerRPCCreds: func() credentials.PerRPCCredentials {
			return oauth.NewComputeEngine()
		},
	}
	,  := .NewWithMode(internal.CredsBundleModeFallback)
	if  != nil {
		logger.Warningf("compute engine creds: failed to create new creds: %v", )
	}
	return 
}
creds implements credentials.Bundle.
Supported modes are defined in internal/internal.go.
The transport credentials associated with this bundle.
The per RPC credentials associated with this bundle.
Creates new per RPC credentials
NewWithMode should make a copy of Bundle, and switch mode. Modifying the existing Bundle may cause races.
func ( *creds) ( string) (credentials.Bundle, error) {
	 := &creds{
		mode:           ,
		newPerRPCCreds: .newPerRPCCreds,
	}
Create transport credentials.
Only the clients can use google default credentials, so we only need to create new ALTS client creds here.
		.transportCreds = alts.NewClientCreds(alts.DefaultClientOptions())
	default:
		return nil, fmt.Errorf("unsupported mode: %v", )
	}

	if  == internal.CredsBundleModeFallback ||  == internal.CredsBundleModeBackendFromBalancer {
		.perRPCCreds = .newPerRPCCreds()
	}

	return , nil