本文整理汇总了Python中cattle.Config.client_certs_dir方法的典型用法代码示例。如果您正苦于以下问题:Python Config.client_certs_dir方法的具体用法?Python Config.client_certs_dir怎么用?Python Config.client_certs_dir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cattle.Config
的用法示例。
在下文中一共展示了Config.client_certs_dir方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_docker_client
# 需要导入模块: from cattle import Config [as 别名]
# 或者: from cattle.Config import client_certs_dir [as 别名]
def _get_docker_client(host, version_override=None):
cluster_connection = None
tls_config = None
try:
cluster_connection = host['clusterConnection']
if cluster_connection.startswith('https'):
try:
account_id = host['accountId']
ca_crt = host['caCrt']
client_crt = host['clientCrt']
client_key = host['clientKey']
client_certs_dir = Config.client_certs_dir()
acct_client_cert_dir = \
path.join(client_certs_dir, str(account_id))
if not path.exists(acct_client_cert_dir):
log.debug('Creating client cert directory: %s',
acct_client_cert_dir)
makedirs(acct_client_cert_dir)
if ca_crt:
log.debug('Writing cert auth')
with open(path.join(acct_client_cert_dir, 'ca.crt'),
'w') as f:
f.write(ca_crt)
if client_crt:
log.debug('Writing client cert')
with open(path.join(acct_client_cert_dir,
'client.crt'),
'w') as f:
f.write(client_crt)
if client_key:
log.debug('Writing client key')
with open(path.join(acct_client_cert_dir,
'client.key'),
'w') as f:
f.write(client_key)
if ca_crt and client_crt and client_key:
tls_config = tls.TLSConfig(
client_cert=(
path.join(acct_client_cert_dir, 'client.crt'),
path.join(acct_client_cert_dir, 'client.key')
),
verify=path.join(acct_client_cert_dir, 'ca.crt'),
assert_hostname=False
)
except (KeyError, AttributeError) as e:
raise Exception(
'Unable to process cert/keys for cluster',
cluster_connection,
e)
except (KeyError, AttributeError):
pass
return docker_client(
version=version_override,
base_url_override=cluster_connection,
tls_config=tls_config)
示例2: _get_docker_client
# 需要导入模块: from cattle import Config [as 别名]
# 或者: from cattle.Config import client_certs_dir [as 别名]
def _get_docker_client(host):
cluster_connection = None
tls_config = None
try:
cluster_connection = host["clusterConnection"]
if cluster_connection.startswith("https"):
try:
account_id = host["accountId"]
ca_crt = host["caCrt"]
client_crt = host["clientCrt"]
client_key = host["clientKey"]
client_certs_dir = Config.client_certs_dir()
acct_client_cert_dir = path.join(client_certs_dir, str(account_id))
if not path.exists(acct_client_cert_dir):
log.debug("Creating client cert directory: %s", acct_client_cert_dir)
makedirs(acct_client_cert_dir)
if ca_crt:
log.debug("Writing cert auth")
with open(path.join(acct_client_cert_dir, "ca.crt"), "w") as f:
f.write(ca_crt)
if client_crt:
log.debug("Writing client cert")
with open(path.join(acct_client_cert_dir, "client.crt"), "w") as f:
f.write(client_crt)
if client_key:
log.debug("Writing client key")
with open(path.join(acct_client_cert_dir, "client.key"), "w") as f:
f.write(client_key)
if ca_crt and client_crt and client_key:
tls_config = tls.TLSConfig(
client_cert=(
path.join(acct_client_cert_dir, "client.crt"),
path.join(acct_client_cert_dir, "client.key"),
),
verify=path.join(acct_client_cert_dir, "ca.crt"),
assert_hostname=False,
)
except (KeyError, AttributeError) as e:
raise Exception("Unable to process cert/keys for cluster", cluster_connection, e)
except (KeyError, AttributeError):
pass
return docker_client(base_url_override=cluster_connection, tls_config=tls_config)