-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
53 lines (39 loc) · 1.29 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
class Logless {
serverless: any
options: any
provider: string
hooks: {[hook: string]: () => void}
constructor(serverless: any, options: any) {
this.serverless = serverless
this.options = options
this.provider = 'aws';
this.hooks = {
'after:package:compileFunctions': this.configLogRetention,
}
}
configLogRetention = () => {
if (this.do) {
this.serverless.cli.log(`Configurating CloudWatch log retention`);
let Resources = this.serverless.service.provider.compiledCloudFormationTemplate.Resources;
this.serverless.service.getAllFunctions().forEach( (name: string) => {
let logGroup = `${name}LogGroup`;
if (Resources[logGroup]) {
this.serverless.cli.log(`Configurating ${logGroup} RetentionInDays: ${this.config.logRetention}`);
Resources[logGroup].Properties.RetentionInDays = this.config.logRetention
}
});
}
}
get do() {
return this.serverless.service.custom && this.serverless.service.custom.logless && this.serverless.service.custom.logless.logRetention
}
get config() {
if (this.do) {
return this.serverless.service.custom.logless;
} else {
this.serverless.cli.log(`No configuration found for Logless`);
return {};
}
}
}
export = Logless;