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

Pull request md #23

Closed
wants to merge 152 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
152 commits
Select commit Hold shift + click to select a range
77e965e
bump version to exist version v1.1.74
ebattat Feb 27, 2023
01f3b4f
Added the purchase option (#568)
athiruma Feb 28, 2023
f2c9321
bump version to exist version v1.1.75
ebattat Feb 28, 2023
8041821
Fix errors in cloud payers (#569)
athiruma Mar 13, 2023
e442266
bump version to exist version v1.1.76
ebattat Mar 13, 2023
215b93a
Added the MonthlySavingsPlanAmortizaton,PremiumSupportFee (#570)
athiruma Mar 14, 2023
aedbaf3
bump version to exist version v1.1.77
ebattat Mar 14, 2023
850757e
Disabled the zombie cluster resourece mailing (#571)
athiruma Mar 14, 2023
fba1f79
bump version to exist version v1.1.78
ebattat Mar 14, 2023
9b265b2
disabled the manager alerts for resources: empty_roles, s3_inactive, …
athiruma Mar 14, 2023
60c3074
bump version to exist version v1.1.79
ebattat Mar 14, 2023
f7d0971
Added the google cloud billing (#573)
athiruma Mar 16, 2023
44ebee5
Added missed secrets name (#574)
athiruma Mar 16, 2023
92b165d
Added new action for gcp secrets (#575)
athiruma Mar 16, 2023
151ea94
Fixed the identation issue in runner (#576)
athiruma Mar 16, 2023
aa3b1b9
Moved gcp env vars to pytest (#577)
athiruma Mar 16, 2023
5475c77
bump version to exist version v1.1.80
ebattat Mar 16, 2023
0f876e9
Run the podman container (#578)
athiruma Mar 20, 2023
1ff8329
Added the apt update in pypi validate (#579)
athiruma Mar 21, 2023
3d18b1a
bump version to exist version v1.1.82
ebattat Mar 21, 2023
5bf2c02
Added the check before removing default in-gress rules (#580)
athiruma Mar 22, 2023
32b598b
bump version to exist version v1.1.83
ebattat Mar 22, 2023
97f454f
added the jenkinsfile for haimpoc (#581)
athiruma Apr 4, 2023
15faa32
bump version to exist version v1.1.84
ebattat Apr 4, 2023
c3b204a
fixed the path error i n jenkinsfile (#583)
athiruma Apr 4, 2023
b10845d
bump version to exist version v1.1.85
ebattat Apr 4, 2023
a462c91
Check username in Name tag before going to cloudtrail (#584)
athiruma Apr 11, 2023
c8009a4
bump version to exist version v1.1.86
ebattat Apr 11, 2023
7d73c76
Fixed the taggig issue (#587)
athiruma Apr 18, 2023
9a844b0
bump version to exist version v1.1.87
ebattat Apr 18, 2023
7c82a30
Added the batch tagging support (#586)
athiruma Apr 19, 2023
2158562
bump version to exist version v1.1.88
ebattat Apr 19, 2023
e8d85ba
check if tags present or not while tagging (#588)
athiruma Apr 20, 2023
c134c76
bump version to exist version v1.1.89
ebattat Apr 20, 2023
c135990
Updated the instance pricing list (#589)
athiruma Apr 20, 2023
cd8f208
bump version to exist version v1.1.90
ebattat Apr 20, 2023
adbcca4
Fixed cluster user missing (#590)
athiruma Apr 21, 2023
bed01d7
bump version to exist version v1.1.91
ebattat Apr 21, 2023
fcfc206
Added the IAM Role create process (#591)
athiruma Apr 27, 2023
a92a183
bump version to exist version v1.1.92
ebattat Apr 27, 2023
3a70fd0
Search cloud_watch metrics for NatGateway Unsed (#592)
athiruma May 2, 2023
c369355
bump version to exist version v1.1.93
ebattat May 2, 2023
db4348f
Cost Explorer User spot usage, savings plans exclude and include (#594)
athiruma May 9, 2023
e2dcf1a
bump version to exist version v1.1.94
ebattat May 9, 2023
38adff8
run cost_explorer policy for haim-account (#595)
athiruma May 10, 2023
c4b06fd
bump version to exist version v1.1.95
ebattat May 10, 2023
c1ad363
added missing policies (#596)
athiruma May 11, 2023
db44921
bump version to exist version v1.1.96
ebattat May 11, 2023
8d8e6ff
Disabilig the dry_run=no (#597)
athiruma May 15, 2023
8fd9ef7
bump version to exist version v1.1.97
ebattat May 15, 2023
67a1e4b
Aggregate the user mail alerts to send aggregated mail (#593)
athiruma May 16, 2023
d54081f
bump version to exist version v1.1.98
ebattat May 16, 2023
fdc04d1
Added the missing es_host and port (#598)
athiruma May 18, 2023
bf62df7
bump version to exist version v1.1.99
ebattat May 18, 2023
3f53cb6
Added the spot usgae of accounts to pyer dashboard (#599)
athiruma May 19, 2023
e53f547
bump version to exist version v1.1.100
ebattat May 19, 2023
849dce0
Updated the new instance prices (#601)
athiruma May 24, 2023
72c0e46
bump version to exist version v1.1.101
ebattat May 24, 2023
05a5c19
cloud_resource_orchestartion: manages the cloud usages (#585)
athiruma May 29, 2023
b2a694f
bump version to exist version v1.1.102
ebattat May 29, 2023
36915cb
Enable the mail cro alert (#603)
athiruma May 30, 2023
d74bf33
bump version to exist version v1.1.103
ebattat May 30, 2023
ed49412
Enabling the CRO mail alert (#605)
athiruma May 31, 2023
ded3eee
bump version to exist version v1.1.104
ebattat May 31, 2023
13032fc
fixed the issue: changed the account name (#606)
athiruma May 31, 2023
7a07113
bump version to exist version v1.1.105
ebattat May 31, 2023
8fe7a18
Removed the extra_args and the savings plans (#607)
athiruma Jun 5, 2023
0922931
bump version to exist version v1.1.106
ebattat Jun 5, 2023
6be3ae3
Added lambda for approving the ticket (#604)
athiruma Jun 5, 2023
3840b7c
bump version to exist version v1.1.107
ebattat Jun 5, 2023
f79079e
Fixed the mail alerts subject, added the template to manifest.in (#608)
athiruma Jun 5, 2023
149403d
bump version to exist version v1.1.108
ebattat Jun 5, 2023
53794f4
added the new, refinement tickets to es,verified any user instances w…
athiruma Jun 7, 2023
0f9ac4a
bump version to exist version v1.1.109
ebattat Jun 7, 2023
ca0e278
Added the mail message changes (#610)
athiruma Jun 12, 2023
c06869c
bump version to exist version v1.1.110
ebattat Jun 12, 2023
b8cff11
Enabeled the mail alert data to save in es (#611)
athiruma Jun 13, 2023
b112dc3
bump version to exist version v1.1.111
ebattat Jun 13, 2023
bf52b74
Fixed the bugs in collecting data (#612)
athiruma Jun 14, 2023
8128023
bump version to exist version v1.1.112
ebattat Jun 14, 2023
435577e
Added the user missing ticket cost to es after sending the CostOverUs…
athiruma Jun 15, 2023
01e0be0
bump version to exist version v1.1.113
ebattat Jun 15, 2023
5638f52
not perform action if it is alredy inprogress state (#615)
athiruma Jun 22, 2023
d000446
bump version to exist version v1.1.114
ebattat Jun 22, 2023
baea59b
Fixed the date range issue (#618)
athiruma Jun 24, 2023
29abd5b
bump version to exist version v1.1.115
ebattat Jun 25, 2023
5a64f4d
Added the manager to manager/cloud_admin ticket approval (#616)
athiruma Jun 26, 2023
b13d8ce
bump version to exist version v1.1.116
ebattat Jun 26, 2023
ef896cf
CRO: Attached the untagged instances to the email body (#619)
athiruma Jun 26, 2023
10ed9db
bump version to exist version v1.1.117
ebattat Jun 26, 2023
fbefb39
Added the missing pytest (#620)
athiruma Jun 27, 2023
4538e30
bump version to exist version v1.1.118
ebattat Jun 27, 2023
41b6ca4
Added the cloudsensei (#614)
athiruma Jun 27, 2023
d7e6eb4
bump version to exist version v1.1.119
ebattat Jun 27, 2023
51f7e8a
Suggesting improvements for html tables in email (#617)
vishnuchalla Jun 27, 2023
7a21444
bump version to exist version v1.1.120
ebattat Jun 27, 2023
f55b2f0
[doc-updates]: Minor Nit to README.md (#622)
krishvoor Jun 28, 2023
d51b2eb
bump version to exist version v1.1.121
ebattat Jun 28, 2023
33cce36
Check if ticket is extended before closing the ticket (#626)
athiruma Jul 3, 2023
522151b
bump version to exist version v1.1.122
ebattat Jul 3, 2023
c16b2c9
test the retirval of azure cost reports of last one day (#627)
athiruma Jul 3, 2023
8a30c04
Missed the start, end date time for the cost usage function (#628)
athiruma Jul 4, 2023
67d157c
Added the http response code error of azure reports (#629)
athiruma Jul 4, 2023
ab98d33
bump version to exist version v1.1.123
ebattat Jul 4, 2023
4dd25e1
Removed the parallel execution (#631)
athiruma Jul 5, 2023
540ceca
bump version to exist version v1.1.124
ebattat Jul 5, 2023
cf40791
pr will run if it have a label ok-to-test (#630)
athiruma Jul 5, 2023
92b4d9b
bump version to exist version v1.1.125
ebattat Jul 5, 2023
b36555f
Added the type synchronize to the pr types (#633)
athiruma Jul 6, 2023
abfa2f6
bump version to exist version v1.1.126
ebattat Jul 6, 2023
c3cbed8
Addded the extended days, cost while tagging (#632)
athiruma Jul 7, 2023
53ebfaa
bump version to exist version v1.1.127
ebattat Jul 7, 2023
54496d8
Bump requests from 2.27.1 to 2.31.0 (#600)
dependabot[bot] Jul 9, 2023
dbe9d00
bump version to exist version v1.1.128
ebattat Jul 9, 2023
02e2021
Bump requests from 2.27.1 to 2.31.0 in /cloudsensei (#621)
dependabot[bot] Jul 9, 2023
ae4bb0a
bump version to exist version v1.1.129
ebattat Jul 9, 2023
eb064be
added the user daily cost usage (#623)
athiruma Jul 10, 2023
f0fe2d8
bump version to exist version v1.1.130
ebattat Jul 10, 2023
5c4c3a4
Added the docs for creating jenkins slave (#602)
athiruma Jul 11, 2023
a94ad97
bump version to exist version v1.1.131
ebattat Jul 11, 2023
1af3b3c
Fixed the agg policy alert message (#634)
athiruma Jul 11, 2023
0e0e0fc
bump version to exist version v1.1.132
ebattat Jul 11, 2023
b15ffe2
Updates the Subject Heading
krishvoor Jul 12, 2023
68fad31
minor nits
krishvoor Jul 13, 2023
5707ee0
Merge pull request #635 from krishvoor/updates-cloud-sensei
athiruma Jul 13, 2023
e04b1a7
bump version to exist version v1.1.133
ebattat Jul 13, 2023
4173d1a
Removed the pr opened type in pr.yml (#638)
athiruma Jul 18, 2023
114f3fb
Added the backend configuration for the terraform (#636)
athiruma Jul 18, 2023
2139484
bump version to exist version v1.1.134
ebattat Jul 18, 2023
750fca2
Spot Usage analysis on aws account (#637)
athiruma Jul 18, 2023
ddcfe97
bump version to exist version v1.1.135
ebattat Jul 18, 2023
bf6a83d
Added concurrency feature to main.yml (#639)
athiruma Jul 18, 2023
ebac77c
bump version to exist version v1.1.136
ebattat Jul 18, 2023
7297d6b
Fixed some changes to the tag_iam_user (#641)
athiruma Jul 20, 2023
0e00e0b
bump version to exist version v1.1.137
ebattat Jul 20, 2023
acff962
Fixed some minor changes (#640)
athiruma Jul 20, 2023
f47abbc
bump version to exist version v1.1.138
ebattat Jul 20, 2023
f43ddd7
Push the data elastic search after getting the results (#643)
athiruma Jul 23, 2023
87b10cb
bump version to exist version v1.1.139
ebattat Jul 23, 2023
c392101
Fixed the elasticsearch operations error (#645)
athiruma Jul 24, 2023
315f262
bump version to exist version v1.1.140
ebattat Jul 24, 2023
c1ec07f
Add the cro dlow diagram (#644)
athiruma Jul 24, 2023
9a51529
bump version to exist version v1.1.141
ebattat Jul 24, 2023
696068a
need the approve to run the stop (#646)
athiruma Jul 24, 2023
2ec0d1d
bump version to exist version v1.1.142
ebattat Jul 24, 2023
4544bb5
Add account to es (#647)
athiruma Jul 25, 2023
06f24dd
bump version to exist version v1.1.143
ebattat Jul 25, 2023
381c93b
Added the env varible for delete resource (#648)
athiruma Jul 27, 2023
87eb36b
bump version to exist version v1.1.144
ebattat Jul 27, 2023
7647b28
Added the budget extension ability (#649)
athiruma Aug 1, 2023
d75f6ef
bump version to exist version v1.1.145
ebattat Aug 1, 2023
b5f8b34
added the pr template
athiruma Aug 2, 2023
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: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[bumpversion]
commit = False
tag = True
current_version = 1.1.74
current_version = 1.1.146
tag_name = v{current_version}
message = GitHub Actions Build {current_version}

Expand Down
29 changes: 29 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
## Type of change

- [ ] Refactor
- [ ] New feature
- [ ] Bug fix
- [ ] Optimization
- [ ] Documentation Update

## Description

<!--- Describe your changes in detail -->

## Related Tickets & Documents

- Related Issue #
- Closes #

## Checklist before requesting a review

- [ ] I have performed a self-review of my code.
- [ ] If it is a core feature, I have added thorough tests.

## Testing
- Does below tests are passed
- [ ] UnitTest
- [ ] IntegrationTest
- Please describe the System Under Test.
- Please provide detailed steps to perform tests related to this code change.
- How were the fix/results from this change verified? Please provide relevant screenshots or results.
16 changes: 16 additions & 0 deletions .github/workflows/Build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ on:
push:
branches: [ main ]

concurrency:
group: merge-queue
cancel-in-progress: false

jobs:
unittest:
name: unittest
Expand All @@ -23,6 +27,7 @@ jobs:
- name: Install dependencies
run: |
# ldap requirements
sudo apt update -y
sudo apt-get install build-essential python3-dev libldap2-dev libsasl2-dev vim -y
python -m pip install --upgrade pip
pip install flake8 pytest pytest-cov
Expand Down Expand Up @@ -131,6 +136,7 @@ jobs:
- name: Install dependencies
run: |
# ldap requirements
sudo apt update -y
sudo apt-get install build-essential python3-dev libldap2-dev libsasl2-dev vim -y
python -m pip install --upgrade pip
pip install flake8 pytest pytest-cov
Expand All @@ -148,6 +154,13 @@ jobs:
aws-access-key-id: ${{ secrets.ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.REGION }}
- name: Set GCP credentials for pytest
env:
GOOGLE_APPLICATION_CREDENTIALS_CONTENTS: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}
RUNNER_PATH: ${{ secrets.RUNNER_PATH }}
run: |
echo "$GOOGLE_APPLICATION_CREDENTIALS_CONTENTS" > "$RUNNER_PATH/gcp_service.json"
echo "GOOGLE_APPLICATION_CREDENTIALS=$RUNNER_PATH/gcp_service.json" >> "$GITHUB_ENV"
- name: 📃 Integration tests with pytest
env:
BUCKET: ${{ secrets.BUCKET }}
Expand All @@ -158,6 +171,8 @@ jobs:
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
GCP_DATABASE_NAME: ${{ secrets.GCP_DATABASE_NAME }}
GCP_DATABASE_TABLE_NAME: ${{ secrets.GCP_DATABASE_TABLE_NAME }}
run: |
pytest -v tests/integration --cov=cloud_governqance --cov-report=term-missing
coverage run -m pytest -v tests/integration
Expand Down Expand Up @@ -252,6 +267,7 @@ jobs:
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: |
# ldap requirements
sudo apt update -y
sudo apt-get install build-essential python3-dev libldap2-dev libsasl2-dev vim -y
echo '⌛ Wait till package will be updated in PyPI'
# Verfiy and wait till latest cloud-governance version will be updated in Pypi (timeout 900 seconds)
Expand Down
29 changes: 25 additions & 4 deletions .github/workflows/PR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,24 @@ name: PR

on:
pull_request_target:
types: [labeled, synchronize]
branches: [ main ]

jobs:
approve: # First step
runs-on: ubuntu-latest
steps:
- name: Approve
run: echo For security reasons, all pull requests need to be approved first before running any automated CI.
unittest:
name: unittest
runs-on: ubuntu-latest
needs: [approve]
strategy:
matrix:
python-version: [ '3.8', '3.9', '3.10' ]
# minimize potential vulnerabilities
if: ${{ contains(github.event.pull_request.labels.*.name, 'ok-to-test') }}
steps:
- uses: actions/checkout@v3
with:
Expand All @@ -25,6 +34,7 @@ jobs:
- name: Install dependencies
run: |
# ldap requirements
sudo apt update -y
sudo apt-get install build-essential python3-dev libldap2-dev libsasl2-dev vim -y
python -m pip install --upgrade pip
pip install flake8 pytest pytest-cov
Expand All @@ -51,7 +61,7 @@ jobs:

terraform_apply:
name: terraform_apply
needs: [unittest]
needs: [unittest, approve]
runs-on: ubuntu-latest
outputs:
INSTANCE_ID: ${{ steps.terraform_instance_id.outputs.INSTANCE_ID }}
Expand Down Expand Up @@ -99,7 +109,7 @@ jobs:

integration:
name: integration
needs: [ unittest, terraform_apply ]
needs: [ unittest, terraform_apply, approve ]
runs-on: ubuntu-latest
strategy:
max-parallel: 1
Expand Down Expand Up @@ -129,6 +139,7 @@ jobs:
- name: Install dependencies
run: |
# ldap requirements
sudo apt update -y
sudo apt-get install build-essential python3-dev libldap2-dev libsasl2-dev vim -y
python -m pip install --upgrade pip
pip install flake8 pytest pytest-cov
Expand All @@ -146,6 +157,13 @@ jobs:
aws-access-key-id: ${{ secrets.ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.REGION }}
- name: Set GCP credentials for pytest
env:
GOOGLE_APPLICATION_CREDENTIALS_CONTENTS: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}
RUNNER_PATH: ${{ secrets.RUNNER_PATH }}
run: |
echo "$GOOGLE_APPLICATION_CREDENTIALS_CONTENTS" > "$RUNNER_PATH/gcp_service.json"
echo "GOOGLE_APPLICATION_CREDENTIALS=$RUNNER_PATH/gcp_service.json" >> "$GITHUB_ENV"
- name: 📃 Integration tests with pytest
env:
BUCKET: ${{ secrets.BUCKET }}
Expand All @@ -156,12 +174,14 @@ jobs:
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
GCP_DATABASE_NAME: ${{ secrets.GCP_DATABASE_NAME }}
GCP_DATABASE_TABLE_NAME: ${{ secrets.GCP_DATABASE_TABLE_NAME }}
run: |
python -m pytest -v tests/integration

terraform_destroy:
name: terraform_destroy
needs: [unittest, terraform_apply, integration]
needs: [unittest, terraform_apply, integration, approve]
if: success() || failure()
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -203,7 +223,7 @@ jobs:

e2e:
name: e2e
needs: [ unittest, terraform_apply, integration ]
needs: [ unittest, terraform_apply, integration, approve ]
runs-on: ubuntu-latest
strategy:
matrix:
Expand All @@ -219,6 +239,7 @@ jobs:
- name: Install dependencies
run: |
# ldap requirements
sudo apt update -y
sudo apt-get install build-essential python3-dev libldap2-dev libsasl2-dev vim -y
python -m pip install --upgrade pip
pip install flake8 pytest pytest-cov
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,4 @@ empty_test_environment_variables.py
/cloud_governance/main/.env
/cloud_governance/main/.test_env
/cloud_governance/policy/send_mail.py
cloudsensei/.env.txt
4 changes: 1 addition & 3 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
include cloud_governance/policy/*.yml
include iam/cloud/azure/CloudGovernanceCostManagement.json



include cloud_governance/common/mails/templates/cro_request_for_manager_approval.j2
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ This tool support the following policies:
* [s3_inactive](cloud_governance/policy/aws/s3_inactive.py): Get the inactive/empty buckets and delete them after 7 days.
* [empty_roles](cloud_governance/policy/aws/empty_roles.py): Get empty roles and delete it after 7 days.
* [zombie_snapshots](cloud_governance/policy/aws/zombie_snapshots.py): Get the zombie snapshots and delete it after 7 days.
* [nat_gateway_unused](cloud_governance/policy/aws/nat_gateway_unused.py): Get the unused nat gateways and deletes it after 7 days.
* [nat_gateway_unused](cloud_governance/policy/aws/unused_nat_gateway.py): Get the unused nat gateways and deletes it after 7 days.
* gitleaks: scan Github repository git leak (security scan)
* [cost_over_usage](cloud_governance/policy/aws/cost_over_usage.py): send mail to aws user if over usage cost

Expand Down
101 changes: 101 additions & 0 deletions aws_lambda_functions/CloudResourceOrchestration/lambda_function.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import json
import boto3
import jira

ssm_client = boto3.client('ssm', region_name='us-east-1')
APPROVED = 'APPROVED'
REJECT = 'REJECT'
REFINEMENT = '61'
CLOSED = '41'
JIRA_TOKEN = 'JIRA_TOKEN'
JIRA_PROJECT = 'JIRA_PROJECT'
JIRA_API_SERVER = 'JIRA_API_SERVER'
CRO_ADMINS = ['athiruma@redhat.com', 'natashba@redhat.com', 'ebattat@redhat.com']


def get_receive_mail_details(event_data):
"""
This method returns the received mail data
:param event_data:
:return:
# """
records = event_data.get('Records')
mail_details = []
if records:
for record in records:
if record.get('eventSource') == 'aws:ses':
ses_data = record.get('ses')
common_headers = ses_data.get('mail', {}).get('commonHeaders', {})
if common_headers:
mail_details.append({
'from': ses_data.get('mail', {}).get('source'),
'to': common_headers.get('to'),
'subject': common_headers.get('subject')
})
return mail_details


def lambda_handler(event, context):
"""
This lambda function is to approve the user budget by Email Receiving
:param event:
:param context:
:return:
"""
try:
parameters = ssm_client.get_parameters(Names=[JIRA_TOKEN, JIRA_PROJECT, JIRA_API_SERVER], WithDecryption=True)['Parameters']
if parameters:
output_parameters = {}
for parameter in parameters:
output_parameters[parameter.get('Name')] = parameter.get('Value')
jira_auth_token = output_parameters.get(JIRA_TOKEN)
jira_server_api = output_parameters.get(JIRA_API_SERVER)
jira_project = output_parameters.get(JIRA_PROJECT)
jira_conn = jira.JIRA(server=jira_server_api, token_auth=jira_auth_token)
mail_results = get_receive_mail_details(event)
for mail_result in mail_results:
action, ticket = mail_result.get('subject').split(';')
manager_mail = mail_result.get('from')
ticket_id = f'{jira_project}-{ticket}'
issue = jira_conn.issue(id=ticket_id)
jira_description = jira_conn.issue(ticket_id).fields.description
fields = {}
for filed_value in jira_description.split('\n'):
if filed_value:
if ':' in filed_value:
key, value = filed_value.strip().split(':', 1)
fields[key.strip()] = value.strip()
CRO_ADMINS.append(fields.get('ManagerApprovalAddress'))
if manager_mail in CRO_ADMINS:
jira_description += f'\nApprovedManager: {mail_result.get("from")}\n'
if action.upper() == APPROVED:
issue.update(description=jira_description, comment=f'From: {manager_mail}\nApproved\nPlease refer to your manager, in case any issues')
jira_conn.transition_issue(issue=ticket_id, transition=REFINEMENT)
return {
'statusCode': 204,
'body': json.dumps(f'Approved the TicketId: {ticket}, by Manager: {manager_mail}')
}
else:
if action.upper() == REJECT:
jira_conn.transition_issue(issue=ticket_id, transition=CLOSED, comment=f'From: {manager_mail}\nRejected\nPlease refer to your manager, in case any issues')
return {
'statusCode': 204,
'body': json.dumps(f'Rejected the TicketId: {ticket}, by Manager: {manager_mail}')
}
else:
issue.update(comment=f'From: {manager_mail}\n{manager_mail.split("@")[0]} is not authorized to perform this action')
return {
'statusCode': 500,
'body': json.dumps(f'{manager_mail} is not authorized to perform this action')
}

else:
return {
'statusCode': 400,
'body': json.dumps(f'Jira Token not found in the parameter store')
}
except Exception as err:
return {
'statusCode': 500,
'body': json.dumps(f'Something went wrong {err}')
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
boto3==1.26.1
jira~=3.4.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
PROJECT_NAME="CloudResourceOrchestration"
SUCCESS_OUTPUT_PATH="/dev/null"
AWS_DEFAULT_REGION="us-east-1"
echo "Clearing if previously created zip file"

PROJECT_PATH="$PWD/$PROJECT_NAME.zip"

if [ -f $PROJECT_PATH ]; then
rm -rf $PROJECT_PATH
rm -rf ./package
echo "Deleted Previously created zip file"
fi

pip install --target ./package -r requirements.txt > $SUCCESS_OUTPUT_PATH
pushd package
zip -r ../$PROJECT_NAME.zip . > $SUCCESS_OUTPUT_PATH
popd
zip -g $PROJECT_NAME.zip lambda_function.py > $SUCCESS_OUTPUT_PATH

echo "#############################"
# Uploading to AWS Lambda
echo "Uploading to AWS Lambda install Region: $AWS_DEFAULT_REGION"
aws lambda update-function-code --function-name CloudResourceOrch --zip-file fileb://$PROJECT_PATH --region $AWS_DEFAULT_REGION > $SUCCESS_OUTPUT_PATH
echo "Uploaded to AWS Lambda"
echo "#############################"
14 changes: 14 additions & 0 deletions cloud_governance/cloud_resource_orchestration/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
## Cloud Resource Orchestration

This is the process to control costs on public clouds. \
This process requires the data how many days a project will run and estimated_cost. \
Details are collected from the front end page @[https://cloud-governance.rdu2.scalelab.redhat.com/](https://cloud-governance.rdu2.scalelab.redhat.com/)
After filling the form, mail sent to manager for approval after approved your request.
Tag your instances with TicketId: #ticket_number. \
Then cloud_governance will start **cloud_resource_orchestration** and monitor your instances.

To start **cloud_resource_orchestration** CI run the below podman command

```commandline
podman run --net="host" --rm --name cloud_resource_orchestration -e AWS_DEFAULT_REGION="ap-south-1" -e CLOUD_RESOURCE_ORCHESTRATION="True" -e account="$account" -e AWS_ACCESS_KEY_ID="$AWS_ACCESS_KEY_ID" -e AWS_SECRET_ACCESS_KEY="$AWS_SECRET_ACCESS_KEY" -e PUBLIC_CLOUD_NAME="$PUBLIC_CLOUD_NAME" -e es_host="$ES_HOST" -e es_port="$ES_PORT" -e CRO_ES_INDEX="$CRO_ES_INDEX" -e log_level="INFO" -e LDAP_HOST_NAME="$LDAP_HOST_NAME" -e JIRA_QUEUE="$JIRA_QUEUE" -e JIRA_TOKEN="$JIRA_TOKEN" -e JIRA_USERNAME="$JIRA_USERNAME" -e JIRA_URL="$JIRA_URL" -e CRO_COST_OVER_USAGE="$CRO_COST_OVER_USAGE" -e CRO_PORTAL="$CRO_PORTAL" -e CRO_DEFAULT_ADMINS="$CRO_DEFAULT_ADMINS" -e CRO_REPLACED_USERNAMES="$CRO_REPLACED_USERNAMES" -e CRO_DURATION_DAYS="30" quay.io/ebattat/cloud-governance:latest
```
Loading
Loading