Skip to content

Commit

Permalink
[BB-220] Native SSO profiles (#232)
Browse files Browse the repository at this point in the history
* PathsHandler class

* configure_sso_profiles feature

* refresh_layer_credentials feature

* move logic into get_layer_profile + debug messages + expiration comparison fix

* move code + basic tests

* missing req for CI

* update tests

* configure_sso_profiles tests

* local.tf + tests

* list of non dicts bug

* refactor + tests

* skip lookup references

* dont use append mode

* simplify refresh logic + tests
  • Loading branch information
Franr authored Feb 1, 2024
1 parent b71c1d0 commit 5603ca2
Show file tree
Hide file tree
Showing 20 changed files with 1,717 additions and 869 deletions.
2 changes: 2 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ docker = "==6.1.0"
dockerpty = "==0.4.1"
questionary = "==1.10.0"
python-hcl2 = "==3.0.1"
boto3 = "==1.33.2"
configupdater = "==3.2"
1,328 changes: 747 additions & 581 deletions Pipfile.lock

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ ruamel.yaml==0.17.10
docker==5.0.0
dockerpty==0.4.1
questionary==1.10.0
python-hcl2 == 3.0.1
python-hcl2==3.0.1
configupdater==3.2
boto3==1.33.2
37 changes: 35 additions & 2 deletions leverage/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from subprocess import PIPE

from click.exceptions import Exit
from configupdater import ConfigUpdater
from docker import DockerClient
from docker.models.containers import Container

Expand Down Expand Up @@ -109,7 +110,7 @@ def __exit__(self, *args, **kwargs):
}
)
# now return file ownership on the aws credentials files
self.container.change_file_ownership(self.container.guest_aws_credentials_dir)
self.container.change_file_ownership(self.container.paths.guest_aws_credentials_dir)


class AwsCredsContainer:
Expand All @@ -136,7 +137,7 @@ def __enter__(self):

def __exit__(self, *args, **kwargs):
# now return file ownership on the aws credentials files
self.tf_container.change_file_ownership(self.tf_container.guest_aws_credentials_dir)
self.tf_container.change_file_ownership(self.tf_container.paths.guest_aws_credentials_dir)


class ExitError(Exit):
Expand Down Expand Up @@ -200,3 +201,35 @@ def tar_directory(host_dir_path: Path) -> bytes:
bytes_array.seek(0)
# return the whole tar file as a byte array
return bytes_array.read()


def key_finder(d: dict, target: str, avoid: str = None):
"""
Iterate over a dict of dicts and/or lists of dicts, looking for a key with value "target".
Collect and return all the values that matches "target" as key.
"""
values = []

for key, value in d.items():
if isinstance(value, dict):
# not the target but a dict? keep iterating recursively
values.extend(key_finder(value, target, avoid))
elif isinstance(value, list):
# not a dict but a list? it must be a list of dicts, keep iterating recursively
for dict_ in [d_ for d_ in value if isinstance(d_, dict)]:
values.extend(key_finder(dict_, target, avoid))
elif key == target:
if avoid and avoid in value:
# we found a key but the value contains <avoid> so skip it
continue
# found the target key, store the value
return [value] # return it as an 1-item array to avoid .extend() to split the string

return values


def get_or_create_section(updater: ConfigUpdater, section_name: str):
if not updater.has_section(section_name):
updater.add_section(section_name)
# add_section doesn't return the section object, so we need to retrieve it either case
return updater.get_section(section_name)
Loading

0 comments on commit 5603ca2

Please sign in to comment.