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
+6
View File
@@ -19,6 +19,12 @@ const (
RoleMember = "member"
)
const (
StatusActive = "active"
StatusDisabled = "disabled"
StatusRevoked = "revoked"
)
type Principal struct {
ID ident.UUID
Kind string
+5 -3
View File
@@ -31,9 +31,11 @@ func (s *Service) CreatePrincipal(ctx context.Context, params CreatePrincipalPar
status := params.Status
if status == "" {
status = "active"
status = StatusActive
}
if status != "active" && status != "disabled" && status != "revoked" {
switch status {
case StatusActive, StatusDisabled, StatusRevoked:
default:
return nil, fmt.Errorf("%w: %q", ErrInvalidStatus, status)
}
@@ -87,7 +89,7 @@ func (s *Service) CreateGuest(ctx context.Context, name string) (*Principal, err
ID: id,
Kind: KindGuest,
Name: name,
Status: "active",
Status: StatusActive,
CreatedAt: now,
}); err != nil {
return err
+2 -2
View File
@@ -27,8 +27,8 @@ func TestCreatePrincipal(t *testing.T) {
if created.Name != "alice" {
t.Fatalf("name = %q, attendu alice", created.Name)
}
if created.Status != "active" {
t.Fatalf("status = %q, attendu active", created.Status)
if created.Status != StatusActive {
t.Fatalf("status = %q, attendu %q", created.Status, StatusActive)
}
if len(created.Groups) != 0 {
t.Fatalf("groupes = %+v, attendu aucun", created.Groups)