Skip to content

Commit

Permalink
Feature/invalidate cache (#16)
Browse files Browse the repository at this point in the history
feature: invalidate cache for LocalPolicyRetriever

* refactor: rename files to better reflect code that resides in them

* testing: add test cases to verify cache invalidation for LocalPolicyRetriever

At time of creation these tests fail with:
```
=== RUN   TestCacheInvalidationLocalPolicyRetrieverIfPolicyIsChanged
    ./cmd/policy-retrieval_test.go:271: Policy arn:aws:iam::000000000000:role/cache-invalidation2 was updated at 2024-12-14 15:53:10.511022552 +0100 CET m=+0.003016620 and now 2024-12-14 15:53:15.520616568 +0100 CET m=+5.012610662 policy manager still sees {
                "Version": "2012-10-17",
                "Statement": [
                        {
                                "Effect": "Allow",
                                "Action": "s3:*",
                                "Resource": "*",
                                "Condition" : {
                                                "StringLike" : {
                                                                "aws:RequestedRegion": "tst-1"
                                                }
                                }
                        }
                ]
        }
--- FAIL: TestCacheInvalidationLocalPolicyRetrieverIfPolicyIsChanged (5.01s)
```
and
```
=== RUN   TestCacheInvalidationLocalPolicyRetrieverIfPolicyIsChanged
    ./cmd/policy-retrieval_test.go:271: Policy arn:aws:iam::000000000000:role/cache-invalidation2 was updated at 2024-12-14 15:53:10.511022552 +0100 CET m=+0.003016620 and now 2024-12-14 15:53:15.520616568 +0100 CET m=+5.012610662 policy manager still sees {
                "Version": "2012-10-17",
                "Statement": [
                        {
                                "Effect": "Allow",
                                "Action": "s3:*",
                                "Resource": "*",
                                "Condition" : {
                                                "StringLike" : {
                                                                "aws:RequestedRegion": "tst-1"
                                                }
                                }
                        }
                ]
        }
--- FAIL: TestCacheInvalidationLocalPolicyRetrieverIfPolicyIsChanged (5.01s)
```

These tests are expected to pass with proper cache invalidation and they also would take less long. If cache invalidation would take longer than 5 seconds that variable can be further tuned but a higher value would also impact user experience.

* feature: localPolicyRetriever cache invalidation [#15]

* lint: add error checking of write for test case

---------

Co-authored-by: Peter Van Bouwel <peter.vanbouwel@vito.be>
  • Loading branch information
pvbouwel and Peter Van Bouwel authored Dec 17, 2024
1 parent f2e0a5c commit cdeab87
Show file tree
Hide file tree
Showing 4 changed files with 485 additions and 186 deletions.
185 changes: 0 additions & 185 deletions cmd/policy-generation.go

This file was deleted.

Loading

0 comments on commit cdeab87

Please sign in to comment.