-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #805 from openziti/organizations
Organizations (MVP) (#537
- Loading branch information
Showing
128 changed files
with
16,506 additions
and
555 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
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(newAdminCreateOrgMemberCommand().cmd) | ||
} | ||
|
||
type adminCreateOrgMemberCommand struct { | ||
cmd *cobra.Command | ||
admin bool | ||
} | ||
|
||
func newAdminCreateOrgMemberCommand() *adminCreateOrgMemberCommand { | ||
cmd := &cobra.Command{ | ||
Use: "org-member <organizationToken> <accountEmail>", | ||
Aliases: []string{"member"}, | ||
Short: "Add an account to an organization", | ||
Args: cobra.ExactArgs(2), | ||
} | ||
command := &adminCreateOrgMemberCommand{cmd: cmd} | ||
cmd.Flags().BoolVar(&command.admin, "admin", false, "Make the new account an admin of the organization") | ||
cmd.Run = command.run | ||
return command | ||
} | ||
|
||
func (cmd *adminCreateOrgMemberCommand) 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.NewAddOrganizationMemberParams() | ||
req.Body.Token = args[0] | ||
req.Body.Email = args[1] | ||
req.Body.Admin = cmd.admin | ||
|
||
_, err = zrok.Admin.AddOrganizationMember(req, mustGetAdminAuth()) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
logrus.Infof("added '%v' to organization '%v", args[0], args[1]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
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(newAdminDeleteOrgMemberCommand().cmd) | ||
} | ||
|
||
type adminDeleteOrgMemberCommand struct { | ||
cmd *cobra.Command | ||
} | ||
|
||
func newAdminDeleteOrgMemberCommand() *adminDeleteOrgMemberCommand { | ||
cmd := &cobra.Command{ | ||
Use: "org-member <organizationToken> <accountEmail>", | ||
Aliases: []string{"member"}, | ||
Short: "Remove an account from an organization", | ||
Args: cobra.ExactArgs(2), | ||
} | ||
command := &adminDeleteOrgMemberCommand{cmd: cmd} | ||
cmd.Run = command.run | ||
return command | ||
} | ||
|
||
func (cmd *adminDeleteOrgMemberCommand) 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.NewRemoveOrganizationMemberParams() | ||
req.Body.Token = args[0] | ||
req.Body.Email = args[1] | ||
|
||
_, err = zrok.Admin.RemoveOrganizationMember(req, mustGetAdminAuth()) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
logrus.Infof("removed '%v' from organization '%v", args[0], args[1]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"github.com/jedib0t/go-pretty/v6/table" | ||
"github.com/openziti/zrok/environment" | ||
"github.com/openziti/zrok/rest_client_zrok/admin" | ||
"github.com/spf13/cobra" | ||
"os" | ||
) | ||
|
||
func init() { | ||
adminListCmd.AddCommand(newAdminListOrgMembersCommand().cmd) | ||
} | ||
|
||
type adminListOrgMembersCommand struct { | ||
cmd *cobra.Command | ||
} | ||
|
||
func newAdminListOrgMembersCommand() *adminListOrgMembersCommand { | ||
cmd := &cobra.Command{ | ||
Use: "org-members <organizationToken>", | ||
Aliases: []string{"members"}, | ||
Short: "List the members of the specified organization", | ||
Args: cobra.ExactArgs(1), | ||
} | ||
command := &adminListOrgMembersCommand{cmd: cmd} | ||
cmd.Run = command.run | ||
return command | ||
} | ||
|
||
func (cmd *adminListOrgMembersCommand) 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.NewListOrganizationMembersParams() | ||
req.Body.Token = args[0] | ||
|
||
resp, err := zrok.Admin.ListOrganizationMembers(req, mustGetAdminAuth()) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
fmt.Println() | ||
t := table.NewWriter() | ||
t.SetOutputMirror(os.Stdout) | ||
t.SetStyle(table.StyleColoredDark) | ||
t.AppendHeader(table.Row{"Account Email", "Admin?"}) | ||
for _, member := range resp.Payload.Members { | ||
t.AppendRow(table.Row{member.Email, member.Admin}) | ||
} | ||
t.Render() | ||
fmt.Println() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"github.com/jedib0t/go-pretty/v6/table" | ||
"github.com/openziti/zrok/environment" | ||
"github.com/openziti/zrok/rest_client_zrok/admin" | ||
"github.com/spf13/cobra" | ||
"os" | ||
) | ||
|
||
func init() { | ||
adminListCmd.AddCommand(newAdminListOrganizationsCommand().cmd) | ||
} | ||
|
||
type adminListOrganizationsCommand struct { | ||
cmd *cobra.Command | ||
} | ||
|
||
func newAdminListOrganizationsCommand() *adminListOrganizationsCommand { | ||
cmd := &cobra.Command{ | ||
Use: "organizations", | ||
Aliases: []string{"orgs"}, | ||
Short: "List all organizations", | ||
Args: cobra.NoArgs, | ||
} | ||
command := &adminListOrganizationsCommand{cmd} | ||
cmd.Run = command.run | ||
return command | ||
} | ||
|
||
func (c *adminListOrganizationsCommand) run(_ *cobra.Command, _ []string) { | ||
env, err := environment.LoadRoot() | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
zrok, err := env.Client() | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
req := admin.NewListOrganizationsParams() | ||
resp, err := zrok.Admin.ListOrganizations(req, mustGetAdminAuth()) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
fmt.Println() | ||
t := table.NewWriter() | ||
t.SetOutputMirror(os.Stdout) | ||
t.SetStyle(table.StyleColoredDark) | ||
t.AppendHeader(table.Row{"Organization Token", "Description"}) | ||
for _, org := range resp.Payload.Organizations { | ||
t.AppendRow(table.Row{org.Token, org.Description}) | ||
} | ||
t.Render() | ||
fmt.Println() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.