adding api to configure target service accounts for client ALTS

pull/22638/head
Taras Galkovskyi 5 years ago
parent ed04792ac5
commit 2b3eca0858
  1. 6
      src/python/grpcio/grpc/__init__.py
  2. 8
      src/python/grpcio/grpc/_cython/_cygrpc/credentials.pyx.pxi
  3. 1
      src/python/grpcio/grpc/_cython/_cygrpc/grpc.pxi
  4. 2
      src/python/grpcio_tests/tests/interop/client.py

@ -1833,15 +1833,17 @@ def local_server_credentials(local_connect_type=LocalConnectionType.LOCAL_TCP):
_cygrpc.server_credentials_local(local_connect_type.value)) _cygrpc.server_credentials_local(local_connect_type.value))
def alts_channel_credentials(): def alts_channel_credentials(service_accounts=[]):
"""Creates a ChannelCredentials for use with an ALTS-enabled Channel. """Creates a ChannelCredentials for use with an ALTS-enabled Channel.
This is an EXPERIMENTAL API. This is an EXPERIMENTAL API.
Args:
service_accounts: list of strings, target service accounts
Returns: Returns:
A ChannelCredentials for use with an ALTS-enabled Channel A ChannelCredentials for use with an ALTS-enabled Channel
""" """
return ChannelCredentials(_cygrpc.channel_credentials_alts()) return ChannelCredentials(_cygrpc.channel_credentials_alts(service_accounts))
def alts_server_credentials(): def alts_server_credentials():

@ -354,8 +354,10 @@ def server_credentials_local(grpc_local_connect_type local_connect_type):
cdef class ALTSChannelCredentials(ChannelCredentials): cdef class ALTSChannelCredentials(ChannelCredentials):
def __cinit__(self): def __cinit__(self, service_accounts):
self.c_options = grpc_alts_credentials_client_options_create() self.c_options = grpc_alts_credentials_client_options_create()
for account in service_accounts:
grpc_alts_credentials_client_options_add_target_service_account(self.c_options, account)
def __dealloc__(self): def __dealloc__(self):
if self.c_options != NULL: if self.c_options != NULL:
@ -365,8 +367,8 @@ cdef class ALTSChannelCredentials(ChannelCredentials):
return grpc_alts_credentials_create(self.c_options) return grpc_alts_credentials_create(self.c_options)
def channel_credentials_alts(): def channel_credentials_alts(service_accounts):
return ALTSChannelCredentials() return ALTSChannelCredentials(service_accounts)
def server_credentials_alts(): def server_credentials_alts():

@ -618,6 +618,7 @@ cdef extern from "grpc/grpc_security.h":
grpc_alts_credentials_options* grpc_alts_credentials_client_options_create() grpc_alts_credentials_options* grpc_alts_credentials_client_options_create()
grpc_alts_credentials_options* grpc_alts_credentials_server_options_create() grpc_alts_credentials_options* grpc_alts_credentials_server_options_create()
void grpc_alts_credentials_options_destroy(grpc_alts_credentials_options *options) void grpc_alts_credentials_options_destroy(grpc_alts_credentials_options *options)
void grpc_alts_credentials_client_options_add_target_service_account(grpc_alts_credentials_options *options, const char *service_account)

@ -107,7 +107,7 @@ def get_secure_channel_parameters(args):
args.server_host_override, args.server_host_override,
),) ),)
else args.use_alts: else args.use_alts:
channel_credentials = grpc.alts_channel_credentials() channel_credentials = grpc.alts_channel_credentials(['svc_account1@gmail.com'])
return channel_credentials, channel_opts return channel_credentials, channel_opts

Loading…
Cancel
Save