File tree 3 files changed +5
-6
lines changed
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:
912
912
- In the serverless.yml file, uncomment the `preHook` function, the `preHook` IAM
913
913
permissions, and the environment variables `PRE_HOOK` and `API_KEYS_SECRET_ID`
914
914
- 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"] `.
916
916
- Build and deploy.
917
917
918
918
# ## Post-Hook
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ const response401 = {
13
13
}
14
14
15
15
// eslint-disable-next-line import/no-mutable-exports
16
- export let apiKeys = new Map ( )
16
+ export let apiKeys = new Map ( ) // string -> string[]
17
17
18
18
const updateApiKeys = async ( ) => {
19
19
await new SecretsManagerClient ( { region : process . env [ 'AWS_REGION' ] || 'us-west-2' } )
@@ -35,8 +35,7 @@ const updateApiKeys = async () => {
35
35
} )
36
36
}
37
37
38
- const READ = [ 'read' ]
39
- const isValidReadToken = ( token ) => READ . includes ( apiKeys . get ( token ) )
38
+ const isValidToken = ( token ) => ( apiKeys . get ( token ) || [ ] ) . includes ( 'write' )
40
39
41
40
export const handler = async ( event , _context ) => {
42
41
let token = null
@@ -54,7 +53,7 @@ export const handler = async (event, _context) => {
54
53
await updateApiKeys ( )
55
54
}
56
55
57
- if ( isValidReadToken ( token ) ) {
56
+ if ( isValidToken ( token ) ) {
58
57
return event
59
58
}
60
59
Original file line number Diff line number Diff line change @@ -90,7 +90,7 @@ test.serial('authenticate cases', async (t) => {
90
90
// @ts -ignore
91
91
. on ( GetSecretValueCommand )
92
92
// @ts -ignore
93
- . resolves ( { SecretString : JSON . stringify ( { ABC : 'read' , DEF : 'other' } ) } )
93
+ . resolves ( { SecretString : JSON . stringify ( { ABC : [ 'write' ] , DEF : [ 'other' ] } ) } )
94
94
95
95
const event = { ...DEFAULT_EVENT }
96
96
const context = { ...DEFAULT_CONTEXT }
You can’t perform that action at this time.
0 commit comments