Skip to content

Commit

Permalink
chore: Set User-Agent header in API client
Browse files Browse the repository at this point in the history
  • Loading branch information
bvargasre committed Aug 6, 2024
1 parent bb9bb15 commit 0b4d0ae
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [5.0.32] - 2024-08-06
### Added
- Set User-Agent header in API client

## [5.0.31] - 2024-07-17
### Changed
- Method `SetDNACWaitTimeToManyRequest` update for update wait time from minutes to seconds.
Expand Down Expand Up @@ -642,4 +646,5 @@ Services removed on Cisco DNA Center 2.3.3.0's API:
[5.0.29]: https://github.com/cisco-en-programmability/dnacenter-go-sdk/compare/v5.0.28...v5.0.29
[5.0.30]: https://github.com/cisco-en-programmability/dnacenter-go-sdk/compare/v5.0.29...v5.0.30
[5.0.31]: https://github.com/cisco-en-programmability/dnacenter-go-sdk/compare/v5.0.30...v5.0.31
[Unreleased]: https://github.com/cisco-en-programmability/dnacenter-go-sdk/compare/v5.0.31...main
[5.0.32]: https://github.com/cisco-en-programmability/dnacenter-go-sdk/compare/v5.0.31...v5.0.32
[Unreleased]: https://github.com/cisco-en-programmability/dnacenter-go-sdk/compare/v5.0.32...main
5 changes: 5 additions & 0 deletions sdk/api_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ const DNAC_PASSWORD = "DNAC_PASSWORD"
const DNAC_DEBUG = "DNAC_DEBUG"
const DNAC_SSL_VERIFY = "DNAC_SSL_VERIFY"
const DNAC_WAIT_TIME = "DNAC_WAIT_TIME"
const VERSION = "2.3.5.3"
const USER_AGENT = "go-cisco-dnacsdk/" + VERSION

type FileDownload struct {
FileName string
Expand Down Expand Up @@ -167,6 +169,7 @@ func NewClientNoAuth() (*Client, error) {
var err error

client := resty.New()
client.SetHeader("User-Agent", USER_AGENT)
c := &Client{}
c.common.client = client
waitTimeToManyRequest := 0
Expand Down Expand Up @@ -198,6 +201,7 @@ func NewClientNoAuth() (*Client, error) {
retry := false
if r.StatusCode() == http.StatusUnauthorized {
cl := resty.New()
cl.SetHeader("User-Agent", USER_AGENT)

username := os.Getenv("DNAC_USERNAME")
password := os.Getenv("DNAC_PASSWORD")
Expand Down Expand Up @@ -339,6 +343,7 @@ func (s *Client) AuthClient() error {

// RestyClient returns the resty.Client used by the sdk
func (s *Client) RestyClient() *resty.Client {
s.common.client.SetHeader("User-Agent", USER_AGENT)
return s.common.client
}

Expand Down

0 comments on commit 0b4d0ae

Please sign in to comment.