Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Set User-Agent header in API client #87

Merged
merged 1 commit into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading