33 lines
1000 B
Go
33 lines
1000 B
Go
package main
|
|
|
|
import (
|
|
"git.zb-server.de/Sebi/ssh-netbox-wrapper/internal/config"
|
|
"git.zb-server.de/Sebi/ssh-netbox-wrapper/internal/netbox"
|
|
"git.zb-server.de/Sebi/ssh-netbox-wrapper/internal/shortcuts"
|
|
)
|
|
|
|
func newNetBoxClient(cfg *config.Config) *netbox.Client {
|
|
if len(cfg.NetBoxes) > 0 {
|
|
sources := make([]netbox.Source, 0, len(cfg.NetBoxes))
|
|
for _, source := range cfg.NetBoxes {
|
|
sources = append(sources, netbox.Source{Name: source.Name, URL: source.URL, Token: source.Token, TokenVersion: source.TokenVersion})
|
|
}
|
|
return netbox.NewMultiClient(sources)
|
|
}
|
|
if cfg.NetBox.URL == "" {
|
|
return nil
|
|
}
|
|
return netbox.NewClient(cfg.NetBox.URL, cfg.NetBox.Token, cfg.NetBox.TokenVersion)
|
|
}
|
|
|
|
func normalizeTarget(cfg config.ShortcutsConfig, qualified bool) func(string) string {
|
|
return func(target string) string {
|
|
source, name := netbox.SplitTarget(target)
|
|
name = shortcuts.Normalize(name, cfg)
|
|
if qualified && source != "" {
|
|
return source + "/" + name
|
|
}
|
|
return name
|
|
}
|
|
}
|