File tree Expand file tree Collapse file tree 3 files changed +5
-6
lines changed Expand file tree Collapse file tree 3 files changed +5
-6
lines changed Original file line number Diff line number Diff line change @@ -912,7 +912,7 @@ To enable this example pre-hook:
912912- In the serverless.yml file, uncomment the `preHook` function, the `preHook` IAM
913913 permissions, and the environment variables `PRE_HOOK` and `API_KEYS_SECRET_ID`
914914- Create a Secrets Manager secret with the name used in `API_KEYS_SECRET_ID` with
915- the keys as the strings allowed for API Keys and the values as `read `.
915+ the keys as the strings allowed for API Keys and the values as an array `["write"] `.
916916- Build and deploy.
917917
918918# ## Post-Hook
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ const response401 = {
1313}
1414
1515// eslint-disable-next-line import/no-mutable-exports
16- export let apiKeys = new Map ( )
16+ export let apiKeys = new Map ( ) // string -> string[]
1717
1818const updateApiKeys = async ( ) => {
1919 await new SecretsManagerClient ( { region : process . env [ 'AWS_REGION' ] || 'us-west-2' } )
@@ -35,8 +35,7 @@ const updateApiKeys = async () => {
3535 } )
3636}
3737
38- const READ = [ 'read' ]
39- const isValidReadToken = ( token ) => READ . includes ( apiKeys . get ( token ) )
38+ const isValidToken = ( token ) => ( apiKeys . get ( token ) || [ ] ) . includes ( 'write' )
4039
4140export const handler = async ( event , _context ) => {
4241 let token = null
@@ -54,7 +53,7 @@ export const handler = async (event, _context) => {
5453 await updateApiKeys ( )
5554 }
5655
57- if ( isValidReadToken ( token ) ) {
56+ if ( isValidToken ( token ) ) {
5857 return event
5958 }
6059
Original file line number Diff line number Diff line change @@ -90,7 +90,7 @@ test.serial('authenticate cases', async (t) => {
9090 // @ts -ignore
9191 . on ( GetSecretValueCommand )
9292 // @ts -ignore
93- . resolves ( { SecretString : JSON . stringify ( { ABC : 'read' , DEF : 'other' } ) } )
93+ . resolves ( { SecretString : JSON . stringify ( { ABC : [ 'write' ] , DEF : [ 'other' ] } ) } )
9494
9595 const event = { ...DEFAULT_EVENT }
9696 const context = { ...DEFAULT_CONTEXT }
You can’t perform that action at this time.
0 commit comments