From be131f541d495d4fd0ab78c22267312adb88311b Mon Sep 17 00:00:00 2001 From: Tarun Menon <64295670+tarunmenon95@users.noreply.github.com> Date: Wed, 24 May 2023 12:56:54 +1000 Subject: [PATCH] Cast MaxAgeSeconds as int in custom resource (#21) * Cast max age as int in CR * Update workflow and add logging * Fixed maxage int updating --- .github/workflows/rspec.yaml | 23 +++-------------------- lambdas/s3_bucket.py | 14 +++++++++++++- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/.github/workflows/rspec.yaml b/.github/workflows/rspec.yaml index b1ee9a7..d0a2ef8 100644 --- a/.github/workflows/rspec.yaml +++ b/.github/workflows/rspec.yaml @@ -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 \ No newline at end of file + rspec: + uses: theonestack/shared-workflows/.github/workflows/rspec.yaml@main + secrets: inherit \ No newline at end of file diff --git a/lambdas/s3_bucket.py b/lambdas/s3_bucket.py index fa000f6..ac4ad38 100644 --- a/lambdas/s3_bucket.py +++ b/lambdas/s3_bucket.py @@ -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={ @@ -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()