Skip to content

Commit

Permalink
Merge pull request #66 from cisco-en-programmability/develop
Browse files Browse the repository at this point in the history
Develop v5.0.15
  • Loading branch information
fmunozmiranda authored Oct 24, 2023
2 parents f88fa92 + fa170b1 commit 1baff4d
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [5.0.15] - 2023-10-24
### Changed
Handle `200 code` with a `Rate Limit` error.

## [5.0.14] - 2023-10-12
### Changed
`dnacenter-go-sdk` now is able to handle `401` API code and refresh token if it's required.
Expand Down Expand Up @@ -556,4 +561,5 @@ Services removed on Cisco DNA Center 2.3.3.0's API:
[5.0.12]: https://github.com/cisco-en-programmability/dnacenter-go-sdk/compare/v5.0.11...v5.0.12
[5.0.13]: https://github.com/cisco-en-programmability/dnacenter-go-sdk/compare/v5.0.12...v5.0.13
[5.0.14]: https://github.com/cisco-en-programmability/dnacenter-go-sdk/compare/v5.0.13...v5.0.14
[Unreleased]: https://github.com/cisco-en-programmability/dnacenter-go-sdk/compare/v5.0.14...main
[5.0.15]: https://github.com/cisco-en-programmability/dnacenter-go-sdk/compare/v5.0.14...v5.0.15
[Unreleased]: https://github.com/cisco-en-programmability/dnacenter-go-sdk/compare/v5.0.15...main
29 changes: 29 additions & 0 deletions examples/execution-id/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package main

import (
"fmt"

dnac "github.com/cisco-en-programmability/dnacenter-go-sdk/v5/sdk"
)

// Client is DNA Center API client
var client *dnac.Client

func main() {
var err error
fmt.Println("Authenticating")
client, err = dnac.NewClientWithOptions("https://192.168.196.2/",
"altus", "Altus123",
"true", "false", nil)
if err != nil {
fmt.Println(err)
return
}
nResponse, _, err := client.Task.GetBusinessAPIExecutionDetails("a919fe4c-70c2-4023-a063-404e2705c277")
if err != nil {
fmt.Println(err)
return
}
fmt.Println(nResponse)

}
14 changes: 12 additions & 2 deletions sdk/api_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/http"
"os"
"strconv"
"strings"
"time"

"io/ioutil"
Expand Down Expand Up @@ -194,6 +195,7 @@ func NewClientNoAuth() (*Client, error) {
// RetryConditionFunc type is for retry condition function
// input: non-nil Response OR request execution error
func(r *resty.Response, err error) bool {
retry := false
if r.StatusCode() == http.StatusUnauthorized {
cl := resty.New()

Expand Down Expand Up @@ -221,8 +223,12 @@ func NewClientNoAuth() (*Client, error) {
c.common.client.SetHeader("X-auth-token", result.Token)
r.Request.SetHeader("X-auth-token", result.Token)
}

return r.StatusCode() == http.StatusTooManyRequests || r.StatusCode() == http.StatusUnauthorized
if strings.Contains(r.Request.URL, "/dna/intent/api/v1/dnacaap/management/execution-status/") {
if strings.Contains(r.Request.Result.(*ResponseTaskGetBusinessAPIExecutionDetails).BapiError, "Rate Limit") && statusIsFailure(r.Request.Result.(*ResponseTaskGetBusinessAPIExecutionDetails).Status) {
retry = true
}
}
return r.StatusCode() == http.StatusTooManyRequests || r.StatusCode() == http.StatusUnauthorized || retry
},
)
c.common.client.
Expand Down Expand Up @@ -353,3 +359,7 @@ func (s *Client) SetDNACWaitTimeToManyRequest(waitTimeToManyRequest int) error {
SetRetryMaxWaitTime(time.Duration(waitTimeToManyRequest+1) * time.Minute)
return err
}

func statusIsFailure(status string) bool {
return status == "failed" || status == "FAILURE"
}

0 comments on commit 1baff4d

Please sign in to comment.