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

Add the env to alert the dry_run=yes policies #740

Merged
merged 1 commit into from
Mar 18, 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
2 changes: 2 additions & 0 deletions cloud_governance/main/environment_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ def __init__(self):
self._environment_variables_dict['MAXIMUM_THRESHOLD'] = EnvironmentVariables.get_env('MAXIMUM_THRESHOLD', '')
self._environment_variables_dict['to_mail'] = EnvironmentVariables.get_env('to_mail', '[]')
self._environment_variables_dict['cc_mail'] = EnvironmentVariables.get_env('cc_mail', '[]')
self._environment_variables_dict['ALERT_DRY_RUN'] = (EnvironmentVariables.
get_boolean_from_environment('ALERT_DRY_RUN', False))

# Google Drive env vars
self._environment_variables_dict['GOOGLE_APPLICATION_CREDENTIALS'] = EnvironmentVariables.get_env('GOOGLE_APPLICATION_CREDENTIALS', '')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def __init__(self):
self.__days_to_delete_resource = int(self.__environment_variables.get('DAYS_TO_DELETE_RESOURCE'))
self.__mail_to = self.__environment_variables.get('EMAIL_TO') # testing purposes
self.__mail_cc = self.__environment_variables.get('EMAIL_CC', [])
self.__alert_dry_run = self.__environment_variables.get('ALERT_DRY_RUN')
self.__mail_message = MailMessage()
self.__postfix = Postfix()
self.__es_operations = ElasticSearchOperations()
Expand Down Expand Up @@ -141,7 +142,11 @@ def __update_delete_days(self, policy_es_data: list):
if not days:
days = 0
alert_user = False
delete_date = ''
delete_date = 'dry_run=yes'
if not record.get('Skip'):
record['Skip'] = 'NA'
if record.get('Skip') != 'NA':
delete_date = 'skip_delete'
if self.__days_to_delete_resource - 5 == days:
delete_date = (datetime.utcnow() + timedelta(days=5)).date()
alert_user = True
Expand All @@ -160,7 +165,7 @@ def __update_delete_days(self, policy_es_data: list):
delete_date = 'dry_run=yes'
alert_user = True
if alert_user:
if delete_date != 'skip_delete' and delete_date != 'dry_run=yes':
if delete_date != 'skip_delete' and (delete_date != 'dry_run=yes' and self.__alert_dry_run):
record['DeleteDate'] = delete_date.__str__()
if record.get('policy') in ['empty_roles', 's3_inactive']:
record['RegionName'] = 'us-east-1'
Expand Down
3 changes: 2 additions & 1 deletion jenkins/tenant/aws/common/run_policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def get_container_cmd(env_dict: dict):
days_to_delete_resource = os.environ.get('days_to_delete_resource', 14)
LDAP_HOST_NAME = os.environ['LDAP_HOST_NAME']
LOGS = os.environ.get('LOGS', 'logs')
ALERT_DRY_RUN = os.environ.get('ALERT_DRY_RUN', False)
ES_HOST = os.environ['ES_HOST']
ES_PORT = os.environ['ES_PORT']
GOOGLE_APPLICATION_CREDENTIALS = os.environ['GOOGLE_APPLICATION_CREDENTIALS']
Expand All @@ -81,7 +82,7 @@ def get_container_cmd(env_dict: dict):
"dry_run": "yes", "LDAP_HOST_NAME": LDAP_HOST_NAME, "DAYS_TO_DELETE_RESOURCE": days_to_delete_resource,
"es_host": ES_HOST, "es_port": ES_PORT,
"MANAGER_EMAIL_ALERT": "False", "EMAIL_ALERT": "False", "log_level": "INFO",
'DAYS_TO_TAKE_ACTION': days_to_delete_resource
'DAYS_TO_TAKE_ACTION': days_to_delete_resource, 'ALERT_DRY_RUN': ALERT_DRY_RUN
}


Expand Down
3 changes: 2 additions & 1 deletion jenkins/tenant/aws/ecoeng_01/PolicyJenkinsfileDaily
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
accounts_list = ["partnerlab": "[email protected], [email protected]"]
accounts_list = ["partnerlab": "[email protected], [email protected], [email protected]"]
pipeline {
options {
disableConcurrentBuilds()
Expand All @@ -16,6 +16,7 @@ pipeline {
LDAP_HOST_NAME = credentials('cloud-governance-ldap-host-name')
ES_HOST = credentials('haim-cloud-governance-elasticsearch-url')
ES_PORT = credentials('haim-cloud-governance-elasticsearch-port')
ALERT_DRY_RUN = true
contact1 = "[email protected]"
contact2 = "[email protected]"
contact3 = "[email protected]"
Expand Down
7 changes: 4 additions & 3 deletions jenkins/tenant/aws/ecoeng_02/PolicyJenkinsfileDaily
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
accounts_list = ['appeng': "[email protected], [email protected], [email protected]",
'fsi-partner': "[email protected], [email protected], [email protected]",
'fsi-ecosystem': "[email protected], [email protected], [email protected]"]
accounts_list = ['appeng': "[email protected], [email protected], [email protected],[email protected]",
'fsi-partner': "[email protected], [email protected], [email protected],[email protected]",
'fsi-ecosystem': "[email protected], [email protected], [email protected],[email protected]"]
pipeline {
options {
disableConcurrentBuilds()
Expand All @@ -18,6 +18,7 @@ pipeline {
LDAP_HOST_NAME = credentials('cloud-governance-ldap-host-name')
ES_HOST = credentials('haim-cloud-governance-elasticsearch-url')
ES_PORT = credentials('haim-cloud-governance-elasticsearch-port')
ALERT_DRY_RUN = true
contact1 = "[email protected]"
contact2 = "[email protected]"
contact3 = "[email protected]"
Expand Down
17 changes: 9 additions & 8 deletions jenkins/tenant/aws/ecoeng_03/PolicyJenkinsfileDaily
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
accounts_list = ['coreos-training': "[email protected], [email protected]",
'industry-partners': "",
'special-projects': "",
'edgeinfra': "",
'specialprojects-qe': "",
'ecoeng-sap': "",
'sysdeseng': "",
'verticals-ui': ""]
accounts_list = ['coreos-training': "[email protected], [email protected], [email protected]",
'industry-partners': "[email protected]",
'special-projects': "[email protected]",
'edgeinfra': "[email protected]",
'specialprojects-qe': "[email protected]",
'ecoeng-sap': "[email protected]",
'sysdeseng': "[email protected]",
'verticals-ui': "[email protected]"]
pipeline {
options {
disableConcurrentBuilds()
Expand All @@ -23,6 +23,7 @@ pipeline {
LDAP_HOST_NAME = credentials('cloud-governance-ldap-host-name')
ES_HOST = credentials('haim-cloud-governance-elasticsearch-url')
ES_PORT = credentials('haim-cloud-governance-elasticsearch-port')
ALERT_DRY_RUN = true
contact1 = "[email protected]"
contact2 = "[email protected]"
contact3 = "[email protected]"
Expand Down
Loading