From 8d6eacf6f07d8c06b7376c9262b9f18a25c44728 Mon Sep 17 00:00:00 2001 From: Thirumalesh Aaraveti Date: Thu, 11 Jan 2024 11:37:12 +0530 Subject: [PATCH] Added the get_policies method in policy file --- jenkins/tenant/aws/common/run_policies.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/jenkins/tenant/aws/common/run_policies.py b/jenkins/tenant/aws/common/run_policies.py index da67f9591..957cec35a 100644 --- a/jenkins/tenant/aws/common/run_policies.py +++ b/jenkins/tenant/aws/common/run_policies.py @@ -1,7 +1,26 @@ import os from ast import literal_eval -from cloud_governance.common.tool.tool import get_policies + +def get_policies(file_type: str = '.py', exclude_policies: list = None): + """ + This method return a list of policies name without extension, that can filter by type + @return: list of custodian policies name + """ + exclude_policies = [] if not exclude_policies else exclude_policies + custodian_policies = [] + root_folder = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) + policies_path = os.path.join(root_folder, 'policy', 'aws') + for (_, _, filenames) in os.walk(policies_path): + for filename in filenames: + if not filename.startswith('__') and filename.endswith(file_type): + if filename.split('.')[0] not in exclude_policies: + if not file_type: + custodian_policies.append(os.path.splitext(filename)[0]) + elif file_type and file_type in filename: + custodian_policies.append(os.path.splitext(filename)[0]) + return custodian_policies + exclude_policies = ['cost_explorer', 'optimize_resources_report', 'monthly_report', 'cost_over_usage', 'skipped_resources', 'cost_explorer_payer_billings', 'cost_billing_reports', 'spot_savings_analysis'] @@ -17,7 +36,7 @@ def run_cmd(cmd: str): :return: :rtype: """ - print(cmd) + os.system(cmd) def get_container_cmd(env_dict: dict):