/
autotag_iam_user_worker.js
55 lines (49 loc) · 1.24 KB
/
autotag_iam_user_worker.js
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
54
55
import AutotagDefaultWorker from './autotag_default_worker';
import AWS from 'aws-sdk';
import co from 'co';
import _ from 'underscore';
class AutotagIAMUserWorker extends AutotagDefaultWorker {
/* tagResource
** method: tagResource
**
** Tag the newly created IAM User
*/
tagResource() {
let _this = this;
return co(function* () {
let roleName = _this.roleName;
let credentials = yield _this.assumeRole(roleName);
_this.iam = new AWS.IAM({
region: _this.event.awsRegion,
credentials: credentials
});
yield _this.tagIamUserResource();
});
}
tagIamUserResource() {
let _this = this;
return new Promise((resolve, reject) => {
try {
let userName = _this.getUserName();
let tags = _this.getAutotagTags();
_this.logTags(userName, tags, _this.constructor.name);
_this.iam.tagUser({
UserName: userName,
Tags: tags
}, (err, res) => {
if (err) {
reject(err);
} else {
resolve(true);
}
});
} catch (e) {
reject(e);
}
});
}
getUserName() {
return this.event.responseElements.user.userName;
}
};
export default AutotagIAMUserWorker;