Skip to content

Commit

Permalink
Added the get_policies method in policy file
Browse files Browse the repository at this point in the history
  • Loading branch information
athiruma committed Jan 11, 2024
1 parent 8489c1c commit 8d6eacf
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions jenkins/tenant/aws/common/run_policies.py
Original file line number Diff line number Diff line change
@@ -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']
Expand All @@ -17,7 +36,7 @@ def run_cmd(cmd: str):
:return:
:rtype:
"""
print(cmd)
os.system(cmd)


def get_container_cmd(env_dict: dict):
Expand Down

0 comments on commit 8d6eacf

Please sign in to comment.