Skip to content

Commit

Permalink
Merge pull request #27 from salesforce/fix/GH-26-csv-fixes
Browse files Browse the repository at this point in the history
CSV Fixes
  • Loading branch information
kmcquade authored Mar 17, 2021
2 parents de6741e + 98fae05 commit 232cca3
Show file tree
Hide file tree
Showing 14 changed files with 1,756 additions and 1,180 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,5 @@ research.py
params*.csv
params*.md
no-params*.md
no-params*.csv
no-params*.csv
all_policies.csv
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ terraform-demo: install
update-policy-table: install
azure-guardrails --help
azure-guardrails generate-terraform --service all --subscription example --no-params
azure-guardrails generate-terraform --service all --subscription example --params-optional
azure-guardrails generate-terraform --service all --subscription example --params-required
azure-guardrails generate-terraform --service all --exclude-services "Guest Configuration" --subscription example --params-optional
azure-guardrails generate-terraform --service all --exclude-services "Guest Configuration" --subscription example --params-required
cp no-params-all-table.csv docs/no-params.csv
cp no-params-all-table.md docs/no-params.md
cp params-optional-all-table.csv docs/params-optional.csv
Expand Down
34 changes: 16 additions & 18 deletions azure_guardrails/command/generate_terraform.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from azure_guardrails import set_log_level
from azure_guardrails.terraform.terraform import TerraformTemplateNoParams, TerraformTemplateWithParamsV2
from azure_guardrails.shared import utils, validate
from azure_guardrails.scrapers.compliance_data import ComplianceCoverage
from azure_guardrails.shared.config import get_default_config, get_config_from_file
from azure_guardrails.guardrails.services import Services

Expand Down Expand Up @@ -160,7 +159,6 @@ def generate_terraform(

if no_params:
display_names = services.get_display_names_sorted_by_service_no_params()
display_names_list = services.display_names_no_params
terraform_template = TerraformTemplateNoParams(
policy_names=display_names,
subscription_name=subscription,
Expand All @@ -172,11 +170,6 @@ def generate_terraform(
params_required=params_required
)

if params_required:
display_names_list = services.display_names_params_required
else:
display_names_list = services.display_names_params_optional

terraform_template = TerraformTemplateWithParamsV2(
parameters=display_names,
subscription_name=subscription,
Expand All @@ -187,22 +180,27 @@ def generate_terraform(
print(result)

if not no_summary:
compliance_coverage = ComplianceCoverage(display_names=display_names_list)

def markdown_summary(file_prefix: str) -> str:
# Write Markdown summary
markdown_table = services.markdown_table(no_params=no_params, params_optional=params_optional, params_required=params_required)
markdown_file_name = f"{file_prefix}.md"
if os.path.exists(markdown_file_name):
if verbosity >= 1:
utils.print_grey(f"Removing the previous file: {markdown_file_name}")
os.remove(markdown_file_name)
with open(markdown_file_name, "w") as f:
f.write(markdown_table)
return markdown_file_name

summary_file_prefix = f"{summary_file_prefix}-{service}-table"

# Write Markdown summary
markdown_table = compliance_coverage.markdown_table()
markdown_file = f"{summary_file_prefix}.md"
if os.path.exists(markdown_file):
if verbosity >= 1:
utils.print_grey(f"Removing the previous file: {markdown_file}")
os.remove(markdown_file)
with open(markdown_file, "w") as f:
f.write(markdown_table)
markdown_file = markdown_summary(file_prefix=summary_file_prefix)

if verbosity >= 1:
utils.print_grey(f"CSV file written to: {markdown_file}")
utils.print_grey(f"Markdown file written to: {markdown_file}")

# Write CSV summary
csv_file = f"{summary_file_prefix}.csv"
compliance_coverage.csv_table(csv_file, verbosity=verbosity)
services.csv_summary(csv_file, verbosity=verbosity, no_params=no_params, params_optional=params_optional, params_required=params_required)
Loading

0 comments on commit 232cca3

Please sign in to comment.