@@ -6,12 +6,76 @@ import {
66 findInitialValues ,
77} from '../views/EditCluster/EditCluster' ;
88import { getUserIndex } from '../shared' ;
9- import { Tokens } from 'shared/components/Tokens' ;
109import {
1110 Kubeconfig ,
1211 KubeconfigNonOIDCAuthToken ,
1312 KubeconfigOIDCAuth ,
1413} from 'types' ;
14+ import { Tokens } from 'shared/components/Tokens' ;
15+
16+ const TokenData = ( { token } : { token : string } ) => {
17+ const { t } = useTranslation ( ) ;
18+
19+ return (
20+ < >
21+ < p className = "cluster-preview__data-header sap-margin-top-small sap-margin-bottom-tiny" >
22+ { `${ t ( 'clusters.token' ) } :` }
23+ </ p >
24+ { token && < div className = "cluster-preview__token" > { token } </ div > }
25+ </ >
26+ ) ;
27+ } ;
28+
29+ const OidcData = ( {
30+ issuerUrl,
31+ clientId,
32+ clientSecret,
33+ extraScopes,
34+ } : {
35+ issuerUrl ?: string ;
36+ clientId ?: string ;
37+ clientSecret ?: string ;
38+ extraScopes ?: string [ ] ;
39+ } ) => {
40+ const { t } = useTranslation ( ) ;
41+
42+ return (
43+ < >
44+ { issuerUrl && (
45+ < >
46+ < p className = "cluster-preview__data-header sap-margin-top-small sap-margin-bottom-tiny" >
47+ { t ( 'clusters.labels.issuer-url' ) } :
48+ </ p >
49+ < div > { issuerUrl } </ div >
50+ </ >
51+ ) }
52+ { clientId && (
53+ < >
54+ < p className = "cluster-preview__data-header sap-margin-top-small sap-margin-bottom-tiny" >
55+ { t ( 'clusters.labels.client-id' ) } :
56+ </ p >
57+ < div > { clientId } </ div >
58+ </ >
59+ ) }
60+ { clientSecret && (
61+ < >
62+ < p className = "cluster-preview__data-header sap-margin-top-small sap-margin-bottom-tiny" >
63+ { t ( 'clusters.labels.client-secret' ) } :
64+ </ p >
65+ < div > { clientSecret } </ div >
66+ </ >
67+ ) }
68+ { extraScopes && (
69+ < >
70+ < p className = "cluster-preview__data-header sap-margin-top-small sap-margin-bottom-tiny" >
71+ { t ( 'clusters.labels.scopes' ) } :
72+ </ p >
73+ { < Tokens tokens = { extraScopes } /> }
74+ </ >
75+ ) }
76+ </ >
77+ ) ;
78+ } ;
1579
1680interface ClusterPreviewProps {
1781 kubeconfig : Kubeconfig ;
@@ -34,76 +98,22 @@ export function ClusterPreview({
3498 ? 'oidc'
3599 : 'token' ;
36100
37- const OidcData = ( ) => {
38- const issuerUrl = findInitialValue (
39- kubeconfig ,
40- 'oidc-issuer-url' ,
41- userIndex ,
42- ) ;
43- const clientId = findInitialValue ( kubeconfig , 'oidc-client-id' , userIndex ) ;
44- const clientSecret = findInitialValue (
45- kubeconfig ,
46- 'oidc-client-secret' ,
47- userIndex ,
48- ) ;
49- const extraScopes = findInitialValues (
50- kubeconfig ,
51- 'oidc-extra-scope' ,
52- userIndex ,
53- ) ;
54-
55- return (
56- < >
57- { issuerUrl && (
58- < >
59- < p className = "cluster-preview__data-header sap-margin-top-small sap-margin-bottom-tiny" >
60- { t ( 'clusters.labels.issuer-url' ) } :
61- </ p >
62- < div > { issuerUrl } </ div >
63- </ >
64- ) }
65- { clientId && (
66- < >
67- < p className = "cluster-preview__data-header sap-margin-top-small sap-margin-bottom-tiny" >
68- { t ( 'clusters.labels.client-id' ) } :
69- </ p >
70- < div > { clientId } </ div >
71- </ >
72- ) }
73- { clientSecret && (
74- < >
75- < p className = "cluster-preview__data-header sap-margin-top-small sap-margin-bottom-tiny" >
76- { t ( 'clusters.labels.client-secret' ) } :
77- </ p >
78- < div > { clientSecret } </ div >
79- </ >
80- ) }
81- { extraScopes && (
82- < >
83- < p className = "cluster-preview__data-header sap-margin-top-small sap-margin-bottom-tiny" >
84- { t ( 'clusters.labels.scopes' ) } :
85- </ p >
86- { < Tokens tokens = { extraScopes } /> }
87- </ >
88- ) }
89- </ >
90- ) ;
91- } ;
92-
93- const TokenData = ( ) => {
94- const token = (
95- kubeconfig ?. users ?. [ userIndex ] ?. user as KubeconfigNonOIDCAuthToken
96- ) ?. token ;
101+ const issuerUrl = findInitialValue ( kubeconfig , 'oidc-issuer-url' , userIndex ) ;
102+ const clientId = findInitialValue ( kubeconfig , 'oidc-client-id' , userIndex ) ;
103+ const clientSecret = findInitialValue (
104+ kubeconfig ,
105+ 'oidc-client-secret' ,
106+ userIndex ,
107+ ) ;
108+ const extraScopes = findInitialValues (
109+ kubeconfig ,
110+ 'oidc-extra-scope' ,
111+ userIndex ,
112+ ) ;
97113
98- return (
99- < >
100- < p className = "cluster-preview__data-header sap-margin-top-small sap-margin-bottom-tiny" >
101- { `${ t ( 'clusters.token' ) } :` }
102- </ p >
103- { token && < div className = "cluster-preview__token" > { token } </ div > }
104- </ >
105- ) ;
106- } ;
114+ const token = (
115+ kubeconfig ?. users ?. [ userIndex ] ?. user as KubeconfigNonOIDCAuthToken
116+ ) ?. token ;
107117
108118 return (
109119 < div className = "cluster-preview" >
@@ -138,7 +148,16 @@ export function ClusterPreview({
138148
139149 < div className = "cluster-preview__content sap-margin-top-small sap-margin-bottom-tiny" >
140150 < div className = "cluster-preview__auth" >
141- { authenticationType === 'token' ? < TokenData /> : < OidcData /> }
151+ { authenticationType === 'token' ? (
152+ < TokenData token = { token } />
153+ ) : (
154+ < OidcData
155+ issuerUrl = { issuerUrl }
156+ clientId = { clientId }
157+ clientSecret = { clientSecret }
158+ extraScopes = { extraScopes }
159+ />
160+ ) }
142161 </ div >
143162 < Button
144163 design = "Transparent"
0 commit comments