5151 clusterInfo bool
5252 remediation string
5353 govcloud bool
54+ readonly bool
5455 }
5556
5657 // loginType derive the login type based on flags and args
@@ -133,6 +134,12 @@ func init() {
133134 "cluster-info" ,
134135 false , "Print basic cluster information after login" ,
135136 )
137+ flags .BoolVar (
138+ & args .readonly ,
139+ "readonly" ,
140+ false ,
141+ "Login with read-only access to the cluster" ,
142+ )
136143}
137144
138145// TODO there is something about the proxy config in relation to overriding with --url
@@ -336,9 +343,10 @@ func runLogin(cmd *cobra.Command, argv []string) (err error) {
336343 logger .WithFields (logger.Fields {
337344 "bpURL" : bpURL ,
338345 "clusterID" : clusterID ,
346+ "readonly" : args .readonly ,
339347 }).Debugln ("Query backplane-api for proxy url of our target cluster" )
340348 // Query backplane-api for proxy url
341- bpAPIClusterURL , err := doLogin (bpURL , clusterID , * accessToken )
349+ bpAPIClusterURL , err := doLoginWithConn (bpURL , clusterID , * accessToken , nil , args . readonly )
342350 if err != nil {
343351 // Declare helperMsg
344352 helperMsg := "\n \033 [1mNOTE: To troubleshoot the connectivity issues, please run `ocm-backplane health-check`\033 [0m\n \n "
@@ -474,7 +482,7 @@ func GetRestConfig(bp config.BackplaneConfiguration, clusterID string) (*rest.Co
474482 return nil , err
475483 }
476484
477- bpAPIClusterURL , err := doLogin (bp .URL , clusterID , * accessToken )
485+ bpAPIClusterURL , err := doLoginWithConn (bp .URL , clusterID , * accessToken , nil , false )
478486 if err != nil {
479487 return nil , fmt .Errorf ("failed to backplane login to cluster %s: %v" , cluster .Name (), err )
480488 }
@@ -503,7 +511,7 @@ func GetRestConfigWithConn(bp config.BackplaneConfiguration, ocmConnection *ocms
503511 return nil , err
504512 }
505513
506- bpAPIClusterURL , err := doLoginWithConn (bp .URL , clusterID , * accessToken , ocmConnection )
514+ bpAPIClusterURL , err := doLoginWithConn (bp .URL , clusterID , * accessToken , ocmConnection , false )
507515 if err != nil {
508516 return nil , fmt .Errorf ("failed to backplane login to cluster %s: %v" , cluster .Name (), err )
509517 }
@@ -557,12 +565,8 @@ func GetRestConfigAsUserWithConn(bp config.BackplaneConfiguration, ocmConn *ocms
557565 return cfg , nil
558566}
559567
560- // doLogin returns the proxy url for the target cluster.
561- func doLogin (api , clusterID , accessToken string ) (string , error ) {
562- return doLoginWithConn (api , clusterID , accessToken , nil )
563- }
564-
565- func doLoginWithConn (api , clusterID , accessToken string , ocmConn * ocmsdk.Connection ) (string , error ) {
568+ // doLoginWithConn returns the proxy url for the target cluster.
569+ func doLoginWithConn (api , clusterID , accessToken string , ocmConn * ocmsdk.Connection , readonly bool ) (string , error ) {
566570 var client BackplaneApi.ClientInterface
567571 var err error = nil
568572 if ocmConn != nil {
@@ -574,7 +578,18 @@ func doLoginWithConn(api, clusterID, accessToken string, ocmConn *ocmsdk.Connect
574578 return "" , fmt .Errorf ("unable to create backplane api client" )
575579 }
576580
577- resp , err := client .LoginCluster (context .TODO (), clusterID )
581+ // Create request editor to add readonly query parameter if needed
582+ var reqEditors []BackplaneApi.RequestEditorFn
583+ if readonly {
584+ reqEditors = append (reqEditors , func (ctx context.Context , req * http.Request ) error {
585+ q := req .URL .Query ()
586+ q .Add ("readonly" , "true" )
587+ req .URL .RawQuery = q .Encode ()
588+ return nil
589+ })
590+ }
591+
592+ resp , err := client .LoginCluster (context .TODO (), clusterID , reqEditors ... )
578593 // Print the whole response if we can't parse it. Eg. 5xx error from http server.
579594 if err != nil {
580595 // trying to determine the error
@@ -732,4 +747,4 @@ func getClusterIDFromExistingKubeConfig() (string, error) {
732747 clusterKey = clusterInfo .ClusterID
733748 logger .Debugf ("Backplane Cluster Infromation data extracted: %+v\n " , clusterInfo )
734749 return clusterKey , nil
735- }
750+ }
0 commit comments