From 109fcd3af915cba5e8786b0071767f8f71401959 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20D=C3=B6ll?= Date: Tue, 14 May 2024 19:39:04 +0000 Subject: [PATCH] wip: create accoun signing keys --- internal/api/adapters/db/accounts.go | 2 +- internal/api/adapters/db/db.go | 2 +- internal/api/controllers/accounts.go | 2 +- internal/api/models/account.go | 2 -- internal/api/models/operator.go | 6 ++---- internal/api/models/system.go | 2 +- 6 files changed, 6 insertions(+), 10 deletions(-) diff --git a/internal/api/adapters/db/accounts.go b/internal/api/adapters/db/accounts.go index 4af1499c..11aac0da 100644 --- a/internal/api/adapters/db/accounts.go +++ b/internal/api/adapters/db/accounts.go @@ -10,7 +10,7 @@ import ( // GetAccount ... func (db *DB) GetAccount(ctx context.Context, account *models.Account) error { - return db.conn.WithContext(ctx).Preload("Token").Preload("Operator").Preload("SigningKeyGroups").Preload("SigningKeyGroups.Key").Preload("Key").First(account).Error + return db.conn.WithContext(ctx).Preload("Token").Preload("SigningKeyGroups").Preload("SigningKeyGroups.Key").Preload("Key").First(account).Error } // CreateAccount ... diff --git a/internal/api/adapters/db/db.go b/internal/api/adapters/db/db.go index c49aae15..f08d7d6e 100644 --- a/internal/api/adapters/db/db.go +++ b/internal/api/adapters/db/db.go @@ -32,8 +32,8 @@ func (db *DB) RunMigrations() error { &adapters.Account{}, &adapters.Session{}, &models.User{}, - &models.Account{}, &models.Operator{}, + &models.Account{}, &models.System{}, &models.Tag{}, &models.Ownership{}, diff --git a/internal/api/controllers/accounts.go b/internal/api/controllers/accounts.go index 232b4acb..a40eb661 100644 --- a/internal/api/controllers/accounts.go +++ b/internal/api/controllers/accounts.go @@ -132,7 +132,7 @@ func (c *accountsController) CreateAccount(ctx context.Context, cmd CreateAccoun ac := jwt.NewAccountClaims(id) ac.Name = cmd.Name ac.Issuer = operator.KeyID - ac.SigningKeys.Add(skg.KeyID) + ac.SigningKeys.Add(skg.Key.ID) token, err := ac.Encode(osk) if err != nil { diff --git a/internal/api/models/account.go b/internal/api/models/account.go index b53a637e..53a594dc 100644 --- a/internal/api/models/account.go +++ b/internal/api/models/account.go @@ -26,8 +26,6 @@ type Account struct { TokenID string `json:"token_id"` // OperatorID is the operator ID. OperatorID uuid.UUID `json:"operator_id"` - // Operator is the operator that owns the account. - Operator Operator `json:"operator" gorm:"foreignKey:OperatorID"` // SigningKeyGroups is the list of signing key groups the account has. SigningKeyGroups []SigningKeyGroup `json:"signing_key_groups" gorm:"many2many:account_signing_key_groups;foreignKey:ID;joinForeignKey:AccountID;joinReferences:SigningKeyGroupID"` // SignedBy is the entity that signs this one. diff --git a/internal/api/models/operator.go b/internal/api/models/operator.go index fc249dc9..9e045984 100644 --- a/internal/api/models/operator.go +++ b/internal/api/models/operator.go @@ -28,10 +28,8 @@ type Operator struct { // SystemAdminAccount is the account that is used to manage the systems. SystemAdminAccount *Account `json:"system_admin_account" gorm:"foreignKey:SystemAdminAccountID"` SystemAdminAccountID *uuid.UUID `json:"system_admin_account_id"` - // Systems is the list of systems that the operator has. - Systems []System `json:"systems" gorm:"many2many:operator_systems;foreignKey:ID;joinForeignKey:OperatorID;joinReferences:SystemID"` - // Accounts is the list of accounts that the operator has. - Accounts []Account `json:"accounts" gorm:"many2many:operator_accounts;foreignKey:ID;joinForeignKey:OperatorID;joinReferences:AccountID"` + // Systems is the systems that are associated with the operator. + Systems []System `json:"systems" gorm:"foreignKey:OperatorID"` // SigningKeyGroups is the list of signing key groups the account has. SigningKeyGroups []SigningKeyGroup `json:"signing_key_groups" gorm:"many2many:operator_signing_key_groups;foreignKey:ID;joinForeignKey:OperatorID;joinReferences:SigningKeyGroupID"` // CreatedAt is the time the operator was created. diff --git a/internal/api/models/system.go b/internal/api/models/system.go index c37a2efd..87a1d65b 100644 --- a/internal/api/models/system.go +++ b/internal/api/models/system.go @@ -30,7 +30,7 @@ type System struct { Clusters []Cluster `json:"clusters" gorm:"foreignKey:SystemID"` // Operator is the operator this is associated with this system to operate. - Operator *Operator `json:"operator" gorm:"foreignKey:OperatorID"` + Operator Operator `json:"operator" gorm:"foreignKey:OperatorID"` OperatorID uuid.UUID `json:"operator_id"` // Tags is the tags that are associated with the system.