Skip to content

Commit

Permalink
Merge pull request #47 from meraki/develop
Browse files Browse the repository at this point in the history
## [4.0.0] - 2025-01-20
  • Loading branch information
fmunozmiranda authored Jan 20, 2025
2 parents 18ea989 + 9b60e0d commit 589f3b9
Show file tree
Hide file tree
Showing 19 changed files with 9,134 additions and 1,844 deletions.
16 changes: 15 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [4.0.0] - 2025-01-20
### Changed
- dashboard-api-go supports now v1.53.0 of Meraki Dashboard API.
- update appliance.go, added new query parameters for GetOrganizationApplianceTrafficShapingVpnExclusionsByNetwork.
- update appliance.go, added new query parameters for GetOrganizationApplianceUplinkStatuses.

## [3.0.10] - 2024-11-27
### Changed
- update networks.go, GetOrganizationPolicyObjectsGroups returns an array.
Expand Down Expand Up @@ -278,6 +284,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- model_create_network_switch_link_aggregation_request_switch_profile_ports_inner service
- model_create_network_switch_port_schedule_request service
- model_create_network_switch_port_schedule_request_port_schedule service
- model_create_network_switch_port_schedule_request_port_schedule_friday service
- model_create_network_switch_port_schedule_request_port_schedule_monday service
- model_create_network_switch_port_schedule_request_port_schedule_saturday service
- model_create_network_switch_port_schedule_request_port_schedule_sunday service
- model_create_network_switch_port_schedule_request_port_schedule_thursday service
- model_create_network_switch_port_schedule_request_port_schedule_tuesday service
- model_create_network_switch_port_schedule_request_port_schedule_wednesday service
- model_create_network_switch_qos_rule_request service
- model_create_network_switch_routing_multicast_rendezvous_point_request service
- model_create_network_switch_stack_request service
Expand Down Expand Up @@ -1399,4 +1412,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[3.0.7]: https://github.com/meraki/dashboard-api-go/compare/v3.0.6...3.0.7
[3.0.8]: https://github.com/meraki/dashboard-api-go/compare/v3.0.7...3.0.8
[3.0.9]: https://github.com/meraki/dashboard-api-go/compare/v3.0.8...3.0.9
[Unreleased]: https://github.com/meraki/dashboard-api-go/compare/v3.0.9...main
[4.0.0]: https://github.com/meraki/dashboard-api-go/compare/v3.0.10...4.0.0
[Unreleased]: https://github.com/meraki/dashboard-api-go/compare/v4.0.0...main
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ client, err = meraki.NewClientWithOptions("https://api.meraki.com/",
|--------------|------------------------------------|
| 2.y.z | 1.33.0 |
| 3.y.z | 1.44.1 |
| 4.y.z | 1.53.0 |


## Changelog
Expand Down
2 changes: 1 addition & 1 deletion examples/testPagination/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"reflect"
"strings"

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

var client *meraki.Client
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/meraki/dashboard-api-go/v3
module github.com/meraki/dashboard-api-go/v4

go 1.21.5

Expand Down
110 changes: 105 additions & 5 deletions sdk/administered.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package meraki

import (
"fmt"
"net/http"
"strings"

"github.com/go-resty/resty/v2"
)
Expand Down Expand Up @@ -33,6 +33,14 @@ type ResponseAdministeredGetAdministeredIDentitiesMeAuthenticationSaml struct {
type ResponseAdministeredGetAdministeredIDentitiesMeAuthenticationTwoFactor struct {
Enabled *bool `json:"enabled,omitempty"` // If twoFactor authentication is enabled for this user
}
type ResponseAdministeredGetAdministeredIDentitiesMeAPIKeys []ResponseItemAdministeredGetAdministeredIDentitiesMeAPIKeys // Array of ResponseAdministeredGetAdministeredIdentitiesMeApiKeys
type ResponseItemAdministeredGetAdministeredIDentitiesMeAPIKeys struct {
CreatedAt string `json:"createdAt,omitempty"` // Date that the API key was created
Suffix string `json:"suffix,omitempty"` // Last 4 characters of the API key
}
type ResponseAdministeredGenerateAdministeredIDentitiesMeAPIKeys struct {
Key string `json:"key,omitempty"` // API key in plaintext. This value will not be accessible outside of key generation
}

//GetAdministeredIDentitiesMe Returns the identity of the current user.
/* Returns the identity of the current user.
Expand All @@ -57,13 +65,105 @@ func (s *AdministeredService) GetAdministeredIDentitiesMe() (*ResponseAdminister
}

if response.IsError() {
if response.StatusCode() == http.StatusUnauthorized {
return s.GetAdministeredIDentitiesMe()
}
return nil, response, fmt.Errorf("error with operation GetApplications")
return nil, response, fmt.Errorf("error with operation GetAdministeredIdentitiesMe")
}

result := response.Result().(*ResponseAdministeredGetAdministeredIDentitiesMe)
return result, response, err

}

//GetAdministeredIDentitiesMeAPIKeys List the non-sensitive metadata associated with the API keys that belong to the user
/* List the non-sensitive metadata associated with the API keys that belong to the user
*/
func (s *AdministeredService) GetAdministeredIDentitiesMeAPIKeys() (*ResponseAdministeredGetAdministeredIDentitiesMeAPIKeys, *resty.Response, error) {
path := "/api/v1/administered/identities/me/api/keys"
s.rateLimiterBucket.Wait(1)

response, err := s.client.R().
SetHeader("Content-Type", "application/json").
SetHeader("Accept", "application/json").
SetResult(&ResponseAdministeredGetAdministeredIDentitiesMeAPIKeys{}).
SetError(&Error).
Get(path)

if err != nil {
return nil, nil, err

}

if response.IsError() {
return nil, response, fmt.Errorf("error with operation GetAdministeredIdentitiesMeApiKeys")
}

result := response.Result().(*ResponseAdministeredGetAdministeredIDentitiesMeAPIKeys)
return result, response, err

}

//GenerateAdministeredIDentitiesMeAPIKeys Generates an API key for an identity
/* Generates an API key for an identity. For users who have access to more than one organization, the change will take up to five minutes to propagate. If one of the organizations is currently under maintenance, the change may not propagate fully until after the maintenance has been completed.
*/

func (s *AdministeredService) GenerateAdministeredIDentitiesMeAPIKeys() (*ResponseAdministeredGenerateAdministeredIDentitiesMeAPIKeys, *resty.Response, error) {
path := "/api/v1/administered/identities/me/api/keys/generate"
s.rateLimiterBucket.Wait(1)

response, err := s.client.R().
SetHeader("Content-Type", "application/json").
SetHeader("Accept", "application/json").
SetResult(&ResponseAdministeredGenerateAdministeredIDentitiesMeAPIKeys{}).
SetError(&Error).
Post(path)

if err != nil {
return nil, nil, err

}

if response.IsError() {
return nil, response, fmt.Errorf("error with operation GenerateAdministeredIdentitiesMeApiKeys")
}

result := response.Result().(*ResponseAdministeredGenerateAdministeredIDentitiesMeAPIKeys)
return result, response, err

}

//RevokeAdministeredIDentitiesMeAPIKeys Revokes an identity's API key, using the last four characters of the key
/* Revokes an identity's API key, using the last four characters of the key. For users who have access to more than one organization, the change will take up to five minutes to propagate. If one of the organizations is currently under maintenance, the change may not propagate fully until after the maintenance has been completed.
@param suffix suffix path parameter.
*/

func (s *AdministeredService) RevokeAdministeredIDentitiesMeAPIKeys(suffix string) (*resty.Response, error) {
path := "/api/v1/administered/identities/me/api/keys/{suffix}/revoke"
s.rateLimiterBucket.Wait(1)
path = strings.Replace(path, "{suffix}", fmt.Sprintf("%v", suffix), -1)

response, err := s.client.R().
SetHeader("Content-Type", "application/json").
SetHeader("Accept", "application/json").
SetError(&Error).
Post(path)

if err != nil {
return nil, err

}

if response.IsError() {
return response, fmt.Errorf("error with operation RevokeAdministeredIdentitiesMeApiKeys")
}

return response, err

}
35 changes: 18 additions & 17 deletions sdk/api_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const (
MERAKI_DASHBOARD_API_KEY = "MERAKI_DASHBOARD_API_KEY"
MERAKI_DEBUG = "MERAKI_DEBUG"
MERAKI_REQUESTS_PER_SECOND = "MERAKI_REQUESTS_PER_SECOND"
DEFAULT_USER_AGENT = "go-meraki/1.44.1"
DEFAULT_USER_AGENT = "go-meraki/1.53.0"
DEFAULT_REQUESTS_PER_SECOND = 10
)

Expand All @@ -28,20 +28,21 @@ type Client struct {
common service // Reuse a single struct instead of allocating one for each service on the heap.

// API Services
Administered *AdministeredService
Appliance *ApplianceService
Camera *CameraService
CellularGateway *CellularGatewayService
Devices *DevicesService
Insight *InsightService
Licensing *LicensingService
Networks *NetworksService
Organizations *OrganizationsService
Sensor *SensorService
Sm *SmService
Switch *SwitchService
Wireless *WirelessService
CustomCall *CustomCallService
Administered *AdministeredService
Appliance *ApplianceService
Camera *CameraService
CellularGateway *CellularGatewayService
Devices *DevicesService
Insight *InsightService
Licensing *LicensingService
Networks *NetworksService
Organizations *OrganizationsService
Sensor *SensorService
Sm *SmService
Switch *SwitchService
Wireless *WirelessService
WirelessController *WirelessControllerService
CustomCall *CustomCallService
}

type service struct {
Expand Down Expand Up @@ -165,7 +166,7 @@ func SetOptions(baseURL string, dashboardApiKey string, debug string, userAgent
var err error

if !validateUserAgent(userAgent) {
return errors.New("user-agent bad format, expected: `AplicationName VendorName`")
return errors.New("user-agent bad format, expected: `AplicationName VendorName Client`")
}

err = os.Setenv(MERAKI_USER_AGENT, userAgent)
Expand Down Expand Up @@ -303,6 +304,6 @@ func convertToString(i interface{}) string {
}

func validateUserAgent(ua string) bool {
regex := regexp.MustCompile(`^\S+\s\S+$`)
regex := regexp.MustCompile(`^\S+ \S+ \S+$`)
return regex.MatchString(ua)
}
10 changes: 5 additions & 5 deletions sdk/api_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type result struct{}

// testClient returns a new Client for testing.
func testClient(t *testing.T) *Client {
err := SetOptions(TEST_MERAKI_BASE_URL, TEST_MERAKI_DASHBOARD_API_KEY, TEST_MERAKI_DEBUG, "Test Cloverhound")
err := SetOptions(TEST_MERAKI_BASE_URL, TEST_MERAKI_DASHBOARD_API_KEY, TEST_MERAKI_DEBUG, "Test Cloverhound TEST")
assert.Equal(t, err, nil)
client, err := NewClient()
assert.Equal(t, err, nil)
Expand All @@ -37,7 +37,7 @@ func testClient(t *testing.T) *Client {

// TestSetOptions tests the Client.SetOptions method.
func TestSetOptions(t *testing.T) {
err := SetOptions(TEST_MERAKI_BASE_URL, TEST_MERAKI_DASHBOARD_API_KEY, TEST_MERAKI_DEBUG, "Test Cloverhound")
err := SetOptions(TEST_MERAKI_BASE_URL, TEST_MERAKI_DASHBOARD_API_KEY, TEST_MERAKI_DEBUG, "Test Cloverhound TEST")
assert.Equal(t, err, nil)
assert.Equal(t, os.Getenv(MERAKI_BASE_URL), TEST_MERAKI_BASE_URL)
assert.Equal(t, os.Getenv(MERAKI_DASHBOARD_API_KEY), TEST_MERAKI_DASHBOARD_API_KEY)
Expand All @@ -46,7 +46,7 @@ func TestSetOptions(t *testing.T) {

// TestSetOptions tests the Client.SetOptionsWithRequests method.
func TestSetOptionsWithRequests(t *testing.T) {
err := SetOptionsWithRequests(TEST_MERAKI_BASE_URL, TEST_MERAKI_DASHBOARD_API_KEY, TEST_MERAKI_DEBUG, "Test Cloverhound", TEST_MERAKI_REQUESTS_PER_SECOND)
err := SetOptionsWithRequests(TEST_MERAKI_BASE_URL, TEST_MERAKI_DASHBOARD_API_KEY, TEST_MERAKI_DEBUG, "Test Cloverhound TEST", TEST_MERAKI_REQUESTS_PER_SECOND)
assert.Equal(t, err, nil)
assert.Equal(t, os.Getenv(MERAKI_BASE_URL), TEST_MERAKI_BASE_URL)
assert.Equal(t, os.Getenv(MERAKI_DASHBOARD_API_KEY), TEST_MERAKI_DASHBOARD_API_KEY)
Expand All @@ -68,7 +68,7 @@ func TestNewClientWithOptions(t *testing.T) {
url := "url"
key := "key"
debug := false
client, err := NewClientWithOptions(url, key, strconv.FormatBool(debug), "Test Cloverhound")
client, err := NewClientWithOptions(url, key, strconv.FormatBool(debug), "Test Cloverhound TEST")
assert.Equal(t, err, nil)
assert.NotEqual(t, client, nil)
assert.Equal(t, client.common.client.HostURL, url)
Expand All @@ -82,7 +82,7 @@ func TestNewClientWithOptionsAndRequests(t *testing.T) {
key := "key"
debug := false
requests := 6
client, err := NewClientWithOptionsAndRequests(url, key, strconv.FormatBool(debug), "Test Cloverhound", requests)
client, err := NewClientWithOptionsAndRequests(url, key, strconv.FormatBool(debug), "Test Cloverhound TEST", requests)
assert.Equal(t, err, nil)
assert.NotEqual(t, client, nil)
assert.Equal(t, client.common.client.HostURL, url)
Expand Down
Loading

0 comments on commit 589f3b9

Please sign in to comment.