UNPKG

3.01 kBPlain TextView Raw
1
2import { IConfigParseResult } from '../libs/config-parse-result';
3import {
4 IPlugin, forwardChildWebpackConfigs, forwardChildPostBuilds,
5 forwardChildIamRoleStatements
6} from '../libs/plugin';
7import {isAuthentication, getProviderKey, getClientSecret, AuthenticationProvider} from './authentication-component';
8import * as deepmerge from 'deepmerge';
9
10/**
11 * Parameters that apply to the whole Plugin, passed by other plugins
12 */
13export interface IIdentityPlugin {
14
15}
16
17/**
18 * We require an AuthenticationPlugin to forward the configuration from lower level webapps
19 * TODO: refactor so that we don't need such dummy plugins!
20 */
21export const AuthenticationPlugin = (props: IIdentityPlugin): IPlugin => {
22 const path = require('path');
23
24 const result: IPlugin = {
25 applies: (component):boolean => {
26
27 return isAuthentication(component);
28 },
29
30 // convert the component into configuration parts
31 // while the component is of Type `any`, its props must be of type `IDataLayerArgs` | `IDataLayerProps`
32 process: (component:any,
33 childConfigs:Array<IConfigParseResult>,
34 infrastructureMode:string | undefined
35 ):IConfigParseResult => {
36
37 // we need to environment variable
38 const slsEnv = {
39 provider: {
40 environment: {
41 }
42
43 }
44 };
45 slsEnv.provider.environment[getProviderKey(component.provider)] = getClientSecret(component.provider);
46
47 console.log("slsEnv: ", slsEnv)
48
49 const iamRoleStatements = [
50 component.provider === AuthenticationProvider.EMAIL ? {
51 Effect: "Allow",
52 Action: [
53 "ses:SendEmail"
54 ],
55 Resource: [
56 '"arn:aws:ses:${self:provider.region}:*:identity/'+`${component.senderEmail}"`
57 ]
58 } : {}
59 ].concat(forwardChildIamRoleStatements(childConfigs));
60
61
62 return {
63
64 slsConfigs: deepmerge.all([slsEnv].concat(childConfigs.map(config => config.slsConfigs)) ),
65
66 // add the server config
67 webpackConfigs: forwardChildWebpackConfigs(childConfigs),
68
69 postBuilds: forwardChildPostBuilds(childConfigs),
70
71 iamRoleStatements: iamRoleStatements
72
73 /* THESE VALUES MUST NOT BE PROVIDED BY A CHILD, THEY ARE NOT FORWARED UPWARDS
74
75 environments: environments,
76
77 //stackName: component.stackName,
78
79 assetsPath: component.assetsPath,
80
81 buildPath: component.buildPath,
82
83 region: component.region,
84
85 domain: domain,
86
87 certArn: certArn,
88
89 supportOfflineStart: true,
90
91 supportCreateDomain: true
92 */
93 }
94 }
95 };
96
97
98 return result;
99
100};
\No newline at end of file