1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-06 16:06:56 +00:00
kyverno/cmd/cli/kubectl-kyverno/commands/create/user-info/command.go
Charles-Edouard Brétéché c51bc5beb8
docs: improve cli commands docs (#8259)
* chore: improve cli commands docs

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* docs

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* fix

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* fix

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* fix test

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* experimental

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* version

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* unit tests

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* oci

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* oci

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* jp

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* apply

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* create

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

---------

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
2023-09-05 05:14:28 +03:00

54 lines
1.7 KiB
Go

package userinfo
import (
"os"
"text/template"
"github.com/kyverno/kyverno/api/kyverno/v1beta1"
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/create/templates"
cobrautils "github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/cobra"
"github.com/spf13/cobra"
authenticationv1 "k8s.io/api/authentication/v1"
)
func Command() *cobra.Command {
var path string
var username string
var roles, clusterRoles, groups []string
cmd := &cobra.Command{
Use: "user-info",
Short: cobrautils.FormatDescription(true, websiteUrl, false, description...),
Long: cobrautils.FormatDescription(false, websiteUrl, false, description...),
Example: cobrautils.FormatExamples(examples...),
RunE: func(cmd *cobra.Command, args []string) error {
tmpl, err := template.New("userinfo").Parse(templates.UserInfoTemplate)
if err != nil {
return err
}
output := os.Stdout
if path != "" {
file, err := os.Create(path)
if err != nil {
return err
}
defer file.Close()
output = file
}
values := v1beta1.RequestInfo{
Roles: roles,
ClusterRoles: clusterRoles,
AdmissionUserInfo: authenticationv1.UserInfo{
Username: username,
Groups: groups,
},
}
return tmpl.Execute(output, values)
},
}
cmd.Flags().StringVarP(&path, "output", "o", "", "Output path (uses standard console output if not set)")
cmd.Flags().StringVarP(&username, "username", "u", "", "User name")
cmd.Flags().StringSliceVarP(&roles, "role", "r", nil, "Role")
cmd.Flags().StringSliceVarP(&clusterRoles, "cluster-role", "c", nil, "Cluster role")
cmd.Flags().StringSliceVarP(&groups, "group", "g", nil, "Group")
return cmd
}