Skip to content

Commit

Permalink
Cast MaxAgeSeconds as int in custom resource (#21)
Browse files Browse the repository at this point in the history
* Cast max age as int in CR

* Update workflow and add logging

* Fixed maxage int updating
  • Loading branch information
tarunmenon95 authored May 24, 2023
1 parent 7bd769f commit be131f5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 21 deletions.
23 changes: 3 additions & 20 deletions .github/workflows/rspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,6 @@ name: cftest
on: [push, pull_request]

jobs:
test:
name: test
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: set up ruby 2.7
uses: actions/setup-ruby@v1
with:
ruby-version: 2.7.x
- name: install gems
run: gem install cfhighlander rspec
- name: set cfndsl spec
run: cfndsl -u
- name: cftest
run: rspec
env:
AWS_ACCESS_KEY: ${{ secrets.AWS_ACCESS_KEY }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: ap-southeast-2
rspec:
uses: theonestack/shared-workflows/.github/workflows/rspec.yaml@main
secrets: inherit
14 changes: 13 additions & 1 deletion lambdas/s3_bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,19 @@ def delete_notification(Bucket):
def add_cors(cors_configuration, bucket_name):
bucket_cors = s3r.BucketCors(bucket_name)
cors_rules = []

# Update MaxAgeSeconds to int if provided
if 'CorsRules' in cors_configuration and len(cors_configuration['CorsRules']) > 0:
for cors_rule in cors_configuration['CorsRules']:
if 'MaxAgeSeconds' in cors_rule:
try:
cors_rule['MaxAgeSeconds'] = int(cors_rule['MaxAgeSeconds'])
except ValueError:
print("Unable to convert MaxAgeSeconds to an integer.")
else:
print("CorsRules key not found.")

print(f"Cors Configuration: {cors_configuration}")

bucket_cors.put(
CORSConfiguration={
Expand All @@ -171,7 +184,6 @@ def add_cors(cors_configuration, bucket_name):
)
print(f"Put cors configuration request completed... for {bucket_name} :)")


def delete_cors(bucket_name):
bucket_cors = s3r.BucketCors(bucket_name)
response = bucket_cors.delete()
Expand Down

0 comments on commit be131f5

Please sign in to comment.