Skip to content

Commit

Permalink
fix: operator skgs
Browse files Browse the repository at this point in the history
  • Loading branch information
katallaxie committed Jul 15, 2024
1 parent 6344588 commit aad2130
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 43 deletions.
5 changes: 1 addition & 4 deletions internal/web/controllers/accounts/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ type CreateControllerImpl struct {

// NewCreateController ...
func NewCreateController(store ports.Datastore) *CreateControllerImpl {
return &CreateControllerImpl{
store: store,
TransactionController: htmx.NewTransactionController(),
}
return &CreateControllerImpl{store: store}
}

// Prepare ...
Expand Down
55 changes: 30 additions & 25 deletions internal/web/controllers/accounts/partials/operator_skgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,53 +6,58 @@ import (
"github.com/google/uuid"
htmx "github.com/zeiss/fiber-htmx"
"github.com/zeiss/fiber-htmx/components/forms"
"github.com/zeiss/fiber-htmx/components/tables"
"github.com/zeiss/fiber-htmx/components/toasts"
"github.com/zeiss/typhoon/internal/api/models"
"github.com/zeiss/typhoon/internal/web/ports"
)

// OperatorSkgsOptionsImpl ...
type OperatorSkgsOptionsImpl struct {
OperatorID uuid.UUID `json:"operator_id" form:"operator_id" query:"operator_id" validate:"required,uuid"`

store ports.Datastore
operator models.Operator
store ports.Datastore
htmx.DefaultController
}

// NewOperatorSkgsOptions ...
func NewOperatorSkgsOptions(store ports.Datastore) *OperatorSkgsOptionsImpl {
return &OperatorSkgsOptionsImpl{
store: store,
DefaultController: htmx.DefaultController{},
}
return &OperatorSkgsOptionsImpl{store: store}
}

// Error ...
func (l *OperatorSkgsOptionsImpl) Error(err error) error {
return toasts.RenderToasts(
l.Ctx(),
toasts.Toasts(
toasts.ToastsProps{},
toasts.ToastAlertError(
toasts.ToastProps{},
htmx.Text(err.Error()),
),
),
)
}

// Prepare ...
func (l *OperatorSkgsOptionsImpl) Prepare() error {
err := l.Ctx().QueryParser(l)
var operator struct {
ID uuid.UUID `json:"operator_id" form:"operator_id" query:"operator_id" validate:"required,uuid"`
}

err := l.Ctx().QueryParser(&operator)
if err != nil {
return err
}

return nil
l.operator.ID = operator.ID

return l.store.ReadTx(l.Context(), func(ctx context.Context, tx ports.ReadTx) error {
return tx.GetOperator(ctx, &l.operator)
})
}

// Get ...
func (l *OperatorSkgsOptionsImpl) Get() error {
operator := models.Operator{
ID: l.OperatorID,
}

err := l.store.ReadTx(l.Context(), func(ctx context.Context, tx ports.ReadTx) error {
return tx.GetOperator(ctx, &operator)
})
if err != nil {
return err
}

skgs := make([]*models.SigningKeyGroup, 0)
for _, skg := range operator.SigningKeyGroups {
skgs = append(skgs, &skg)
}

return l.Render(
forms.SelectBordered(
Expand All @@ -67,7 +72,7 @@ func (l *OperatorSkgsOptionsImpl) Get() error {
htmx.ID("operator-skgs"),
htmx.Name("operator_skgs_id"),
htmx.Group(
htmx.ForEach(skgs, func(e *models.SigningKeyGroup, idx int) htmx.Node {
htmx.ForEach(tables.RowsPtr(l.operator.SigningKeyGroups), func(e *models.SigningKeyGroup, idx int) htmx.Node {
return htmx.Option(
htmx.Attribute("value", e.KeyID),
htmx.Text(e.Name),
Expand Down
18 changes: 9 additions & 9 deletions internal/web/controllers/dashboard/index.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package dashboard

import (
"github.com/zeiss/fiber-htmx/components/cards"
"github.com/zeiss/typhoon/internal/web/components"

htmx "github.com/zeiss/fiber-htmx"
"github.com/zeiss/fiber-htmx/components/stats"
)

// IndexDashboardController ...
Expand All @@ -26,15 +26,15 @@ func (l *IndexDashboardController) Get() error {
},
components.Layout(
components.LayoutProps{
Path: l.Ctx().Path(),
Path: l.Path(),
},
components.Wrap(
components.WrapProps{},
stats.Stats(
stats.StatsProps{},
stats.Title(
stats.TitleProps{},
htmx.Text("Dashboard"),
cards.CardBordered(
cards.CardProps{},
cards.Body(
cards.BodyProps{},
cards.Title(
cards.TitleProps{},
htmx.Text("Welcome to Typhoon"),
),
),
),
Expand Down
36 changes: 31 additions & 5 deletions internal/web/controllers/operators/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ func (l *CreateControllerImpl) Post() error {
operator.AccountServerURL = l.body.AccountServerURL
}

// Create operator signing key group
oskg := models.SigningKeyGroup{Name: "Default", Description: "Default signing key group"}
// The operator public key
opk, err := nkeys.CreateOperator()
if err != nil {
return err
Expand All @@ -95,7 +94,32 @@ func (l *CreateControllerImpl) Post() error {
if err != nil {
return err
}
oskg.Key = models.NKey{ID: id, Seed: oseed}

// Add the private key.
operator.Key = models.NKey{ID: id, Seed: oseed}

// Create operator signing key group
oskg := models.SigningKeyGroup{Name: "Default", Description: "Default signing key group"}

sgpk, err := nkeys.CreateOperator()
if err != nil {
return err
}

sgkid, err := sgpk.PublicKey()
if err != nil {
return err
}

skgseed, err := sgpk.Seed()
if err != nil {
return err
}

oskg.Key = models.NKey{ID: sgkid, Seed: skgseed}
oskg.KeyID = sgkid

// Add the signing key group to the operator
operator.SigningKeyGroups = append(operator.SigningKeyGroups, oskg)

// Setup account
Expand Down Expand Up @@ -130,11 +154,13 @@ func (l *CreateControllerImpl) Post() error {
return err
}

skgseed, err := askgpk.Seed()
askgseed, err := askgpk.Seed()
if err != nil {
return err
}
askg.Key = models.NKey{ID: askgid, Seed: skgseed}

askg.Key = models.NKey{ID: askgid, Seed: askgseed}
askg.KeyID = askgid
account.SigningKeyGroups = append(account.SigningKeyGroups, askg)

// Create account claim
Expand Down

0 comments on commit aad2130

Please sign in to comment.