Skip to content

Commit

Permalink
simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
mucsi96 committed Mar 17, 2024
1 parent 9cbb928 commit 7802d7a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 26 deletions.
16 changes: 3 additions & 13 deletions scripts/build_test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,13 @@
from src.docker_utils import build_and_push_docker_img

root_directory = Path(__file__).parent.parent
access_token = sys.argv[1]
vault_key = sys.argv[2]

with NamedTemporaryFile() as vault_key_file:
vault_key_file.write(vault_key.encode())
vault_key_file.flush()
data = load_vars(vault_key_file.name, root_directory / 'vars/vault.yaml')

if not access_token:
print("GitHub access token is missing", flush=True, file=sys.stderr)
exit(1)
secrets = load_vars(sys.argv[2], root_directory / 'vars/vault.yaml')

build_and_push_docker_img(
src="src",
tag_prefix="docker-image",
image_name="publish-tools-test",
docker_username=environ.get('GITHUB_REPOSITORY_OWNER'),
docker_password=data['docker_password'],
github_access_token=access_token
docker_password=secrets['docker_password'],
github_access_token=sys.argv[1]
)
15 changes: 2 additions & 13 deletions src/ansible_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import sys

from os import makedirs, path
from pathlib import Path
from secrets import choice
Expand All @@ -9,19 +7,10 @@
from ansible.parsing.dataloader import DataLoader


def read_file(file_path: Path):
try:
with open(file_path, 'rb') as file:
return file.read().strip()
except:
print("Error reading file at", file_path, flush=True, file=sys.stderr)


def load_vars(vault_secret_file: Path, vars_file: Path):
vault_secret = read_file(vault_secret_file)
def load_vars(vault_secret: str, vars_file: Path):
loader = DataLoader()
loader.set_vault_secrets(
[(DEFAULT_VAULT_ID_MATCH, VaultSecret(vault_secret))])
[(DEFAULT_VAULT_ID_MATCH, VaultSecret(vault_secret.encode()))])
return loader.load_from_file(str(vars_file))


Expand Down

0 comments on commit 7802d7a

Please sign in to comment.