Skip to content

Commit

Permalink
feat: add account server url
Browse files Browse the repository at this point in the history
  • Loading branch information
katallaxie committed Jul 4, 2024
1 parent 8d50019 commit 680c5f5
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 36 deletions.
2 changes: 2 additions & 0 deletions internal/api/models/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ type Operator struct {
SystemAccount Account `json:"system_account" gorm:"Constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
// SystemAccountID is the account that is used to manage the systems.
SystemAccountID uuid.UUID `json:"system_account_id" gorm:"type:uuid"`
// AccountServerURL is the URL of the account server.
AccountServerURL string `json:"account_server_url" form:"account_server_url" xml:"account_server_url" validate:"url"`
// Accounts is the accounts that are associated with the operator.
Accounts []Account `json:"accounts" gorm:"many2many:operator_accounts;foreignKey:ID;joinForeignKey:OperatorID;joinReferences:AccountID"`
// Systems is the systems that are associated with the operator.
Expand Down
14 changes: 10 additions & 4 deletions internal/web/controllers/operators/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ const (

var validate *validator.Validate

type createControllerBody struct {
Name string `json:"name" form:"name" validate:"required,min=3,max=100"`
Description string `json:"description" form:"description" validate:"required,min=3,max=1024"`
type CreateControllerBody struct {
Name string `json:"name" form:"name" validate:"required,min=3,max=100"`
Description string `json:"description" form:"description" validate:"required,min=3,max=1024"`
AccountServerURL string `json:"account_server_url" form:"account_server_url" validate:"url"`
}

// CreateControllerImpl ...
type CreateControllerImpl struct {
body createControllerBody
body CreateControllerBody
store ports.Datastore
htmx.DefaultController
}
Expand Down Expand Up @@ -74,6 +75,10 @@ func (l *CreateControllerImpl) Post() error {
return err
}

if l.body.AccountServerURL != "" {
operator.AccountServerURL = l.body.AccountServerURL
}

// Create operator signing key group
oskg := models.SigningKeyGroup{Name: "Default", Description: "Default signing key group"}
opk, err := nkeys.CreateOperator()
Expand Down Expand Up @@ -168,6 +173,7 @@ func (l *CreateControllerImpl) Post() error {
// Create operator claim
oc := jwt.NewOperatorClaims(id)
oc.Name = operator.Name
oc.AccountServerURL = operator.AccountServerURL

for _, sk := range operator.SigningKeyGroups {
oc.SigningKeys.Add(sk.Key.ID, sk.Key.ID, sk.Key.ID)
Expand Down
106 changes: 74 additions & 32 deletions internal/web/controllers/operators/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,45 +77,87 @@ func (l *NewOperatorControllerImpl) Get() error {
htmx.Text("The name must be from 3 to 100 characters. At least 3 characters must be non-whitespace."),
),
),
forms.FormControl(
forms.FormControlProps{
ClassNames: htmx.ClassNames{},
},
forms.FormControlLabel(
forms.FormControlLabelProps{},
forms.FormControlLabelText(
forms.FormControlLabelTextProps{
ClassNames: htmx.ClassNames{},
),
forms.FormControl(
forms.FormControlProps{
ClassNames: htmx.ClassNames{},
},
forms.FormControlLabel(
forms.FormControlLabelProps{},
forms.FormControlLabelText(
forms.FormControlLabelTextProps{
ClassNames: htmx.ClassNames{},
},
htmx.Text("Description"),
),
),
forms.FormControlLabel(
forms.FormControlLabelProps{},
forms.FormControlLabelText(
forms.FormControlLabelTextProps{
ClassNames: htmx.ClassNames{
"text-neutral-500": true,
},
htmx.Text("Description"),
),
},
htmx.Text("A brief description of the operator to provide context."),
),
forms.FormControlLabel(
forms.FormControlLabelProps{},
forms.FormControlLabelText(
forms.FormControlLabelTextProps{
ClassNames: htmx.ClassNames{
"text-neutral-500": true,
},
),
forms.TextareaBordered(
forms.TextareaProps{
Name: "description",
},
),
forms.FormControlLabel(
forms.FormControlLabelProps{},
forms.FormControlLabelText(
forms.FormControlLabelTextProps{
ClassNames: htmx.ClassNames{
"text-neutral-500": true,
},
htmx.Text("A brief description of the operator to provide context."),
),
},
htmx.Text("The description must be from 3 to 1024 characters."),
),
forms.TextareaBordered(
forms.TextareaProps{
Name: "description",
),
),
),
),
cards.CardBordered(
cards.CardProps{},
cards.Body(
cards.BodyProps{},
cards.Title(
cards.TitleProps{},
htmx.Text("Account Server"),
),
forms.FormControl(
forms.FormControlProps{
ClassNames: htmx.ClassNames{},
},
forms.FormControlLabel(
forms.FormControlLabelProps{},
forms.FormControlLabelText(
forms.FormControlLabelTextProps{
ClassNames: htmx.ClassNames{
"text-neutral-500": true,
},
},
htmx.Text("The URL to the Account Server to use for authentication."),
),
forms.FormControlLabel(
forms.FormControlLabelProps{},
forms.FormControlLabelText(
forms.FormControlLabelTextProps{
ClassNames: htmx.ClassNames{
"text-neutral-500": true,
},
),
forms.TextInputBordered(
forms.TextInputProps{
Name: "account_server_url",
},
),
forms.FormControlLabel(
forms.FormControlLabelProps{},
forms.FormControlLabelText(
forms.FormControlLabelTextProps{
ClassNames: htmx.ClassNames{
"text-neutral-500": true,
},
htmx.Text("The description must be from 3 to 1024 characters."),
),
},
htmx.Text("A valid URL with a scheme of http or https. Certificates need be valid."),
),
),
),
Expand Down

0 comments on commit 680c5f5

Please sign in to comment.