Documentation ¶
Index ¶
- Constants
- Variables
- func Create[T any](ctx context.Context, netboxClient *NetboxClient, object *T) (*T, error)
- func CreateMockServer() *httptest.Server
- func GetAll[T any](ctx context.Context, netboxClient *NetboxClient, extraParams string) ([]T, error)
- func GetVersion(ctx context.Context, netboxClient *NetboxClient) (string, error)
- func Patch[T any](ctx context.Context, netboxClient *NetboxClient, objectID int, ...) (*T, error)
- type APIResponse
- type FailingHTTPClient
- type FailingHTTPClientRead
- type FaultyReader
- type NetboxClient
- type Response
- type VersionResponse
Constants ¶
const (
MockVersionResponseJSON = "{\"django-version\": \"4.2.10\"}"
)
Variables ¶
var ( MockTagsGetResponse = Response[objects.Tag]{ Count: 2, Next: nil, Previous: nil, Results: []objects.Tag{ { ID: 0, Name: "Source: proxmox", Slug: "source-proxmox", Color: "9e9e9e", Description: "Automatically created tag by netbox-ssot for source proxmox", }, { ID: 1, Name: "netbox-ssot", Slug: "netbox-ssot", Color: "00add8", Description: "Tag used by netbox-ssot to mark devices that are managed by it", }, }, } MockTagPatchResponse = objects.Tag{ ID: 1, Name: "netbox-ssot", Slug: "netbox-ssot", Color: "00add8", Description: "patched description", } MockTagCreateResponse = objects.Tag{ ID: 1, Name: "netbox-ssot", Slug: "netbox-ssot", Color: "00add8", Description: "created description", } )
Hardcoded mock API responses for tags endpoint.
var ( MockTenantsGetResponse = Response[objects.Tenant]{ Count: 2, Next: nil, Previous: nil, Results: []objects.Tenant{ { NetboxObject: objects.NetboxObject{ ID: 1, Tags: []*objects.Tag{ MockDefaultSsotTag, }, }, Name: "MockTenant1", Slug: "mock-tenant-1", }, { NetboxObject: objects.NetboxObject{ ID: 2, Tags: []*objects.Tag{ MockDefaultSsotTag, }, }, Name: "MockTenant2", Slug: "mock-tenant-2", }, }, } MockTenantCreateResponse = objects.Tenant{ NetboxObject: objects.NetboxObject{ ID: 3, }, Name: "MockTenant3", Slug: "mock-tenant-3", } MockTenantPatchResponse = objects.Tenant{ NetboxObject: objects.NetboxObject{ ID: 1, }, Name: "MockPatched", Slug: "mock-patched-tenant", } )
Hardcoded mock api return values for tenant endpoint.
var ( MockSitesGetResponse = Response[objects.Site]{ Count: 2, Next: nil, Previous: nil, Results: []objects.Site{ { NetboxObject: objects.NetboxObject{ ID: 1, Tags: []*objects.Tag{ MockDefaultSsotTag, }, }, Name: "MockSite1", Slug: "mock-site-1", }, { NetboxObject: objects.NetboxObject{ ID: 2, Tags: []*objects.Tag{ MockDefaultSsotTag, }, }, Name: "MockSite2", Slug: "mock-site-2", }, }, } MockSiteCreateResponse = objects.Site{ NetboxObject: objects.NetboxObject{ ID: 3, }, Name: "MockSite3", Slug: "mock-site-3", } MockSitePatchResponse = objects.Site{ NetboxObject: objects.NetboxObject{ ID: 1, }, Name: "MockSitePatched", Slug: "mock-site-patched", } )
Hardcoded mock api return values for site endpoint.
var FailingMockNetboxClient = &NetboxClient{ HTTPClient: &http.Client{Transport: &FailingHTTPClient{}}, Logger: &logger.Logger{Logger: log.Default()}, BaseURL: "", APIToken: "testtoken", Timeout: constants.DefaultAPITimeout, }
var MockDefaultSsotTag = &objects.Tag{ ID: 0, Name: constants.SsotTagName, }
var MockNetboxClient = &NetboxClient{ HTTPClient: &http.Client{}, Logger: &logger.Logger{Logger: log.Default()}, BaseURL: "", APIToken: "testtoken", Timeout: constants.DefaultAPITimeout, }
var MockNetboxClientWithReadError = &NetboxClient{ HTTPClient: &http.Client{Transport: &FailingHTTPClientRead{}}, Logger: &logger.Logger{Logger: log.Default()}, BaseURL: "", APIToken: "testtoken", Timeout: constants.DefaultAPITimeout, }
Functions ¶
func Create ¶
func Create[T any](ctx context.Context, netboxClient *NetboxClient, object *T) (*T, error)
Create func creates the new NetboxObject of type T, with the given api path and body.
func CreateMockServer ¶ added in v0.3.3
func GetAll ¶
func GetAll[T any]( ctx context.Context, netboxClient *NetboxClient, extraParams string, ) ([]T, error)
GetAll queries all objects of type T from Netbox's API. It is querying objects via pagination of limit=200.
extraParams in a string format of: &extraParam1=...&extraParam2=...
func GetVersion ¶ added in v1.0.1
func GetVersion(ctx context.Context, netboxClient *NetboxClient) (string, error)
Function that queries and returns netbox version on success.
Types ¶
type APIResponse ¶
APIResponse is a struct that represents a response from the Netbox API.
type FailingHTTPClient ¶ added in v0.3.3
type FailingHTTPClient struct{}
type FailingHTTPClientRead ¶ added in v0.3.3
type FailingHTTPClientRead struct{}
type FaultyReader ¶ added in v0.3.3
type FaultyReader struct{}
type NetboxClient ¶ added in v0.3.3
type NetboxClient struct { Logger *logger.Logger HTTPClient *http.Client BaseURL string APIToken string Timeout int // in seconds MaxRetires int }
NetboxClient is a service used for communicating with the Netbox API. It is created via constructor func newNetboxAPI().
func NewNetboxClient ¶ added in v0.3.3
func NewNetboxClient(logger *logger.Logger, baseURL string, apiToken string, validateCert bool, timeout int, caCert string) (*NetboxClient, error)
Constructor function for creating a new netBoxAPI instance.
func (*NetboxClient) BulkDeleteObjects ¶ added in v0.3.3
func (api *NetboxClient) BulkDeleteObjects( ctx context.Context, objectPath constants.APIPath, idSet map[int]bool, ) error
Function that deletes object on path objectPath. It deletes objects in pages of 50 so we don't stress the API too much.
func (*NetboxClient) DeleteObject ¶ added in v0.6.0
Function that deletes objectas on path objectPath. It deletes a single object at a time. It is alternative to bulk delete because if one delete fails other still go.
type Response ¶
type Response[T any] struct { Count int `json:"count"` Next *string `json:"next"` Previous *string `json:"previous"` Results []T `json:"results"` }
Standard response format from Netbox's API.
type VersionResponse ¶ added in v0.3.3
type VersionResponse struct {
NetboxVersion string `json:"netbox-version"`
}