mirror of
https://github.com/openziti/zrok.git
synced 2025-02-01 19:10:05 +01:00
add/delete org plumbed through to CLI (#537)
This commit is contained in:
parent
c98aaa8e00
commit
4473571b37
52
cmd/zrok/adminCreateOrganization.go
Normal file
52
cmd/zrok/adminCreateOrganization.go
Normal file
@ -0,0 +1,52 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/openziti/zrok/environment"
|
||||
"github.com/openziti/zrok/rest_client_zrok/admin"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func init() {
|
||||
adminCreateCmd.AddCommand(newAdminCreateOrganizationCommand().cmd)
|
||||
}
|
||||
|
||||
type adminCreateOrganizationCommand struct {
|
||||
cmd *cobra.Command
|
||||
description string
|
||||
}
|
||||
|
||||
func newAdminCreateOrganizationCommand() *adminCreateOrganizationCommand {
|
||||
cmd := &cobra.Command{
|
||||
Use: "organization",
|
||||
Aliases: []string{"org"},
|
||||
Short: "Create a new organization",
|
||||
Args: cobra.NoArgs,
|
||||
}
|
||||
command := &adminCreateOrganizationCommand{cmd: cmd}
|
||||
cmd.Flags().StringVarP(&command.description, "description", "d", "", "Organization description")
|
||||
cmd.Run = command.run
|
||||
return command
|
||||
}
|
||||
|
||||
func (cmd *adminCreateOrganizationCommand) run(_ *cobra.Command, _ []string) {
|
||||
env, err := environment.LoadRoot()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
zrok, err := env.Client()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
req := admin.NewCreateOrganizationParams()
|
||||
req.Body = admin.CreateOrganizationBody{Description: cmd.description}
|
||||
|
||||
resp, err := zrok.Admin.CreateOrganization(req, mustGetAdminAuth())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
logrus.Infof("created new organization with token '%v'", resp.Payload.Token)
|
||||
}
|
50
cmd/zrok/adminDeleteOrganization.go
Normal file
50
cmd/zrok/adminDeleteOrganization.go
Normal file
@ -0,0 +1,50 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/openziti/zrok/environment"
|
||||
"github.com/openziti/zrok/rest_client_zrok/admin"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func init() {
|
||||
adminDeleteCmd.AddCommand(newAdminDeleteOrganizationCommand().cmd)
|
||||
}
|
||||
|
||||
type adminDeleteOrganizationCommand struct {
|
||||
cmd *cobra.Command
|
||||
}
|
||||
|
||||
func newAdminDeleteOrganizationCommand() *adminDeleteOrganizationCommand {
|
||||
cmd := &cobra.Command{
|
||||
Use: "organization <organizationToken>",
|
||||
Aliases: []string{"org"},
|
||||
Short: "Delete an organization",
|
||||
Args: cobra.ExactArgs(1),
|
||||
}
|
||||
command := &adminDeleteOrganizationCommand{cmd: cmd}
|
||||
cmd.Run = command.run
|
||||
return command
|
||||
}
|
||||
|
||||
func (cmd *adminDeleteOrganizationCommand) run(_ *cobra.Command, args []string) {
|
||||
env, err := environment.LoadRoot()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
zrok, err := env.Client()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
req := admin.NewDeleteOrganizationParams()
|
||||
req.Body.Token = args[0]
|
||||
|
||||
_, err = zrok.Admin.DeleteOrganization(req, mustGetAdminAuth())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
logrus.Infof("deleted organization with token '%v'", args[0])
|
||||
}
|
@ -38,5 +38,10 @@ func (h *deleteOrganizationHandler) Handle(params admin.DeleteOrganizationParams
|
||||
return admin.NewDeleteOrganizationInternalServerError()
|
||||
}
|
||||
|
||||
if err := trx.Commit(); err != nil {
|
||||
logrus.Errorf("error committing transaction: %v", err)
|
||||
return admin.NewDeleteOrganizationInternalServerError()
|
||||
}
|
||||
|
||||
return admin.NewDeleteOrganizationOK()
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ func (str *Store) CreateOrganization(org *Organization, trx *sqlx.Tx) (int, erro
|
||||
|
||||
func (str *Store) FindOrganizationByToken(token string, trx *sqlx.Tx) (*Organization, error) {
|
||||
org := &Organization{}
|
||||
if err := trx.QueryRowx("select * from organizations where token = $1", token).StructScan(org); err != nil {
|
||||
if err := trx.QueryRowx("select * from organizations where token = $1 and not deleted", token).StructScan(org); err != nil {
|
||||
return nil, errors.Wrap(err, "error selecting frontend by token")
|
||||
}
|
||||
return org, nil
|
||||
|
Loading…
Reference in New Issue
Block a user