|
33 | 33 | 'API_PUBLIC_ENDPOINT',
|
34 | 34 | 'API_PRIVATE_ENDPOINT',
|
35 | 35 | 'IAMClient',
|
| 36 | + 'CertificateClient' |
36 | 37 | ]
|
37 | 38 |
|
38 | 39 | VALID_CALL_ARGS = set((
|
@@ -144,12 +145,7 @@ def create_client_from_env(username=None,
|
144 | 145 |
|
145 | 146 |
|
146 | 147 | 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.""" |
153 | 149 | return create_client_from_env(**kwargs)
|
154 | 150 |
|
155 | 151 |
|
@@ -390,6 +386,52 @@ def __repr__(self):
|
390 | 386 | def __len__(self):
|
391 | 387 | return 0
|
392 | 388 |
|
| 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 |
393 | 435 |
|
394 | 436 | class IAMClient(BaseClient):
|
395 | 437 | """IBM ID Client for using IAM authentication
|
|
0 commit comments