1 |
|
2 | import { IConfigParseResult } from '../libs/config-parse-result';
|
3 | import {
|
4 | IPlugin, forwardChildWebpackConfigs, forwardChildPostBuilds,
|
5 | forwardChildIamRoleStatements
|
6 | } from '../libs/plugin';
|
7 | import {isAuthentication, getProviderKey, getClientSecret, AuthenticationProvider} from './authentication-component';
|
8 | import * as deepmerge from 'deepmerge';
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | export interface IIdentityPlugin {
|
14 |
|
15 | }
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | export 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 |
|
31 |
|
32 | process: (component:any,
|
33 | childConfigs:Array<IConfigParseResult>,
|
34 | infrastructureMode:string | undefined
|
35 | ):IConfigParseResult => {
|
36 |
|
37 |
|
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 |
|
67 | webpackConfigs: forwardChildWebpackConfigs(childConfigs),
|
68 |
|
69 | postBuilds: forwardChildPostBuilds(childConfigs),
|
70 |
|
71 | iamRoleStatements: iamRoleStatements
|
72 |
|
73 | |
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 | }
|
94 | }
|
95 | };
|
96 |
|
97 |
|
98 | return result;
|
99 |
|
100 | }; |
\ | No newline at end of file |