646fa0f840
Add a Terraform provider that manages the Gitea token secrets engine (vault-plugin-secrets-gitea) on Vault/OpenBao, so terraform-vault can drive the engine's mount, config, and roles declaratively. - add the provider (source git.unkin.net/unkin/giteavaultsecret, prefix gitea_) - add gitea_secret_backend (mount + config with seeded admin credentials) - add gitea_secret_backend_role (username, scopes list, ttls, token_name_prefix) - add the Vault API client plumbing, conversions, and unit tests - add examples, a real terraform+Vault+mock-Gitea e2e, and Woodpecker pipelines releasing the provider zip to the artifactapi terraform registry Claude-Session: https://claude.ai/code/session_015ur3i7D2azsMAWTSVABApv
67 lines
1.4 KiB
Go
67 lines
1.4 KiB
Go
package provider
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strings"
|
|
)
|
|
|
|
// toStringSlice coerces the list shapes Vault returns (a JSON array decodes to
|
|
// []interface{}) into a []string. A nil or non-list value yields an empty slice.
|
|
func toStringSlice(v interface{}) []string {
|
|
switch xs := v.(type) {
|
|
case []string:
|
|
return xs
|
|
case []interface{}:
|
|
out := make([]string, 0, len(xs))
|
|
for _, x := range xs {
|
|
if s, ok := x.(string); ok {
|
|
out = append(out, s)
|
|
}
|
|
}
|
|
return out
|
|
default:
|
|
return []string{}
|
|
}
|
|
}
|
|
|
|
// 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
|
|
}
|
|
}
|
|
|
|
// splitBackendName splits an import ID of the form "<backend>/<marker>/<name>"
|
|
// (e.g. "rancher/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
|
|
}
|