Internal updates by allmightyspiff · Pull Request #2243 · softlayer/softlayer-python · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 77 additions & 60 deletions SoftLayer/API.py
2 changes: 1 addition & 1 deletion SoftLayer/CLI/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from SoftLayer.CLI import formatting
from SoftLayer import consts

# pylint: disable=too-many-public-methods, broad-except, unused-argument
# pylint: disable=too-many-public-methods, broad-except, unused-argument, invalid-name
# pylint: disable=redefined-builtin, super-init-not-called, arguments-differ

START_TIME = time.time()
Expand Down
47 changes: 46 additions & 1 deletion SoftLayer/CLI/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,60 @@ def censor_password(value):


@click.command(cls=SLCommand)
@click.option('--session-token',
default=None,
help='An existing employee session token (hash). Click the "Copy Session Token" in the internal portal '
'to get this value.'
'Can also be set via the SLCLI_SESSION_TOKEN environment variable.',
envvar='SLCLI_SESSION_TOKEN')
@click.option('--user-id',
default=None,
type=int,
help='Employee IMS ID. The number in the url when you click your username in the internal portal, '
'under "user information". Can also be set via the SLCLI_USER_ID environment variable. '
'Or read from the configuration file.',
envvar='SLCLI_USER_ID')
@click.option('--legacy',
default=False,
type=bool,
is_flag=True,
help='Login with username, password, yubi key combination. Only valid if ISV is not required. '
'If using ISV, use your session token.')
@environment.pass_env
def cli(env):
def cli(env, session_token, user_id, legacy):
"""Logs you into the internal SoftLayer Network.

username: Set this in either the softlayer config, or SL_USER ENV variable
password: Set this in SL_PASSWORD env variable. You will be prompted for them otherwise.

To log in with an existing session token instead of username/password/2FA:

slcli login --session-token <token> --user-id <id>

Or via environment variables:

SLCLI_SESSION_TOKEN=<token> SLCLI_USER_ID=<id> slcli login
"""
config_settings = config.get_config(config_file=env.config_file)
settings = config_settings['softlayer']

if not user_id:
user_id = int(settings.get('userid', 0)) or int(os.environ.get('SLCLI_USER_ID', 0))
# --session-token supplied on the CLI (or via SLCLI_SESSION_TOKEN env var):
# authenticate directly, persist to config, and return immediately.
if not legacy:
if not user_id:
user_id = int(input("User ID (number): "))
if not session_token:
session_token = os.environ.get('SLCLI_SESSION_TOKEN', '') or input("Session Token: ")
env.client.authenticate_with_hash(user_id, session_token)
settings['access_token'] = session_token
settings['userid'] = str(user_id)
config_settings['softlayer'] = settings
config.write_config(config_settings, env.config_file)
click.echo(f"Logged in with session token for user ID {user_id}.")
return

username = settings.get('username') or os.environ.get('SLCLI_USER', None)
password = os.environ.get('SLCLI_PASSWORD', '')
yubi = None
Expand Down
5 changes: 1 addition & 4 deletions tests/api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,10 +389,7 @@ def test_expired_token_is_really_expired(self, api_response):
@mock.patch('SoftLayer.API.BaseClient.call')
def test_account_check(self, _call):
self.client.transport = self.mocks
exception = self.assertRaises(
exceptions.SoftLayerError,
self.client.call, "SoftLayer_Account", "getObject")
self.assertEqual(str(exception), "SoftLayer_Account service requires an ID")

self.client.account_id = 1234
self.client.call("SoftLayer_Account", "getObject")
self.client.call("SoftLayer_Account", "getObject1", id=9999)
Expand Down
2 changes: 1 addition & 1 deletion tools/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

click >= 8.0.4
click == 8.0.4
requests >= 2.32.2
prompt_toolkit >= 2
pygments >= 2.0.0
Expand Down
2 changes: 1 addition & 1 deletion tools/test-requirements.txt
Loading