Skip to content

Commit

Permalink
Merge pull request #65 from cisco-en-programmability/develop
Browse files Browse the repository at this point in the history
## [5.0.14] - 2023-10-12
  • Loading branch information
fmunozmiranda authored Oct 12, 2023
2 parents 55f71f5 + 13c1bc4 commit f88fa92
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 5 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ 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.14] - 2023-10-12
### Changed
`dnacenter-go-sdk` now is able to handle `401` API code and refresh token if it's required.

## [5.0.13] - 2023-09-19
### Changed
`IsCommonPool` property added to `ResponseSdaGetIPPoolFromSdaVirtualNetwork`
Expand Down Expand Up @@ -551,4 +555,5 @@ Services removed on Cisco DNA Center 2.3.3.0's API:
[5.0.11]: https://github.com/cisco-en-programmability/dnacenter-go-sdk/compare/v5.0.10...v5.0.11
[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
[Unreleased]: https://github.com/cisco-en-programmability/dnacenter-go-sdk/compare/v5.0.13...main
[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
16 changes: 14 additions & 2 deletions examples/applications/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,19 @@ func main() {
nResponse, _, err := client.Applications.Applications(queryParams)
if err != nil {
fmt.Println(err)
return
// return
}
if nResponse != nil {
fmt.Println(nResponse.Response)
}
fmt.Println(nResponse.Response)

// nResponse, _, err = client.Applications.Applications(queryParams)
// if err != nil {
// fmt.Println(err)
// // return
// }
// if nResponse != nil {
// fmt.Println(nResponse.Response)
// }

}
32 changes: 30 additions & 2 deletions sdk/api_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dnac
import (
"crypto/tls"
"fmt"
"log"
"net/http"
"os"
"strconv"
Expand Down Expand Up @@ -168,7 +169,6 @@ func NewClientNoAuth() (*Client, error) {
c := &Client{}
c.common.client = client
waitTimeToManyRequest := 0

if os.Getenv(DNAC_DEBUG) == "true" {
client.SetDebug(true)
}
Expand All @@ -194,7 +194,35 @@ 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 {
return r.StatusCode() == http.StatusTooManyRequests
if r.StatusCode() == http.StatusUnauthorized {
cl := resty.New()

username := os.Getenv("DNAC_USERNAME")
password := os.Getenv("DNAC_PASSWORD")
baseUrl := os.Getenv("DNAC_BASE_URL")
if os.Getenv(DNAC_SSL_VERIFY) == "false" {
cl.SetTLSClientConfig(&tls.Config{InsecureSkipVerify: true})
}

cl.SetBaseURL(baseUrl)

response, err := cl.R().
SetBasicAuth(username, password).
SetResult(&AuthenticationAPIResponse{}).
Post("dna/system/api/v1/auth/token")
if err != nil {
log.Printf("Err: %s", err.Error())
return false
}
result := response.Result().(*AuthenticationAPIResponse)
// log.Printf("resty: %s", response.String())
// request.SetHeader("X-auth-token", result.Token)
// request.SetHeader("X-auth-token", result.Token)
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
},
)
c.common.client.
Expand Down

0 comments on commit f88fa92

Please sign in to comment.