func getGrpcClient()

in e2e-examples/gcs/main.go [60:103]


func getGrpcClient() gcspb.StorageClient {

	var grpcOpts []grpc.DialOption
	endpoint := target

	if *dp {
		endpoint = "dns:///" + target
		grpcOpts = []grpc.DialOption{
			grpc.WithCredentialsBundle(
				grpcgoogle.NewComputeEngineCredentials(),
			),
			grpc.WithDisableServiceConfig(),
			grpc.WithDefaultServiceConfig(`{"loadBalancingConfig":[{"grpclb":{"childPolicy":[{"pick_first":{}}]}}]}`),
		}
	} else if *corp {
		// client is calling from corp machine
		keyFile := os.Getenv("GOOGLE_APPLICATION_CREDENTIALS")
		perRPC, err := oauth.NewServiceAccountFromFile(keyFile, scope)
		if err != nil {
			fmt.Println("Failed to create credentials: %v", err)
			os.Exit(1)
		}
		grpcOpts = []grpc.DialOption{
			grpc.WithTransportCredentials(credentials.NewClientTLSFromCert(nil, "")),
			grpc.WithPerRPCCredentials(perRPC),
		}
	} else {
		// client is calling from GCE
		grpcOpts = []grpc.DialOption{
			grpc.WithCredentialsBundle(
				grpcgoogle.NewComputeEngineCredentials(),
			),
		}
	}

	cc, err := grpc.Dial(endpoint, grpcOpts...)

	if err != nil {
		fmt.Println("Failed to create clientconn: %v", err)
		os.Exit(1)
	}

	return gcspb.NewStorageClient(cc)
}