Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sc-12506 standardize config data output to always have projects #21

Merged
merged 1 commit into from
May 6, 2024
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
23 changes: 11 additions & 12 deletions src/dynamic_importer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def process_configs(

click.echo(f"Writing config data to: {config_out_file}")
with open(config_out_file, "w+") as fp:
json.dump(config_data, fp, indent=4)
json.dump({project: config_data}, fp, indent=4)


@import_config.command()
Expand Down Expand Up @@ -160,13 +160,14 @@ def regenerate_template(default_values, env_values, file_type, data_file):
input_files[env] = file_path
click.echo(f"Processing {file_type} files from: {', '.join(input_files)}")

config_data = {}
project_config_data = {}
with open(data_file, "r") as fp:
config_data = json.load(fp)
project_config_data = json.load(fp)

processing_class = get_processor_class(file_type)
processor: BaseProcessor = processing_class(input_files)
template, _ = processor.process(hints=config_data)
for _, config_data in project_config_data.items():
processing_class = get_processor_class(file_type)
processor: BaseProcessor = processing_class(input_files)
template, _ = processor.process(hints=config_data)

input_filename = ".".join(
list(input_files.values())[0].split("/")[-1].split(".")[:-1]
Expand All @@ -191,17 +192,15 @@ def regenerate_template(default_values, env_values, file_type, data_file):
help="Full path to template file generated from process_configs command",
required=True,
)
@click.option(
"-p", "--project", help="CloudTruth project to import data into", required=True
)
@click.option("-k", help="Ignore SSL certificate verification", is_flag=True)
@click.option("-c", help="Create missing projects and enviroments", is_flag=True)
@click.option("-u", help="Upsert values", is_flag=True)
def create_data(data_file, template_file, project, k, c, u):
def create_data(data_file, template_file, k, c, u):
with open(data_file, "r") as dfp, open(template_file, "r") as tfp:
config_data = json.load(dfp)
project_config_data = json.load(dfp)
template_data = tfp.read()
_create_data(config_data, str(template_file), template_data, project, k, c, u)
for project, config_data in project_config_data.items():
_create_data(config_data, str(template_file), template_data, project, k, c, u)

click.echo("Data upload to CloudTruth complete!")

Expand Down
8 changes: 2 additions & 6 deletions src/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def test_create_data_no_api_key(tmp_path):
NamedTemporaryFile(dir=td, delete=False) as tmp_data,
NamedTemporaryFile(dir=td, delete=False) as tmp_template,
):
tmp_data.write(b"{}")
tmp_data.write(b'{"nullproj": {}}')
tmp_data.close()
tmp_template.write(b"{}")
tmp_template.close()
Expand All @@ -133,12 +133,10 @@ def test_create_data_no_api_key(tmp_path):
f"{tmp_data.name}",
"-m",
f"{tmp_template.name}",
"-p",
"testproj",
],
catch_exceptions=False,
)
assert result.exit_code == 2
assert result.exit_code == 2, result.output
assert (
"Error: CLOUDTRUTH_API_KEY environment variable is required."
in result.output
Expand Down Expand Up @@ -315,8 +313,6 @@ def test_cli_import_data_json(mock_get, mock_post, tmp_path):
f"{td}/testproj-json.ctconfig",
"-m",
f"{td}/testproj-json.cttemplate",
"-p",
"testproj",
],
catch_exceptions=False,
)
Expand Down
Loading