File tree Expand file tree Collapse file tree 6 files changed +49
-11
lines changed Expand file tree Collapse file tree 6 files changed +49
-11
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import { getStackResources } from "../services/stackResources";
77import { padString } from "../utils/padString" ;
88import { lambdaStatisticsModal , lambdaInvokeModal } from "../modals" ;
99import { getLambdaFunctions } from "../services" ;
10+ import { abbreviateFunction } from "../utils/abbreviateFunction" ;
1011
1112const contrib = require ( "blessed-contrib" ) ;
1213const open = require ( "open" ) ;
@@ -256,9 +257,9 @@ class ResourceTable {
256257 this . table . data = lambdaFunctionResources . map ( ( lam ) => {
257258 const funcName = lam . PhysicalResourceId ;
258259 const func = this . lambdaFunctions [ funcName ] ;
259- const shortenedFuncName = lam . PhysicalResourceId . replace (
260- ` ${ this . program . stackName } -` ,
261- ""
260+ const shortenedFuncName = abbreviateFunction (
261+ lam . PhysicalResourceId ,
262+ this . program . stackName
262263 ) ;
263264 this . fullFunctionNames [ shortenedFuncName ] = funcName ;
264265 let timeout = "?" ;
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import {
1212 getStackResources ,
1313 getLambdaFunctions ,
1414} from "../services" ;
15+ import Serverless from "../services/serverless" ;
1516
1617const infoLog = chalk . greenBright ;
1718const titleLog = chalk . greenBright . underline . bold ;
@@ -55,6 +56,8 @@ class GuardianCI {
5556 if ( this . config ) {
5657 this . ignoreConfig = this . config . ignore ;
5758 }
59+
60+ this . SLS = new Serverless ( program . location ) ;
5861 }
5962
6063 async getAllLambdaFunctions ( ) {
@@ -139,7 +142,12 @@ class GuardianCI {
139142 // eslint-disable-next-line no-restricted-syntax
140143 for ( const Check of this . checksToRun ) {
141144 console . group ( ) ;
142- const check = new Check ( this . AWS , this . stackName , this . stackFunctions ) ;
145+ const check = new Check (
146+ this . AWS ,
147+ this . stackName ,
148+ this . stackFunctions ,
149+ this . SLS
150+ ) ;
143151 if ( ! this . ignoreCheck ( check ) ) {
144152 const filteredStack = this . ignoreArns ( check , this . stackFunctions ) ;
145153 check . stackFunctions = filteredStack ;
Original file line number Diff line number Diff line change 1+ import { abbreviateFunction } from "../../../../utils/abbreviateFunction" ;
2+
13class NoDefaultMemory {
2- constructor ( AWS , stackName , stackFunctions ) {
4+ constructor ( AWS , stackName , stackFunctions , SLS ) {
35 this . name = "no-default-memory" ;
46 this . AWS = AWS ;
57 this . stackName = stackName ;
68 this . stackFunctions = stackFunctions ;
79 this . result = false ;
810 this . defaultMemory = 1024 ;
911 this . failingResources = [ ] ;
12+ this . SLS = SLS ;
1013 this . failureMessage =
1114 "The following functions have their memory set as default." ;
1215 this . rulePage =
1316 "See (https://theodo-uk.github.io/sls-dev-tools/docs/no-default-memory) for impact and how to to resolve." ;
1417 }
1518
1619 hasDefaultMemory ( lambdaFunction ) {
17- return lambdaFunction . MemorySize === this . defaultMemory ;
20+ const shortenedName = abbreviateFunction (
21+ lambdaFunction . FunctionName ,
22+ this . stackName
23+ ) ;
24+ return (
25+ lambdaFunction . MemorySize === this . defaultMemory &&
26+ ! this . SLS . getFunctionConfig ( shortenedName ) . memorySize
27+ ) ;
1828 }
1929
2030 async run ( ) {
Original file line number Diff line number Diff line change 1+ import { abbreviateFunction } from "../../../../utils/abbreviateFunction" ;
2+
13class NoDefaultTimeout {
2- constructor ( AWS , stackName , stackFunctions ) {
4+ constructor ( AWS , stackName , stackFunctions , SLS ) {
35 this . name = "no-default-timeout" ;
46 this . AWS = AWS ;
57 this . stackName = stackName ;
@@ -8,17 +10,23 @@ class NoDefaultTimeout {
810 this . defaultTimeoutAWS = 3 ;
911 this . defaultTimeoutServerlessFramework = 6 ;
1012 this . failingResources = [ ] ;
13+ this . SLS = SLS ;
1114 this . failureMessage =
1215 "The following functions have their timeout set as default." ;
1316 this . rulePage =
1417 "See (https://theodo-uk.github.io/sls-dev-tools/docs/no-default-timeout) for impact and how to to resolve." ;
1518 }
1619
1720 hasDefaultTimeout ( lambdaFunction ) {
18- return [
19- this . defaultTimeoutAWS ,
20- this . defaultTimeoutServerlessFramework ,
21- ] . includes ( lambdaFunction . Timeout ) ;
21+ const shortenedName = abbreviateFunction (
22+ lambdaFunction . FunctionName ,
23+ this . stackName
24+ ) ;
25+ return (
26+ [ this . defaultTimeoutAWS , this . defaultTimeoutServerlessFramework ] . includes (
27+ lambdaFunction . Timeout
28+ ) && ! this . SLS . getFunctionConfig ( shortenedName ) . timeout
29+ ) ;
2230 }
2331
2432 async run ( ) {
Original file line number Diff line number Diff line change @@ -20,6 +20,10 @@ class Serverless {
2020 }
2121 }
2222
23+ getFunctionConfig ( functionName ) {
24+ return this . config . functions [ functionName ] ;
25+ }
26+
2327 getStage ( ) {
2428 if ( typeof this . config !== "object" ) {
2529 return "dev" ;
Original file line number Diff line number Diff line change 1+ function abbreviateFunction ( fullFuncName , stackName ) {
2+ return fullFuncName . replace ( `${ stackName } -` , "" ) ;
3+ }
4+
5+ module . exports = {
6+ abbreviateFunction,
7+ } ;
You can’t perform that action at this time.
0 commit comments