Skip to content

Commit

Permalink
Support: service API Key for cluster config
Browse files Browse the repository at this point in the history
  • Loading branch information
kavya498 committed Sep 6, 2021
1 parent e7648c2 commit da5522a
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions api/container/containerv2/openshift.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,21 +120,23 @@ func (r *clusters) FetchOCTokenForKubeConfig(kubecfg []byte, cMeta *ClusterInfo,
}

var token, passcode string
trace.Logger.Println("Creating user passcode to login for getting oc token")
if r.client.Config.BluemixAPIKey == "" {
trace.Logger.Println("Creating user passcode to login for getting oc token")

// Retry to cover rate limiting on passcode endpoint in particular
for try := 1; try <= 3; try++ {
passcode, err = r.client.TokenRefresher.GetPasscode()
// Retry to cover rate limiting on passcode endpoint in particular
for try := 1; try <= 3; try++ {
passcode, err = r.client.TokenRefresher.GetPasscode()

if err == nil {
break
}
if err == nil {
break
}

if err != nil && try == 3 {
return kubecfg, err
}
if err != nil && try == 3 {
return kubecfg, err
}

time.Sleep(1 * time.Second)
time.Sleep(1 * time.Second)
}
}

authEP, err := func(meta *ClusterInfo) (*authEndpoints, error) {
Expand Down Expand Up @@ -206,8 +208,15 @@ func neverRedirect(req *http.Request, via []*http.Request) error {
}

func (r *clusters) openShiftAuthorizePasscode(authEP *authEndpoints, passcode string, skipSSLVerification bool) (string, string, error) {
request := rest.GetRequest(authEP.AuthorizationEndpoint+"?response_type=token&client_id=openshift-challenging-client").
Set("Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("passcode:%s", passcode))))
var request *rest.Request
if r.client.Config.BluemixAPIKey != "" {
apikey := r.client.Config.BluemixAPIKey
request = rest.GetRequest(authEP.AuthorizationEndpoint+"?response_type=token&client_id=openshift-challenging-client").
Set("Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("apikey:%s", apikey))))
} else {
request = rest.GetRequest(authEP.AuthorizationEndpoint+"?response_type=token&client_id=openshift-challenging-client").
Set("Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("passcode:%s", passcode))))
}

// Creating a new client instance (instead of tempering with existing one) to avoid race conditions
copyConfig := r.client.Config.Copy()
Expand Down

0 comments on commit da5522a

Please sign in to comment.