Skip to content

Commit 5341ba9

Browse files
committed
fixed single remove command
1 parent 061a6b3 commit 5341ba9

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

index.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ class ServerlessStepFunctions {
1212
this.service = this.serverless.service.service;
1313
this.region = this.provider.getRegion();
1414
this.stage = this.provider.getStage();
15-
this.awsStateLanguage = {};
1615
this.functionArns = {};
1716
this.iamRoleArn = {};
17+
this.stateMachineArns = {};
1818
this.iamPolicyStatement = `{
1919
"Version": "2012-10-17",
2020
"Statement": [
@@ -100,7 +100,6 @@ class ServerlessStepFunctions {
100100
state: {
101101
usage: 'Name of the State Machine',
102102
shortcut: 't',
103-
required: true,
104103
},
105104
stage: {
106105
usage: 'Stage of the service',
@@ -205,7 +204,7 @@ class ServerlessStepFunctions {
205204
message += `${chalk.yellow('stage:')} ${this.stage}\n`;
206205
message += `${chalk.yellow('region:')} ${this.region}\n\n`;
207206
message += `${chalk.yellow.underline('State Machine Information')}\n`;
208-
message += `${chalk.yellow(this.options.state)}${chalk.yellow(':')} ${this.stateMachineArn}\n`;
207+
message += `${chalk.yellow(this.options.state)}${chalk.yellow(':')} ${this.stateMachineArns[this.options.state]}\n`;
209208
this.serverless.cli.consoleLog(message);
210209
return BbPromise.resolve();
211210
});
@@ -270,8 +269,8 @@ class ServerlessStepFunctions {
270269
return name.substr(0, 64);
271270
}
272271

273-
getIamPolicyName() {
274-
let name = `${this.service}-${this.region}-${this.stage}-${this.options.state}-`;
272+
getIamPolicyName(state) {
273+
let name = `${this.service}-${this.region}-${this.stage}-${state}-`;
275274
name += 'ssf-exepolicy';
276275
return name.substr(0, 64);
277276
}
@@ -342,7 +341,7 @@ class ServerlessStepFunctions {
342341
'createPolicy',
343342
{
344343
PolicyDocument: this.iamPolicyStatement,
345-
PolicyName: this.getIamPolicyName(),
344+
PolicyName: this.getIamPolicyName(state),
346345
},
347346
this.options.stage,
348347
this.options.region);
@@ -359,21 +358,22 @@ class ServerlessStepFunctions {
359358
.then(() => BbPromise.resolve());
360359
}
361360

362-
deleteIamRole() {
361+
deleteIamRole(state) {
362+
state = state || this.options.state;
363363
let policyArn;
364364
return this.provider.request('STS',
365365
'getCallerIdentity',
366366
{},
367367
this.options.stage,
368368
this.options.region)
369369
.then((result) => {
370-
policyArn = `arn:aws:iam::${result.Account}:policy/${this.getIamPolicyName()}`;
370+
policyArn = `arn:aws:iam::${result.Account}:policy/${this.getIamPolicyName(state)}`;
371371

372372
return this.provider.request('IAM',
373373
'detachRolePolicy',
374374
{
375375
PolicyArn: policyArn,
376-
RoleName: this.getIamRoleName(this.options.state),
376+
RoleName: this.getIamRoleName(state),
377377
},
378378
this.options.stage,
379379
this.options.region);
@@ -389,23 +389,24 @@ class ServerlessStepFunctions {
389389
.then(() => this.provider.request('IAM',
390390
'deleteRole',
391391
{
392-
RoleName: this.getIamRoleName(this.options.state),
392+
RoleName: this.getIamRoleName(state),
393393
},
394394
this.options.stage,
395395
this.options.region)
396396
)
397397
.then(() => BbPromise.resolve());
398398
}
399399

400-
getStateMachineArn() {
400+
getStateMachineArn(state) {
401+
state = state || this.options.state
401402
return this.provider.request('STS',
402403
'getCallerIdentity',
403404
{},
404405
this.options.stage,
405406
this.options.region)
406407
.then((result) => {
407-
this.stateMachineArn =
408-
`arn:aws:states:${this.region}:${result.Account}:stateMachine:${this.getStateMachineName()}`;
408+
this.stateMachineArns[state] =
409+
`arn:aws:states:${this.region}:${result.Account}:stateMachine:${this.getStateMachineName(state)}`;
409410
return BbPromise.resolve();
410411
});
411412
}
@@ -417,7 +418,6 @@ class ServerlessStepFunctions {
417418
this.options.stage,
418419
this.options.region)
419420
.then((result) => {
420-
this.stateMachineArns = {};
421421
_.forEach(this.serverless.service.stepFunctions, (value, key) => {
422422
this.stateMachineArns[key] =
423423
`arn:aws:states:${this.region}:${result.Account}:stateMachine:${this.getStateMachineName(key)}`;
@@ -602,13 +602,13 @@ class ServerlessStepFunctions {
602602
throw new this.serverless.classes.Error(errorMessage);
603603
}
604604

605-
this.awsStateLanguage[this.options.state] =
605+
this.serverless.service.stepFunctions[this.options.state] =
606606
JSON.stringify(this.serverless.service.stepFunctions[this.options.state]);
607607

608608
_.forEach(this.functionArns, (value, key) => {
609609
const regExp = new RegExp(`"Resource":"${key}"`, 'g');
610-
this.awsStateLanguage[this.options.state] =
611-
this.awsStateLanguage[this.options.state].replace(regExp, `"Resource":"${value}"`);
610+
this.serverless.service.stepFunctions[this.options.state] =
611+
this.serverless.service.stepFunctions[this.options.state].replace(regExp, `"Resource":"${value}"`);
612612
});
613613
return BbPromise.resolve();
614614
}

0 commit comments

Comments
 (0)