Skip to content

Commit

Permalink
refresh-credentials command
Browse files Browse the repository at this point in the history
  • Loading branch information
Franr committed Oct 4, 2023
1 parent 85a14e7 commit 6f064b1
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
5 changes: 5 additions & 0 deletions leverage/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,11 @@ def check_for_layer_location(self):
logger.error("This command can only run at [bold]layer[/bold] level.")
raise Exit(1)

def refresh_credentials(self):
with AwsCredsEntryPoint(self, override_entrypoint=""):
if exit_code := self._start('echo "Done."'):
return exit_code

def start(self, command, *arguments):
with AwsCredsEntryPoint(self, self.entrypoint):
return self._start(command, *arguments)
Expand Down
9 changes: 9 additions & 0 deletions leverage/modules/terraform.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,15 @@ def _import(tf, address, _id):
raise Exit(exit_code)


@terraform.command("refresh-credentials")
@pass_container
def refresh_credentials(tf):
"""Refresh the AWS credentials used on the current layer."""
tf.check_for_layer_location()
if exit_code := tf.refresh_credentials():
raise Exit(exit_code)


# ###########################################################################
# HANDLER FOR MANAGING THE BASE COMMANDS (init, plan, apply, destroy, output)
# ###########################################################################
Expand Down
1 change: 1 addition & 0 deletions tests/test_containers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ def container_fixture_factory(container_class):
with patch("leverage.container.load_env", return_value=FAKE_ENV):
container = container_class(mocked_client)
container._run = Mock()
container._check_sso_token = Mock()
return container
11 changes: 11 additions & 0 deletions tests/test_containers/test_terraform.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,14 @@ def test_tf_plugin_cache_dir(terraform_container):

# and the cache folder mounted
assert next(m for m in container_args["host_config"]["Mounts"] if m["Target"] == "/home/testing/.terraform/cache")


def test_refresh_credentials(terraform_container):
terraform_container.enable_sso()
terraform_container.refresh_credentials()
container_args = terraform_container.client.api.create_container.call_args_list[0][1]

# we want a shell, so -> /bin/bash with no entrypoint
assert container_args["command"] == 'echo "Done."'
# import ipdb; ipdb.set_trace()
assert container_args["entrypoint"] == "/root/scripts/aws-sso/aws-sso-entrypoint.sh -- "

0 comments on commit 6f064b1

Please sign in to comment.