Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #467

Merged
merged 5 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
linters-settings:
lll:
line-length: 120
misspell:
locale: US
errcheck:
Expand All @@ -23,12 +25,12 @@ linters:
enable:
- revive
- gocyclo
- lll
# - dupl # TODO: enable in future
# - errorlint # TODO: enable in future
# - gocognit # TODO: enable in future
# - cyclop # TODO: enable in future
# - paralleltest # TODO: enable in future
# - lll # TODO: enable in future
# - nestif # TODO: enable in future
# - maintidx # TODO: enable in future
# - exhaustive # TODO: enable in future
Expand Down
29 changes: 18 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@ repos:
hooks:
- id: golangci-lint

# - repo: https://github.com/segmentio/golines
# rev: v0.12.2
# hooks:
# - id: golines
# name: golines
# description: A golang formatter that fixes long lines.
# entry: golines -w
# types: [go]
# language: golang
- repo: https://github.com/segmentio/golines
rev: v0.12.2
hooks:
- id: golines
name: golines
description: A golang formatter that fixes long lines.
entry: golines -w ./internal
pass_filenames: true
types: [go]
language: golang

- repo: https://github.com/dnephin/pre-commit-golang
rev: v0.5.1
Expand All @@ -32,15 +33,21 @@ repos:
- id: go-mod-tidy

- repo: https://github.com/gitleaks/gitleaks
rev: v8.23.1
rev: v8.23.3
hooks:
- id: gitleaks

- repo: https://github.com/streetsidesoftware/cspell-cli
rev: v8.17.1
rev: v8.17.2
hooks:
- id: cspell

- repo: https://github.com/google/osv-scanner/
rev: v2.0.0-beta1
hooks:
- id: osv-scanner
args: ["-r", "."]

- repo: https://github.com/mxab/pre-commit-trivy.git
rev: v0.14.0
hooks:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Example configuration can be found [here](#example-config).

| Parameter | Description | Type | Possible values | Default | Required |
| ------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | --------------- | ------------- | -------- |
| `netbox.apiToken` | Netbox [API token](https://demo.netbox.dev/static/docs/rest-api/authentication/). | str | Any valid token | "" | Yes |
| `netbox.apiToken` | Netbox API token | str | Any valid token | "" | Yes |
| `netbox.hostname` | Hostname of your netbox instance (e.g `netbox.example.com`). | str | Valid hostname | "" | Yes |
| `netbox.port` | Port of your netbox instance. | int | 0-65536 | 443 | No |
| `netbox.httpScheme` | HTTP scheme of your netbox instance. | str | [http, https] | https | No |
Expand Down
11 changes: 5 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
module github.com/bl4ko/netbox-ssot

go 1.23.1
go 1.23.6

require (
github.com/PaloAltoNetworks/pango v0.10.2
github.com/bl4ko/go-devicetype-library v0.1.45
github.com/cisco-en-programmability/dnacenter-go-sdk/v6 v6.0.0
github.com/cisco-en-programmability/dnacenter-go-sdk/v7 v7.0.0
github.com/luthermonson/go-proxmox v0.2.1
github.com/ovirt/go-ovirt v4.3.4+incompatible
Expand All @@ -20,13 +19,13 @@ require (
github.com/creack/pty v1.1.24 // indirect
github.com/diskfs/go-diskfs v1.4.2 // indirect
github.com/djherbis/times v1.6.0 // indirect
github.com/go-resty/resty/v2 v2.16.2 // indirect
github.com/go-resty/resty/v2 v2.16.5 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
github.com/jinzhu/copier v0.4.0 // indirect
github.com/magefile/mage v1.15.0 // indirect
github.com/sirikothe/gotextfsm v1.0.1-0.20200816110946-6aa2cfd355e4 // indirect
golang.org/x/crypto v0.31.0 // indirect
golang.org/x/net v0.33.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/crypto v0.32.0 // indirect
golang.org/x/net v0.34.0 // indirect
golang.org/x/sys v0.30.0 // indirect
)
35 changes: 11 additions & 24 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
github.com/PaloAltoNetworks/pango v0.10.2 h1:Tjn6vIzzAq6Dd7N0mDuiP8w8pz8k5W9zz/TTSUQCsQY=
github.com/PaloAltoNetworks/pango v0.10.2/go.mod h1:GztcRnVLur7G+VFG7Z5ZKNFgScLtsycwPMp1qVebE5g=
github.com/bl4ko/go-devicetype-library v0.1.39 h1:kbNz5SLevOZfU+1/azfCMrIFoO1dYap6bt9OE+tdoL8=
github.com/bl4ko/go-devicetype-library v0.1.39/go.mod h1:Pzm1BlRyR4uECezsRINDA6ZieFPumdFL+6yySpXM6t8=
github.com/bl4ko/go-devicetype-library v0.1.40 h1:LOmVYWKRlr2EZmMbP4G39LCimcdNyCYSmqVUVjddnL8=
github.com/bl4ko/go-devicetype-library v0.1.40/go.mod h1:Pzm1BlRyR4uECezsRINDA6ZieFPumdFL+6yySpXM6t8=
github.com/bl4ko/go-devicetype-library v0.1.41 h1:3oLwoLfEnd3Doz5ao/MkxUDWd2yHMBUbRk88mz+02WU=
github.com/bl4ko/go-devicetype-library v0.1.41/go.mod h1:Pzm1BlRyR4uECezsRINDA6ZieFPumdFL+6yySpXM6t8=
github.com/bl4ko/go-devicetype-library v0.1.42 h1:oWRXPI8+VGbdlQM7bqEW1Z0ng0OrOWdBlKeybX8WwgM=
github.com/bl4ko/go-devicetype-library v0.1.42/go.mod h1:Pzm1BlRyR4uECezsRINDA6ZieFPumdFL+6yySpXM6t8=
github.com/bl4ko/go-devicetype-library v0.1.43 h1:WUJDxXo01fxuk6EEtkLQB/giXNGxK9JO7REqf0ntv7o=
github.com/bl4ko/go-devicetype-library v0.1.43/go.mod h1:Pzm1BlRyR4uECezsRINDA6ZieFPumdFL+6yySpXM6t8=
github.com/bl4ko/go-devicetype-library v0.1.45 h1:UsxWYNHBrpNAcp8OA6PQzzCk2OqtWuarh6OEb0JHirQ=
github.com/bl4ko/go-devicetype-library v0.1.45/go.mod h1:Pzm1BlRyR4uECezsRINDA6ZieFPumdFL+6yySpXM6t8=
github.com/buger/goterm v1.0.4 h1:Z9YvGmOih81P0FbVtEYTFF6YsSgxSUKEhf/f9bTMXbY=
github.com/buger/goterm v1.0.4/go.mod h1:HiFWV3xnkolgrBV3mY8m0X0Pumt4zg4QhbdOzQtB8tE=
github.com/cisco-en-programmability/dnacenter-go-sdk/v6 v6.0.0 h1:UAkph9VReeOVkE3pX6G12IuJOWFg41Q7PL4er3zD3Sc=
github.com/cisco-en-programmability/dnacenter-go-sdk/v6 v6.0.0/go.mod h1:Chafvg+TCkqlROEOlX/WlK5Wk8nTtMCqhuCZSYtlLCE=
github.com/cisco-en-programmability/dnacenter-go-sdk/v7 v7.0.0 h1:oAHsGmf+Vvs3lHRshDEFA+nKoTLcfL0NHBr4kGN46M0=
github.com/cisco-en-programmability/dnacenter-go-sdk/v7 v7.0.0/go.mod h1:UcGpH8J9EboPCWB4UEH/p2ZfUzJ3LpH2qCL7Fk1EAMo=
github.com/creack/pty v1.1.24 h1:bJrF4RRfyJnbTJqzRLHzcGaZK1NeM5kTC9jGgovnR1s=
github.com/creack/pty v1.1.24/go.mod h1:08sCNb52WyoAwi2QDyzUCTgcvVFhUzewun7wtTfvcwE=
Expand All @@ -27,8 +16,8 @@ github.com/djherbis/times v1.6.0 h1:w2ctJ92J8fBvWPxugmXIv7Nz7Q3iDMKNx9v5ocVH20c=
github.com/djherbis/times v1.6.0/go.mod h1:gOHeRAz2h+VJNZ5Gmc/o7iD9k4wW7NMVqieYCY99oc0=
github.com/elliotwutingfeng/asciiset v0.0.0-20230602022725-51bbb787efab h1:h1UgjJdAAhj+uPL68n7XASS6bU+07ZX1WJvVS2eyoeY=
github.com/elliotwutingfeng/asciiset v0.0.0-20230602022725-51bbb787efab/go.mod h1:GLo/8fDswSAniFG+BFIaiSPcK610jyzgEhWYPQwuQdw=
github.com/go-resty/resty/v2 v2.16.2 h1:CpRqTjIzq/rweXUt9+GxzzQdlkqMdt8Lm/fuK/CAbAg=
github.com/go-resty/resty/v2 v2.16.2/go.mod h1:0fHAoK7JoBy/Ch36N8VFeMsK7xQOHhvWaC3iOktwmIU=
github.com/go-resty/resty/v2 v2.16.5 h1:hBKqmWrr7uRc3euHVqmh1HTHcKn99Smr7o5spptdhTM=
github.com/go-resty/resty/v2 v2.16.5/go.mod h1:hkJtXbA2iKHzJheXYvQ8snQES5ZLGKMwQ07xAwp/fiA=
github.com/go-test/deep v1.0.8 h1:TDsG77qcSprGbC6vTN8OuXp5g+J+b5Pcguhf7Zt61VM=
github.com/go-test/deep v1.0.8/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
Expand Down Expand Up @@ -72,18 +61,16 @@ github.com/ulikunitz/xz v0.5.11 h1:kpFauv27b6ynzBNT/Xy+1k+fK4WswhN/6PN5WhFAGw8=
github.com/ulikunitz/xz v0.5.11/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
github.com/vmware/govmomi v0.48.0 h1:CP5bCvkDNGkmn29UlcJKTWMLwDg3iusP8anrZnedWrg=
github.com/vmware/govmomi v0.48.0/go.mod h1:bYwUHpGpisE4AOlDl5eph90T+cjJMIcKx/kaa5v5rQM=
golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U=
golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I=
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
golang.org/x/crypto v0.32.0 h1:euUpcYgM8WcP71gNpTqQCn6rC2t6ULUPiOzfWaXVVfc=
golang.org/x/crypto v0.32.0/go.mod h1:ZnnJkOaASj8g0AjIduWNlq2NRxL0PlBrbKVyZ6V/Ugc=
golang.org/x/net v0.34.0 h1:Mb7Mrk043xzHgnRM88suvJFwzVrRfHEHJEl5/71CKw0=
golang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k=
golang.org/x/sys v0.0.0-20210331175145-43e1dd70ce54/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220615213510-4f61da869c0c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.27.0 h1:WP60Sv1nlK1T6SupCHbXzSaN0b9wUmsPoRS9b61A23Q=
golang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM=
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.28.0 h1:/Ts8HFuMR2E6IP/jlo7QVLZHggjKQbhu/7H0LJFr3Gg=
golang.org/x/term v0.28.0/go.mod h1:Sw/lC2IAUZ92udQNf3WodGtn4k/XoLyZoh8v/8uiwek=
golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM=
golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY=
golang.org/x/time v0.6.0 h1:eTDhh4ZXt5Qf0augr54TN6suAUudPcawVZeIAPU7D4U=
Expand Down
6 changes: 4 additions & 2 deletions internal/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ const OrphanTagDescription = "Tag used by netbox-ssot to mark orphaned objects"

const DefaultVlanGroupName = "DefaultVlanGroup"

const DefaultVlanGroupDescription = "Default netbox-ssot VlanGroup for all vlans that are not part of any other vlanGroup. This group is required for netbox-ssot vlan index to work."
const DefaultVlanGroupDescription = "Default netbox-ssot VlanGroup for all vlans that are not part of " +
"any other vlanGroup. This group is required for netbox-ssot vlan index to work."

const DefaultArpTagName = "arp-entry"
const DefaultArpTagColor = ColorRed
Expand Down Expand Up @@ -330,7 +331,8 @@ const (
MaxVMNameLength = 64
MaxVMInterfaceNameLength = 64

// Limitations for devices: https://github.com/netbox-community/netbox/blob/d03d302eef3819db64cad8ae74dc5255647045f6/netbox/dcim/models/device_components.py.
//nolint:lll
// Limitations for devices https://github.com/netbox-community/netbox/blob/d03d302eef3819db64cad8ae74dc5255647045f6/netbox/dcim/models/device_components.py.
MaxDeviceNameLength = 64
MaxSerialNumberLength = 50
MaxAssetTagLength = 50
Expand Down
83 changes: 74 additions & 9 deletions internal/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ type Logger struct {
level int
}

// New creates a new Logger instance, which writes to the specified destination (file) or stdout if dest is empty. It also sets the log level.
// New creates a new Logger instance, which writes to the specified destination (file) or stdout if dest is empty.
// It also sets the log level.
func New(dest string, logLevel int) (*Logger, error) {
var output io.Writer
if dest == "" {
Expand Down Expand Up @@ -72,60 +73,124 @@ func (l *Logger) Output(calldepth int, s string) error {

func (l *Logger) Debug(ctx context.Context, v ...interface{}) error {
if l.level <= DEBUG {
return l.Output(logCallDepth, fmt.Sprintf("%-7s (%s): %s", "DEBUG", ctx.Value(constants.CtxSourceKey), fmt.Sprint(v...)))
return l.Output(
logCallDepth,
fmt.Sprintf(
"%-7s (%s): %s",
"DEBUG",
ctx.Value(constants.CtxSourceKey),
fmt.Sprint(v...),
),
)
}
return nil
}

// Debugf logs a formatted debug message.
func (l *Logger) Debugf(ctx context.Context, format string, v ...interface{}) error {
if l.level <= DEBUG {
return l.Output(logCallDepth, fmt.Sprintf("%-7s (%s): %s", "DEBUG", ctx.Value(constants.CtxSourceKey), fmt.Sprintf(format, v...)))
return l.Output(
logCallDepth,
fmt.Sprintf(
"%-7s (%s): %s",
"DEBUG",
ctx.Value(constants.CtxSourceKey),
fmt.Sprintf(format, v...),
),
)
}
return nil
}

func (l *Logger) Info(ctx context.Context, v ...interface{}) error {
if l.level <= INFO {
return l.Output(logCallDepth, fmt.Sprintf("%-7s (%s): %s", "INFO", ctx.Value(constants.CtxSourceKey), fmt.Sprint(v...)))
return l.Output(
logCallDepth,
fmt.Sprintf(
"%-7s (%s): %s",
"INFO",
ctx.Value(constants.CtxSourceKey),
fmt.Sprint(v...),
),
)
}
return nil
}

// Infof logs a formatted info message.
func (l *Logger) Infof(ctx context.Context, format string, v ...interface{}) error {
if l.level <= INFO {
return l.Output(logCallDepth, fmt.Sprintf("%-7s (%s): %s", "INFO", ctx.Value(constants.CtxSourceKey), fmt.Sprintf(format, v...)))
return l.Output(
logCallDepth,
fmt.Sprintf(
"%-7s (%s): %s",
"INFO",
ctx.Value(constants.CtxSourceKey),
fmt.Sprintf(format, v...),
),
)
}
return nil
}

func (l *Logger) Warning(ctx context.Context, v ...interface{}) error {
if l.level <= WARNING {
return l.Output(logCallDepth, fmt.Sprintf("%-7s (%s): %s", "WARNING", ctx.Value(constants.CtxSourceKey), fmt.Sprint(v...)))
return l.Output(
logCallDepth,
fmt.Sprintf(
"%-7s (%s): %s",
"WARNING",
ctx.Value(constants.CtxSourceKey),
fmt.Sprint(v...),
),
)
}
return nil
}

// Warningf logs a formatted warning message.
func (l *Logger) Warningf(ctx context.Context, format string, v ...interface{}) error {
if l.level <= WARNING {
return l.Output(logCallDepth, fmt.Sprintf("%-7s (%s): %s", "WARNING", ctx.Value(constants.CtxSourceKey), fmt.Sprintf(format, v...)))
return l.Output(
logCallDepth,
fmt.Sprintf(
"%-7s (%s): %s",
"WARNING",
ctx.Value(constants.CtxSourceKey),
fmt.Sprintf(format, v...),
),
)
}
return nil
}

func (l *Logger) Error(ctx context.Context, v ...interface{}) error {
if l.level <= ERROR {
return l.Output(logCallDepth, fmt.Sprintf("%-7s (%s): %s", "ERROR", ctx.Value(constants.CtxSourceKey), fmt.Sprint(v...)))
return l.Output(
logCallDepth,
fmt.Sprintf(
"%-7s (%s): %s",
"ERROR",
ctx.Value(constants.CtxSourceKey),
fmt.Sprint(v...),
),
)
}
return nil
}

// Errorf logs a formatted error message.
func (l *Logger) Errorf(ctx context.Context, format string, v ...interface{}) error {
if l.level <= ERROR {
return l.Output(logCallDepth, fmt.Sprintf("%-7s (%s): %s", "ERROR", ctx.Value(constants.CtxSourceKey), fmt.Sprintf(format, v...)))
return l.Output(
logCallDepth,
fmt.Sprintf(
"%-7s (%s): %s",
"ERROR",
ctx.Value(constants.CtxSourceKey),
fmt.Sprintf(format, v...),
),
)
}
return nil
}
Loading