Skip to content

Commit

Permalink
wip: create account
Browse files Browse the repository at this point in the history
  • Loading branch information
katallaxie authored May 11, 2024
1 parent 154261a commit 2e1df53
Show file tree
Hide file tree
Showing 9 changed files with 143 additions and 91 deletions.
15 changes: 1 addition & 14 deletions api/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ paths:
tags:
- Account
requestBody:
$ref: "#/components/requestBodies/CreateAccount"
$ref: "./requests/createAccount.yml#/components/requestBodies/CreateAccount"
responses:
201:
description: Created
Expand Down Expand Up @@ -928,19 +928,6 @@ components:
type: string
description:
type: string
# Body for creating an account
CreateAccount:
content:
application/json:
schema:
type: object
required:
- name
properties:
name:
type: string
description:
type: string

# Body for updating an account
UpdateAccount:
Expand Down
24 changes: 14 additions & 10 deletions api/out.yml
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,7 @@ components:
type: string
description:
type: string
CreateAccount:
UpdateAccount:
content:
application/json:
schema:
Expand All @@ -914,7 +914,9 @@ components:
type: string
description:
type: string
UpdateAccount:
claims:
$ref: '#/components/schemas/JWTAccountClaims'
CreateOperatorAccountUser:
content:
application/json:
schema:
Expand All @@ -924,11 +926,9 @@ components:
properties:
name:
type: string
description:
email:
type: string
claims:
$ref: '#/components/schemas/JWTAccountClaims'
CreateOperatorAccountUser:
CreateOperator:
content:
application/json:
schema:
Expand All @@ -938,22 +938,26 @@ components:
properties:
name:
type: string
email:
description:
type: string
CreateOperator:
contactEmail:
type: string
CreateAccount:
content:
application/json:
schema:
type: object
required:
- systemId
- name
properties:
systemId:
type: string
format: uuid
name:
type: string
description:
type: string
contactEmail:
type: string
securitySchemes:
bearerAuth:
type: http
Expand Down
18 changes: 18 additions & 0 deletions api/requests/createAccount.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
components:
requestBodies:
CreateAccount:
content:
application/json:
schema:
type: object
required:
- systemId
- name
properties:
systemId:
type: string
format: uuid
name:
type: string
description:
type: string
26 changes: 19 additions & 7 deletions internal/api/controllers/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,31 @@ import (
"github.com/zeiss/typhoon/internal/api/ports"
)

// CreateAccountRequest ...
type CreateAccountRequest struct {
Name string `json:"name"`
Description string `json:"description"`
SystemID uuid.UUID `json:"system_id"`
}

// CreateAccountResponse ...
type CreateAccountResponse struct {
Account models.Account `json:"account"`
}

// ListAccountsRequest ...
type ListAccountsRequest struct {
SystemID uuid.UUID
Limit int
Offset int
SystemID uuid.UUID `json:"system_id"`
Limit int `json:"limit"`
Offset int `json:"offset"`
}

// ListAccountsResponse ...
type ListAccountsResponse struct {
Accounts []models.Account
Total int
Offset int
Limit int
Accounts []models.Account `json:"accounts"`
Total int `json:"total"`
Offset int `json:"offset"`
Limit int `json:"limit"`
}

// AccountsController is the interface that wraps the methods to access accounts.
Expand Down
2 changes: 1 addition & 1 deletion internal/api/controllers/systems.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (s *SystemsControllerImpl) UpdateSystemOperator(ctx context.Context, system
return system, err
}

system.OperatorID = &operatorID
system.OperatorID = operatorID

if err := s.db.UpdateSystem(ctx, &system); err != nil {
return system, err
Expand Down
6 changes: 6 additions & 0 deletions internal/api/models/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,18 @@ type Account struct {
ID uuid.UUID `json:"id" gorm:"type:uuid;primary_key;default:gen_random_uuid()"`
// Name is the name of the account.
Name string `json:"name"`
// Description is the description of the account.
Description *string `json:"description"`
// Key is the issuer key identifier.
Key NKey `json:"key"`
KeyID string `json:"key_id" gorm:"foreignKey:ID"`
// Token is the JWT token used to authenticate the account.
Token Token `json:"token" gorm:"foreignKey:TokenID"`
TokenID string `json:"token_id"`
// System is the system the account belongs to.
System *System `json:"system" gorm:"foreignKey:SystemID"`
// SystemID is the system the account belongs to.
SystemID uuid.UUID `json:"system_id"`
// 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.
Expand Down
8 changes: 4 additions & 4 deletions internal/api/models/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ 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"`
OperatorID *uuid.UUID `json:"operator_id"`
Operator *Operator `json:"operator" gorm:"foreignKey:OperatorID"`
OperatorID uuid.UUID `json:"operator_id"`

// SystemAccount is the account that is used to control the system.
// The system account needs to be signed by the operator.
SystemAccount Account `json:"system_account" gorm:"foreignKey:SystemAccountID"`
SystemAccountID *uuid.UUID `json:"system_account_id"`
SystemAccount Account `json:"system_account" gorm:"foreignKey:SystemAccountID"`
SystemAccountID uuid.UUID `json:"system_account_id"`

// Tags is the tags that are associated with the system.
Tags []*Tag `json:"tags" gorm:"polymorphic:Taggable;polymorphicValue:system;"`
Expand Down
23 changes: 23 additions & 0 deletions pkg/apis/dto/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,33 @@ package dto

import (
"github.com/zeiss/typhoon/internal/api/controllers"
"github.com/zeiss/typhoon/internal/api/models"
"github.com/zeiss/typhoon/internal/utils"
openapi "github.com/zeiss/typhoon/pkg/apis"
)

// FromCreateAccountRequest ...
func FromCreateAccountRequest(req openapi.CreateAccountRequestObject) controllers.CreateAccountRequest {
return controllers.CreateAccountRequest{
SystemID: req.Body.SystemId,
Name: req.Body.Name,
Description: utils.PtrStr(req.Body.Description),
}
}

// ToCreateAccountResponse ...
func ToCreateAccountResponse(account models.Account) openapi.CreateAccount201JSONResponse {
res := openapi.CreateAccount201JSONResponse{}

res.Id = utils.PtrUUID(account.ID)
res.Name = account.Name
res.CreatedAt = utils.PtrTime(account.CreatedAt)
res.UpdatedAt = utils.PtrTime(account.UpdatedAt)
res.DeletedAt = utils.PtrTime(account.DeletedAt.Time)

return res
}

// ToListAccountResponse ...
func ToListAccountResponse(output controllers.ListAccountsResponse) openapi.ListAccounts200JSONResponse {
res := openapi.ListAccounts200JSONResponse{}
Expand Down
112 changes: 57 additions & 55 deletions pkg/apis/models.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2e1df53

Please sign in to comment.