auth

package
v0.0.8 Latest Latest
Warning

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

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

Documentation

Overview

Package auth provides the auth command project for the medic CLI.

Index

Constants

This section is empty.

Variables

View Source
var AuthCmd = &cobra.Command{
	Use:   "auth",
	Short: "Authorize and manage accounts within a mediator control plane",
	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()
	},
}

AuthCmd represents the account command

View Source
var Auth_revokeproviderCmd = &cobra.Command{
	Use:   "revoke_provider",
	Short: "Revoke access tokens for provider",
	Long:  `It can revoke access tokens for specific provider.`,
	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) {

		all := util.GetConfigValue("all", "all", cmd, false).(bool)
		project := viper.GetString("project-id")
		provider := util.GetConfigValue("provider", "provider", cmd, "").(string)

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

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

		ctx, cancel := util.GetAppContext()
		defer cancel()
		client := pb.NewOAuthServiceClient(conn)
		if all {
			result, err := client.RevokeOauthTokens(ctx, &pb.RevokeOauthTokensRequest{})
			util.ExitNicelyOnError(err, "Error revoking tokens")
			cmd.Println("Revoked a total of ", result.RevokedTokens, " tokens")
		} else {
			_, err := client.RevokeOauthProjectToken(ctx, &pb.RevokeOauthProjectTokenRequest{Provider: provider, ProjectId: project})
			util.ExitNicelyOnError(err, "Error revoking tokens")
			if project == "" {
				cmd.Println("Revoked token for default project")
			} else {
				cmd.Println("Revoked token for project ", project)
			}
		}
	},
}

Auth_revokeproviderCmd represents the auth revoke 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