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 }
@@ -559,10 +567,10 @@ func GetRestConfigAsUserWithConn(bp config.BackplaneConfiguration, ocmConn *ocms
559567
560568// doLogin returns the proxy url for the target cluster.
561569func doLogin (api , clusterID , accessToken string ) (string , error ) {
562- return doLoginWithConn (api , clusterID , accessToken , nil )
570+ return doLoginWithConn (api , clusterID , accessToken , nil , false )
563571}
564572
565- func doLoginWithConn (api , clusterID , accessToken string , ocmConn * ocmsdk.Connection ) (string , error ) {
573+ func doLoginWithConn (api , clusterID , accessToken string , ocmConn * ocmsdk.Connection , readonly bool ) (string , error ) {
566574 var client BackplaneApi.ClientInterface
567575 var err error = nil
568576 if ocmConn != nil {
@@ -574,7 +582,18 @@ func doLoginWithConn(api, clusterID, accessToken string, ocmConn *ocmsdk.Connect
574582 return "" , fmt .Errorf ("unable to create backplane api client" )
575583 }
576584
577- resp , err := client .LoginCluster (context .TODO (), clusterID )
585+ // Create request editor to add readonly query parameter if needed
586+ var reqEditors []BackplaneApi.RequestEditorFn
587+ if readonly {
588+ reqEditors = append (reqEditors , func (ctx context.Context , req * http.Request ) error {
589+ q := req .URL .Query ()
590+ q .Add ("readonly" , "true" )
591+ req .URL .RawQuery = q .Encode ()
592+ return nil
593+ })
594+ }
595+
596+ resp , err := client .LoginCluster (context .TODO (), clusterID , reqEditors ... )
578597 // Print the whole response if we can't parse it. Eg. 5xx error from http server.
579598 if err != nil {
580599 // trying to determine the error
@@ -732,4 +751,4 @@ func getClusterIDFromExistingKubeConfig() (string, error) {
732751 clusterKey = clusterInfo .ClusterID
733752 logger .Debugf ("Backplane Cluster Infromation data extracted: %+v\n " , clusterInfo )
734753 return clusterKey , nil
735- }
754+ }
0 commit comments