Skip to content

Commit

Permalink
Merge pull request scottdware#92 from f5devcentral/devel_vendor_sync_…
Browse files Browse the repository at this point in the history
…02012024

adding vendor changes
  • Loading branch information
RavinderReddyF5 authored Jan 2, 2024
2 parents 95f22f4 + bede401 commit 074c3e5
Showing 1 changed file with 51 additions and 2 deletions.
53 changes: 51 additions & 2 deletions bigip.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,19 @@ func NewTokenSession(bigipConfig *Config) (b *BigIP, err error) {
Token struct {
Token string
}
Timeout struct {
Timeout int64
}
}

type timeoutReq struct {
Timeout int64 `json:"timeout"`
}

type timeoutResp struct {
Timeout struct {
Timeout int64
}
}

auth := authReq{
Expand All @@ -152,15 +165,15 @@ func NewTokenSession(bigipConfig *Config) (b *BigIP, err error) {
bigipConfig.LoginReference,
}

marshalJSON, err := json.Marshal(auth)
marshalJSONauth, err := json.Marshal(auth)
if err != nil {
return
}

req := &APIRequest{
Method: "post",
URL: "mgmt/shared/authn/login",
Body: string(marshalJSON),
Body: string(marshalJSONauth),
ContentType: "application/json",
}

Expand Down Expand Up @@ -207,6 +220,42 @@ func NewTokenSession(bigipConfig *Config) (b *BigIP, err error) {

b.Token = aresp.Token.Token

//Once we have obtained a token, we should actually apply the configured timeout to it
if time.Duration(aresp.Timeout.Timeout)*time.Second != bigipConfig.ConfigOptions.TokenTimeout { // The inital value is the max timespan
timeout := timeoutReq{
int64(bigipConfig.ConfigOptions.TokenTimeout.Seconds()),
}

marshalJSONtimeout, errToken := json.Marshal(timeout)
if errToken != nil {
return b, errToken
}

timeoutReq := &APIRequest{
Method: "patch",
URL: ("mgmt/shared/authz/tokens/" + b.Token),
Body: string(marshalJSONtimeout),
ContentType: "application/json",
}
resp, errToken := b.APICall(timeoutReq)
if errToken != nil {
return b, errToken
}

if resp == nil {
errToken = fmt.Errorf("unable to update token timeout")
return b, errToken
}
var tresp map[string]interface{}
errToken = json.Unmarshal(resp, &tresp)
if err != nil {
return b, errToken
}
if time.Duration(int64(tresp["timeout"].(float64)))*time.Second != bigipConfig.ConfigOptions.TokenTimeout {
err = fmt.Errorf("failed to update token lifespan")
return
}
}
return
}

Expand Down

0 comments on commit 074c3e5

Please sign in to comment.