File tree Expand file tree Collapse file tree 4 files changed +98
-4
lines changed Expand file tree Collapse file tree 4 files changed +98
-4
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " aws-sdk-js-codemod " : patch
3
+ ---
4
+
5
+ Insert credentials at the first occurrence of a security credential key
Original file line number Diff line number Diff line change
1
+ import AWS from "aws-sdk" ;
2
+
3
+ const credsAfter = new AWS . Config ( {
4
+ logger : console ,
5
+ region : "us-east-1" ,
6
+ accessKeyId : "KEY" ,
7
+ secretAccessKey : "SECRET"
8
+ } ) ;
9
+
10
+ const credsBefore = new AWS . Config ( {
11
+ accessKeyId : "KEY" ,
12
+ secretAccessKey : "SECRET" ,
13
+ logger : console ,
14
+ region : "us-east-1" ,
15
+ } ) ;
16
+
17
+ const credsInBetween = new AWS . Config ( {
18
+ logger : console ,
19
+ accessKeyId : "KEY" ,
20
+ secretAccessKey : "SECRET" ,
21
+ region : "us-east-1" ,
22
+ } ) ;
23
+
24
+ const credsDispersedBefore = new AWS . Config ( {
25
+ accessKeyId : "KEY" ,
26
+ logger : console ,
27
+ secretAccessKey : "SECRET" ,
28
+ region : "us-east-1"
29
+ } ) ;
30
+
31
+ const credsDispersedAfter = new AWS . Config ( {
32
+ logger : console ,
33
+ accessKeyId : "KEY" ,
34
+ region : "us-east-1" ,
35
+ secretAccessKey : "SECRET" ,
36
+ } ) ;
Original file line number Diff line number Diff line change
1
+ const credsAfter = {
2
+ logger : console ,
3
+ region : "us-east-1" ,
4
+
5
+ credentials : {
6
+ accessKeyId : "KEY" ,
7
+ secretAccessKey : "SECRET"
8
+ }
9
+ } ;
10
+
11
+ const credsBefore = {
12
+ credentials : {
13
+ accessKeyId : "KEY" ,
14
+ secretAccessKey : "SECRET"
15
+ } ,
16
+
17
+ logger : console ,
18
+ region : "us-east-1"
19
+ } ;
20
+
21
+ const credsInBetween = {
22
+ logger : console ,
23
+
24
+ credentials : {
25
+ accessKeyId : "KEY" ,
26
+ secretAccessKey : "SECRET"
27
+ } ,
28
+
29
+ region : "us-east-1"
30
+ } ;
31
+
32
+ const credsDispersedBefore = {
33
+ credentials : {
34
+ accessKeyId : "KEY" ,
35
+ secretAccessKey : "SECRET"
36
+ } ,
37
+
38
+ logger : console ,
39
+ region : "us-east-1"
40
+ } ;
41
+
42
+ const credsDispersedAfter = {
43
+ logger : console ,
44
+
45
+ credentials : {
46
+ accessKeyId : "KEY" ,
47
+ secretAccessKey : "SECRET"
48
+ } ,
49
+
50
+ region : "us-east-1"
51
+ } ;
Original file line number Diff line number Diff line change @@ -67,6 +67,12 @@ export const getObjectWithUpdatedAwsConfigKeys = (
67
67
68
68
if ( securityCredentialKeys . includes ( propertyKey . name ) ) {
69
69
credentials . properties . push ( property ) ;
70
+
71
+ // Push credentials key only once.
72
+ if ( credentials . properties . length === 1 ) {
73
+ return j . objectProperty ( j . identifier ( "credentials" ) , credentials ) ;
74
+ }
75
+
70
76
return undefined ;
71
77
}
72
78
@@ -107,10 +113,6 @@ export const getObjectWithUpdatedAwsConfigKeys = (
107
113
} )
108
114
. filter ( ( property ) => property !== undefined ) ;
109
115
110
- if ( credentials . properties . length > 0 ) {
111
- updatedProperties . unshift ( j . objectProperty ( j . identifier ( "credentials" ) , credentials ) ) ;
112
- }
113
-
114
116
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
115
117
// @ts -ignore is Argument is not assignable to parameter
116
118
return j . objectExpression ( updatedProperties ) ;
You can’t perform that action at this time.
0 commit comments