Full web : clusters gérés dans l'UI, primaire et cibles, comptes pve
This commit is contained in:
1 parent
3e9cb563be
commit
ec3b7c9a01
5 files changed
+617
-453
No files matched your search
@@ -5,6 +5,8 @@ package adapter
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"sort"
|
||||
@@ -60,7 +62,59 @@ type Adapter interface {
|
||||
|
||||
// All returns the adapters in dependency order.
|
||||
func All() []Adapter {
|
||||
return []Adapter{datacenter{}, zone{}, vnet{}, subnet{}}
|
||||
return []Adapter{datacenter{}, group{}, role{}, user{}, password{}, zone{}, vnet{}, subnet{}}
|
||||
}
|
||||
|
||||
// KindDeps: replicating a kind needs these kinds too (a password needs its
|
||||
// account on the target, an account its groups).
|
||||
var KindDeps = map[model.Kind][]model.Kind{
|
||||
model.KindPassword: {model.KindUser},
|
||||
model.KindUser: {model.KindGroup},
|
||||
}
|
||||
|
||||
// Sensitive is implemented by adapters whose fields must never be shown nor
|
||||
// journaled (password hashes): they are replaced by Redact.
|
||||
type Sensitive interface {
|
||||
Sensitive(field string) bool
|
||||
}
|
||||
|
||||
// Parented is implemented by adapters whose objects need other objects on the
|
||||
// target ("kind/id" keys): an account needs its groups, a password its account.
|
||||
type Parented interface {
|
||||
Parents(o model.Object) []string
|
||||
}
|
||||
|
||||
// IsSensitive tells whether a field of a kind is secret.
|
||||
func IsSensitive(k model.Kind, field string) bool {
|
||||
a, err := ByKind(k)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
s, ok := a.(Sensitive)
|
||||
return ok && s.Sensitive(field)
|
||||
}
|
||||
|
||||
// Redact replaces a secret value by a short digest: two different hashes stay
|
||||
// distinguishable in a diff, the value itself is never shown.
|
||||
func Redact(v any) any {
|
||||
s, ok := v.(string)
|
||||
if !ok || s == "" {
|
||||
return v
|
||||
}
|
||||
sum := sha256.Sum256([]byte(s))
|
||||
return "<masqué " + hex.EncodeToString(sum[:3]) + ">"
|
||||
}
|
||||
|
||||
// Parents returns the keys of the objects o needs on the target.
|
||||
func Parents(o model.Object) []string {
|
||||
a, err := ByKind(o.Kind)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
if p, ok := a.(Parented); ok {
|
||||
return p.Parents(o)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ByKind returns the adapter of a kind.
|
||||
|
||||
Reference in new issue
Block a user