-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: ✨ Support Nautobot 2.x * Use latest 1.x version * full test * update ci version * bump nautobot to 2.1.9 * switch to correct git module * fix dependencies * Remove old commands * switch to openapi-generator� * switch to swagger-codegen * Nautobot bindings 2.16-beta * fix github workflow * simplify code generation * Patch spec file * Fix spec patching, add missing "time" imports * Auto generate tests and update to nautobot 2.3.1 * Do not skip spec validation * Update github workflow to nautobot 2.3.1 * Re-add LICENSE * remove unused patches * install docker-compose in ci * Add temporary branch for terraform * Make cloud_account_count not required for Manufacturer * Remove all _count properties from Manufacturer's required list * Remove all _count parameters from required list * Document what needs to be fixed in spec patcher * Update to Nautobot 2.3.2 * Correctly fix PowerFeed and Prefix * Remove .travis.yml * Fix AvailableIP spec * Use manual README and release workflow --------- Co-authored-by: Christian Adell <chadell@gmail.com> Co-authored-by: TobiPeterG <tobi.goergens@gmail.com>
- Loading branch information
1 parent
4d653a8
commit 117bd94
Showing
2,119 changed files
with
1,589,501 additions
and
354,964 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
# go-nautobot | ||
|
||
## :warning: Disclaimer :warning: | ||
|
||
This project is in **beta** development stage, and it's suitable to change before being released as generally available. Use it at your own discretion. | ||
|
||
## Introduction | ||
|
||
`go-nautobot` package provides the Go Bindings to interact with [Nautobot Source of Truth](https://nautobot.readthedocs.io/en/stable/) API. Nautobot provides OpenAPI 3.0 specs and an `api_version` query parameter to specify the `major.minor` version to generate the schema from. | ||
|
||
This package is auto-generated from Nautobot, and it comes with its own versioning schema, independent of Nautobot. For more details about versioning, check the [Release Versioning](#release-versioning) section. | ||
|
||
## Customization | ||
|
||
This package only generates the bindings for the Nautobot Core application, and not for the rich [apps ecosystem](https://docs.nautobot.com/projects/core/en/stable/apps/) around it. It's likely that the bindings in this package are not 100% correspond to your Nautobot environment, as you may have installed some public apps or your own homegrown ones. | ||
|
||
Being aware of it, most often than not, you would need to generate your own bindings using the OpenAPI schema provided by your Nautobot deployment (with the installed apps). These are the steps to reproduce it: | ||
|
||
1. Install `openapi-codegen`. | ||
|
||
```bash | ||
$ wget https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/7.8.0/openapi-generator-cli-7.8.0.jar -O openapi-generator-cli.jar | ||
``` | ||
|
||
2. Define your `openapi-codegen` config file. You can use the [one in this repository](development/oapi-config.yml). | ||
|
||
3. Download the `swagger.yaml` from the API, using the proper minor version: | ||
|
||
```bash | ||
$ wget --header="Authorization: Token <your-nautobot-token>" http://<your_nautobot>/api/swagger.yaml?api_version=<major.minor_version> -O swagger.yaml | ||
``` | ||
|
||
4. Generate the Go bindings | ||
|
||
```bash | ||
$ export _JAVA_OPTIONS=-DmaxYamlCodePoints=99999999 | ||
$ java ./openapi-generator-cli.jar generate --config oapi-config.yaml \ | ||
--input-spec swagger.yaml \ | ||
--output ./ \ | ||
--inline-schema-options RESOLVE_INLINE_ENUMS=true \ | ||
--http-user-agent go-nautobot/$(<major.minor_version>) | ||
``` | ||
|
||
## Release Versioning | ||
|
||
`go-nautobot` uses semantic versioning with a loose dependency on the Nautobot major-minor versioning used to generate the bindings. | ||
|
||
The minor version in `go-nautobot` will always match the minor version from Nautobot, but the patch version will evolve independently. | ||
|
||
For example, a fictitious release process would be: | ||
|
||
| Nautobot | `go-nautobot` | | ||
| -------- | ---------------------- | | ||
| 5.1.0 | 5.1.0 | | ||
| 5.1.1 | 5.1.1 | | ||
| 5.1.1\* | 5.1.2 (some local fix) | | ||
| 5.1.2 | 5.1.3 | | ||
|
||
> the "\*" case shows that when regenerating the bindings for the same Nautobot version, a increment on the patch release of `go-nautobot` occurs. | ||
This way the project versioning will keep a relationship with the original minor Nautobot version while it also enables its own release lifecycle. | ||
|
||
## How to use `go-nautobot` package | ||
|
||
### Go Get Nautobot package | ||
|
||
Simply point your `get` for the `nautobot` package to the version you require, in this example version `1.5.8-beta`: | ||
|
||
```bash | ||
$ go get github.com/nautobot/go-nautobot@latest | ||
``` | ||
|
||
### Go main example | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
nb "github.com/nautobot/go-nautobot" | ||
) | ||
|
||
func check(err error) { | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
func main() { | ||
token := "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" | ||
|
||
config := nb.NewConfiguration() | ||
config.Servers[0].URL = "demo.nautobot.com/api" | ||
c := nb.NewAPIClient(config) | ||
|
||
ctx := context.Background() | ||
auth := context.WithValue( | ||
ctx, | ||
nb.ContextAPIKeys, | ||
map[string]nb.APIKey{ | ||
"tokenAuth": { | ||
Key: token, | ||
Prefix: "Token", | ||
}, | ||
}, | ||
) | ||
|
||
resp, _, err := c.DcimAPI.DcimManufacturersList(auth).Execute() | ||
check(err) | ||
|
||
fmt.Printf("%v", string(resp.Results)) | ||
|
||
} | ||
|
||
``` | ||
|
||
### Other usage examples | ||
|
||
- [Terraform Provider for Nautobot](https://github.com/nautobot/terraform-provider-nautobot/) | ||
|
||
### Documentation | ||
See the `docs` folder for documentation | ||
|
||
## Local Development | ||
|
||
> See the `Development` folder's README for instructions. | ||
### Run tests locally | ||
|
||
``` | ||
go test -v -gcflags="-e" ./... | ||
``` | ||
|
||
> Hint: If you get a build fail during testing, check that you are not limiting container memory to 2GB. Upgrade to 4GB. | ||
### Trigger the release manually | ||
|
||
The release process can be triggered manually from GitHub Actions CLI (with the proper permissions): | ||
|
||
``` | ||
gh workflow run release.yml -f tag=1.3.2 | ||
``` | ||
|
||
## TODO | ||
- get rid of the openAPI spec patcher, this means either solving issues with the code generator or with the Nautobot API (see `development/scripts/fix-spec.py`) | ||
- create tests for API functions | ||
|
||
## Author | ||
- @chadell Maintainer of go-nautobot | ||
- @TobiPeterG (Tobias Görgens) brought up go-nautobot for Nautobot 2.x |
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
# Default owner(s) of all files in this repository | ||
* @chadell | ||
* @TobiPeterG |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,24 @@ | ||
.idea_modules/ | ||
|
||
# JIRA plugin | ||
atlassian-ide-plugin.xml | ||
|
||
# Cursive Clojure plugin | ||
.idea/replstate.xml | ||
|
||
# Crashlytics plugin (for Android Studio and IntelliJ) | ||
com_crashlytics_export_strings.xml | ||
crashlytics.properties | ||
crashlytics-build.properties | ||
fabric.properties | ||
|
||
# Editor-based Rest Client | ||
.idea/httpRequests | ||
|
||
# Android studio 3.1+ serialized cache file | ||
.idea/caches/build_file_checksums.ser | ||
|
||
### PyCharm Patch ### | ||
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 | ||
|
||
# *.iml | ||
# modules.xml | ||
# .idea/misc.xml | ||
# *.ipr | ||
|
||
# Sonarlint plugin | ||
# https://plugins.jetbrains.com/plugin/7973-sonarlint | ||
.idea/**/sonarlint/ | ||
|
||
# SonarQube Plugin | ||
# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin | ||
.idea/**/sonarIssues.xml | ||
|
||
# Markdown Navigator plugin | ||
# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced | ||
.idea/**/markdown-navigator.xml | ||
.idea/**/markdown-navigator-enh.xml | ||
.idea/**/markdown-navigator/ | ||
|
||
# Cache file creation bug | ||
# See https://youtrack.jetbrains.com/issue/JBR-2257 | ||
.idea/$CACHE_FILE$ | ||
|
||
# CodeStream plugin | ||
# https://plugins.jetbrains.com/plugin/12206-codestream | ||
.idea/codestream.xml | ||
|
||
### vscode ### | ||
.vscode/* | ||
*.code-workspace | ||
# Compiled Object files, Static and Dynamic libs (Shared Objects) | ||
*.o | ||
*.a | ||
*.so | ||
|
||
# Folders | ||
_obj | ||
_test | ||
|
||
# Architecture specific extensions/prefixes | ||
*.[568vq] | ||
[568vq].out | ||
|
||
*.cgo1.go | ||
*.cgo2.c | ||
_cgo_defun.c | ||
_cgo_gotypes.go | ||
_cgo_export.* | ||
|
||
_testmain.go | ||
|
||
*.exe | ||
*.test | ||
*.prof |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# OpenAPI Generator Ignore | ||
# Generated by openapi-generator https://github.com/openapitools/openapi-generator | ||
|
||
# Use this file to prevent files from being overwritten by the generator. | ||
# The patterns follow closely to .gitignore or .dockerignore. | ||
|
||
# As an example, the C# client generator defines ApiClient.cs. | ||
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: | ||
#ApiClient.cs | ||
|
||
# You can match any string of characters against a directory, file or extension with a single asterisk (*): | ||
#foo/*/qux | ||
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux | ||
|
||
# You can recursively match patterns against a directory, file or extension with a double asterisk (**): | ||
#foo/**/qux | ||
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux | ||
|
||
# You can also negate patterns with an exclamation (!). | ||
# For example, you can ignore all files in a docs folder with the file extension .md: | ||
#docs/*.md | ||
# Then explicitly reverse the ignore rule for a single file: | ||
#!docs/README.md |
Oops, something went wrong.