This commit is contained in:
yangzhouhan 2015-08-14 11:20:13 -07:00
Родитель 9f5d4180bd
Коммит 41ee26a353
2 изменённых файлов: 13 добавлений и 5 удалений

Просмотреть файл

@ -66,7 +66,7 @@ type jwtAccess struct {
ts oauth2.TokenSource
}
func NewJwtAccessFromFile(keyFile string, audience string) (credentials.Credentials, error) {
func NewJWTAccessFromFile(keyFile string, audience string) (credentials.Credentials, error) {
jsonKey, err := ioutil.ReadFile(keyFile)
if err != nil {
return nil, fmt.Errorf("credentials: failed to read the service account key file: %v", err)
@ -78,6 +78,14 @@ func NewJwtAccessFromFile(keyFile string, audience string) (credentials.Credenti
return jwtAccess{ts: ts}, nil
}
func NewJWTAccessFromKey(jsonKey []byte, audience string) (credentials.Credentials, error) {
ts, err := google.JWTAccessTokenSourceFromJSON(jsonKey, audience)
if err != nil {
return nil, err
}
return jwtAccess{ts: ts}, nil
}
func (j jwtAccess) GetRequestMetadata(ctx context.Context) (map[string]string, error) {
token, err := j.ts.Token()
if err != nil {

Просмотреть файл

@ -340,7 +340,7 @@ func doServiceAccountCreds(tc testpb.TestServiceClient) {
grpclog.Println("ServiceAccountCreds done")
}
func doJwtTokenCreds(tc testpb.TestServiceClient) {
func doJWTTokenCreds(tc testpb.TestServiceClient) {
pl := newPayload(testpb.PayloadType_COMPRESSABLE, largeReqSize)
req := &testpb.SimpleRequest{
ResponseType: testpb.PayloadType_COMPRESSABLE.Enum(),
@ -357,7 +357,7 @@ func doJwtTokenCreds(tc testpb.TestServiceClient) {
if !strings.Contains(string(jsonKey), user) {
grpclog.Fatalf("Got user name %q which is NOT a substring of %q.", user, jsonKey)
}
grpclog.Println("JwttokenCreds done")
grpclog.Println("JWTtokenCreds done")
}
var (
@ -440,7 +440,7 @@ func main() {
}
opts = append(opts, grpc.WithPerRPCCredentials(jwtCreds))
} else if *testCase == "jwt_token_creds" {
jwtCreds, err := oauth.NewJwtAccessFromFile(*serviceAccountKeyFile, "https://"+*serverHost+":"+string(*serverPort)+"/"+"TestService")
jwtCreds, err := oauth.NewJWTAccessFromFile(*serviceAccountKeyFile, "https://"+*serverHost+":"+string(*serverPort)+"/"+"TestService")
if err != nil {
grpclog.Fatalf("Failed to create JWT credentials: %v", err)
}
@ -482,7 +482,7 @@ func main() {
if !*useTLS {
grpclog.Fatalf("TLS is not enabled. TLS is required to execute service_account_creds test case.")
}
doJwtTokenCreds(tc)
doJWTTokenCreds(tc)
case "cancel_after_begin":
doCancelAfterBegin(tc)
case "cancel_after_first_response":