Skip to content

Commit

Permalink
First commit, catalystcenter-go-sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
fmunozmiranda committed Sep 11, 2024
0 parents commit dec3c04
Show file tree
Hide file tree
Showing 77 changed files with 61,387 additions and 0 deletions.
31 changes: 31 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
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/catalystcenter-go-sdk/tree/main#compatibility-matrix)

**Describe the bug**
A clear and concise description of what the bug is.

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
Please provide an screenshot of the successful API call with cuRL, Postman, etc.

**Environment (please complete the following information):**
* Cisco Catalyst Center Version and patch:
* Go Version:
* SDK version:
* OS Version:

**Additional context**
Add any other context about the problem here.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: ''
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
31 changes: 31 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Go

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.17

- name: FmtCheck
run: scripts/gofmtcheck.sh

- name: ErrCheck
run: scripts/errcheck.sh

- name: Build
run: go build -v ./...

- name: Test
run: go test -v ./...
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/
58 changes: 58 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Changelog
All notable changes to this project will be documented in this file.

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]

## [1.0.0] - 2024-09-11

### Added
New services for Cisco Catalyst Center 2.3.7.6's API:
- CiscoTrustedCertificates *CiscoTrustedCertificatesService
- Authentication *AuthenticationService
- ApplicationPolicy *ApplicationPolicyService
- Applications *ApplicationsService
- Clients *ClientsService
- CommandRunner *CommandRunnerService
- Compliance *ComplianceService
- ConfigurationArchive *ConfigurationArchiveService
- ConfigurationTemplates *ConfigurationTemplatesService
- DeviceOnboardingPnp *DeviceOnboardingPnpService
- DeviceReplacement *DeviceReplacementService
- Devices *DevicesService
- Discovery *DiscoveryService
- Eox *EoxService
- EventManagement *EventManagementService
- FabricWireless *FabricWirelessService
- File *FileService
- HealthAndPerformance *HealthAndPerformanceService
- Itsm *ItsmService
- ItsmIntegration *ItsmIntegrationService
- Issues *IssuesService
- LanAutomation *LanAutomationService
- Licenses *LicensesService
- NetworkSettings *NetworkSettingsService
- PathTrace *PathTraceService
- Platform *PlatformService
- Reports *ReportsService
- Sda *SdaService
- SecurityAdvisories *SecurityAdvisoriesService
- Sensors *SensorsService
- SiteDesign *SiteDesignService
- Sites *SitesService
- SoftwareImageManagementSwim *SoftwareImageManagementSwimService
- SystemSettings *SystemSettingsService
- Tag *TagService
- Task *TaskService
- Topology *TopologyService
- UserandRoles *UserandRolesService
- Users *UsersService
- Wireless *WirelessService
- CustomCall *CustomCallService
- CiscoDnaCenterSystem *CiscoDnaCenterSystemService
- CiscoTrustedCertificates *CiscoTrustedCertificatesService

[6.0.0]: https://github.com/cisco-en-programmability/catalystcenter-go-sdk/commits/v1.0.0
[Unreleased]: https://github.com/cisco-en-programmability/catalystcenter-go-sdk/compare/v1.0.0...main
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019-2020 Cisco Systems

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
21 changes: 21 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
GOFMT_FILES?=$$(find . -name '*.go' |grep -v vendor)
default: fmt fmtcheck errcheck


fmt:
gofmt -w $(GOFMT_FILES)

fmtcheck:
scripts/gofmtcheck.sh

errcheck:
scripts/errcheck.sh

vet:
@echo "go vet ."
@go vet $$(go list ./... | grep -v vendor/) ; if [ $$? -eq 1 ]; then \
echo ""; \
echo "Vet found suspicious constructs. Please check the reported constructs"; \
echo "and fix them if necessary before submitting the code for review."; \
exit 1; \
fi
110 changes: 110 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# catalystcenter-go-sdk

catalystcenter-go-sdk is a Go client library for [Catalyst Center Platform](https://developer.cisco.com/dnacenter/).

## Usage

```go
import catalyst "github.com/cisco-en-programmability/catalystcenter-go-sdk/sdk"
```

## Introduction

The catalystcenter-go-sdk makes it easier to work with the Cisco Catalyst Center Platform RESTFul APIs from Go.

It supports version 2.3.5.3, but it is backward compatible with other versions as long as those versions use the same URLs and options as version 2.3.5.3.

## Getting started

The first think you need to do is to generate an API client. There are two options to do it:

1. Parameters
2. Environment variables

### Parameters

The client could be generated with the following parameters:

- `baseURL`: The base URL, FQDN or IP, of the Catalyst Center instance.
- `username`: The username for the API authentication and authorization.
- `password`: The password for the API authentication and authorization.
- `debug`: Boolean to enable debugging
- `sslVerify`: Boolean to enable or disable SSL certificate verification.
- `waitTimeToManyRequest`: Time in minutes SDK will wait after API responds with 429 status code (to many requests) it defaults is in 1 minute.

```go
Client, err = catalyst.NewClientWithOptions("https://sandboxdnac.cisco.com",
"devnetuser", "Cisco123!",
"false", "false", nil)
devicesCount, _, err := Client.Devices.GetDeviceCount()
```

### Using environment variables

The client can be configured with the following environment variables:

- `CATALYST_BASE_URL`: The base URL, FQDN or IP, of the Catalyst Center instance.
- `CATALYST_USERNAME`: The username for the API authentication and authorization.
- `CATALYST_PASSWORD`: The password for the API authentication and authorization.
- `CATALYST_DEBUG`: Boolean to enable debugging
- `CATALYST_SSL_VERIFY`: Boolean to enable or disable SSL certificate verification.
- `CATALYST_WAIT_TIME`: Time in minutes SDK will wait after API responds with 429 status code (to many requests) it defaults is in 1 minute.

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

## Examples

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 = catalyst.NewClientWithOptions("https://sandboxdnac.cisco.com",
"devnetuser", "Cisco123!",
"false", "false",nil)
devicesCount, _, err := Client.Devices.GetDeviceCount()
if err != nil {
fmt.Println(err)
}
fmt.Println("Device Count:", devicesCount.Response)
getDeviceListQueryParams = &catalyst.GetDeviceListQueryParams{
PlatformID: []string{"C9300-24UX"},
}
fmt.Println("Printing device list ... PlatformID is C9300-24UX")
devices, _, err = Client.Devices.GetDeviceList(getDeviceListQueryParams)
if err != nil {
fmt.Println(err)
}
if devices.Response != nil {
for id, device := range *devices.Response {
fmt.Println("GET:", id, device.ID, device.MacAddress, device.ManagementIPAddress, device.PlatformID)
}
}
```

## Documentation
### catalystcenter-go-sdk
[![PkgGoDev](https://pkg.go.dev/badge/github.com/)](https://pkg.go.dev/github.com/cisco-en-programmability/catalystcenter-go-sdk)
## Compatibility matrix

| SDK versions | Cisco Catalyst Center version supported |
|--------------|------------------------------------|
| 0.y.z | 2.1.2 |
| 1.y.z | 2.1.2 |
| 2.y.z | 2.2.2.3 |
| 3.y.z | 2.2.3.3 |
| 4.y.z | 2.3.3.0 |
| 5.y.z | 2.3.5.3 |
| 6.y.z | 2.3.7.6 |

## Changelog

All notable changes to this project will be documented in the [CHANGELOG](https://github.com/cisco-en-programmability/catalystcenter-go-sdk/blob/main/CHANGELOG.md) file.

The development team may make additional name changes as the library evolves with the Cisco Catalyst Center APIs.


## License

This library is distributed under the MIT license found in the [LICENSE](./LICENSE) file.
32 changes: 32 additions & 0 deletions examples/application-policy/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package main

import (
"fmt"

catalyst "github.com/cisco-en-programmability/catalystcenter-go-sdk/sdk"
)

// Client is Catalyst Center API client
var client *catalyst.Client

func main() {
var err error
fmt.Println("Authenticating")
client, err = catalyst.NewClientWithOptions("https://192.168.196.2/",
"altus", "Altus123",
"true", "false", nil)
if err != nil {
fmt.Println(err)
return
}
// client.SetCatalystWaitTimeToManyRequest(2)
for i := 0; i < 10; i++ {
nResponse, _, err := client.ApplicationPolicy.GetApplicationsCount()
if err != nil {
fmt.Println(err)
return
}
fmt.Println(nResponse.Response)
}

}
47 changes: 47 additions & 0 deletions examples/applications/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package main

import (
"fmt"

catalyst "github.com/cisco-en-programmability/catalystcenter-go-sdk/sdk"
)

// Client is Catalyst Center API client
var client *catalyst.Client

func main() {
var err error
fmt.Println("Authenticating")
client, err = catalyst.NewClientWithOptions("https://192.168.196.2/",
"altus", "Altus123",
"true", "false", nil)
if err != nil {
fmt.Println(err)
return
}

queryParams := &catalyst.ApplicationsQueryParams{
SiteID: "1",
Offset: 1,
Limit: 5,
}

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

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

}
Loading

0 comments on commit dec3c04

Please sign in to comment.