Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup: Use projects instead of groups and orgs #1054

Merged
merged 1 commit into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cmd/cli/app/apply/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import (
"gopkg.in/yaml.v3"

"github.com/stacklok/mediator/cmd/cli/app"
"github.com/stacklok/mediator/cmd/cli/app/group"
"github.com/stacklok/mediator/cmd/cli/app/org"
"github.com/stacklok/mediator/cmd/cli/app/project"
"github.com/stacklok/mediator/cmd/cli/app/role"
"github.com/stacklok/mediator/internal/util"
)
Expand Down Expand Up @@ -110,8 +110,8 @@ var ApplyCmd = &cobra.Command{
org.Org_createCmd.Run(cmd, args)
} else if object.Object == "role" {
role.Role_createCmd.Run(cmd, args)
} else if object.Object == "group" {
group.Group_createCmd.Run(cmd, args)
} else if object.Object == "project" {
project.Project_createCmd.Run(cmd, args)
} else {
fmt.Fprintf(os.Stderr, "Error: unknown object type %s\n", object.Object)
os.Exit(1)
Expand Down
8 changes: 4 additions & 4 deletions cmd/cli/app/artifact/artifact_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var artifact_listCmd = &cobra.Command{
if provider != auth.Github {
return fmt.Errorf("only %s is supported at this time", auth.Github)
}
groupID := viper.GetInt32("group-id")
projectID := viper.GetString("project-id")

switch format {
case "json":
Expand All @@ -67,8 +67,8 @@ var artifact_listCmd = &cobra.Command{
artifacts, err := client.ListArtifacts(
ctx,
&pb.ListArtifactsRequest{
Provider: provider,
GroupId: groupID,
Provider: provider,
ProjectId: projectID,
},
)

Expand Down Expand Up @@ -113,7 +113,7 @@ func init() {
ArtifactCmd.AddCommand(artifact_listCmd)
artifact_listCmd.Flags().StringP("output", "f", "", "Output format (json or yaml)")
artifact_listCmd.Flags().StringP("provider", "n", "", "Name for the provider to enroll")
artifact_listCmd.Flags().Int32P("group-id", "g", 0, "ID of the group for repo registration")
artifact_listCmd.Flags().StringP("project-id", "g", "", "ID of the project for repo registration")

if err := artifact_listCmd.MarkFlagRequired("provider"); err != nil {
fmt.Fprintf(os.Stderr, "Error marking flag as required: %s\n", err)
Expand Down
4 changes: 2 additions & 2 deletions cmd/cli/app/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// It does make a good example of how to use the generated client code
// for others to use as a reference.

// Package auth provides the auth command group for the medic CLI.
// Package auth provides the auth command project for the medic CLI.
package auth

import (
Expand All @@ -32,7 +32,7 @@ import (
var AuthCmd = &cobra.Command{
Use: "auth",
Short: "Authorize and manage accounts within a mediator control plane",
Long: `The medic auth command group lets you create accounts and grant or revoke
Long: `The medic auth command project lets you create accounts and grant or revoke
authorization to existing accounts within a mediator control plane.`,
RunE: func(cmd *cobra.Command, args []string) error {
return cmd.Usage()
Expand Down
16 changes: 8 additions & 8 deletions cmd/cli/app/auth/auth_revoke_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ var Auth_revokeproviderCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
// check if we need to revoke all tokens or the user one
all := util.GetConfigValue("all", "all", cmd, false).(bool)
group := viper.GetInt32("group-id")
project := viper.GetString("project-id")
provider := util.GetConfigValue("provider", "provider", cmd, "").(string)

if all && group != 0 {
fmt.Fprintf(os.Stderr, "Error: you can't use --all and --group-id together\n")
if all && project != "" {
fmt.Fprintf(os.Stderr, "Error: you can't use --all and --project-id together\n")
os.Exit(1)
}

Expand All @@ -65,12 +65,12 @@ var Auth_revokeproviderCmd = &cobra.Command{
util.ExitNicelyOnError(err, "Error revoking tokens")
cmd.Println("Revoked a total of ", result.RevokedTokens, " tokens")
} else {
_, err := client.RevokeOauthGroupToken(ctx, &pb.RevokeOauthGroupTokenRequest{Provider: provider, GroupId: group})
_, err := client.RevokeOauthProjectToken(ctx, &pb.RevokeOauthProjectTokenRequest{Provider: provider, ProjectId: project})
util.ExitNicelyOnError(err, "Error revoking tokens")
if group == 0 {
cmd.Println("Revoked token for default group")
if project == "" {
cmd.Println("Revoked token for default project")
} else {
cmd.Println("Revoked token for group ", group)
cmd.Println("Revoked token for project ", project)
}
}
},
Expand All @@ -79,6 +79,6 @@ var Auth_revokeproviderCmd = &cobra.Command{
func init() {
AuthCmd.AddCommand(Auth_revokeproviderCmd)
Auth_revokeproviderCmd.Flags().StringP("provider", "n", "", "Name for the provider to revoke tokens for")
Auth_revokeproviderCmd.Flags().Int32P("group-id", "g", 0, "ID of the group for repo registration")
Auth_revokeproviderCmd.Flags().StringP("project-id", "g", "", "ID of the project for repo registration")
Auth_revokeproviderCmd.Flags().BoolP("all", "a", false, "Revoke all tokens")
}
8 changes: 4 additions & 4 deletions cmd/cli/app/keys/keys_generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ var genKeys_listCmd = &cobra.Command{
Use: "generate",
Short: "Generate keys within a mediator control plane",
Long: `The medic keys generate subcommand lets you create keys within a
mediator control plane for an specific group.`,
mediator control plane for an specific project.`,
PreRun: func(cmd *cobra.Command, args []string) {
if err := viper.BindPFlags(cmd.Flags()); err != nil {
fmt.Fprintf(os.Stderr, "Error binding flags: %s\n", err)
}
},
RunE: func(cmd *cobra.Command, args []string) error {

group_id := util.GetConfigValue("group-id", "group-id", cmd, int32(0))
project_id := viper.GetString("project-id")
out := util.GetConfigValue("output", "output", cmd, "").(string)
pass := util.GetConfigValue("passphrase", "passphrase", cmd, "").(string)
var passphrase []byte
Expand All @@ -72,7 +72,7 @@ mediator control plane for an specific group.`,

keyResp, err := client.CreateKeyPair(ctx, &pb.CreateKeyPairRequest{
Passphrase: base64.RawStdEncoding.EncodeToString(passphrase),
GroupId: group_id.(int32),
ProjectId: project_id,
})
if err != nil {
util.ExitNicelyOnError(err, "Error calling create keys")
Expand Down Expand Up @@ -103,7 +103,7 @@ mediator control plane for an specific group.`,

func init() {
KeysCmd.AddCommand(genKeys_listCmd)
genKeys_listCmd.Flags().Int32P("group-id", "g", 0, "group id to list roles for")
genKeys_listCmd.Flags().StringP("project-id", "g", "", "project id to list roles for")
genKeys_listCmd.Flags().StringP("output", "o", "", "Output public key to file")
genKeys_listCmd.Flags().StringP("passphrase", "p", "", "Passphrase to use for key generation")
}
6 changes: 3 additions & 3 deletions cmd/cli/app/org/org_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ mediator control plane.`,
},
Run: func(cmd *cobra.Command, args []string) {
// delete the org via GRPC
id := util.GetConfigValue("org-id", "org-id", cmd, int32(0)).(int32)
id := viper.GetString("org-id")
force := util.GetConfigValue("force", "force", cmd, false).(bool)

conn, err := util.GrpcForCommand(cmd)
Expand All @@ -69,9 +69,9 @@ mediator control plane.`,

func init() {
OrgCmd.AddCommand(org_deleteCmd)
org_deleteCmd.Flags().Int32P("org-id", "o", 0, "id of organization to delete")
org_deleteCmd.Flags().StringP("org-id", "o", "", "id of organization to delete")
org_deleteCmd.Flags().BoolP("force", "f", false,
"Force deletion of organization, even if it has associated groups")
"Force deletion of organization, even if it has associated projects")
err := org_deleteCmd.MarkFlagRequired("org-id")
util.ExitNicelyOnError(err, "Error marking flag as required")
}
8 changes: 4 additions & 4 deletions cmd/cli/app/org/org_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ mediator control plane.`,
ctx, cancel := util.GetAppContext()
defer cancel()

id := viper.GetInt32("id")
id := viper.GetString("id")
name := viper.GetString("name")
format := util.GetConfigValue("output", "output", cmd, "").(string)
if format == "" {
format = app.JSON
}

// check mutually exclusive flags
if id > 0 && name != "" {
if id != "" && name != "" {
fmt.Fprintf(os.Stderr, "Error: mutually exclusive flags: id and name\n")
os.Exit(1)
}
Expand All @@ -83,7 +83,7 @@ mediator control plane.`,
}

// get by id or name
if id > 0 {
if id != "" {
org, err := client.GetOrganization(ctx, &pb.GetOrganizationRequest{
OrganizationId: id,
})
Expand All @@ -105,7 +105,7 @@ mediator control plane.`,

func init() {
OrgCmd.AddCommand(org_getCmd)
org_getCmd.Flags().Int32P("id", "i", -1, "ID for the organization to query")
org_getCmd.Flags().StringP("id", "i", "", "ID for the organization to query")
org_getCmd.Flags().StringP("name", "n", "", "Name for the organization to query")
org_getCmd.Flags().StringP("output", "o", "", "Output format (json or yaml)")
}
2 changes: 1 addition & 1 deletion cmd/cli/app/org/org_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ mediator control plane.`,

for _, v := range resp.Organizations {
row := []string{
fmt.Sprintf("%d", v.Id),
v.Id,
v.Name,
v.Company,
v.GetCreatedAt().AsTime().Format(time.RFC3339),
Expand Down
2 changes: 1 addition & 1 deletion cmd/cli/app/policy/policy_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
var Policy_createCmd = &cobra.Command{
Use: "create",
Short: "Create a policy within a mediator control plane",
Long: `The medic policy create subcommand lets you create new policies for a group
Long: `The medic policy create subcommand lets you create new policies for a project
within a mediator control plane.`,
PreRun: func(cmd *cobra.Command, args []string) {
if err := viper.BindPFlags(cmd.Flags()); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions cmd/cli/app/policy/policy_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ mediator control plane.`,
policy, err := client.GetPolicyById(ctx, &pb.GetPolicyByIdRequest{
Context: &pb.Context{
Provider: provider,
// TODO set up group if specified
// TODO set up project if specified
// Currently it's inferred from the authorization token
},
Id: id,
Expand Down Expand Up @@ -87,7 +87,7 @@ func init() {
policy_getCmd.Flags().StringP("id", "i", "", "ID for the policy to query")
policy_getCmd.Flags().StringP("output", "o", app.Table, "Output format (json, yaml or table)")
policy_getCmd.Flags().StringP("provider", "p", "github", "Provider for the policy")
// TODO set up group if specified
// TODO set up project if specified

if err := policy_getCmd.MarkFlagRequired("id"); err != nil {
fmt.Fprintf(os.Stderr, "Error marking flag as required: %s\n", err)
Expand Down
8 changes: 4 additions & 4 deletions cmd/cli/app/policy/policy_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var policy_listCmd = &cobra.Command{
Use: "list",
Short: "List policies within a mediator control plane",
Long: `The medic policy list subcommand lets you list policies within a
mediator control plane for an specific group.`,
mediator control plane for an specific project.`,
PreRun: func(cmd *cobra.Command, args []string) {
if err := viper.BindPFlags(cmd.Flags()); err != nil {
fmt.Fprintf(os.Stderr, "Error binding flags: %s\n", err)
Expand Down Expand Up @@ -63,7 +63,7 @@ mediator control plane for an specific group.`,
resp, err := client.ListPolicies(ctx, &pb.ListPoliciesRequest{
Context: &pb.Context{
Provider: provider,
// TODO set up group if specified
// TODO set up project if specified
// Currently it's inferred from the authorization token
},
})
Expand Down Expand Up @@ -94,8 +94,8 @@ func init() {
PolicyCmd.AddCommand(policy_listCmd)
policy_listCmd.Flags().StringP("provider", "p", "", "Provider to list policies for")
policy_listCmd.Flags().StringP("output", "o", app.Table, "Output format (json, yaml or table)")
// TODO: Take group ID into account
// policy_listCmd.Flags().Int32P("group-id", "g", 0, "group id to list roles for")
// TODO: Take project ID into account
// policy_listCmd.Flags().Int32P("project-id", "g", 0, "project id to list roles for")

if err := policy_listCmd.MarkFlagRequired("provider"); err != nil {
fmt.Fprintf(os.Stderr, "Error marking flag as required: %s\n", err)
Expand Down
10 changes: 5 additions & 5 deletions cmd/cli/app/policy_status/policy_status_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var policystatus_getCmd = &cobra.Command{
Use: "get",
Short: "Get policy status within a mediator control plane",
Long: `The medic policy_status get subcommand lets you get policy status within a
mediator control plane for an specific provider/group or policy id, entity type and entity id.`,
mediator control plane for an specific provider/project or policy id, entity type and entity id.`,
PreRun: func(cmd *cobra.Command, args []string) {
if err := viper.BindPFlags(cmd.Flags()); err != nil {
fmt.Fprintf(os.Stderr, "Error binding flags: %s\n", err)
Expand All @@ -50,7 +50,7 @@ mediator control plane for an specific provider/group or policy id, entity type
defer cancel()

provider := viper.GetString("provider")
group := viper.GetString("group")
project := viper.GetString("project")
policyId := viper.GetString("policy")
entityId := viper.GetString("entity")
entityType := viper.GetString("entity-type")
Expand All @@ -77,8 +77,8 @@ mediator control plane for an specific provider/group or policy id, entity type
},
}

if group != "" {
req.Context.Group = &group
if project != "" {
req.Context.Project = &project
}

resp, err := client.GetPolicyStatusById(ctx, req)
Expand Down Expand Up @@ -106,7 +106,7 @@ mediator control plane for an specific provider/group or policy id, entity type
func init() {
PolicyStatusCmd.AddCommand(policystatus_getCmd)
policystatus_getCmd.Flags().StringP("provider", "p", "github", "Provider to get policy status for")
policystatus_getCmd.Flags().StringP("group", "g", "", "group id to get policy status for")
policystatus_getCmd.Flags().StringP("project", "g", "", "project id to get policy status for")
policystatus_getCmd.Flags().StringP("policy", "i", "", "policy id to get policy status for")
policystatus_getCmd.Flags().StringP("entity-type", "t", "",
fmt.Sprintf("the entity type to get policy status for (one of %s)", entities.KnownTypesCSV()))
Expand Down
10 changes: 5 additions & 5 deletions cmd/cli/app/policy_status/policy_status_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var policystatus_listCmd = &cobra.Command{
Use: "list",
Short: "List policy status within a mediator control plane",
Long: `The medic policy_status list subcommand lets you list policy status within a
mediator control plane for an specific provider/group or policy id.`,
mediator control plane for an specific provider/project or policy id.`,
PreRun: func(cmd *cobra.Command, args []string) {
if err := viper.BindPFlags(cmd.Flags()); err != nil {
fmt.Fprintf(os.Stderr, "Error binding flags: %s\n", err)
Expand All @@ -49,7 +49,7 @@ mediator control plane for an specific provider/group or policy id.`,
defer cancel()

provider := viper.GetString("provider")
group := viper.GetString("group")
project := viper.GetString("project")
policyId := viper.GetString("policy")
format := viper.GetString("output")
all := viper.GetBool("detailed")
Expand All @@ -74,8 +74,8 @@ mediator control plane for an specific provider/group or policy id.`,
Rule: rule,
}

if group != "" {
req.Context.Group = &group
if project != "" {
req.Context.Project = &project
}

resp, err := client.GetPolicyStatusById(ctx, req)
Expand Down Expand Up @@ -107,7 +107,7 @@ mediator control plane for an specific provider/group or policy id.`,
func init() {
PolicyStatusCmd.AddCommand(policystatus_listCmd)
policystatus_listCmd.Flags().StringP("provider", "p", "github", "Provider to list policy status for")
policystatus_listCmd.Flags().StringP("group", "g", "", "group id to list policy status for")
policystatus_listCmd.Flags().StringP("project", "g", "", "project id to list policy status for")
policystatus_listCmd.Flags().StringP("policy", "i", "", "policy id to list policy status for")
policystatus_listCmd.Flags().StringP("output", "o", app.Table, "Output format (json, yaml or table)")
policystatus_listCmd.Flags().BoolP("detailed", "d", false, "List all policy violations")
Expand Down
16 changes: 8 additions & 8 deletions cmd/cli/app/group/group.go → cmd/cli/app/project/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,26 @@
// It does make a good example of how to use the generated client code
// for others to use as a reference.

// Package group contains the group logic for the control plane
package group
// Package project contains the project logic for the control plane
package project

import (
"github.com/spf13/cobra"

"github.com/stacklok/mediator/cmd/cli/app"
)

// GroupCmd is the root command for the group subcommands
var GroupCmd = &cobra.Command{
Use: "group",
Short: "Manage groups within a mediator control plane",
Long: `The medic group commands allow the management of groups within a
// ProjectCmd is the root command for the project subcommands
var ProjectCmd = &cobra.Command{
Use: "project",
Short: "Manage projects within a mediator control plane",
Long: `The medic project commands allow the management of projects within a
mediator control plane.`,
RunE: func(cmd *cobra.Command, args []string) error {
return cmd.Usage()
},
}

func init() {
app.RootCmd.AddCommand(GroupCmd)
app.RootCmd.AddCommand(ProjectCmd)
}
Loading