本文整理汇总了Python中grpc.metadata_call_credentials方法的典型用法代码示例。如果您正苦于以下问题:Python grpc.metadata_call_credentials方法的具体用法?Python grpc.metadata_call_credentials怎么用?Python grpc.metadata_call_credentials使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类grpc
的用法示例。
在下文中一共展示了grpc.metadata_call_credentials方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: lnd_client
# 需要导入模块: import grpc [as 别名]
# 或者: from grpc import metadata_call_credentials [as 别名]
def lnd_client(self):
if self._lnd_client is not None:
return self._lnd_client
auth_credentials = grpc.metadata_call_credentials(
self.metadata_callback)
credentials = grpc.composite_channel_credentials(
self.get_cert_credentials(),
auth_credentials)
grpc_channel = grpc.secure_channel(
f'{self.grpc_host}:{self.grpc_port}',
credentials,
options=self.grpc_options
)
self._lnd_client = lnrpc.LightningStub(grpc_channel)
return self._lnd_client
示例2: combined_credentials
# 需要导入模块: import grpc [as 别名]
# 或者: from grpc import metadata_call_credentials [as 别名]
def combined_credentials(self) -> grpc.CallCredentials:
"""
Combine ssl and macaroon credentials
:return: grpc.composite_channel_credentials
"""
cert_creds = grpc.ssl_channel_credentials(self.tls_cert)
auth_creds = grpc.metadata_call_credentials(self.metadata_callback)
return grpc.composite_channel_credentials(cert_creds, auth_creds)
示例3: get_rpc_channel
# 需要导入模块: import grpc [as 别名]
# 或者: from grpc import metadata_call_credentials [as 别名]
def get_rpc_channel(host="localhost", port="10009", cert_path=None, macaroon_path=None):
if not macaroon_path:
raise Exception("need to specify a macaroon path!")
def metadata_callback(context, callback):
# for more info see grpc docs
callback([('macaroon', macaroon)], None)
# Due to updated ECDSA generated tls.cert we need to let gprc know that
# we need to use that cipher suite otherwise there will be a handshake
# error when we communicate with the lnd rpc server.
os.environ["GRPC_SSL_CIPHER_SUITES"] = 'HIGH+ECDSA'
if not cert_path:
cert_path = os.path.expanduser('~/.lnd/tls.cert')
assert isfile(cert_path) and os.access(cert_path, os.R_OK), \
"File {} doesn't exist or isn't readable".format(cert_path)
cert = open(cert_path, 'rb').read()
with open(macaroon_path, 'rb') as f:
macaroon_bytes = f.read()
macaroon = codecs.encode(macaroon_bytes, 'hex')
# build ssl credentials using the cert the same as before
cert_creds = grpc.ssl_channel_credentials(cert)
# now build meta data credentials
auth_creds = grpc.metadata_call_credentials(metadata_callback)
# combine the cert credentials and the macaroon auth credentials
# such that every call is properly encrypted and authenticated
combined_creds = grpc.composite_channel_credentials(cert_creds, auth_creds)
# finally pass in the combined credentials when creating a channel
return grpc.secure_channel('{}:{}'.format(host, port), combined_creds)
示例4: getCredentials
# 需要导入模块: import grpc [as 别名]
# 或者: from grpc import metadata_call_credentials [as 别名]
def getCredentials():
sslCred = grpc.ssl_channel_credentials()
authCred = grpc.metadata_call_credentials(credentials)
return grpc.composite_channel_credentials(sslCred, authCred)
### END OF COMMON ###
# gRPC channel
示例5: getCredentials
# 需要导入模块: import grpc [as 别名]
# 或者: from grpc import metadata_call_credentials [as 别名]
def getCredentials():
sslCred = grpc.ssl_channel_credentials()
authCred = grpc.metadata_call_credentials(credentials)
return grpc.composite_channel_credentials(sslCred, authCred)
### END OF COMMON ###
# TTS : getText2VoiceStream
示例6: getCredentials
# 需要导入模块: import grpc [as 别名]
# 或者: from grpc import metadata_call_credentials [as 别名]
def getCredentials():
sslCred = grpc.ssl_channel_credentials()
authCred = grpc.metadata_call_credentials(credentials)
return grpc.composite_channel_credentials(sslCred, authCred)
### END OF COMMON ###
示例7: getCredentials
# 需要导入模块: import grpc [as 别名]
# 或者: from grpc import metadata_call_credentials [as 别名]
def getCredentials():
sslCred = grpc.ssl_channel_credentials()
authCred = grpc.metadata_call_credentials(credentials)
return grpc.composite_channel_credentials(sslCred, authCred)
### END OF COMMON ###
# DIALOG : queryByText
示例8: getCredentials
# 需要导入模块: import grpc [as 别名]
# 或者: from grpc import metadata_call_credentials [as 别名]
def getCredentials():
sslCred = grpc.ssl_channel_credentials()
authCred = grpc.metadata_call_credentials(credentials)
return grpc.composite_channel_credentials(sslCred, authCred)
### END OF COMMON ###
# TTS : getText2VoiceUrl
示例9: getCredentials
# 需要导入模块: import grpc [as 别名]
# 或者: from grpc import metadata_call_credentials [as 别名]
def getCredentials():
with open('../data/ca-bundle.pem', 'rb') as f:
trusted_certs = f.read()
sslCred = grpc.ssl_channel_credentials(root_certificates=trusted_certs)
authCred = grpc.metadata_call_credentials(credentials)
return grpc.composite_channel_credentials(sslCred, authCred)
### KWS
示例10: getCredentials
# 需要导入模块: import grpc [as 别名]
# 或者: from grpc import metadata_call_credentials [as 别名]
def getCredentials():
with open('/home/pi/ai-makers-kit/data/ca-bundle.pem', 'rb') as f:
trusted_certs = f.read()
sslCred = grpc.ssl_channel_credentials(root_certificates=trusted_certs)
authCred = grpc.metadata_call_credentials(credentials)
return grpc.composite_channel_credentials(sslCred, authCred)
### END OF COMMON ###
# TTS : getText2VoiceStream
示例11: getCredentials
# 需要导入模块: import grpc [as 别名]
# 或者: from grpc import metadata_call_credentials [as 别名]
def getCredentials():
with open('../data/ca-bundle.pem', 'rb') as f:
trusted_certs = f.read()
sslCred = grpc.ssl_channel_credentials(root_certificates=trusted_certs)
authCred = grpc.metadata_call_credentials(credentials)
return grpc.composite_channel_credentials(sslCred, authCred)
### END OF COMMON ###
### STT
示例12: getCredentials
# 需要导入模块: import grpc [as 别名]
# 或者: from grpc import metadata_call_credentials [as 别名]
def getCredentials():
with open('../data/ca-bundle.pem', 'rb') as f:
trusted_certs = f.read()
sslCred = grpc.ssl_channel_credentials(root_certificates=trusted_certs)
authCred = grpc.metadata_call_credentials(credentials)
return grpc.composite_channel_credentials(sslCred, authCred)
### END OF COMMON ###
# TTS : getText2VoiceStream
示例13: getCredentials
# 需要导入模块: import grpc [as 别名]
# 或者: from grpc import metadata_call_credentials [as 别名]
def getCredentials():
sslCred = grpc.ssl_channel_credentials()
authCred = grpc.metadata_call_credentials(credentials)
return grpc.composite_channel_credentials(sslCred, authCred)
### END OF COMMON ###
示例14: id_token_call_credentials
# 需要导入模块: import grpc [as 别名]
# 或者: from grpc import metadata_call_credentials [as 别名]
def id_token_call_credentials(credentials):
"""Constructs `grpc.CallCredentials` using
`google.auth.Credentials.id_token`.
Args:
credentials (google.auth.credentials.Credentials): The credentials to use.
Returns:
grpc.CallCredentials: The call credentials.
"""
request = google.auth.transport.requests.Request()
return grpc.metadata_call_credentials(
IdTokenAuthMetadataPlugin(credentials, request)
)
示例15: generate_credentials
# 需要导入模块: import grpc [as 别名]
# 或者: from grpc import metadata_call_credentials [as 别名]
def generate_credentials(cert, macaroon):
"""Create composite channel credentials using cert and macaroon metatdata"""
# create cert credentials from the tls.cert file
cert_creds = grpc.ssl_channel_credentials(cert)
# build meta data credentials
metadata_plugin = MacaroonMetadataPlugin(macaroon)
auth_creds = grpc.metadata_call_credentials(metadata_plugin)
# combine the cert credentials and the macaroon auth credentials
# such that every call is properly encrypted and authenticated
return grpc.composite_channel_credentials(cert_creds, auth_creds)