acl

package
v0.13.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AddCmd = &cobra.Command{
	Use:   "add",
	Short: "Add acl for client",
	Long: `Add acl for client with id. For example:
mim acl add <clientid> -file acls.json
or
mim acl add <clientid> -f acls.json
`,
	Run: func(cmd *cobra.Command, args []string) {
		format := utils.ResolveFormat(cmd)
		if format == "json" {
			pterm.DisableOutput()
		}

		server, token, err := login.ResolveCredentials()
		utils.HandleError(err)

		pterm.EnableDebugMessages()

		clientId := args[0]

		file, err := cmd.Flags().GetString("file")
		utils.HandleError(err)

		acls, err := utils.ReadInput(file)
		utils.HandleError(err)
		pterm.Success.Println("Read acl file")

		sm := api.NewSecurityManager(server, token)
		err = sm.AddClientAcl(clientId, acls)

		utils.HandleError(err)

		pterm.Success.Println("Set acl for client on server")

		pterm.Println()
	},
	TraverseChildren: true,
}

addCmd represents the add command

View Source
var GetCmd = &cobra.Command{
	Use:   "get",
	Short: "Get ACL for given client",
	Long: `Get the ACL with given name, For example:
mim acl get <name>
`,
	Run: func(cmd *cobra.Command, args []string) {
		format := utils.ResolveFormat(cmd)
		if format == "json" {
			pterm.DisableOutput()
		}
		server, token, err := login.ResolveCredentials()
		utils.HandleError(err)

		clientId, err := cmd.Flags().GetString("clientId")
		utils.HandleError(err)
		if len(args) > 0 && clientId == "" {
			clientId = args[0]
		}

		if clientId == "" {
			pterm.Warning.Println("You must provide a clientId")
			pterm.Println()
			os.Exit(1)
		}

		pterm.EnableDebugMessages()

		sm := api.NewSecurityManager(server, token)
		clients, err := sm.GetClientAcl(clientId)
		utils.HandleError(err)

		out, err := json.Marshal(clients)
		utils.HandleError(err)
		fmt.Println(string(out))
	},
	TraverseChildren: true,
	ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
		if len(args) != 0 {
			return nil, cobra.ShellCompDirectiveNoFileComp
		}
		return api.GetClientsCompletion(toComplete), cobra.ShellCompDirectiveNoFileComp
	},
}

deleteCmd represents the delete 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