role

package
v0.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 5, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package role provides the cli subcommands for managing roles within a mediator control plane

Index

Constants

This section is empty.

Variables

View Source
var RoleCmd = &cobra.Command{
	Use:   "role",
	Short: "Manage roles within a mediator control plane",
	Long: `The medic role subcommands allows the management of roles within
a mediator controlplane.`,
	RunE: func(cmd *cobra.Command, args []string) error {
		return cmd.Usage()
	},
}

RoleCmd is the root command for the role subcommands

View Source
var Role_createCmd = &cobra.Command{
	Use:   "create",
	Short: "Create a role within a mediator control plane",
	Long: `The medic role create subcommand lets you create new roles for a project
within a mediator control plane.`,
	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)
		}
	},
	Run: func(cmd *cobra.Command, args []string) {
		org := viper.GetString("org-id")
		project := viper.GetString("project-id")
		name := util.GetConfigValue("name", "name", cmd, "")
		isAdmin := viper.GetBool("is_admin")
		isProtected := viper.GetBool("is_protected")

		conn, err := util.GrpcForCommand(cmd)
		util.ExitNicelyOnError(err, "Error getting grpc connection")
		defer conn.Close()

		util.ExitNicelyOnError(err, "Error getting grpc connection")

		client := pb.NewRoleServiceClient(conn)
		ctx, cancel := util.GetAppContext()
		defer cancel()

		adminPtr := &isAdmin
		protectedPtr := &isProtected

		if project == "" {

			resp, err := client.CreateRoleByOrganization(ctx, &pb.CreateRoleByOrganizationRequest{
				OrganizationId: org,
				Name:           name.(string),
				IsAdmin:        adminPtr,
				IsProtected:    protectedPtr,
			})
			util.ExitNicelyOnError(err, "Error creating role")
			out, err := util.GetJsonFromProto(resp)
			util.ExitNicelyOnError(err, "Error getting json from proto")
			fmt.Println(out)
		} else {

			resp, err := client.CreateRoleByProject(ctx, &pb.CreateRoleByProjectRequest{
				OrganizationId: org,
				ProjectId:      project,
				Name:           name.(string),
				IsAdmin:        adminPtr,
				IsProtected:    protectedPtr,
			})
			util.ExitNicelyOnError(err, "Error creating role")
			out, err := util.GetJsonFromProto(resp)
			util.ExitNicelyOnError(err, "Error getting json from proto")
			fmt.Println(out)
		}

	},
}

Role_createCmd represents the role create command

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL