@@ -2,9 +2,11 @@ import React from "react";
22import { api_key } from "../../proto/api_key_ts_proto" ;
33import { bazel_config } from "../../proto/bazel_config_ts_proto" ;
44import authService , { User } from "../auth/auth_service" ;
5+ import CertificateDownloadLink from "../auth/certificate_download_link" ;
56import capabilities from "../capabilities/capabilities" ;
67import Banner from "../components/banner/banner" ;
78import LinkButton from "../components/button/link_button" ;
9+ import { TextLink } from "../components/link/link" ;
810import Select , { Option } from "../components/select/select" ;
911import Spinner from "../components/spinner/spinner" ;
1012import error_service from "../errors/error_service" ;
@@ -56,12 +58,18 @@ export default class SetupCodeComponent extends React.Component<Props, State> {
5658 rpcService . service
5759 . getBazelConfig ( request )
5860 . then ( ( response ) => {
59- this . fetchAPIKeyValue ( response , 0 ) ;
61+ if ( ! this . isAPIKeyValueReadbackExplicitlyDisabled ( ) ) {
62+ this . fetchAPIKeyValue ( response , 0 ) ;
63+ }
6064 this . setState ( { bazelConfigResponse : response , selectedCredentialIndex : 0 } ) ;
6165 } )
6266 . catch ( ( e ) => error_service . handleError ( e ) ) ;
6367 }
6468
69+ private isAPIKeyValueReadbackExplicitlyDisabled ( ) {
70+ return capabilities . config . apiKeyValueReadbackEnabled === false ;
71+ }
72+
6573 getSelectedCredential ( ) : bazel_config . Credentials | null {
6674 const { bazelConfigResponse : response , selectedCredentialIndex : index } = this . state ;
6775 if ( ! response ?. credential ) return null ;
@@ -144,10 +152,13 @@ export default class SetupCodeComponent extends React.Component<Props, State> {
144152 if ( this . state . auth == "key" ) {
145153 const selectedCredential = this . getSelectedCredential ( ) ;
146154 if ( ! selectedCredential ?. apiKey ) return null ;
155+ const value = this . isAPIKeyValueReadbackExplicitlyDisabled ( )
156+ ? "YOUR_API_KEY_HERE"
157+ : selectedCredential . apiKey . value ;
147158
148159 return (
149160 < div >
150- < div > common --remote_header=x-buildbuddy-api-key={ selectedCredential . apiKey . value } </ div >
161+ < div > common --remote_header=x-buildbuddy-api-key={ value } </ div >
151162 </ div >
152163 ) ;
153164 }
@@ -199,6 +210,9 @@ export default class SetupCodeComponent extends React.Component<Props, State> {
199210 }
200211
201212 async fetchAPIKeyValue ( bazelConfigResponse : bazel_config . IGetBazelConfigResponse , selectedIndex : number ) {
213+ if ( this . isAPIKeyValueReadbackExplicitlyDisabled ( ) ) {
214+ return ;
215+ }
202216 this . setState ( { apiKeyLoading : true } ) ;
203217 try {
204218 const creds = bazelConfigResponse . credential ;
@@ -223,7 +237,9 @@ export default class SetupCodeComponent extends React.Component<Props, State> {
223237
224238 onChangeCredential ( e : React . ChangeEvent < HTMLSelectElement > ) {
225239 const selectedIndex = Number ( e . target . value ) ;
226- this . fetchAPIKeyValue ( this . state . bazelConfigResponse ! , selectedIndex ) ;
240+ if ( ! this . isAPIKeyValueReadbackExplicitlyDisabled ( ) ) {
241+ this . fetchAPIKeyValue ( this . state . bazelConfigResponse ! , selectedIndex ) ;
242+ }
227243 this . setState ( { selectedCredentialIndex : selectedIndex } ) ;
228244 }
229245
@@ -330,7 +346,8 @@ export default class SetupCodeComponent extends React.Component<Props, State> {
330346 </ span >
331347 ) }
332348
333- { ( this . state . auth === "cert" || this . state . auth === "key" ) &&
349+ { ! this . isAPIKeyValueReadbackExplicitlyDisabled ( ) &&
350+ ( this . state . auth === "cert" || this . state . auth === "key" ) &&
334351 ( this . state . bazelConfigResponse ?. credential ?. length || 0 ) > 1 && (
335352 < span >
336353 < Select
@@ -435,6 +452,10 @@ export default class SetupCodeComponent extends React.Component<Props, State> {
435452 </ span >
436453 ) }
437454 </ div >
455+ < div className = "setup-api-key-settings-note" >
456+ To create a new API key{ this . isCertEnabled ( ) ? " or certificate" : "" } , see{ " " }
457+ < TextLink href = "/settings/org/api-keys" > Settings</ TextLink > .
458+ </ div >
438459 { this . state . executionChecked && (
439460 < div className = "setup-notice" >
440461 < b > Note:</ b > You've enabled remote execution. In addition to these .bazelrc flags, you'll also need to
@@ -478,39 +499,31 @@ export default class SetupCodeComponent extends React.Component<Props, State> {
478499 ) }
479500 { this . state . auth == "cert" && (
480501 < div >
481- < div className = "downloads" >
482- { selectedCredential ?. certificate ?. cert && (
483- < div >
484- < a
485- download = "buildbuddy-cert.pem"
486- href = { window . URL . createObjectURL (
487- new Blob ( [ selectedCredential . certificate . cert ] , {
488- type : "text/plain" ,
489- } )
490- ) } >
491- Download buildbuddy-cert.pem
492- </ a >
493- </ div >
494- ) }
495- { selectedCredential ?. certificate ?. key && (
496- < div >
497- < a
498- download = "buildbuddy-key.pem"
499- href = { window . URL . createObjectURL (
500- new Blob ( [ selectedCredential . certificate . key ] , {
501- type : "text/plain" ,
502- } )
503- ) } >
504- Download buildbuddy-key.pem
505- </ a >
502+ { ! this . isAPIKeyValueReadbackExplicitlyDisabled ( ) && (
503+ < >
504+ < div className = "downloads" >
505+ { selectedCredential ?. certificate ?. cert && (
506+ < CertificateDownloadLink
507+ filename = "buildbuddy-cert.pem"
508+ contents = { selectedCredential . certificate . cert } >
509+ Download buildbuddy-cert.pem
510+ </ CertificateDownloadLink >
511+ ) }
512+ { selectedCredential ?. certificate ?. key && (
513+ < CertificateDownloadLink
514+ filename = "buildbuddy-key.pem"
515+ contents = { selectedCredential . certificate . key } >
516+ Download buildbuddy-key.pem
517+ </ CertificateDownloadLink >
518+ ) }
506519 </ div >
507- ) }
508- </ div >
509- To use certificate based auth, download the two files above and place them in your workspace directory .
510- If you place them outside of your workspace, update the paths in your { " " }
511- < span className = "code" > .bazelrc </ span > file to point to the correct location.
512- < br />
513- < br />
520+ To use certificate based auth, download the two files above and place them in your workspace
521+ directory. If you place them outside of your workspace, update the paths in your { " " }
522+ < span className = "code" > .bazelrc </ span > file to point to the correct location .
523+ < br />
524+ < br />
525+ < />
526+ ) }
514527 Note: Certificate based auth is only compatible with Bazel version 3.1 and above.
515528 </ div >
516529 ) }
0 commit comments