-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: init diode-go-sdk (part 2) (#2)
--------- Signed-off-by: Michal Fiedorowicz <mfiedorowicz@netboxlabs.com>
- Loading branch information
1 parent
6a34790
commit 64f0fde
Showing
21 changed files
with
4,479 additions
and
939 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
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 |
---|---|---|
|
@@ -9,3 +9,4 @@ | |
|
||
# Go | ||
coverage.txt | ||
.coverage/ |
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,22 @@ | ||
.PHONY: deps | ||
deps: | ||
@go mod tidy | ||
|
||
.PHONY: lint | ||
lint: | ||
@golangci-lint run ./... --config .github/golangci.yaml | ||
|
||
.PHONY: test | ||
test: | ||
@go test -race ./... | ||
|
||
.PHONY: test-coverage | ||
test-coverage: | ||
@mkdir -p .coverage | ||
@go test `go list ./... | grep -Ev "diodepb|examples|internal"` -race -cover -json -coverprofile=.coverage/cover.out.tmp ./... | tparse -format=markdown > .coverage/test-report.md | ||
@cat .coverage/cover.out.tmp > .coverage/cover.out | ||
@go tool cover -func=.coverage/cover.out | grep total | awk '{print substr($$3, 1, length($$3)-1)}' > .coverage/coverage.txt | ||
|
||
.PHONY: codegen | ||
codegen: | ||
@go run internal/cmd/codegen/main.go | gofmt > ./diode/ingester.go |
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,3 +1,140 @@ | ||
# diode-sdk-go | ||
# Diode SDK Go | ||
|
||
TBD | ||
Diode SDK Go is a Go library for interacting with the Diode ingestion service utilizing gRPC. | ||
|
||
Diode is a new [NetBox](https://netboxlabs.com/oss/netbox/) ingestion service that greatly simplifies and enhances the | ||
process to add and update network data | ||
in NetBox, ensuring your network source of truth is always accurate and can be trusted to power your network automation | ||
pipelines. | ||
|
||
More information about Diode can be found | ||
at [https://netboxlabs.com/blog/introducing-diode-streamlining-data-ingestion-in-netbox/](https://netboxlabs.com/blog/introducing-diode-streamlining-data-ingestion-in-netbox/). | ||
|
||
## Installation | ||
|
||
```bash | ||
go install github.com/netboxlabs/diode-sdk-go | ||
``` | ||
|
||
## Usage | ||
|
||
### Environment variables | ||
|
||
* `DIODE_API_KEY` - API key for the Diode service | ||
* `DIODE_SDK_LOG_LEVEL` - Log level for the SDK (default: `INFO`) | ||
|
||
### Example | ||
|
||
* `target` should be the address of the Diode service, e.g. `grpc://localhost:8081` for insecure connection | ||
or `grpcs://example.com` for secure connection. | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"context" | ||
"log" | ||
|
||
"github.com/netboxlabs/diode-sdk-go/diode" | ||
) | ||
|
||
func main() { | ||
client, err := diode.NewClient( | ||
"grpc://localhost:8080/diode", | ||
"example-app", | ||
"0.1.0", | ||
diode.WithAPIKey("YOUR_API_KEY"), | ||
) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
// Create a device | ||
deviceEntity := &diode.Device{ | ||
Name: diode.String("Device A"), | ||
DeviceType: &diode.DeviceType{ | ||
Model: diode.String("Device Type A"), | ||
Manufacturer: &diode.Manufacturer{ | ||
Name: diode.String("Manufacturer A"), | ||
}, | ||
}, | ||
Platform: &diode.Platform{ | ||
Name: diode.String("Platform A"), | ||
Manufacturer: &diode.Manufacturer{ | ||
Name: diode.String("Manufacturer A"), | ||
}, | ||
}, | ||
Site: &diode.Site{ | ||
Name: diode.String("Site ABC"), | ||
}, | ||
Role: &diode.Role{ | ||
Name: diode.String("Role ABC"), | ||
Tags: []*diode.Tag{ | ||
{ | ||
Name: diode.String("tag 1"), | ||
}, | ||
{ | ||
Name: diode.String("tag 2"), | ||
}, | ||
}, | ||
}, | ||
Serial: diode.String("123456"), | ||
AssetTag: diode.String("123456"), | ||
Status: diode.String("active"), | ||
Comments: diode.String("Lorem ipsum dolor sit amet"), | ||
Tags: []*diode.Tag{ | ||
{ | ||
Name: diode.String("tag 1"), | ||
}, | ||
{ | ||
Name: diode.String("tag 3"), | ||
}, | ||
}, | ||
} | ||
|
||
entities := []diode.Entity{ | ||
deviceEntity, | ||
} | ||
|
||
resp, err := client.Ingest(context.Background(), entities) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
if resp != nil && resp.Errors != nil { | ||
log.Printf("Errors: %v\n", resp.Errors) | ||
} else { | ||
log.Printf("Success\n") | ||
} | ||
|
||
} | ||
``` | ||
|
||
See all [examples](./examples/main.go) for reference. | ||
|
||
## Supported entities (object types) | ||
|
||
* Device | ||
* Device Type | ||
* IP Address | ||
* Interface | ||
* Manufacturer | ||
* Platform | ||
* Prefix | ||
* Role | ||
* Site | ||
|
||
#### Linting | ||
|
||
```shell | ||
make list | ||
``` | ||
|
||
#### Testing | ||
|
||
```shell | ||
make test | ||
``` | ||
|
||
## License | ||
|
||
Distributed under the Apache 2.0 License. See [LICENSE.txt](./LICENSE.txt) for more information. |
Oops, something went wrong.