Skip to content

Commit 5f2024d

Browse files
Added in employee auth to consolidate repos
1 parent 4f0fb13 commit 5f2024d

File tree

6 files changed

+42
-54
lines changed

6 files changed

+42
-54
lines changed

SoftLayer/API.py

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -180,16 +180,7 @@ def employee_client(username=None,
180180
:param bool verify: decide to verify the server's SSL/TLS cert. DO NOT SET
181181
TO FALSE WITHOUT UNDERSTANDING THE IMPLICATIONS.
182182
183-
Usage:
184-
185-
>>> import SoftLayer
186-
>>> client = SoftLayer.create_client_from_env()
187-
>>> resp = client.call('Account', 'getObject')
188-
>>> resp['companyName']
189-
'Your Company'
190-
191183
"""
192-
# SSL verification is OFF because internal api uses a self signed cert
193184
settings = config.get_client_settings(username=username,
194185
api_key=None,
195186
endpoint_url=endpoint_url,
@@ -198,14 +189,12 @@ def employee_client(username=None,
198189
verify=verify,
199190
config_file=config_file)
200191

201-
url = settings.get('endpoint_url') or consts.API_EMPLOYEE_ENDPOINT
192+
url = settings.get('endpoint_url')
202193

203194
if 'internal' not in url:
204-
raise exceptions.SoftLayerError("{} does not look like an Internal Employee url. Try {}".format(
205-
url, consts.API_EMPLOYEE_ENDPOINT))
195+
raise exceptions.SoftLayerError(f"{url} does not look like an Internal Employee url.")
206196

207197
if transport is None:
208-
209198
if url is not None and '/rest' in url:
210199
# If this looks like a rest endpoint, use the rest transport
211200
transport = transports.RestTransport(
@@ -241,7 +230,6 @@ def employee_client(username=None,
241230
return EmployeeClient(auth=None, transport=transport)
242231

243232

244-
245233
def Client(**kwargs):
246234
"""Get a SoftLayer API Client using environmental settings."""
247235
return create_client_from_env(**kwargs)
@@ -251,8 +239,7 @@ class BaseClient(object):
251239
"""Base SoftLayer API client.
252240
253241
:param auth: auth driver that looks like SoftLayer.auth.AuthenticationBase
254-
:param transport: An object that's callable with this signature:
255-
transport(SoftLayer.transports.Request)
242+
:param transport: An object that's callable with this signature: transport(SoftLayer.transports.Request)
256243
"""
257244

258245
_prefix = "SoftLayer_"
@@ -288,9 +275,7 @@ def __init__(self, auth=None, transport=None, config_file=None):
288275

289276
self.transport = transport
290277

291-
def authenticate_with_password(self, username, password,
292-
security_question_id=None,
293-
security_question_answer=None):
278+
def authenticate_with_password(self, username, password, security_question_id=None, security_question_answer=None):
294279
"""Performs Username/Password Authentication
295280
296281
:param string username: your SoftLayer username
@@ -353,8 +338,7 @@ def call(self, service, method, *args, **kwargs):
353338

354339
invalid_kwargs = set(kwargs.keys()) - VALID_CALL_ARGS
355340
if invalid_kwargs:
356-
raise TypeError(
357-
'Invalid keyword arguments: %s' % ','.join(invalid_kwargs))
341+
raise TypeError('Invalid keyword arguments: %s' % ','.join(invalid_kwargs))
358342

359343
prefixes = (self._prefix, 'BluePages_Search', 'IntegratedOfferingTeam_Region')
360344
if self._prefix and not service.startswith(prefixes):

SoftLayer/CLI/core.py

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -73,35 +73,28 @@ def get_version_message(ctx, param, value):
7373
epilog="""Run 'islcli login' to authenticate""",
7474
cls=CommandLoader,
7575
context_settings=CONTEXT_SETTINGS)
76-
@click.option('--format',
77-
default=DEFAULT_FORMAT,
78-
show_default=True,
76+
@click.option('--format', default=DEFAULT_FORMAT, show_default=True,
7977
help="Output format",
8078
type=click.Choice(VALID_FORMATS))
81-
@click.option('-C', '--config',
82-
required=False,
79+
@click.option('-C', '--config', required=False, show_default=True,
8380
default=click.get_app_dir('softlayer', force_posix=True),
84-
show_default=True,
8581
help="Config file location",
8682
type=click.Path(resolve_path=True))
8783
@click.option('--verbose', '-v',
8884
help="Sets the debug noise level, specify multiple times for more verbosity.",
8985
type=click.IntRange(0, 3, clamp=True),
9086
count=True)
91-
@click.option('--proxy',
92-
required=False,
87+
@click.option('--proxy', required=False,
9388
help="HTTPS or HTTP proxy to be use to make API calls")
94-
@click.option('--really / --not-really', '-y',
95-
is_flag=True,
96-
required=False,
89+
@click.option('--really / --not-really', '-y', is_flag=True, required=False,
9790
help="Confirm all prompt actions")
98-
@click.option('--demo / --no-demo',
99-
is_flag=True,
100-
required=False,
91+
@click.option('--demo / --no-demo', is_flag=True, required=False,
10192
help="Use demo data instead of actually making API calls")
10293
@click.option('--version', is_flag=True, expose_value=False, is_eager=True, callback=get_version_message,
10394
help="Show version information.", allow_from_autoenv=False,)
104-
@click.option('--account', '-a', help="Account Id")
95+
@click.option('--account', '-a', help="Account Id, only needed for some API calls.")
96+
@click.option('--internal', '-i', is_flag=True, required=False,
97+
help="Use the Employee Client instead of the Customer Client.")
10598
@environment.pass_env
10699
def cli(env,
107100
format='table',
@@ -111,6 +104,7 @@ def cli(env,
111104
really=False,
112105
demo=False,
113106
account=None,
107+
internal=False,
114108
**kwargs):
115109
"""Main click CLI entry-point."""
116110

@@ -119,7 +113,10 @@ def cli(env,
119113
env.config_file = config
120114
env.format = format
121115
env.set_env_theme(config_file=config)
122-
env.ensure_client(config_file=config, is_demo=demo, proxy=proxy)
116+
if internal:
117+
env.ensure_emp_client(config_file=config, is_demo=demo, proxy=proxy)
118+
else:
119+
env.ensure_client(config_file=config, is_demo=demo, proxy=proxy)
123120
env.vars['_start'] = time.time()
124121
logger = logging.getLogger()
125122

@@ -134,7 +131,6 @@ def cli(env,
134131
env.vars['_timings'] = SoftLayer.DebugTransport(env.client.transport)
135132
env.vars['verbose'] = verbose
136133
env.client.transport = env.vars['_timings']
137-
print("Account ID is now: {}".format(account))
138134
env.client.account_id = account
139135

140136

SoftLayer/CLI/environment.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -183,16 +183,26 @@ def ensure_client(self, config_file=None, is_demo=False, proxy=None):
183183

184184
# Environment can be passed in explicitly. This is used for testing
185185
if is_demo:
186-
client = SoftLayer.BaseClient(
187-
transport=SoftLayer.FixtureTransport(),
188-
auth=None,
189-
)
186+
client = SoftLayer.BaseClient(transport=SoftLayer.FixtureTransport(), auth=None)
190187
else:
191188
# Create SL Client
192-
client = SoftLayer.employee_client(
193-
proxy=proxy,
194-
config_file=config_file,
195-
)
189+
client = SoftLayer.create_client_from_env(proxy=proxy, config_file=config_file)
190+
self.client = client
191+
192+
def ensure_emp_client(self, config_file=None, is_demo=False, proxy=None):
193+
"""Create a new SLAPI client to the environment.
194+
195+
This will be a no-op if there is already a client in this environment.
196+
"""
197+
if self.client is not None:
198+
return
199+
200+
# Environment can be passed in explicitly. This is used for testing
201+
if is_demo:
202+
client = SoftLayer.BaseClient(transport=SoftLayer.FixtureTransport(), auth=None)
203+
else:
204+
# Create SL Client
205+
client = SoftLayer.employee_client(proxy=proxy, config_file=config_file)
196206
self.client = client
197207

198208
def set_env_theme(self, config_file=None):

SoftLayer/CLI/login.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@
1212
from SoftLayer.CLI import environment
1313

1414

15-
# def get_username(env):
16-
# """Gets the username from config or env"""
17-
# settings =
18-
1915
def censor_password(value):
2016
if value:
2117
value = '*' * len(value)

SoftLayer/consts.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,5 @@
1010
API_PRIVATE_ENDPOINT = 'https://api.service.softlayer.com/xmlrpc/v3.1/'
1111
API_PUBLIC_ENDPOINT_REST = 'https://api.softlayer.com/rest/v3.1/'
1212
API_PRIVATE_ENDPOINT_REST = 'https://api.service.softlayer.com/rest/v3.1/'
13-
API_EMPLOYEE_ENDPOINT = 'https://internal.applb.dal10.softlayer.local/v3/internal/xmlrpc/'
1413
USER_AGENT = "softlayer-python/%s" % VERSION
1514
CONFIG_FILE = "~/.softlayer"

SoftLayer/transports/transport.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,12 @@ def __repr__(self):
9999
"""Prints out what this call is all about"""
100100
pretty_mask = utils.clean_string(self.mask)
101101
pretty_filter = self.filter
102-
param_string = "id={id}, mask='{mask}', filter='{filter}', args={args}, limit={limit}, offset={offset}".format(
103-
id=self.identifier, mask=pretty_mask, filter=pretty_filter,
104-
args=self.args, limit=self.limit, offset=self.offset)
102+
clean_args = self.args
103+
# Passwords can show up here, so censor them before logging.
104+
if self.method in ["performExternalAuthentication", "refreshEncryptedToken", "getPortalLoginToken"]:
105+
clean_args = "*************"
106+
param_string = (f"id={self.identifier}, mask='{pretty_mask}', filter='{pretty_filter}', args={clean_args}, "
107+
f"limit={self.limit}, offset={self.offset}")
105108
return "{service}::{method}({params})".format(
106109
service=self.service, method=self.method, params=param_string)
107110

0 commit comments

Comments
 (0)