Skip to content

Commit

Permalink
Adding support for refresh Token api (#3589)
Browse files Browse the repository at this point in the history
  • Loading branch information
vklohiya authored Oct 25, 2024
1 parent 56cb4c3 commit 656418a
Show file tree
Hide file tree
Showing 7 changed files with 254 additions and 89 deletions.
2 changes: 1 addition & 1 deletion pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func RunController(params Params) *Controller {
ctlr.addInformers()

// Start Sync CM token Manager
go ctlr.CMTokenManager.Start(make(chan struct{}), tokenmanager.CMAccessTokenExpiration)
go ctlr.CMTokenManager.Start(make(chan struct{}), tokenmanager.CMRefreshTokenExpiration)

// start request handler
ctlr.RequestHandler.startRequestHandler()
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ var _ = Describe("New Controller", func() {
})
It("should create, start and stop the controller", func() {
statusCode = 200
responseLogin := tokenmanager.TokenResponse{
responseLogin := tokenmanager.AccessTokenResponse{
AccessToken: "test.token",
}
server.AppendHandlers(
Expand All @@ -99,7 +99,7 @@ var _ = Describe("New Controller", func() {
ctlr := NewController(params, mockStatusManager)
Expect(ctlr).ToNot(BeNil())
time.Sleep(1 * time.Second)
token := ctlr.CMTokenManager.GetToken()
token := ctlr.CMTokenManager.GetAccessToken()
Expect(token).To(BeEquivalentTo("test.token"), "Token should be empty")
Expect(ctlr.CMTokenManager.CMVersion).To(Equal("20.1.0"))
Expect(ctlr.RequestHandler).ToNot(BeNil())
Expand Down
24 changes: 12 additions & 12 deletions pkg/controller/postManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func (postMgr *PostManager) postConfig(cfg *as3Config) {
}
log.Infof("%v[AS3]%v posting request to %v", getRequestPrefix(cfg.id), postMgr.postManagerPrefix, cfg.as3APIURL)
// add authorization header to the req
req.Header.Add("Authorization", "Bearer "+postMgr.tokenManager.GetToken())
req.Header.Add("Authorization", "Bearer "+postMgr.tokenManager.GetAccessToken())
// add content type header to the req
req.Header.Add("Content-Type", "application/json")
httpResp, responseMap := postMgr.httpPOST(req)
Expand Down Expand Up @@ -268,17 +268,17 @@ func (postMgr *PostManager) postConfig(cfg *as3Config) {
// return
// }
// // add authorization header to the req
// if postMgr.tokenManager.GetToken() == "" {
// if postMgr.tokenManager.GetAccessToken() == "" {
// log.Debugf("[AS3] Waiting for max 5 seconds for token syncing..")
// t := 0
// for t < 5 {
// time.Sleep(1 * time.Second)
// if postMgr.tokenManager.GetToken() != "" {
// if postMgr.tokenManager.GetAccessToken() != "" {
// log.Debugf("[AS3] Token is now available")
// break
// }
// }
// if postMgr.tokenManager.GetToken() == "" {
// if postMgr.tokenManager.GetAccessToken() == "" {
// log.Errorf("[AS3]%v Creating new HTTP request error: access token missing ", postMgr.postManagerPrefix)
// return
// }
Expand Down Expand Up @@ -311,7 +311,7 @@ func (postMgr *PostManager) postConfig(cfg *as3Config) {
// }
// log.Debugf("[AS3]%v posting request to %v", postMgr.postManagerPrefix, cfg.as3APIURL+"/deployments")
// // add authorization header to the req
// deployReq.Header.Add("Authorization", "Bearer "+postMgr.tokenManager.GetToken())
// deployReq.Header.Add("Authorization", "Bearer "+postMgr.tokenManager.GetAccessToken())
// deployReq.Header.Add("Content-Type", "application/json")

// httpDeployResp, deployResponseMap := postMgr.httpPOST(deployReq)
Expand Down Expand Up @@ -343,7 +343,7 @@ func (postMgr *PostManager) postConfig(cfg *as3Config) {
// }
// log.Debugf("[AS3]%v posting request to %v", postMgr.postManagerPrefix, cfg.as3APIURL)
// // add authorization header to the req
// declareReq.Header.Add("Authorization", "Bearer "+postMgr.tokenManager.GetToken())
// declareReq.Header.Add("Authorization", "Bearer "+postMgr.tokenManager.GetAccessToken())

// httpDeclareResp, declareResponseMap := postMgr.httpPOST(declareReq)
// if httpDeclareResp == nil || declareResponseMap == nil {
Expand Down Expand Up @@ -378,7 +378,7 @@ func (postMgr *PostManager) postConfig(cfg *as3Config) {
// }
// log.Debugf("[AS3]%v posting update request to %v", postMgr.postManagerPrefix, cfg.as3APIURL+docID)
// // add authorization header to the req
// updateReq.Header.Add("Authorization", "Bearer "+postMgr.tokenManager.GetToken())
// updateReq.Header.Add("Authorization", "Bearer "+postMgr.tokenManager.GetAccessToken())
// updateReq.Header.Add("Content-Type", "application/json")

// httpUpdateResp, updateResponseMap := postMgr.httpPOST(updateReq)
Expand Down Expand Up @@ -411,7 +411,7 @@ func (postMgr *PostManager) postConfig(cfg *as3Config) {
// }
// log.Debugf("[AS3]%v posting request to %v", postMgr.postManagerPrefix, cfg.as3APIURL+docID)
// // add authorization header to the req
// deleteReq.Header.Add("Authorization", "Bearer "+postMgr.tokenManager.GetToken())
// deleteReq.Header.Add("Authorization", "Bearer "+postMgr.tokenManager.GetAccessToken())

// httpDeclareResp, declareResponseMap := postMgr.httpPOST(deleteReq)
// if httpDeclareResp == nil || declareResponseMap == nil {
Expand Down Expand Up @@ -570,7 +570,7 @@ func (postMgr *PostManager) getTenantConfigStatus(id string, cfg *as3Config) {
}
log.Debugf("[AS3]%v posting request with taskId to %v", postMgr.postManagerPrefix, url)
// add authorization header to the req
req.Header.Add("Authorization", "Bearer "+postMgr.tokenManager.GetToken())
req.Header.Add("Authorization", "Bearer "+postMgr.tokenManager.GetAccessToken())

httpResp, responseMap := postMgr.httpPOST(req)
if httpResp == nil || responseMap == nil {
Expand Down Expand Up @@ -795,7 +795,7 @@ func (postMgr *PostManager) GetBigipAS3Version() (string, string, string, error)

log.Debugf("[AS3]%v posting GET BIGIP AS3 Version request on %v", postMgr.postManagerPrefix, url)
// add authorization header to the req
req.Header.Add("Authorization", postMgr.tokenManager.GetToken())
req.Header.Add("Authorization", postMgr.tokenManager.GetAccessToken())

httpResp, responseMap := postMgr.httpReq(req)
if httpResp == nil || responseMap == nil {
Expand Down Expand Up @@ -833,7 +833,7 @@ func (postMgr *PostManager) GetBigipRegKey() (string, error) {

log.Debugf("[AS3]%v Posting GET BIGIP Reg Key request on %v", postMgr.postManagerPrefix, url)
// add authorization header to the req
req.Header.Add("Authorization", postMgr.tokenManager.GetToken())
req.Header.Add("Authorization", postMgr.tokenManager.GetAccessToken())

httpResp, responseMap := postMgr.httpReq(req)
if httpResp == nil || responseMap == nil {
Expand Down Expand Up @@ -865,7 +865,7 @@ func (postMgr *PostManager) GetAS3DeclarationFromBigIP() (map[string]interface{}

log.Debugf("[AS3]%v posting GET BIGIP AS3 declaration request on %v", postMgr.postManagerPrefix, url)
// add authorization header to the req
req.Header.Add("Authorization", postMgr.tokenManager.GetToken())
req.Header.Add("Authorization", postMgr.tokenManager.GetAccessToken())

httpResp, responseMap := postMgr.httpReq(req)
if httpResp == nil || responseMap == nil {
Expand Down
10 changes: 5 additions & 5 deletions pkg/networkmanager/networkmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func (nm *NetworkManager) SetInstanceIds(bigIpConfigs []cisapiv1.BigIpConfig, co
}

// Set authorization header
req.Header.Set("Authorization", "Bearer "+nm.CMTokenManager.GetToken())
req.Header.Set("Authorization", "Bearer "+nm.CMTokenManager.GetAccessToken())

// Perform request
resp, err := nm.httpClient.Do(req)
Expand Down Expand Up @@ -263,7 +263,7 @@ func (nm *NetworkManager) GetL3ForwardsFromInstance(instanceId string, controlle
}

// Set authorization header
req.Header.Set("Authorization", "Bearer "+nm.CMTokenManager.GetToken())
req.Header.Set("Authorization", "Bearer "+nm.CMTokenManager.GetAccessToken())

// Perform request
resp, err := nm.httpClient.Do(req)
Expand Down Expand Up @@ -336,7 +336,7 @@ func (nm *NetworkManager) DeleteL3Forward(instanceId, l3ForwardID string) error
}

// Set authorization header
req.Header.Set("Authorization", "Bearer "+nm.CMTokenManager.GetToken())
req.Header.Set("Authorization", "Bearer "+nm.CMTokenManager.GetAccessToken())

// Perform request
resp, err := nm.httpClient.Do(req)
Expand Down Expand Up @@ -387,7 +387,7 @@ func (nm *NetworkManager) GetTaskStatus(taskRef string) (string, string, error)
return "", "", err
}
// Set authorization header
req.Header.Set("Authorization", "Bearer "+nm.CMTokenManager.GetToken())
req.Header.Set("Authorization", "Bearer "+nm.CMTokenManager.GetAccessToken())

// Perform request
resp, err := nm.httpClient.Do(req)
Expand Down Expand Up @@ -576,7 +576,7 @@ func (nm *NetworkManager) HandleL3ForwardRequest(req *NetworkConfigRequest, l3Fo
}

// create the l3 forward
err := nm.PostL3Forward(nm.CMTokenManager.ServerURL+InstancesURI+req.BigIp.InstanceId+L3Forwards, nm.CMTokenManager.GetToken(), l3Forward)
err := nm.PostL3Forward(nm.CMTokenManager.ServerURL+InstancesURI+req.BigIp.InstanceId+L3Forwards, nm.CMTokenManager.GetAccessToken(), l3Forward)
if err != nil {
bigipStatus.L3Status = &cisapiv1.L3Status{
Message: Create + Failed,
Expand Down
8 changes: 4 additions & 4 deletions pkg/networkmanager/networkmanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func stringToJson(s string) map[string]interface{} {
var _ = Describe("Network Manager Tests", func() {
var tokenManager *tokenmanager.TokenManager
var server *ghttp.Server
var tokenResponse tokenmanager.TokenResponse
var tokenResponse tokenmanager.AccessTokenResponse
var networkManager *NetworkManager
var inventoryResponse string
var l3ForwardResponse string
Expand Down Expand Up @@ -66,7 +66,7 @@ var _ = Describe("Network Manager Tests", func() {
Password: "admin",
}, "", true, mockStatusManager)

tokenResponse = tokenmanager.TokenResponse{
tokenResponse = tokenmanager.AccessTokenResponse{
AccessToken: "test.token",
}
server.AppendHandlers(
Expand Down Expand Up @@ -218,7 +218,7 @@ var _ = Describe("Network Manager Tests", func() {
Password: "admin",
}, "", true, mockStatusManager)

tokenResponse = tokenmanager.TokenResponse{
tokenResponse = tokenmanager.AccessTokenResponse{
AccessToken: "test.token",
}
server.AppendHandlers(
Expand Down Expand Up @@ -401,7 +401,7 @@ var _ = Describe("Network Manager Tests", func() {
Password: "admin",
}, "", true, mockStatusManager)

tokenResponse = tokenmanager.TokenResponse{
tokenResponse = tokenmanager.AccessTokenResponse{
AccessToken: "test.token",
}
server.AppendHandlers(
Expand Down
Loading

0 comments on commit 656418a

Please sign in to comment.