Skip to content

Commit

Permalink
New main branch SDK doesn't use the intended user agent string format #…
Browse files Browse the repository at this point in the history
…21

Incorrect links to documentation in code #23 [Removed]
API Rate limiting is not handled in client #20
Refactor api client to adhere to rate limits #25
  • Loading branch information
fmunozmiranda committed Mar 12, 2024
1 parent a548f8e commit 2d468ea
Show file tree
Hide file tree
Showing 22 changed files with 1,355 additions and 572 deletions.
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ assignees: ''
**Prerequisites**
* [ ] Have you tested the operation in the API directly?
* [ ] Do you have the latest SDK version?
* [ ] Review [compability matrix](https://github.com/cisco-en-programmability/dnacenter-go-sdk/tree/main#compatibility-matrix)
* [ ] Review [compability matrix](https://github.com/meraki/dashboard-api-go?tab=readme-ov-file#compatibility-matrix)

**Describe the bug**
A clear and concise description of what the bug is.
Expand All @@ -22,7 +22,7 @@ A clear and concise description of what you expected to happen.
Please provide an screenshot of the successful API call with cuRL, Postman, etc.

**Environment (please complete the following information):**
* Cisco DNA Center Version and patch:
* Cisco Dasboard Meraki Version and patch:
* Go Version:
* SDK version:
* OS Version:
Expand Down
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ The client could be generated with the following parameters:
- `baseURL`: The base URL, FQDN or IP, of the MERAKI instance.
- `dashboardApiKey`: The meraki_key for access to API.
- `debug`: Boolean to enable debugging
- `sslVerify`: Boolean to enable or disable SSL certificate verification.
- `customUserAgent`: Set Custom user agent, if is nil, default is: (golang/*)

This comment has been minimized.

Copy link
@TKIPisalegacycipher

TKIPisalegacycipher Mar 13, 2024

Contributor

Users should not be able to override the UA in this way.

- `requestPerSecond`: Set request per second allowed for client, if is nil, default is: (10)

```go
client, err = meraki.NewClientWithOptions("https://api.meraki.com/",
"MERAKI_KEY",
"true", "false")
"true", nil,nil)
nResponse, _, err := client.Administered.GetAdministeredIDentitiesMe()
if err != nil {
fmt.Println(err)
Expand All @@ -48,10 +49,10 @@ The client can be configured with the following environment variables:
- `MERAKI_BASE_URL`: The base URL, FQDN or IP, of the MERAKI instance.
- `MERAKI_DASHBOARD_API_KEY`: The meraki_key for access to API.
- `MERAKI_DEBUG`: Boolean to enable debugging
- `MERAKI_SSL_VERIFY`: Boolean to enable or disable SSL certificate verification.
- `MERAKI_USER_AGENT`: Custom user agent can be set. Default (golang/*)

This comment has been minimized.

Copy link
@TKIPisalegacycipher

TKIPisalegacycipher Mar 13, 2024

Contributor

This should be called MERAKI_GO_SDK_CALLER to match line 86 of https://github.com/meraki/dashboard-api-python/blob/main/meraki/config.py

This comment has been minimized.

Copy link
@TKIPisalegacycipher

TKIPisalegacycipher Mar 13, 2024

Contributor

We do not need to mention the user agent string in this docstring.


```go
Client, err = meraki.NewClient()
Client, err = meraki.NewClient(nil)
devicesCount, _, err := Client.Devices.GetDeviceCount()
```

Expand All @@ -60,9 +61,12 @@ devicesCount, _, err := Client.Devices.GetDeviceCount()
Here is an example of how we can generate a client, get a device count and then a list of devices filtering them using query params.

```go
client, err = meraki.NewClientWithOptions("https://api.meraki.com/",
"Meraki_key",
"true", "false")

requestPerSecond := 5
custom_user_agent := "customUA"
client, err = meraki.NewClientWithOptions("https://api.meraki.com/",
"APIKEY",
"true", &custom_user_agent, &requestPerSecond)
if err != nil {
fmt.Println(err)
return
Expand Down
22 changes: 14 additions & 8 deletions examples/administered/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,48 @@ package main

import (
"fmt"
"os"

meraki "github.com/meraki/dashboard-api-go/v2/sdk"
)

// Client is DNA Center API client
// Client is Dasboard Meraki API client
var client *meraki.Client

func main() {
var err error
fmt.Println("Authenticating")
requestPerSecond := 5
custom_user_agent := "customUA"
client, err = meraki.NewClientWithOptions("https://api.meraki.com/",
"12f2eb53588c75e28d89e108a05ea0c2487b08cf",
"true", "false")
"true", &custom_user_agent, &requestPerSecond)
if err != nil {
fmt.Println(err)
return
}

nResponse, _, err := client.Administered.GetAdministeredIDentitiesMe()
if err != nil {
fmt.Println(err)

os.Exit(1)
return
}
if nResponse != nil {
fmt.Println(nResponse)

return
}

nResponse2, _, err := client.Administered.GetAdministeredIDentitiesMe()
nResponse2, _, err := client.Organizations.GetOrganization("828099381482762270")
if err != nil {
fmt.Println(err)

os.Exit(1)
return
}
if nResponse2 != nil {
fmt.Println(nResponse)
fmt.Println(nResponse2)

return
}
fmt.Println("There's no data on response")

}
2 changes: 1 addition & 1 deletion examples/networks/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func main() {
fmt.Println("Authenticating")
client, err = meraki.NewClientWithOptions("https://api.meraki.com/",
"12f2eb53588c75e28d89e108a05ea0c2487b08cf",
"true", "false")
"true", nil, nil)
if err != nil {
fmt.Println(err)
return
Expand Down
2 changes: 1 addition & 1 deletion examples/organizations/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func main() {
fmt.Println("Authenticating")
client, err = meraki.NewClientWithOptions("https://api.meraki.com/",
"12f2eb53588c75e28d89e108a05ea0c2487b08cf",
"true", "false")
"true", nil, nil)
if err != nil {
fmt.Println(err)
return
Expand Down
2 changes: 1 addition & 1 deletion examples/testPagination/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func main() {
fmt.Println("Authenticating")
client, err = meraki.NewClientWithOptions("https://api.meraki.com/",
"12f2eb53588c75e28d89e108a05ea0c2487b08cf",
"false", "false")
"false", nil, nil)
if err != nil {
fmt.Println(err)
return
Expand Down
6 changes: 5 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ go 1.21.5
require (
github.com/go-resty/resty/v2 v2.11.0
github.com/google/go-querystring v1.1.0
github.com/juju/ratelimit v1.0.2
)

require golang.org/x/net v0.17.0 // indirect
require (
golang.org/x/net v0.17.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
)
9 changes: 9 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/juju/ratelimit v1.0.2 h1:sRxmtRiajbvrcLQT7S+JbqU0ntsb9W2yhSdNN8tWfaI=
github.com/juju/ratelimit v1.0.2/go.mod h1:qapgC/Gy+xNh9UxzV13HGGl/6UXNN+ct+vwSgWNm/qk=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
Expand Down Expand Up @@ -47,3 +54,5 @@ golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
6 changes: 3 additions & 3 deletions sdk/administered.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ type ResponseAdministeredGetAdministeredIDentitiesMeAuthenticationTwoFactor stru
/* Returns the identity of the current user.
Documentation Link: https://developer.cisco.com/docs/dna-center/#!get-administered-identities-me
*/
*/
func (s *AdministeredService) GetAdministeredIDentitiesMe() (*ResponseAdministeredGetAdministeredIDentitiesMe, *resty.Response, error) {
path := "/api/v1/administered/identities/me"

s.rateLimiterBucket.Wait(1)
response, err := s.client.R().
SetHeader("Content-Type", "application/json").
SetHeader("Accept", "application/json").
Expand Down
Loading

0 comments on commit 2d468ea

Please sign in to comment.