bff97965a9
Terraform/OpenBao-Vault provider that manages the vault-plugin-secrets-netbox engine: netbox_secret_backend (mount + connection config incl. seeded admin token) and netbox_secret_backend_role (per-user mint policy: write_enabled, ttl/max_ttl). Framework + Vault API client mirrored from the ranchervaultsecret provider. Unit tests for conversions/import parsing; tag-driven zip release to the artifactapi terraform-unkin registry. Claude-Session: https://claude.ai/code/session_01JUoARVdmhxKQHyyyp1pxeT
54 lines
1.1 KiB
Go
54 lines
1.1 KiB
Go
package provider
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strings"
|
|
)
|
|
|
|
// toInt64 coerces the numeric shapes Vault returns (json.Number, float64, int)
|
|
// into an int64.
|
|
func toInt64(v interface{}) (int64, bool) {
|
|
switch n := v.(type) {
|
|
case json.Number:
|
|
i, err := n.Int64()
|
|
if err != nil {
|
|
f, ferr := n.Float64()
|
|
if ferr != nil {
|
|
return 0, false
|
|
}
|
|
return int64(f), true
|
|
}
|
|
return i, true
|
|
case float64:
|
|
return int64(n), true
|
|
case int64:
|
|
return n, true
|
|
case int:
|
|
return int64(n), true
|
|
default:
|
|
return 0, false
|
|
}
|
|
}
|
|
|
|
// toBool coerces a Vault-returned value into a bool.
|
|
func toBool(v interface{}) (bool, bool) {
|
|
b, ok := v.(bool)
|
|
return b, ok
|
|
}
|
|
|
|
// splitBackendName splits an import ID of the form "<backend>/<marker>/<name>"
|
|
// (e.g. "netbox/roles/ci") into its backend and name parts.
|
|
func splitBackendName(id, marker string) (backend, name string, ok bool) {
|
|
sep := "/" + marker + "/"
|
|
idx := strings.LastIndex(id, sep)
|
|
if idx <= 0 {
|
|
return "", "", false
|
|
}
|
|
backend = id[:idx]
|
|
name = id[idx+len(sep):]
|
|
if backend == "" || name == "" {
|
|
return "", "", false
|
|
}
|
|
return backend, name, true
|
|
}
|