Skip to content

Commit a6061ee

Browse files
authored
Merge pull request #163 from unity-sds/mcp-clone
Implement CI/CD system deployable to dev/test/prod shared environments.
2 parents bc07f0d + f901c36 commit a6061ee

12 files changed

+2300
-327
lines changed

ci_cd/Dev/main.tf

Lines changed: 560 additions & 0 deletions
Large diffs are not rendered by default.

ci_cd/Prod/main.tf

Lines changed: 560 additions & 0 deletions
Large diffs are not rendered by default.

ci_cd/Test/main.tf

Lines changed: 560 additions & 0 deletions
Large diffs are not rendered by default.
48.7 KB
Binary file not shown.

ci_cd/lambda_function.py renamed to ci_cd/code/lambda_function.py

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import json
22
import os
33
import subprocess
4+
import jwt
45

56
import boto3
67
from botocore.exceptions import ClientError
78

89

910
def get_secret():
10-
1111
secret_name = "MCP-GLU-Clone"
1212
region_name = "us-west-2"
1313

@@ -33,6 +33,20 @@ def get_secret():
3333
return mcp_glu_id, mcp_glu_access_token, mcp_glu_trigger_token
3434

3535

36+
def get_end_user_info(event):
37+
cgroup = None
38+
cuser = None
39+
try:
40+
if (event['headers']) and (event['headers']['Authorization']) and (event['headers']['Authorization'] != None):
41+
cog_auth_token = event['headers']['Authorization'].split(' ')[1]
42+
jwt_dict = jwt.decode(cog_auth_token, options={"verify_signature": False})
43+
cgroup = jwt_dict['cognito:groups']
44+
cuser = jwt_dict['username']
45+
except KeyError:
46+
print('No cognito authorization token')
47+
return cuser, cgroup
48+
49+
3650
def lambda_handler(event, context):
3751
# TODO implement
3852
id, token, ttoken = get_secret()
@@ -89,16 +103,35 @@ def lambda_handler(event, context):
89103
clone_url = body[my_key]
90104
except KeyError:
91105
print('No clone_url')
92-
93-
curl_cmd_p = 'curl -X POST --fail ' \
94-
'-F token={0} ' \
95-
'-F "ref=main" ' \
96-
'-F "variables[MCP_GLU_ID_ES]={1}" ' \
97-
'-F "variables[MCP_ACCESS_TOKEN_ES]={2}" ' \
98-
'-F "variables[PROJ_TO_CLONE]={3}" ' \
99-
'https://gitlab.mcp.nasa.gov/api/v4/projects/341/trigger/pipeline'
100-
curl_cmd = curl_cmd_p.format(ttoken, id, token, clone_url)
106+
107+
cuser, cgroups = get_end_user_info(event)
108+
no_subgroup = True
109+
if (cuser == None) or no_subgroup:
110+
curl_cmd_p = 'curl -X POST --fail ' \
111+
'-F token={0} ' \
112+
'-F "ref=main" ' \
113+
'-F "variables[MCP_GLU_ID_ES]={1}" ' \
114+
'-F "variables[MCP_ACCESS_TOKEN_ES]={2}" ' \
115+
'-F "variables[PROJ_TO_CLONE]={3}" ' \
116+
'https://gitlab.mcp.nasa.gov/api/v4/projects/341/trigger/pipeline'
117+
curl_cmd = curl_cmd_p.format(ttoken, id, token, clone_url)
118+
else:
119+
curl_cmd_p = 'curl -X POST --fail ' \
120+
'-F token={0} ' \
121+
'-F "ref=main" ' \
122+
'-F "variables[MCP_GLU_ID_ES]={1}" ' \
123+
'-F "variables[MCP_ACCESS_TOKEN_ES]={2}" ' \
124+
'-F "variables[PROJ_TO_CLONE]={3}" ' \
125+
'-F "variables[SGROUP]={4}" ' \
126+
'https://gitlab.mcp.nasa.gov/api/v4/projects/341/trigger/pipeline'
127+
curl_cmd = curl_cmd_p.format(ttoken, id, token, clone_url, cuser)
128+
101129
cprocess = subprocess.run(curl_cmd, shell=True, capture_output=True, text=True)
130+
print('========v unity-mcp-clone trigger stdout')
131+
print(cprocess.stdout)
132+
print('========v unity-mcp-clone trigger stderr')
133+
print(cprocess.stderr)
134+
print('========')
102135

103136
response_body = {}
104137
response_body['clone_url'] = clone_url

ci_cd/gl_executor_ids.tf

Lines changed: 0 additions & 5 deletions
This file was deleted.

ci_cd/main.tf

Lines changed: 0 additions & 312 deletions
This file was deleted.

0 commit comments

Comments
 (0)