Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
rarylson committed Nov 5, 2022
2 parents 73a4dc2 + b4018fc commit 698a105
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 3 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ update-conf-py-DO-NOT-USE
>
> Also, the code will be stored into 2 repos: CodeCommit, to better test the full AWS Code\* stack; GitHub, as Coveralls free plan only supports it.
TODO: ![](https://img.shields.io/badge/tests-passing-green.svg?logo=amazonaws&color=44cc11)

[![Test Status](https://codebuild.us-east-1.amazonaws.com/badges?uuid=eyJlbmNyeXB0ZWREYXRhIjoiOWZsM0ZQeXEwTWtXd3dIc3cyVFZBcFducUE3NVgrODduT21lMTRrUzMzRXJuQTFrS1oxd1pNcmZhalZscDFWSS9KNHFMQjNDSGdaUWJ1WDA5Vm44VzFnPSIsIml2UGFyYW1ldGVyU3BlYyI6Img0VkhSNlVkOG1HZUIrMGEiLCJtYXRlcmlhbFNldFNlcmlhbCI6MX0%3D&branch=master)](https://us-east-1.console.aws.amazon.com/codesuite/codebuild/projects/update-conf-py-DO-NOT-USE-tests/)
[![Test Status](https://img.shields.io/endpoint?label=tests&logo=amazonaws&url=https%3A%2F%2Fkpa3zv4xkp3bpxpanhpwly7keu0rxzcd.lambda-url.us-east-1.on.aws%2Fupdate-conf-py-DO-NOT-USE-tests)](https://us-east-1.console.aws.amazon.com/codesuite/codebuild/projects/update-conf-py-DO-NOT-USE-tests/)
[![Coverage Status](https://img.shields.io/coveralls/github/rarylson/update-conf-py-DO-NOT-USE/HEAD?logo=coveralls)](https://coveralls.io/github/rarylson/update-conf-py-DO-NOT-USE)
[![PyPI - Python](https://img.shields.io/pypi/pyversions/update-conf.py?logo=python&logoColor=white)](https://pypi.python.org/pypi/update-conf.py/)
[![PyPI - Downloads](https://img.shields.io/pypi/dm/update-conf.py.svg)](https://pypi.python.org/pypi/update-conf.py/)
[![PyPI - Version](https://img.shields.io/pypi/v/update-conf.py.svg)](https://pypi.python.org/pypi/update-conf.py/)
[![License](https://img.shields.io/pypi/l/update-conf.py.svg)](LICENSE)

> Default CodeBuild badge: [![Test Status](https://codebuild.us-east-1.amazonaws.com/badges?uuid=eyJlbmNyeXB0ZWREYXRhIjoiOWZsM0ZQeXEwTWtXd3dIc3cyVFZBcFducUE3NVgrODduT21lMTRrUzMzRXJuQTFrS1oxd1pNcmZhalZscDFWSS9KNHFMQjNDSGdaUWJ1WDA5Vm44VzFnPSIsIml2UGFyYW1ldGVyU3BlYyI6Img0VkhSNlVkOG1HZUIrMGEiLCJtYXRlcmlhbFNldFNlcmlhbCI6MX0%3D&branch=master)](https://us-east-1.console.aws.amazon.com/codesuite/codebuild/projects/update-conf-py-DO-NOT-USE-tests/)
Generate config files from `conf.d` like directories.

Split your config file into smaller files, called snippets, in a `conf.d` like directory. The generated config file will be the concatenation of all snippets, with snippets ordered by the lexical order of their names.
Expand Down
32 changes: 32 additions & 0 deletions extras/lambda/codebuild-badges-api/iam-role-template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowCreateLogGroup",
"Effect": "Allow",
"Action": "logs:CreateLogGroup",
"Resource": "arn:aws:logs:us-east-1:{AWS_ACCOUNT}:*"
},
{
"Sid": "AllowPutLogEvents",
"Effect": "Allow",
"Action": [
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": [
"arn:aws:logs:us-east-1:{AWS_ACCOUNT}:log-group:/aws/lambda/{LAMBDA_FUNCTION}:*"
]
},
{
"Sid": "AllowGetItemDynamoDBTable",
"Effect": "Allow",
"Action": [
"dynamodb:GetItem"
],
"Resource": [
"arn:aws:dynamodb:us-east-1:{AWS_ACCOUNT}:table/{DYNAMODB_TABLE}"
]
}
]
}
56 changes: 56 additions & 0 deletions extras/lambda/codebuild-badges-api/lambda_function.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
""" Return CodeBuild build status information for API integration with
shields.io
"""

import json
import os

import boto3


def lambda_handler(event, context):
if event["requestContext"]["http"]["method"] == "GET":
build_project = event["requestContext"]["http"]["path"].split("/")[1]
return {
'statusCode': 200,
'body': get_shields_io_json(build_project)
}
else:
return {
'statusCode': 405
}


def get_shields_io_json(build_project):
dynamodb_client = boto3.client("dynamodb")

# Get build_status
response = dynamodb_client.get_item(
TableName=os.environ["DYNAMODB_TABLE"],
Key={"build_project": {"S": build_project}}
)
try:
build_status = response["Item"]["build_status"]["S"]
except KeyError:
build_status = None

# Map build status to message/color
if build_status == "SUCCEEDED":
message = "passing"
color = "success"
elif build_status == "FAILED":
message = "failing"
color = "critical"
else:
message = "no status"
color = "inactive"

# Return JSON in the format expected by shields.io
# See: https://shields.io/endpoint
return json.dumps({
"schemaVersion": 1,
"label": build_project,
"message": message,
"color": color
}, indent=4)

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"source": ["aws.codebuild"],
"detail-type": ["CodeBuild Build State Change"],
"detail": {
"build-status": ["SUCCEEDED", "FAILED"],
"project-name": ["{PROJECT_1}", "{PROJECT_2}"]
}
}
32 changes: 32 additions & 0 deletions extras/lambda/codebuild-badges-eventbridge/iam-role-template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowCreateLogGroup",
"Effect": "Allow",
"Action": "logs:CreateLogGroup",
"Resource": "arn:aws:logs:us-east-1:{AWS_ACCOUNT}:*"
},
{
"Sid": "AllowPutLogEvents",
"Effect": "Allow",
"Action": [
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": [
"arn:aws:logs:us-east-1:{AWS_ACCOUNT}:log-group:/aws/lambda/{LAMBDA_FUNCTION}:*"
]
},
{
"Sid": "AllowPutItemDynamoDBTable",
"Effect": "Allow",
"Action": [
"dynamodb:PutItem"
],
"Resource": [
"arn:aws:dynamodb:us-east-1:{AWS_ACCOUNT}:table/{DYNAMODB_TABLE}"
]
}
]
}
28 changes: 28 additions & 0 deletions extras/lambda/codebuild-badges-eventbridge/lambda_function.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
""" Update build status information from CodeBuild EventBridge events
"""

import os

import boto3


def lambda_handler(event, context):
if (event["detail-type"] == "CodeBuild Build State Change"
and event["detail"]["build-status"] in ["SUCCEEDED", "FAILED"]):
set_build_status(
event["detail"]["project-name"],
event["detail"]["build-status"]
)


def set_build_status(build_project, build_status):
dynamodb_client = boto3.client("dynamodb")

dynamodb_client.put_item(
TableName=os.environ["DYNAMODB_TABLE"],
Item={
"build_project": {"S": build_project},
"build_status": {"S": build_status}
}
)

0 comments on commit 698a105

Please sign in to comment.