Skip to content

Commit a4609c6

Browse files
authored
[BL-302] Updating url to prevent sso login url deprecation warning (#304)
* updating url to prevent sso login url deprecation warning * fmt * leave a note but don't force it yet * version warnings now mess up with indexing * fixing regex * Update __init__.py
1 parent 7f0e550 commit a4609c6

File tree

4 files changed

+16
-14
lines changed

4 files changed

+16
-14
lines changed

leverage/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
MINIMUM_VERSIONS = {
1111
"TERRAFORM": "1.3.5",
12-
"TOOLBOX": "0.2.0",
12+
"TOOLBOX": "0.2.4",
1313
}
1414

1515
import sys

leverage/container.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ class SSOContainer(LeverageContainer):
314314
AWS_SSO_LOGOUT_SCRIPT = "/home/leverage/scripts/aws-sso/aws-sso-logout.sh"
315315

316316
# SSO constants
317-
AWS_SSO_LOGIN_URL = "https://device.sso.{region}.amazonaws.com/?user_code={user_code}"
317+
AWS_SSO_LOGIN_URL = "{sso_url}/#/device?user_code={user_code}"
318318
AWS_SSO_CODE_WAIT_SECONDS = 2
319319
AWS_SSO_CODE_ATTEMPTS = 10
320320
FALLBACK_LINK_MSG = "Opening the browser... if it fails, open this link in your browser:\n{link}"
@@ -365,7 +365,7 @@ def sso_login(self) -> int:
365365
# now let's grab the user code from the logs
366366
user_code = self.get_sso_code(container)
367367
# with the user code, we can now autocomplete the url
368-
link = self.AWS_SSO_LOGIN_URL.format(region=region.strip(), user_code=user_code)
368+
link = self.AWS_SSO_LOGIN_URL.format(sso_url=self.paths.common_conf["sso_start_url"], user_code=user_code)
369369
webbrowser.open_new_tab(link)
370370
# The SSO code is only valid once: if the browser was able to open it, the fallback link will be invalid
371371
logger.info(self.FALLBACK_LINK_MSG.format(link=link))

tests/bats/leverage.bats

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ teardown(){
3737

3838
run leverage run -l
3939

40-
assert_line --index 0 "Tasks in build file \`build.py\`:"
41-
assert_line --index 1 --regexp "^ hello\s+Say hello.$"
42-
assert_line --index 2 --regexp "^Powered by Leverage [0-9]+.[0-9]+.[0-9]+$"
40+
assert_line --partial "Tasks in build file \`build.py\`:"
41+
assert_line --regexp "hello\s+Say hello."
42+
assert_line --regexp "Powered by Leverage [0-9]+.[0-9]+.[0-9]+"
4343
}
4444

4545
@test "Lists tasks with build script in parent directory" {
@@ -51,9 +51,9 @@ teardown(){
5151

5252
run leverage run -l
5353

54-
assert_line --index 0 "Tasks in build file \`build.py\`:"
55-
assert_line --index 1 --regexp "^ hello\s+Say hello.$"
56-
assert_line --index 2 --regexp "^Powered by Leverage [0-9]+.[0-9]+.[0-9]+$"
54+
assert_line --partial "Tasks in build file \`build.py\`:"
55+
assert_line --regexp "hello\s+Say hello."
56+
assert_line --regexp "Powered by Leverage [0-9]+.[0-9]+.[0-9]+"
5757
}
5858

5959
@test "Simple task runs correctly" {
@@ -66,8 +66,8 @@ teardown(){
6666
run leverage run hello
6767

6868
assert_output --partial "Hello"
69-
assert_line --index 0 --regexp "\[[0-9]+:[0-9]+:[0-9]+\.[0-9]+\] \[ build\.py - ➜ Starting task hello \]"
70-
assert_line --index 2 --regexp "\[[0-9]+:[0-9]+:[0-9]+\.[0-9]+\] \[ build\.py - ✔ Completed task hello \]"
69+
assert_line --regexp "\[[0-9]+:[0-9]+:[0-9]+\.[0-9]+\] \[ build\.py - ➜ Starting task hello \]"
70+
assert_line --regexp "\[[0-9]+:[0-9]+:[0-9]+\.[0-9]+\] \[ build\.py - ✔ Completed task hello \]"
7171
}
7272

7373
@test "Values are loaded from .env file in current directory" {

tests/test_containers/test_aws.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,15 @@ def test_sso_login(mocked_new_tab, aws_container, fake_os_user, propagate_logs,
5050
"""
5151
Test that we call the correct script and open the correct url.
5252
"""
53-
test_link = "https://device.sso.us-east-1.amazonaws.com/?user_code=TEST-CODE"
54-
aws_container.sso_login()
53+
sso_start_url = "https://test.sso.us-east-1.amazonaws.com"
54+
test_link = "https://test.sso.us-east-1.amazonaws.com/#/device?user_code=TEST-CODE"
55+
with patch.dict(aws_container.paths.common_conf, {"sso_start_url": sso_start_url}):
56+
aws_container.sso_login()
5557

5658
container_args = aws_container.client.api.create_container.call_args_list[0][1]
5759
# make sure we: point to the correct script
5860
assert container_args["command"] == "/home/leverage/scripts/aws-sso/aws-sso-login.sh"
5961
# the browser tab points to the correct code and the correct region
60-
assert mocked_new_tab.call_args[0][0] == "https://device.sso.us-east-1.amazonaws.com/?user_code=TEST-CODE"
62+
assert mocked_new_tab.call_args[0][0] == test_link
6163
# and the fallback method is printed
6264
assert caplog.messages[0] == aws_container.FALLBACK_LINK_MSG.format(link=test_link)

0 commit comments

Comments
 (0)