Skip to content

Commit c5e3fcf

Browse files
Cleaned up CertificateClient
1 parent 317434a commit c5e3fcf

File tree

1 file changed

+48
-6
lines changed

1 file changed

+48
-6
lines changed

SoftLayer/API.py

+48-6
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
'API_PUBLIC_ENDPOINT',
3434
'API_PRIVATE_ENDPOINT',
3535
'IAMClient',
36+
'CertificateClient'
3637
]
3738

3839
VALID_CALL_ARGS = set((
@@ -144,12 +145,7 @@ def create_client_from_env(username=None,
144145

145146

146147
def Client(**kwargs):
147-
"""Get a SoftLayer API Client using environmental settings.
148-
149-
Deprecated in favor of create_client_from_env()
150-
"""
151-
warnings.warn("use SoftLayer.create_client_from_env() instead",
152-
DeprecationWarning)
148+
"""Get a SoftLayer API Client using environmental settings."""
153149
return create_client_from_env(**kwargs)
154150

155151

@@ -390,6 +386,52 @@ def __repr__(self):
390386
def __len__(self):
391387
return 0
392388

389+
class CertificateClient(BaseClient):
390+
"""Client that works with a X509 Certificate for authentication.
391+
392+
Will read the certificate file from the config file (~/.softlayer usually).
393+
> auth_cert = /path/to/authentication/cert.pm
394+
> server_cert = /path/to/CAcert.pem
395+
Set auth to a SoftLayer.auth.Authentication class to manually set authentication
396+
"""
397+
398+
def __init__(self, auth=None, transport=None, config_file=None):
399+
if config_file is None:
400+
config_file = CONFIG_FILE
401+
self.config_file = config_file
402+
self.settings = config.get_config(self.config_file)
403+
404+
if auth is None:
405+
auth_cert = self.settings['softlayer'].get('auth_cert')
406+
serv_cert = self.settings['softlayer'].get('server_cert', None)
407+
auth = slauth.X509Authentication(auth_cert, serv_cert)
408+
self.auth = auth
409+
410+
411+
412+
if transport is None:
413+
url = self.settings['softlayer'].get('endpoint_url')
414+
if url is not None and '/rest' in url:
415+
# If this looks like a rest endpoint, use the rest transport
416+
transport = transports.RestTransport(
417+
endpoint_url=url,
418+
proxy=self.settings['softlayer'].get('proxy'),
419+
# prevents an exception incase timeout is a float number.
420+
timeout=int(self.settings['softlayer'].getfloat('timeout', 0)),
421+
user_agent=consts.USER_AGENT,
422+
verify=self.settings['softlayer'].getboolean('verify'),
423+
)
424+
else:
425+
# Default the transport to use XMLRPC
426+
transport = transports.XmlRpcTransport(
427+
endpoint_url=url,
428+
proxy=self.settings['softlayer'].get('proxy'),
429+
timeout=int(self.settings['softlayer'].getfloat('timeout', 0)),
430+
user_agent=consts.USER_AGENT,
431+
verify=self.settings['softlayer'].getboolean('verify'),
432+
)
433+
434+
self.transport = transport
393435

394436
class IAMClient(BaseClient):
395437
"""IBM ID Client for using IAM authentication

0 commit comments

Comments
 (0)