@@ -14,7 +14,7 @@ log.info(`command line args: ${args}`);
1414
1515 let mode = args [ 0 ] ;
1616 let result ;
17- let projectKey , featureFlagKey , environmentKeyQuery ;
17+ let projectKey , featureFlagKey , environmentKeyQuery , customRoleKey ;
1818
1919 switch ( mode ) {
2020 case 'getFeatureFlags' :
@@ -31,15 +31,15 @@ log.info(`command line args: ${args}`);
3131 featureFlagKey = args [ 2 ] ;
3232 environmentKeyQuery = args [ 3 ] ;
3333 if ( ! projectKey || projectKey . trim ( ) === '' ) {
34- result = 'please supply a projectKey as second parameter'
34+ result = 'please supply a projectKey as second parameter' ;
3535 break ;
3636 }
3737 if ( ! featureFlagKey || featureFlagKey . trim ( ) === '' ) {
38- result = 'please supply a featureFlagKey as third parameter'
38+ result = 'please supply a featureFlagKey as third parameter' ;
3939 break ;
4040 }
4141 if ( ! environmentKeyQuery || environmentKeyQuery . trim ( ) === '' ) {
42- result = 'please supply a environmentKeyQuery as fourth parameter'
42+ result = 'please supply a environmentKeyQuery as fourth parameter' ;
4343 break ;
4444 }
4545 result = await ldUtils . getFeatureFlag ( projectKey , featureFlagKey , environmentKeyQuery ) ;
@@ -50,15 +50,15 @@ log.info(`command line args: ${args}`);
5050 featureFlagKey = args [ 2 ] ;
5151 environmentKeyQuery = args [ 3 ] ;
5252 if ( ! projectKey || projectKey . trim ( ) === '' ) {
53- result = 'please supply a projectKey as second parameter'
53+ result = 'please supply a projectKey as second parameter' ;
5454 break ;
5555 }
5656 if ( ! featureFlagKey || featureFlagKey . trim ( ) === '' ) {
57- result = 'please supply a featureFlagKey as third parameter'
57+ result = 'please supply a featureFlagKey as third parameter' ;
5858 break ;
5959 }
6060 if ( ! environmentKeyQuery || environmentKeyQuery . trim ( ) === '' ) {
61- result = 'please supply a environmentKeyQuery as fourth parameter'
61+ result = 'please supply a environmentKeyQuery as fourth parameter' ;
6262 break ;
6363 }
6464 result = await ldUtils . getFeatureFlagState ( projectKey , featureFlagKey , environmentKeyQuery ) ;
@@ -69,20 +69,20 @@ log.info(`command line args: ${args}`);
6969 featureFlagKey = args [ 2 ] ;
7070 environmentKeyQuery = args [ 3 ] ;
7171 if ( ! projectKey || projectKey . trim ( ) === '' ) {
72- result = 'please supply a projectKey as second parameter'
72+ result = 'please supply a projectKey as second parameter' ;
7373 break ;
7474 }
7575 if ( ! featureFlagKey || featureFlagKey . trim ( ) === '' ) {
76- result = 'please supply a featureFlagKey as third parameter'
76+ result = 'please supply a featureFlagKey as third parameter' ;
7777 break ;
7878 }
7979 if ( ! environmentKeyQuery || environmentKeyQuery . trim ( ) === '' ) {
80- result = 'please supply a environmentKeyQuery as fourth parameter'
80+ result = 'please supply a environmentKeyQuery as fourth parameter' ;
8181 break ;
8282 }
8383 let enabled = args [ 4 ] ;
8484 if ( enabled === undefined || ! [ 'true' , 'false' ] . includes ( enabled ) ) {
85- result = ' please supply either \ 'true\ ' or \ 'false\ ' as fifth parameter' ;
85+ result = ` please supply either 'true' or 'false' as fifth parameter` ;
8686 break ;
8787 }
8888 enabled = enabled === 'true' ;
@@ -93,8 +93,103 @@ log.info(`command line args: ${args}`);
9393 result = await ldUtils . getCustomRoles ( ) ;
9494 break ;
9595
96+ case 'getCustomRole' :
97+ customRoleKey = args [ 1 ] ;
98+ if ( ! customRoleKey || customRoleKey . trim ( ) === '' ) {
99+ result = 'please supply a customRoleKey as second parameter'
100+ break ;
101+ }
102+ result = await ldUtils . getCustomRole ( customRoleKey ) ;
103+ break ;
104+
105+ case 'createCustomRole' :
106+ customRoleKey = args [ 1 ] ;
107+ let customRoleName = args [ 2 ] ;
108+ let customRolePolicyArray = JSON . parse ( args [ 3 ] ) ;
109+ let customRoleDescription = args [ 4 ] ;
110+
111+ if ( ! customRoleKey || customRoleKey . trim ( ) === '' ) {
112+ result = 'please supply a customRoleKey as second parameter' ;
113+ break ;
114+ }
115+
116+ if ( ! customRoleName || customRoleName . trim ( ) === '' ) {
117+ result = 'please supply a customRoleName as third parameter' ;
118+ break ;
119+ }
120+
121+ if ( ! customRolePolicyArray ) {
122+ result = 'please supply a customRolePolicyArray as fourth parameter' ;
123+ break ;
124+ }
125+
126+ result = await ldUtils . createCustomRole (
127+ customRoleKey ,
128+ customRoleName ,
129+ customRolePolicyArray ,
130+ customRoleDescription
131+ ) ;
132+
133+ break ;
134+
135+ case 'updateCustomRole' :
136+ customRoleKey = args [ 1 ] ;
137+ customRoleName = args [ 2 ] ;
138+ customRolePolicyArray = JSON . parse ( args [ 3 ] ) ;
139+ customRoleDescription = args [ 4 ] ;
140+
141+ if ( ! customRoleKey || customRoleKey . trim ( ) === '' ) {
142+ result = 'please supply a customRoleKey as second parameter' ;
143+ break ;
144+ }
145+
146+ if ( ! customRoleName || customRoleName . trim ( ) === '' ) {
147+ result = 'please supply a customRoleName as third parameter' ;
148+ break ;
149+ }
150+
151+ if ( ! customRolePolicyArray ) {
152+ result = 'please supply a customRolePolicyArray as fourth parameter' ;
153+ break ;
154+ }
155+ result = await ldUtils . updateCustomRole (
156+ customRoleKey ,
157+ customRoleName ,
158+ customRolePolicyArray ,
159+ customRoleDescription
160+ ) ;
161+ break ;
162+
163+ case 'upsertCustomRole' :
164+ customRoleKey = args [ 1 ] ;
165+ customRoleName = args [ 2 ] ;
166+ customRolePolicyArray = JSON . parse ( args [ 3 ] ) ;
167+ customRoleDescription = args [ 4 ] ;
168+
169+ if ( ! customRoleKey || customRoleKey . trim ( ) === '' ) {
170+ result = 'please supply a customRoleKey as second parameter' ;
171+ break ;
172+ }
173+
174+ if ( ! customRoleName || customRoleName . trim ( ) === '' ) {
175+ result = 'please supply a customRoleName as third parameter' ;
176+ break ;
177+ }
178+
179+ if ( ! customRolePolicyArray ) {
180+ result = 'please supply a customRolePolicyArray as fourth parameter' ;
181+ break ;
182+ }
183+ result = await ldUtils . upsertCustomRole (
184+ customRoleKey ,
185+ customRoleName ,
186+ customRolePolicyArray ,
187+ customRoleDescription
188+ ) ;
189+ break ;
190+
96191 default :
97- result = 'please supply a mode parameter: getFeatureFlags, getFeatureFlag ' ;
192+ result = 'please supply a valid mode parameter' ;
98193
99194 }
100195
0 commit comments