Skip to content

Commit 9d61c5a

Browse files
authored
add environments to api (#23)
1 parent fbfcf72 commit 9d61c5a

8 files changed

Lines changed: 69 additions & 4 deletions

File tree

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,14 @@ Send JSON in this format:
262262
"main": [],
263263
"others": ["List of strings"]
264264
},
265+
"environments": {
266+
"dev": "Boolean",
267+
"int": "Boolean",
268+
"uat": "Boolean",
269+
"preprod": "Boolean",
270+
"prod": "Boolean",
271+
"postprod": "Boolean",
272+
},
265273
"infrastructure": {
266274
"main": [],
267275
"others": ["List of strings"]
@@ -417,6 +425,14 @@ Send JSON in this format:
417425
"main": [],
418426
"others": ["List of strings"]
419427
},
428+
"environments": {
429+
"dev": "Boolean",
430+
"int": "Boolean",
431+
"uat": "Boolean",
432+
"preprod": "Boolean",
433+
"prod": "Boolean",
434+
"postprod": "Boolean",
435+
},
420436
"infrastructure": {
421437
"main": [],
422438
"others": ["List of strings"]
@@ -475,7 +491,7 @@ Send JSON in this format:
475491
}
476492
}
477493
```
478-
Edits a project by checking if the languages, database, frameworks, cicd, infrastructure, or source control are missing from the `array_data.json` bucket. If any are missing, they are added.
494+
Edits a project by checking if the languages, database, frameworks, cicd, environments, infrastructure, publishing or source control are missing from the `array_data.json` bucket. If any are missing, they are added.
479495

480496

481497
## Authorization with Cognito and API Gateway

aws_lambda_script/app/api_models.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,19 @@ def get_project_model():
159159
},
160160
)
161161
),
162+
"environments": fields.Nested(
163+
ns.model(
164+
"environments",
165+
{
166+
"dev": fields.Boolean(required=False, description="Development environment status"),
167+
"int": fields.Boolean(required=False, description="Integration environment status"),
168+
"uat": fields.Boolean(required=False, description="User Acceptance Testing environment status"),
169+
"preprod": fields.Boolean(required=False, description="Pre-production or staging environment status"),
170+
"prod": fields.Boolean(required=False, description="Production environment status"),
171+
"postprod": fields.Boolean(required=False, description="Post-production environment status")
172+
}
173+
)
174+
),
162175
"infrastructure": fields.Nested(
163176
ns.model(
164177
"Infrastructure",

aws_lambda_script/app/resources.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
required_param = {"Authorization": "ID Token required"}
3131

3232
# Set logger for AWS cloudwatch to return just errors
33-
logging.basicConfig(level=logging.DEBUG)
33+
logging.basicConfig(level=logging.INFO)
3434
logger = logging.getLogger(__name__)
3535

3636

@@ -250,6 +250,7 @@ def get(self):
250250
"database": ["architecture", "database"],
251251
"frameworks": ["architecture", "frameworks"],
252252
"cicd": ["architecture", "CICD"],
253+
"environments": ["architecture", "environments"],
253254
"infrastructure": ["architecture", "infrastructure"],
254255
"publishing": ["architecture", "publishing"],
255256
}
@@ -386,6 +387,14 @@ def post(self):
386387
{"email": owner_email, "roles": ["Editor"], "grade": ""}
387388
)
388389

390+
# Validate environments
391+
environments = new_project.get("architecture", {}).get("environments", {})
392+
if not isinstance(environments, dict):
393+
abort(400, description="Invalid environments data: Must be a dictionary")
394+
for key in ["dev", "int", "uat", "preprod", "prod", "postprod"]:
395+
if key not in environments or not isinstance(environments[key], bool):
396+
abort(400, description=f"Invalid environments data: '{key}' must be a boolean")
397+
389398
data = read_data("new_project_data.json")
390399

391400
# Check if project with same name exists and has any matching user emails
@@ -477,6 +486,15 @@ def put(self, project_name):
477486
logger.error("Missing JSON data")
478487
abort(406, description="Missing JSON data")
479488

489+
# Validate environments
490+
environments = updated_project.get("architecture", {}).get("environments", {})
491+
if not isinstance(environments, dict):
492+
abort(400, description="Invalid environments data: Must be a dictionary")
493+
for key in ["dev", "int", "uat", "preprod", "prod", "postprod"]:
494+
if key not in environments or not isinstance(environments[key], bool):
495+
abort(400, description=f"Invalid environments data: '{key}' must be a boolean")
496+
497+
480498
# Ensure the email is set to owner_email
481499

482500
data = read_data("new_project_data.json")
@@ -663,4 +681,4 @@ def exchange_code_for_tokens(code):
663681
raise Exception(f"Error: {response.status_code}, {response.json()}")
664682

665683
# Return the parsed JSON response
666-
return response.json()
684+
return response.json()

aws_lambda_script/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
app = create_app()
66

77
logger = logging.getLogger()
8-
logger.setLevel(logging.DEBUG)
8+
logger.setLevel(logging.INFO)
99

1010
def lambda_handler(event, context):
1111
"""

docs/endpoints/filter.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Requires a valid Cognito ID token in the Authorization header.
2828
| `database` | string | Database types to filter by (comma-separated) | False |
2929
| `frameworks` | string | Frameworks to filter by (comma-separated) | False |
3030
| `cicd` | string | CI/CD tools to filter by (comma-separated) | False |
31+
| `environments` | dict | List of environments that project are deployed | False |
3132
| `infrastructure` | string | Infrastructure tools to filter by (comma-separated) | False |
3233
| `publishing` | string | Publishing target to filter by (comma-separated) | False |
3334
| `return` | string | Sections to return in response (user, details, developed, source_control, architecture) | False |

docs/endpoints/project.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,14 @@ Requires a valid Cognito ID token in the Authorization header.
135135
"string"
136136
]
137137
},
138+
"environments": {
139+
"dev": "Boolean",
140+
"int": "Boolean",
141+
"uat": "Boolean",
142+
"preprod": "Boolean",
143+
"prod": "Boolean",
144+
"postprod": "Boolean",
145+
},
138146
"infrastructure": {
139147
"main": [
140148
"string"

docs/endpoints/projects.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,14 @@ Requires a valid Cognito ID token in the Authorization header.
122122
"string"
123123
]
124124
},
125+
"environments": {
126+
"dev": "Boolean",
127+
"int": "Boolean",
128+
"uat": "Boolean",
129+
"preprod": "Boolean",
130+
"prod": "Boolean",
131+
"postprod": "Boolean",
132+
},
125133
"infrastructure": {
126134
"main": [
127135
"string"

testing/test_api.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ def test_post_and_get_project_with_timestamp(
133133
"languages": {"main": ["Python"], "others": ["JavaScript", "Java"]},
134134
"frameworks": {"main": [], "others": ["Flask"]},
135135
"cicd": {"main": [], "others": ["Github Actions"]},
136+
"environments": { "dev": True, "int": False, "uat": False, "preprod": True, "prod": True, "postprod": False },
136137
"infrastructure": {"main": [], "others": ["Jenkins"]},
137138
"publishing": {"main": [], "others": ["Pypi"]},
138139
},

0 commit comments

Comments
 (0)