Migrate to use secrets store plugin
Move secrets related code to plugin_secrets_store While here, mute gosecs false positive for G101 on secretsPath
This commit is contained in:
parent
92eacc150c
commit
2bca52c094
6 changed files with 381 additions and 381 deletions
287
devices.go
287
devices.go
|
@ -14,200 +14,196 @@ type DevicesService service
|
|||
|
||||
// Devices is used for Netbox dcim_device_list return struct
|
||||
type Devices struct {
|
||||
Count int `json:"count"`
|
||||
Next string `json:"next"`
|
||||
Previous string `json:"previous"`
|
||||
Results []Device `json:"results"`
|
||||
Count int `json:"count"`
|
||||
}
|
||||
|
||||
type Device struct {
|
||||
ID int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
DisplayName string `json:"display_name"`
|
||||
DeviceType struct {
|
||||
ID int `json:"id"`
|
||||
URL string `json:"url"`
|
||||
Manufacturer struct {
|
||||
ID int `json:"id"`
|
||||
URL string `json:"url"`
|
||||
Name string `json:"name"`
|
||||
Slug string `json:"slug"`
|
||||
DevicetypeCount int `json:"devicetype_count"`
|
||||
} `json:"manufacturer"`
|
||||
Model string `json:"model"`
|
||||
Slug string `json:"slug"`
|
||||
DisplayName string `json:"display_name"`
|
||||
DeviceCount int `json:"device_count"`
|
||||
} `json:"device_type"`
|
||||
DeviceRole struct {
|
||||
ID int `json:"id"`
|
||||
URL string `json:"url"`
|
||||
Name string `json:"name"`
|
||||
Slug string `json:"slug"`
|
||||
DeviceCount int `json:"device_count"`
|
||||
VirtualmachineCount int `json:"virtualmachine_count"`
|
||||
} `json:"device_role"`
|
||||
Tenant struct {
|
||||
ID int `json:"id"`
|
||||
URL string `json:"url"`
|
||||
Name string `json:"name"`
|
||||
Slug string `json:"slug"`
|
||||
} `json:"tenant"`
|
||||
Platform struct {
|
||||
ID int `json:"id"`
|
||||
URL string `json:"url"`
|
||||
Name string `json:"name"`
|
||||
Slug string `json:"slug"`
|
||||
DeviceCount int `json:"device_count"`
|
||||
VirtualmachineCount int `json:"virtualmachine_count"`
|
||||
} `json:"platform"`
|
||||
Serial string `json:"serial"`
|
||||
AssetTag string `json:"asset_tag"`
|
||||
Site struct {
|
||||
ID int `json:"id"`
|
||||
URL string `json:"url"`
|
||||
Name string `json:"name"`
|
||||
Slug string `json:"slug"`
|
||||
} `json:"site"`
|
||||
Rack struct {
|
||||
ID int `json:"id"`
|
||||
URL string `json:"url"`
|
||||
Name string `json:"name"`
|
||||
DisplayName string `json:"display_name"`
|
||||
DeviceCount int `json:"device_count"`
|
||||
} `json:"rack"`
|
||||
Position int `json:"position"`
|
||||
Face struct {
|
||||
Label string `json:"label"`
|
||||
Value string `json:"value"`
|
||||
} `json:"face"`
|
||||
ParentDevice struct {
|
||||
ID int `json:"id"`
|
||||
URL string `json:"url"`
|
||||
Name string `json:"name"`
|
||||
DisplayName string `json:"display_name"`
|
||||
} `json:"parent_device"`
|
||||
LastUpdated time.Time `json:"last_updated"`
|
||||
CustomFields interface{} `json:"custom_fields,omitempty"`
|
||||
ConfigContext interface{} `json:"config_context"`
|
||||
Status struct {
|
||||
Label string `json:"label"`
|
||||
Value string `json:"value"`
|
||||
} `json:"status"`
|
||||
PrimaryIP struct {
|
||||
ID int `json:"id"`
|
||||
URL string `json:"url"`
|
||||
Family int `json:"family"`
|
||||
Address string `json:"address"`
|
||||
} `json:"primary_ip"`
|
||||
PrimaryIP4 struct {
|
||||
ID int `json:"id"`
|
||||
URL string `json:"url"`
|
||||
Family int `json:"family"`
|
||||
Address string `json:"address"`
|
||||
} `json:"primary_ip4"`
|
||||
PrimaryIP6 struct {
|
||||
ID int `json:"id"`
|
||||
URL string `json:"url"`
|
||||
Family int `json:"family"`
|
||||
Address string `json:"address"`
|
||||
} `json:"primary_ip6"`
|
||||
Cluster struct {
|
||||
ID int `json:"id"`
|
||||
URL string `json:"url"`
|
||||
Face struct {
|
||||
Label string `json:"label"`
|
||||
Value string `json:"value"`
|
||||
} `json:"face"`
|
||||
Name string `json:"name"`
|
||||
VirtualmachineCount int `json:"virtualmachine_count"`
|
||||
} `json:"cluster"`
|
||||
VirtualChassis struct {
|
||||
ID int `json:"id"`
|
||||
URL string `json:"url"`
|
||||
Master struct {
|
||||
ID int `json:"id"`
|
||||
AssetTag string `json:"asset_tag"`
|
||||
Comments string `json:"comments"`
|
||||
DisplayName string `json:"display_name"`
|
||||
Created string `json:"created"`
|
||||
Serial string `json:"serial"`
|
||||
ParentDevice struct {
|
||||
URL string `json:"url"`
|
||||
Name string `json:"name"`
|
||||
DisplayName string `json:"display_name"`
|
||||
} `json:"master"`
|
||||
MemberCount int `json:"member_count"`
|
||||
} `json:"virtual_chassis"`
|
||||
VcPosition int `json:"vc_position"`
|
||||
VcPriority int `json:"vc_priority"`
|
||||
Comments string `json:"comments"`
|
||||
// LocalContextData string `json:"local_context_data"`
|
||||
Tags []struct {
|
||||
ID int `json:"id"`
|
||||
} `json:"parent_device"`
|
||||
Tenant struct {
|
||||
URL string `json:"url"`
|
||||
Name string `json:"name"`
|
||||
Slug string `json:"slug"`
|
||||
ID int `json:"id"`
|
||||
} `json:"tenant"`
|
||||
Site struct {
|
||||
URL string `json:"url"`
|
||||
Name string `json:"name"`
|
||||
Slug string `json:"slug"`
|
||||
ID int `json:"id"`
|
||||
} `json:"site"`
|
||||
Tags []struct {
|
||||
URL string `json:"url"`
|
||||
Name string `json:"name"`
|
||||
Slug string `json:"slug"`
|
||||
Color string `json:"color"`
|
||||
ID int `json:"id"`
|
||||
} `json:"tags"`
|
||||
CustomFields interface{} `json:"custom_fields,omitempty"`
|
||||
ConfigContext interface{} `json:"config_context"`
|
||||
Created string `json:"created"`
|
||||
LastUpdated time.Time `json:"last_updated"`
|
||||
Rack struct {
|
||||
URL string `json:"url"`
|
||||
Name string `json:"name"`
|
||||
DisplayName string `json:"display_name"`
|
||||
ID int `json:"id"`
|
||||
DeviceCount int `json:"device_count"`
|
||||
} `json:"rack"`
|
||||
PrimaryIP4 struct {
|
||||
URL string `json:"url"`
|
||||
Address string `json:"address"`
|
||||
ID int `json:"id"`
|
||||
Family int `json:"family"`
|
||||
} `json:"primary_ip4"`
|
||||
PrimaryIP struct {
|
||||
URL string `json:"url"`
|
||||
Address string `json:"address"`
|
||||
ID int `json:"id"`
|
||||
Family int `json:"family"`
|
||||
} `json:"primary_ip"`
|
||||
Cluster struct {
|
||||
URL string `json:"url"`
|
||||
Name string `json:"name"`
|
||||
ID int `json:"id"`
|
||||
VirtualmachineCount int `json:"virtualmachine_count"`
|
||||
} `json:"cluster"`
|
||||
PrimaryIP6 struct {
|
||||
URL string `json:"url"`
|
||||
Address string `json:"address"`
|
||||
ID int `json:"id"`
|
||||
Family int `json:"family"`
|
||||
} `json:"primary_ip6"`
|
||||
VirtualChassis struct {
|
||||
URL string `json:"url"`
|
||||
Master struct {
|
||||
URL string `json:"url"`
|
||||
Name string `json:"name"`
|
||||
DisplayName string `json:"display_name"`
|
||||
ID int `json:"id"`
|
||||
} `json:"master"`
|
||||
ID int `json:"id"`
|
||||
MemberCount int `json:"member_count"`
|
||||
} `json:"virtual_chassis"`
|
||||
DeviceRole struct {
|
||||
URL string `json:"url"`
|
||||
Name string `json:"name"`
|
||||
Slug string `json:"slug"`
|
||||
ID int `json:"id"`
|
||||
DeviceCount int `json:"device_count"`
|
||||
VirtualmachineCount int `json:"virtualmachine_count"`
|
||||
} `json:"device_role"`
|
||||
Platform struct {
|
||||
URL string `json:"url"`
|
||||
Name string `json:"name"`
|
||||
Slug string `json:"slug"`
|
||||
ID int `json:"id"`
|
||||
DeviceCount int `json:"device_count"`
|
||||
VirtualmachineCount int `json:"virtualmachine_count"`
|
||||
} `json:"platform"`
|
||||
DeviceType struct {
|
||||
URL string `json:"url"`
|
||||
Model string `json:"model"`
|
||||
Slug string `json:"slug"`
|
||||
DisplayName string `json:"display_name"`
|
||||
Manufacturer struct {
|
||||
URL string `json:"url"`
|
||||
Name string `json:"name"`
|
||||
Slug string `json:"slug"`
|
||||
ID int `json:"id"`
|
||||
DevicetypeCount int `json:"devicetype_count"`
|
||||
} `json:"manufacturer"`
|
||||
ID int `json:"id"`
|
||||
DeviceCount int `json:"device_count"`
|
||||
} `json:"device_type"`
|
||||
Position int `json:"position"`
|
||||
VcPriority int `json:"vc_priority"`
|
||||
VcPosition int `json:"vc_position"`
|
||||
ID int `json:"id"`
|
||||
}
|
||||
|
||||
type NewDevice struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
DeviceType int `json:"device_type,omitempty"`
|
||||
DeviceRole int `json:"device_role,omitempty"`
|
||||
Tenant int `json:"tenant,omitempty"`
|
||||
Platform int `json:"platform,omitempty"`
|
||||
CustomFields interface{} `json:"custom_fields,omitempty"`
|
||||
Face string `json:"face,omitempty"`
|
||||
LocalContextData string `json:"local_context_data,omitempty"`
|
||||
Comments string `json:"comments,omitempty"`
|
||||
Status string `json:"status,omitempty"`
|
||||
Serial string `json:"serial,omitempty"`
|
||||
AssetTag string `json:"asset_tag,omitempty"`
|
||||
Site int `json:"site,omitempty"`
|
||||
Rack int `json:"rack,omitempty"`
|
||||
Position int `json:"position,omitempty"`
|
||||
Face string `json:"face,omitempty"`
|
||||
ParentDevice struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
} `json:"parent_device,omitempty"`
|
||||
Status string `json:"status,omitempty"`
|
||||
PrimaryIP4 int `json:"primary_ip4,omitempty"`
|
||||
PrimaryIP6 int `json:"primary_ip6,omitempty"`
|
||||
Cluster int `json:"cluster,omitempty"`
|
||||
VirtualChassis int `json:"virtual_chassis,omitempty"`
|
||||
VcPosition int `json:"vc_position,omitempty"`
|
||||
VcPriority int `json:"vc_priority,omitempty"`
|
||||
Comments string `json:"comments,omitempty"`
|
||||
LocalContextData string `json:"local_context_data,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Tags []struct {
|
||||
Name string `json:"name"`
|
||||
Slug string `json:"slug"`
|
||||
Color string `json:"color"`
|
||||
} `json:"tags"`
|
||||
CustomFields interface{} `json:"custom_fields,omitempty"`
|
||||
Cluster int `json:"cluster,omitempty"`
|
||||
Platform int `json:"platform,omitempty"`
|
||||
Tenant int `json:"tenant,omitempty"`
|
||||
PrimaryIP4 int `json:"primary_ip4,omitempty"`
|
||||
PrimaryIP6 int `json:"primary_ip6,omitempty"`
|
||||
Site int `json:"site,omitempty"`
|
||||
VirtualChassis int `json:"virtual_chassis,omitempty"`
|
||||
VcPosition int `json:"vc_position,omitempty"`
|
||||
VcPriority int `json:"vc_priority,omitempty"`
|
||||
DeviceRole int `json:"device_role,omitempty"`
|
||||
DeviceType int `json:"device_type,omitempty"`
|
||||
Position int `json:"position,omitempty"`
|
||||
Rack int `json:"rack,omitempty"`
|
||||
}
|
||||
|
||||
type UpdateDevice struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
DeviceType int `json:"device_type,omitempty"`
|
||||
DeviceRole int `json:"device_role,omitempty"`
|
||||
Tenant int `json:"tenant,omitempty"`
|
||||
Platform int `json:"platform,omitempty"`
|
||||
Serial string `json:"serial,omitempty"`
|
||||
AssetTag string `json:"asset_tag,omitempty"`
|
||||
Site int `json:"site,omitempty"`
|
||||
Rack int `json:"rack,omitempty"`
|
||||
Position int `json:"position,omitempty"`
|
||||
Face string `json:"face,omitempty"`
|
||||
CustomFields interface{} `json:"custom_fields,omitempty"`
|
||||
ParentDevice *struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
} `json:"parent_device,omitempty"`
|
||||
Face string `json:"face,omitempty"`
|
||||
LocalContextData string `json:"local_context_data,omitempty"`
|
||||
Comments string `json:"comments,omitempty"`
|
||||
Serial string `json:"serial,omitempty"`
|
||||
AssetTag string `json:"asset_tag,omitempty"`
|
||||
Status string `json:"status,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Tags []string `json:"tags,omitempty"`
|
||||
Position int `json:"position,omitempty"`
|
||||
DeviceType int `json:"device_type,omitempty"`
|
||||
Site int `json:"site,omitempty"`
|
||||
PrimaryIP4 int `json:"primary_ip4,omitempty"`
|
||||
PrimaryIP6 int `json:"primary_ip6,omitempty"`
|
||||
Cluster int `json:"cluster,omitempty"`
|
||||
VirtualChassis int `json:"virtual_chassis,omitempty"`
|
||||
VcPosition int `json:"vc_position,omitempty"`
|
||||
VcPriority int `json:"vc_priority,omitempty"`
|
||||
Comments string `json:"comments,omitempty"`
|
||||
LocalContextData string `json:"local_context_data,omitempty"`
|
||||
Tags []string `json:"tags,omitempty"`
|
||||
CustomFields interface{} `json:"custom_fields,omitempty"`
|
||||
Platform int `json:"platform,omitempty"`
|
||||
Tenant int `json:"tenant,omitempty"`
|
||||
Rack int `json:"rack,omitempty"`
|
||||
DeviceRole int `json:"device_role,omitempty"`
|
||||
}
|
||||
|
||||
// DeviceFilter is used to filter dcim_device_list query to the Netbox API
|
||||
type DeviceFilter struct {
|
||||
Offset int64 `schema:"offset,omitempty"`
|
||||
Limit int64 `schema:"limit,omitempty"`
|
||||
|
||||
// User specific filters
|
||||
ID string `schema:"id,omitempty"`
|
||||
Name string `schema:"name,omitempty"`
|
||||
|
@ -249,6 +245,9 @@ type DeviceFilter struct {
|
|||
Interfaces string `schema:"interfaces,omitempty"`
|
||||
PassThroughPorts string `schema:"pass_through_ports,omitempty"`
|
||||
Tag string `schema:"tag,omitempty"`
|
||||
|
||||
Offset int `schema:"offset,omitempty"`
|
||||
Limit int `schema:"limit,omitempty"`
|
||||
}
|
||||
|
||||
const devicesPath = dcimPath + "/devices"
|
||||
|
|
40
netbox.go
40
netbox.go
|
@ -10,10 +10,7 @@ import (
|
|||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// Client struct is used to create a new NetBox endpoint
|
||||
|
@ -162,43 +159,6 @@ func (c *Client) SetToken(token string) {
|
|||
c.Token = token
|
||||
}
|
||||
|
||||
// FetchSessionKey fetches sessionkey
|
||||
func (c *Client) FetchSessionKey(privatekey string) error {
|
||||
form := url.Values{}
|
||||
form.Add("private_key", privatekey)
|
||||
query := form.Encode()
|
||||
|
||||
ctx := context.Background()
|
||||
req, err := http.NewRequestWithContext(ctx, "POST", c.baseURL.String()+secretsPath+"/get-session-key/", strings.NewReader(query))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
req.Header.Add("Accept", "application/json")
|
||||
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
||||
|
||||
if c.FetchMode != "" {
|
||||
req.Header.Add("js.fetch:mode", "no-cors")
|
||||
}
|
||||
|
||||
req.Header.Add("Authorization", " Token "+c.Token)
|
||||
|
||||
var sessionkey NetBoxSessionKey
|
||||
|
||||
res, err := c.do(req, &sessionkey)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if res.StatusCode != http.StatusOK {
|
||||
return errors.Errorf("response was: %d should be %d\n%s\n", res.StatusCode, http.StatusOK, res.Header)
|
||||
}
|
||||
|
||||
c.SessionKey = sessionkey.XSessionKey
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// newRequest is used to make new request to endpoints
|
||||
func (c *Client) newRequest(ctx context.Context, method, path string, query string, body interface{}) (*http.Request, error) {
|
||||
var err error
|
||||
|
|
139
plugin_secrets_store.go
Normal file
139
plugin_secrets_store.go
Normal file
|
@ -0,0 +1,139 @@
|
|||
package netboxgo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/schema"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type SecretsService service
|
||||
|
||||
// Secrets contains secrets
|
||||
type Secrets struct {
|
||||
Next interface{} `json:"next"`
|
||||
Previous interface{} `json:"previous"`
|
||||
Results []struct {
|
||||
CustomFields struct{} `json:"custom_fields"`
|
||||
LastUpdated time.Time `json:"last_updated"`
|
||||
Role struct {
|
||||
URL string `json:"url"`
|
||||
Display string `json:"display"`
|
||||
Name string `json:"name"`
|
||||
Slug string `json:"slug"`
|
||||
ID int `json:"id"`
|
||||
} `json:"role"`
|
||||
AssignedObject struct {
|
||||
URL string `json:"url"`
|
||||
Display string `json:"display"`
|
||||
Name string `json:"name"`
|
||||
ID int `json:"id"`
|
||||
} `json:"assigned_object"`
|
||||
Name string `json:"name"`
|
||||
Created string `json:"created"`
|
||||
AssignedObjectType string `json:"assigned_object_type"`
|
||||
Display string `json:"display"`
|
||||
Plaintext string `json:"plaintext"`
|
||||
Hash string `json:"hash"`
|
||||
URL string `json:"url"`
|
||||
Tags []interface{} `json:"tags"`
|
||||
AssignedObjectID int `json:"assigned_object_id"`
|
||||
ID int `json:"id"`
|
||||
} `json:"results"`
|
||||
Count int `json:"count"`
|
||||
}
|
||||
|
||||
// SecretFilter is used to filter out secrets
|
||||
type SecretFilter struct {
|
||||
Offset int64 `schema:"offset,omitempty"`
|
||||
Limit int64 `schema:"limit,omitempty"`
|
||||
|
||||
// User specific filters
|
||||
Name string `schema:"name,omitempty"`
|
||||
Role string `schema:"role,omitempty"`
|
||||
RoleID string `schema:"role_id,omitempty"`
|
||||
DeviceID string `schema:"device_id,omitempty"`
|
||||
TypeID string `schema:"type_id,omitempty"`
|
||||
Device string `schema:"device,omitempty"`
|
||||
IDIn string `schema:"id__in,omitempty"`
|
||||
Q string `schema:"q,omitempty"`
|
||||
Tag string `schema:"tag,omitempty"`
|
||||
}
|
||||
|
||||
// #nosec CWE-798 - gosec mute false positive
|
||||
const secretsPath = "/plugins/netbox_secretstore"
|
||||
|
||||
// List secrets. SecretsFilter is used to list based on filter queries.
|
||||
func (s *SecretsService) List(ctx context.Context, f *SecretFilter) (*Secrets, error) {
|
||||
var secrets Secrets
|
||||
var query string
|
||||
var req *http.Request
|
||||
var err error
|
||||
|
||||
if s.client.SessionKey == "" {
|
||||
return &secrets, fmt.Errorf("session key needed when interacting with secrets. no session key found: you need to fetch a session key with FetchSessionKey()")
|
||||
}
|
||||
|
||||
encoder := schema.NewEncoder()
|
||||
|
||||
form := url.Values{}
|
||||
err = encoder.Encode(f, form)
|
||||
if err != nil {
|
||||
return &secrets, err
|
||||
}
|
||||
query = form.Encode()
|
||||
|
||||
req, err = s.client.newRequest(ctx, "GET", secretsPath+"/secrets", query, nil)
|
||||
if err != nil {
|
||||
return &secrets, err
|
||||
}
|
||||
|
||||
_, err = s.client.do(req, &secrets)
|
||||
if err != nil {
|
||||
return &secrets, err
|
||||
}
|
||||
|
||||
return &secrets, nil
|
||||
}
|
||||
|
||||
// FetchSessionKey fetches sessionkey
|
||||
func (s *SecretsService) FetchSessionKey(privatekey string) error {
|
||||
form := url.Values{}
|
||||
form.Add("private_key", privatekey)
|
||||
query := form.Encode()
|
||||
|
||||
ctx := context.Background()
|
||||
req, err := http.NewRequestWithContext(ctx, "POST", s.client.baseURL.String()+secretsPath+"/get-session-key/", strings.NewReader(query))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
req.Header.Add("Accept", "application/json")
|
||||
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
||||
|
||||
if s.client.FetchMode != "" {
|
||||
req.Header.Add("js.fetch:mode", "no-cors")
|
||||
}
|
||||
|
||||
req.Header.Add("Authorization", " Token "+s.client.Token)
|
||||
|
||||
var sessionkey NetBoxSessionKey
|
||||
|
||||
res, err := s.client.do(req, &sessionkey)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if res.StatusCode != http.StatusOK {
|
||||
return errors.Errorf("response was: %d should be %d\n%s\n", res.StatusCode, http.StatusOK, res.Header)
|
||||
}
|
||||
|
||||
s.client.SessionKey = sessionkey.XSessionKey
|
||||
|
||||
return nil
|
||||
}
|
19
prefixes.go
19
prefixes.go
|
@ -29,11 +29,8 @@ type NewPrefix struct {
|
|||
IsPool bool `json:"is_pool"`
|
||||
}
|
||||
|
||||
// Prefixes is used for the return value from NetBox API ipam_prefixes_list
|
||||
type Prefixes struct {
|
||||
Next string `json:"next"`
|
||||
Previous string `json:"previous"`
|
||||
Results []struct {
|
||||
// Prefix is a prefix
|
||||
type Prefix struct {
|
||||
LastUpdated time.Time `json:"last_updated"`
|
||||
CustomFields interface{} `json:"custom_fields"`
|
||||
VLAN struct {
|
||||
|
@ -41,7 +38,7 @@ type Prefixes struct {
|
|||
Name string `json:"name"`
|
||||
DisplayName string `json:"display_name"`
|
||||
ID int `json:"id"`
|
||||
Vid int `json:"vid"`
|
||||
VID int `json:"vid"`
|
||||
} `json:"vlan"`
|
||||
Tenant struct {
|
||||
URL string `json:"url"`
|
||||
|
@ -62,7 +59,7 @@ type Prefixes struct {
|
|||
Prefix string `json:"prefix"`
|
||||
Description string `json:"description"`
|
||||
Created string `json:"created"`
|
||||
Vrf struct {
|
||||
VRF struct {
|
||||
URL string `json:"url"`
|
||||
Name string `json:"name"`
|
||||
Rd string `json:"rd"`
|
||||
|
@ -90,7 +87,13 @@ type Prefixes struct {
|
|||
} `json:"role"`
|
||||
ID int `json:"id"`
|
||||
IsPool bool `json:"is_pool"`
|
||||
} `json:"results"`
|
||||
}
|
||||
|
||||
// Prefixes is used for the return value from NetBox API ipam_prefixes_list
|
||||
type Prefixes struct {
|
||||
Next string `json:"next"`
|
||||
Previous string `json:"previous"`
|
||||
Results []Prefix `json:"results"`
|
||||
Count int `json:"count"`
|
||||
}
|
||||
|
||||
|
|
101
secrets.go
101
secrets.go
|
@ -1,101 +0,0 @@
|
|||
package netboxgo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/schema"
|
||||
)
|
||||
|
||||
type SecretsService service
|
||||
|
||||
// Secrets contains secrets
|
||||
type Secrets struct {
|
||||
Count int `json:"count"`
|
||||
Next string `json:"next"`
|
||||
Previous string `json:"previous"`
|
||||
Results []struct {
|
||||
ID int `json:"id"`
|
||||
Device struct {
|
||||
ID int `json:"id"`
|
||||
URL string `json:"url"`
|
||||
Name string `json:"name"`
|
||||
DisplayName string `json:"display_name"`
|
||||
} `json:"device"`
|
||||
Role struct {
|
||||
ID int `json:"id"`
|
||||
URL string `json:"url"`
|
||||
Name string `json:"name"`
|
||||
Slug string `json:"slug"`
|
||||
SecretCount int `json:"secret_count"`
|
||||
} `json:"role"`
|
||||
Name string `json:"name"`
|
||||
Plaintext string `json:"plaintext"`
|
||||
Hash string `json:"hash"`
|
||||
Tags []struct {
|
||||
ID int `json:"id"`
|
||||
URL string `json:"url"`
|
||||
Name string `json:"name"`
|
||||
Slug string `json:"slug"`
|
||||
Color string `json:"color"`
|
||||
} `json:"tags"`
|
||||
CustomFields interface{} `json:"custom_fields"`
|
||||
Created string `json:"created"`
|
||||
LastUpdated time.Time `json:"last_updated"`
|
||||
} `json:"results"`
|
||||
}
|
||||
|
||||
// SecretFilter is used to filter out secrets
|
||||
type SecretFilter struct {
|
||||
Offset int64 `schema:"offset,omitempty"`
|
||||
Limit int64 `schema:"limit,omitempty"`
|
||||
|
||||
// User specific filters
|
||||
Name string `schema:"name,omitempty"`
|
||||
Role string `schema:"role,omitempty"`
|
||||
RoleID string `schema:"role_id,omitempty"`
|
||||
DeviceID string `schema:"device_id,omitempty"`
|
||||
TypeID string `schema:"type_id,omitempty"`
|
||||
Device string `schema:"device,omitempty"`
|
||||
IDIn string `schema:"id__in,omitempty"`
|
||||
Q string `schema:"q,omitempty"`
|
||||
Tag string `schema:"tag,omitempty"`
|
||||
}
|
||||
|
||||
const secretsPath = "/secrets"
|
||||
|
||||
// List secrets. SecretsFilter is used to list based on filter queries.
|
||||
func (s *SecretsService) List(ctx context.Context, f *SecretFilter) (*Secrets, error) {
|
||||
var secrets Secrets
|
||||
var query string
|
||||
var req *http.Request
|
||||
var err error
|
||||
|
||||
if s.client.SessionKey == "" {
|
||||
return &secrets, fmt.Errorf("session key needed when interacting with secrets. no session key found: you need to fetch a session key with FetchSessionKey()")
|
||||
}
|
||||
|
||||
encoder := schema.NewEncoder()
|
||||
|
||||
form := url.Values{}
|
||||
err = encoder.Encode(f, form)
|
||||
if err != nil {
|
||||
return &secrets, err
|
||||
}
|
||||
query = form.Encode()
|
||||
|
||||
req, err = s.client.newRequest(ctx, "GET", secretsPath+"/secrets", query, nil)
|
||||
if err != nil {
|
||||
return &secrets, err
|
||||
}
|
||||
|
||||
_, err = s.client.do(req, &secrets)
|
||||
if err != nil {
|
||||
return &secrets, err
|
||||
}
|
||||
|
||||
return &secrets, nil
|
||||
}
|
24
tenants.go
24
tenants.go
|
@ -26,28 +26,28 @@ type NewTenant struct {
|
|||
// Tenant represents a tenant
|
||||
type Tenant struct {
|
||||
LastUpdated time.Time `json:"last_updated"`
|
||||
CustomFields interface{} `json:"custom_fields"`
|
||||
VirtualmachineCount interface{} `json:"virtualmachine_count"`
|
||||
RackCount interface{} `json:"rack_count"`
|
||||
IpaddressCount interface{} `json:"ipaddress_count"`
|
||||
CircuitCount interface{} `json:"circuit_count"`
|
||||
VrfCount interface{} `json:"vrf_count"`
|
||||
CustomFields map[string]interface{} `json:"custom_fields"`
|
||||
Created string `json:"created"`
|
||||
Name string `json:"name"`
|
||||
Slug string `json:"slug"`
|
||||
Description string `json:"description"`
|
||||
Comments string `json:"comments"`
|
||||
Group struct {
|
||||
URL string `json:"url"`
|
||||
Name string `json:"name"`
|
||||
Slug string `json:"slug"`
|
||||
ID int `json:"id"`
|
||||
} `json:"group"`
|
||||
Created string `json:"created"`
|
||||
Comments string `json:"comments"`
|
||||
Description string `json:"description"`
|
||||
Slug string `json:"slug"`
|
||||
Name string `json:"name"`
|
||||
Tags []interface{} `json:"tags"`
|
||||
VRFCount int `json:"vrf_count"`
|
||||
CircuitCount int `json:"circuit_count"`
|
||||
IPAddressCount int `json:"ipaddress_count"`
|
||||
VirtualmachineCount int `json:"virtualmachine_count"`
|
||||
RackCount int `json:"rack_count"`
|
||||
DeviceCount int `json:"device_count"`
|
||||
PrefixCount int `json:"prefix_count"`
|
||||
SiteCount int `json:"site_count"`
|
||||
VlanCount int `json:"vlan_count"`
|
||||
VLANCount int `json:"vlan_count"`
|
||||
ID int `json:"id"`
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue