@@ -8,7 +8,15 @@ const { errors } = require('arsenal');
88const { program } = require ( 'commander' ) ;
99const werelogs = require ( 'werelogs' ) ;
1010const async = require ( 'async' ) ;
11- const { IAM } = require ( 'aws-sdk' ) ;
11+ const {
12+ IAMClient,
13+ GetUserCommand,
14+ CreateUserCommand,
15+ GetUserPolicyCommand,
16+ PutUserPolicyCommand,
17+ ListAccessKeysCommand,
18+ CreateAccessKeyCommand,
19+ } = require ( '@aws-sdk/client-iam' ) ;
1220const { version } = require ( '../package.json' ) ;
1321
1422const systemPrefix = '/scality-internal/' ;
@@ -33,7 +41,7 @@ function generateUserPolicyDocument() {
3341}
3442
3543function createIAMClient ( opts ) {
36- return new IAM ( {
44+ return new IAMClient ( {
3745 endpoint : opts . iamEndpoint ,
3846 region : 'us-east-1' ,
3947 } ) ;
@@ -98,22 +106,18 @@ class UserHandler extends BaseHandler {
98106 resourceType = 'user' ;
99107
100108 async collect ( ) {
101- return this . iamClient
102- . getUser ( {
103- UserName : this . serviceName ,
104- } )
105- . promise ( )
106- . then ( res => res . User ) ;
109+ const res = await this . iamClient . send ( new GetUserCommand ( {
110+ UserName : this . serviceName ,
111+ } ) ) ;
112+ return res . User ;
107113 }
108114
109115 async create ( ) {
110- return this . iamClient
111- . createUser ( {
112- UserName : this . serviceName ,
113- Path : systemPrefix ,
114- } )
115- . promise ( )
116- . then ( res => res . User ) ;
116+ const res = await this . iamClient . send ( new CreateUserCommand ( {
117+ UserName : this . serviceName ,
118+ Path : systemPrefix ,
119+ } ) ) ;
120+ return res . User ;
117121 }
118122
119123 conflicts ( u ) {
@@ -125,26 +129,22 @@ class UserPolicyHandler extends BaseHandler {
125129 resourceType = 'userPolicy' ;
126130
127131 async collect ( ) {
128- return this . iamClient
129- . getUserPolicy ( {
130- UserName : this . serviceName ,
131- PolicyName : this . serviceName ,
132- } )
133- . promise ( )
134- . then ( ( ) => true ) ;
132+ await this . iamClient . send ( new GetUserPolicyCommand ( {
133+ UserName : this . serviceName ,
134+ PolicyName : this . serviceName ,
135+ } ) ) ;
136+ return true ;
135137 }
136138
137139 async create ( ) {
138140 const doc = generateUserPolicyDocument ( ) ;
139141
140- return this . iamClient
141- . putUserPolicy ( {
142- UserName : this . serviceName ,
143- PolicyName : this . serviceName ,
144- PolicyDocument : JSON . stringify ( doc ) ,
145- } )
146- . promise ( )
147- . then ( ( ) => true ) ;
142+ await this . iamClient . send ( new PutUserPolicyCommand ( {
143+ UserName : this . serviceName ,
144+ PolicyName : this . serviceName ,
145+ PolicyDocument : JSON . stringify ( doc ) ,
146+ } ) ) ;
147+ return true ;
148148 }
149149
150150 conflicts ( ) {
@@ -158,22 +158,18 @@ class AccessKeyHandler extends BaseHandler {
158158 async collect ( ) {
159159 // if at least one key already exists, the script won't create a new key
160160 // and will display the list of existing keys
161- return this . iamClient
162- . listAccessKeys ( {
163- UserName : this . serviceName ,
164- MaxItems : 100 ,
165- } )
166- . promise ( )
167- . then ( res => res . AccessKeyMetadata ) ;
161+ const res = await this . iamClient . send ( new ListAccessKeysCommand ( {
162+ UserName : this . serviceName ,
163+ MaxItems : 100 ,
164+ } ) ) ;
165+ return res . AccessKeyMetadata ;
168166 }
169167
170168 async create ( ) {
171- return this . iamClient
172- . createAccessKey ( {
173- UserName : this . serviceName ,
174- } )
175- . promise ( )
176- . then ( res => res . AccessKey ) ;
169+ const res = await this . iamClient . send ( new CreateAccessKeyCommand ( {
170+ UserName : this . serviceName ,
171+ } ) ) ;
172+ return res . AccessKey ;
177173 }
178174
179175 conflicts ( ) {
@@ -185,7 +181,7 @@ function collectResource(v, done) {
185181 v . collect ( )
186182 . then ( res => done ( null , res ) )
187183 . catch ( ( err ) => {
188- if ( err . code === 'NoSuchEntity' ) {
184+ if ( err && ( err . code === 'NoSuchEntity' || err . name === 'NoSuchEntity' ) ) {
189185 return done ( ) ;
190186 }
191187
0 commit comments