@@ -22,14 +22,15 @@ export enum SecretType {
22
22
}
23
23
24
24
const secretFormExplanation = {
25
- source : 'Source secrets allow you to authenticate against the SCM server.' ,
26
- webhook : 'Webhook secrets allow you to authenticate a webhook trigger.' ,
25
+ [ SecretTypeAbstraction . source ] : 'Source secrets allow you to authenticate against the SCM server.' ,
26
+ [ SecretTypeAbstraction . webhook ] : 'Webhook secrets allow you to authenticate a webhook trigger.' ,
27
27
} ;
28
28
29
- const determineDefaultSecretType = ( typeAbstraction ) => {
30
- return typeAbstraction === ' source' ? SecretType . basicAuth : SecretType . opaque ;
29
+ const determineDefaultSecretType = ( typeAbstraction : SecretTypeAbstraction ) => {
30
+ return typeAbstraction === SecretTypeAbstraction . source ? SecretType . basicAuth : SecretType . opaque ;
31
31
} ;
32
32
33
+
33
34
const determineSecretTypeAbstraction = ( data ) => {
34
35
return _ . has ( data , WebHookSecretKey ) ? SecretTypeAbstraction . webhook : SecretTypeAbstraction . source ;
35
36
} ;
@@ -40,12 +41,11 @@ const generateSecret = () => {
40
41
return s4 ( ) + s4 ( ) + s4 ( ) + s4 ( ) ;
41
42
} ;
42
43
43
- // withSecretForm returns SubformComponent which is a Higher Order Component for all the types of secret forms.
44
- const withSecretForm = ( SubformComponent ) => class SecretFormComponent extends React . Component < BaseEditSecretProps_ , BaseEditSecretState_ > {
44
+ // withSecretForm returns SubForm which is a Higher Order Component for all the types of secret forms.
45
+ const withSecretForm = ( SubForm ) => class SecretFormComponent extends React . Component < BaseEditSecretProps_ , BaseEditSecretState_ > {
45
46
constructor ( props ) {
46
47
super ( props ) ;
47
- const inputObj = _ . get ( props . obj , 'data' ) ;
48
- const existingSecret = _ . pick ( inputObj , [ 'metadata' , 'type' ] ) ;
48
+ const existingSecret = _ . pick ( props . obj , [ 'metadata' , 'type' ] ) ;
49
49
const defaultSecretType = determineDefaultSecretType ( this . props . secretTypeAbstraction ) ;
50
50
const secret = _ . defaultsDeep ( { } , props . fixed , existingSecret , {
51
51
apiVersion : 'v1' ,
@@ -62,7 +62,7 @@ const withSecretForm = (SubformComponent) => class SecretFormComponent extends R
62
62
secret : secret ,
63
63
inProgress : false ,
64
64
type : defaultSecretType ,
65
- stringData : _ . mapValues ( _ . get ( inputObj , 'data' ) , window . atob ) ,
65
+ stringData : _ . mapValues ( _ . get ( props . obj , 'data' ) , window . atob ) ,
66
66
} ;
67
67
this . onDataChanged = this . onDataChanged . bind ( this ) ;
68
68
this . onNameChanged = this . onNameChanged . bind ( this ) ;
@@ -71,7 +71,7 @@ const withSecretForm = (SubformComponent) => class SecretFormComponent extends R
71
71
onDataChanged ( secretsData ) {
72
72
this . setState ( {
73
73
stringData : { ...secretsData . stringData } ,
74
- type : secretsData . authenticationType ,
74
+ type : secretsData . type ,
75
75
} ) ;
76
76
}
77
77
onNameChanged ( event ) {
@@ -100,7 +100,7 @@ const withSecretForm = (SubformComponent) => class SecretFormComponent extends R
100
100
< Helmet >
101
101
< title > { title } </ title >
102
102
</ Helmet >
103
- < form className = "co-m-pane__body-group create-secret-form" onSubmit = { this . save } >
103
+ < form className = "co-m-pane__body-group co- create-secret-form" onSubmit = { this . save } >
104
104
< h1 className = "co-m-pane__heading" > { title } </ h1 >
105
105
< p className = "co-m-pane__explanation" > { this . props . explanation } </ p >
106
106
@@ -119,7 +119,7 @@ const withSecretForm = (SubformComponent) => class SecretFormComponent extends R
119
119
</ div >
120
120
</ div >
121
121
</ fieldset >
122
- < SubformComponent
122
+ < SubForm
123
123
onChange = { this . onDataChanged . bind ( this ) }
124
124
stringData = { this . state . stringData }
125
125
secretType = { this . state . secret . type }
@@ -178,14 +178,15 @@ class SourceSecretForm extends React.Component<SourceSecretFormProps, SourceSecr
178
178
constructor ( props ) {
179
179
super ( props ) ;
180
180
this . state = {
181
- authenticationType : this . props . secretType ,
181
+ type : this . props . secretType ,
182
182
stringData : this . props . stringData || { } ,
183
183
} ;
184
184
this . changeAuthenticationType = this . changeAuthenticationType . bind ( this ) ;
185
+ this . onDataChanged = this . onDataChanged . bind ( this ) ;
185
186
}
186
187
changeAuthenticationType ( event ) {
187
188
this . setState ( {
188
- authenticationType : event . target . value
189
+ type : event . target . value
189
190
} , ( ) => this . props . onChange ( this . state ) ) ;
190
191
}
191
192
onDataChanged ( secretsData ) {
@@ -197,26 +198,26 @@ class SourceSecretForm extends React.Component<SourceSecretFormProps, SourceSecr
197
198
return < React . Fragment >
198
199
{ this . props . isCreate
199
200
? < div className = "form-group" >
200
- < label className = "control-label" > Authentication Type</ label >
201
- < div className = "modal-body__field" >
202
- < select onChange = { this . changeAuthenticationType } value = { this . state . authenticationType } className = "form-control" >
203
- < option key = "kubernetes.io/basic-auth" value = "kubernetes.io/basic-auth" > Basic Authentication</ option >
204
- < option key = "kubernetes.io/ssh-auth" value = "kubernetes.io/ssh-auth" > SSH Key</ option >
201
+ < label className = "control-label" htmlFor = "secret-type" > Authentication Type</ label >
202
+ < div >
203
+ < select onChange = { this . changeAuthenticationType } value = { this . state . type } className = "form-control" id = "secret-type ">
204
+ < option value = "kubernetes.io/basic-auth" > Basic Authentication</ option >
205
+ < option value = "kubernetes.io/ssh-auth" > SSH Key</ option >
205
206
</ select >
206
207
</ div >
207
208
</ div >
208
209
: null
209
210
}
210
- { this . state . authenticationType === 'kubernetes.io/basic-auth'
211
- ? < BasicAuthSubform onChange = { this . onDataChanged . bind ( this ) } stringData = { this . state . stringData } />
212
- : < SSHAuthSubform onChange = { this . onDataChanged . bind ( this ) } stringData = { this . state . stringData } />
211
+ { this . state . type === 'kubernetes.io/basic-auth'
212
+ ? < BasicAuthSubform onChange = { this . onDataChanged } stringData = { this . state . stringData } />
213
+ : < SSHAuthSubform onChange = { this . onDataChanged } stringData = { this . state . stringData } />
213
214
}
214
215
</ React . Fragment > ;
215
216
}
216
217
}
217
218
218
219
const secretFormFactory = secretType => {
219
- return secretType === ' webhook' ? withSecretForm ( WebHookSecretForm ) : withSecretForm ( SourceSecretForm ) ;
220
+ return secretType === SecretTypeAbstraction . webhook ? withSecretForm ( WebHookSecretForm ) : withSecretForm ( SourceSecretForm ) ;
220
221
} ;
221
222
222
223
class BasicAuthSubform extends React . Component < BasicAuthSubformProps , BasicAuthSubformState > {
@@ -237,7 +238,7 @@ class BasicAuthSubform extends React.Component<BasicAuthSubformProps, BasicAuthS
237
238
return < React . Fragment >
238
239
< div className = "form-group" >
239
240
< label className = "control-label" htmlFor = "username" > Username</ label >
240
- < div className = "modal-body__field" >
241
+ < div >
241
242
< input className = "form-control"
242
243
id = "username"
243
244
aria-describedby = "username-help"
@@ -251,7 +252,7 @@ class BasicAuthSubform extends React.Component<BasicAuthSubformProps, BasicAuthS
251
252
</ div >
252
253
< div className = "form-group" >
253
254
< label className = "control-label" htmlFor = "password" > Password or Token</ label >
254
- < div className = "modal-body__field" >
255
+ < div >
255
256
< input className = "form-control"
256
257
id = "password"
257
258
aria-describedby = "password-help"
@@ -274,6 +275,7 @@ class SSHAuthSubform extends React.Component<SSHAuthSubformProps, SSHAuthSubform
274
275
'ssh-privatekey' : this . props . stringData [ 'ssh-privatekey' ] || '' ,
275
276
} ;
276
277
this . changeData = this . changeData . bind ( this ) ;
278
+ this . onFileChange = this . onFileChange . bind ( this ) ;
277
279
}
278
280
changeData ( event ) {
279
281
this . setState ( {
@@ -288,17 +290,17 @@ class SSHAuthSubform extends React.Component<SSHAuthSubformProps, SSHAuthSubform
288
290
render ( ) {
289
291
return < div className = "form-group" >
290
292
< label className = "control-label" htmlFor = "ssh-privatekey" > SSH Private Key</ label >
291
- < div className = "modal-body__field" >
292
- < FileInput onChange = { this . onFileChange . bind ( this ) } />
293
+ < div >
294
+ < FileInput onChange = { this . onFileChange } />
293
295
< p className = "help-block" > Upload your private SSH key file.</ p >
294
296
< textarea className = "form-control form-textarea"
295
297
id = "ssh-privatekey"
296
298
name = "privateKey"
297
299
onChange = { this . changeData }
298
300
value = { this . state [ 'ssh-privatekey' ] }
299
- required >
300
- </ textarea >
301
- < p className = "help-block" > Private SSH key file for Git authentication.</ p >
301
+ aria-describedby = "ssh-privatekey-help"
302
+ required / >
303
+ < p className = "help-block" id = "ssh-privatekey-help" > Private SSH key file for Git authentication.</ p >
302
304
</ div >
303
305
</ div > ;
304
306
}
@@ -309,12 +311,11 @@ const SecretLoadingWrapper = props => {
309
311
const SecretFormComponent = secretFormFactory ( secretTypeAbstraction ) ;
310
312
const fixed = _ . reduce ( props . fixedKeys , ( acc , k ) => ( { ...acc , k : _ . get ( props . obj . data , k ) } ) , { } ) ;
311
313
return < StatusBox { ...props . obj } >
312
- < SecretFormComponent
314
+ < SecretFormComponent { ... props }
313
315
secretTypeAbstraction = { secretTypeAbstraction }
314
316
obj = { props . obj . data }
315
317
fixed = { fixed }
316
318
explanation = { secretFormExplanation [ secretTypeAbstraction ] }
317
- { ...props }
318
319
/>
319
320
</ StatusBox > ;
320
321
} ;
@@ -338,7 +339,7 @@ export type BaseEditSecretState_ = {
338
339
secretTypeAbstraction ?: SecretTypeAbstraction ,
339
340
secret : K8sResourceKind ,
340
341
inProgress : boolean ,
341
- type : string ,
342
+ type : SecretType ,
342
343
stringData : { [ key : string ] : string } ,
343
344
error ?: any ,
344
345
} ;
@@ -355,13 +356,17 @@ export type BaseEditSecretProps_ = {
355
356
} ;
356
357
357
358
export type SourceSecretFormState = {
358
- authenticationType : SecretType ,
359
- stringData : { [ key : string ] : string } ,
359
+ type : SecretType ,
360
+ stringData : {
361
+ [ key : string ] : string
362
+ } ,
360
363
} ;
361
364
362
365
export type SourceSecretFormProps = {
363
366
onChange : Function ;
364
- stringData : { [ key : string ] : string } ,
367
+ stringData : {
368
+ [ key : string ] : string
369
+ } ,
365
370
secretType : SecretType ,
366
371
isCreate : boolean ,
367
372
} ;
@@ -373,7 +378,9 @@ export type BasicAuthSubformState = {
373
378
374
379
export type BasicAuthSubformProps = {
375
380
onChange : Function ,
376
- stringData : { [ key : string ] : string } ,
381
+ stringData : {
382
+ [ key : string ] : string
383
+ } ,
377
384
} ;
378
385
379
386
export type SSHAuthSubformState = {
@@ -382,15 +389,21 @@ export type SSHAuthSubformState = {
382
389
383
390
export type SSHAuthSubformProps = {
384
391
onChange : Function ;
385
- stringData : { [ key : string ] : string } ,
392
+ stringData : {
393
+ [ key : string ] : string
394
+ } ,
386
395
} ;
387
396
388
397
export type WebHookSecretFormState = {
389
- stringData : { [ key : string ] : string } ,
398
+ stringData : {
399
+ [ key : string ] : string
400
+ } ,
390
401
} ;
391
402
392
403
export type WebHookSecretFormProps = {
393
404
onChange : Function ;
394
- stringData : { [ WebHookSecretKey : string ] : string } ,
405
+ stringData : {
406
+ WebHookSecretKey : string
407
+ } ,
395
408
} ;
396
409
/* eslint-enable no-undef */
0 commit comments