Skip to content

Commit

Permalink
tweaks and fixes related to api key creation
Browse files Browse the repository at this point in the history
  • Loading branch information
SachinShekhar committed May 9, 2020
1 parent de66925 commit f4f8957
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ export interface AuthorizationMode {
*/
readonly userPoolConfig?: UserPoolConfig;
/**
* If authorizationType is `AuthorizationType.API_KEY`, this option can be confogured.
* If authorizationType is `AuthorizationType.API_KEY`, this option can be configured. If AuthorizationType.API_KEY` is in `additionalAuthorizationModes`, this option is required.
*/
readonly apiKeyConfig?: ApiKeyConfig;
/**
* If authorizationType is `AuthorizationType.OIDC`, this option can be configured.
* If authorizationType is `AuthorizationType.OIDC`, this option is required.
*/
readonly openIdConnectConfig?: OpenIdConnectConfig;
}
Expand Down Expand Up @@ -417,6 +417,15 @@ export class GraphQLApi extends Construct {
'Missing User Pool Configuration inside an additional authorization mode'
);
}

if (
authorizationMode.authorizationType === AuthorizationType.API_KEY &&
!authorizationMode.apiKeyConfig
) {
throw new Error(
'Missing API Key Configuration inside an additional authorization mode'
);
}
}
);
}
Expand Down Expand Up @@ -468,16 +477,8 @@ export class GraphQLApi extends Construct {
): CfnGraphQLApi.AdditionalAuthenticationProviderProperty[] {
return authModes.reduce<
CfnGraphQLApi.AdditionalAuthenticationProviderProperty[]
>((acc, authMode) => {
if (authMode.authorizationType === AuthorizationType.API_KEY) {
const apiKeyConfig: ApiKeyConfig = authMode.apiKeyConfig || {
name: 'DefaultAPIKey',
description: 'Default API Key created by CDK',
};

this.createAPIKey(apiKeyConfig);
}
return [
>(
(acc, authMode) => [
...acc,
{
authenticationType: authMode.authorizationType,
Expand All @@ -490,8 +491,9 @@ export class GraphQLApi extends Construct {
? this.formatOpenIdConnectConfig(authMode.openIdConnectConfig!)
: undefined,
},
];
}, []);
],
[]
);
}

/**
Expand Down

0 comments on commit f4f8957

Please sign in to comment.