replace static status definition by const

This commit is contained in:
venture
2026-11-14 09:57:52 +01:00
parent 276a9fe320
commit f16363cb60
10 changed files with 65 additions and 48 deletions
+14 -13
View File
@@ -9,6 +9,7 @@ import (
"mediarr/cluster"
"mediarr/database"
"mediarr/ident"
"mediarr/identity"
"time"
)
@@ -42,20 +43,20 @@ func (n *Node) ensureClusterIdentity(ctx context.Context) error {
switch {
case err == nil:
identity, loadErr := cluster.LoadOrCreate(n.clusterKeyPath, false)
clusterIdentity, loadErr := cluster.LoadOrCreate(n.clusterKeyPath, false)
if loadErr != nil {
return fmt.Errorf("cluster : principal présent en base mais clé indisponible : %w", loadErr)
}
if !bytes.Equal(principal.PublicKey, identity.PublicKey) {
if !bytes.Equal(principal.PublicKey, clusterIdentity.PublicKey) {
return errors.New("cluster : la clé publique de cluster.key ne correspond pas au principal en base")
}
n.cluster = identity
n.cluster = clusterIdentity
return nil
case errors.Is(err, sql.ErrNoRows):
identity, createErr := cluster.LoadOrCreate(n.clusterKeyPath, true)
clusterIdentity, createErr := cluster.LoadOrCreate(n.clusterKeyPath, true)
if createErr != nil {
return createErr
}
@@ -69,21 +70,21 @@ func (n *Node) ensureClusterIdentity(ctx context.Context) error {
ID: clusterID,
Kind: "cluster",
Name: "cluster",
PublicKey: identity.PublicKeyBytes(),
Status: "active",
PublicKey: clusterIdentity.PublicKeyBytes(),
Status: identity.StatusActive,
CreatedAt: time.Now().UnixMilli(),
})
if createErr != nil {
existing, getErr := n.db.Queries.GetClusterPrincipal(ctx)
if getErr == nil && bytes.Equal(existing.PublicKey, identity.PublicKey) {
n.cluster = identity
if getErr == nil && bytes.Equal(existing.PublicKey, clusterIdentity.PublicKey) {
n.cluster = clusterIdentity
return nil
}
return fmt.Errorf("cluster : création du principal : %w", createErr)
}
n.cluster = identity
n.cluster = clusterIdentity
return nil
default:
@@ -99,28 +100,28 @@ func requiredNodePrincipals(now int64) []database.CreatePrincipalParams {
ID: ident.MustParse("00000000-0000-7000-8000-000000000001"),
Kind: "system",
Name: "system",
Status: "active",
Status: identity.StatusActive,
CreatedAt: now,
},
{
ID: ident.MustParse("00000000-0000-7000-8000-000000000002"),
Kind: "group",
Name: "admins",
Status: "active",
Status: identity.StatusActive,
CreatedAt: now,
},
{
ID: ident.MustParse("00000000-0000-7000-8000-000000000003"),
Kind: "group",
Name: "members",
Status: "active",
Status: identity.StatusActive,
CreatedAt: now,
},
{
ID: ident.MustParse("00000000-0000-7000-8000-000000000004"),
Kind: "group",
Name: "guests",
Status: "active",
Status: identity.StatusActive,
CreatedAt: now,
},
}