feat: all-access and operator token from CLI (#285)

* chore: include enum values in openapi generated code

* chore: add enum template to list of template overrides

* chore: update template and generated code

* feat: generate permissions list from openapi spec

* feat: all-access and operator token from CLI

Closes #22510

* fix: cloud fixed the resources endpoint

* fix: all access and operator permissions cannot be composed

* fix: review comments from dan-moran
This commit is contained in:
Sam Arnold
2021-10-05 14:33:02 -04:00
committed by GitHub
parent ade82cc4fe
commit 714a73d9eb
25 changed files with 1144 additions and 190 deletions

View File

@ -1,6 +1,8 @@
package main
import (
"fmt"
"github.com/influxdata/influx-cli/v2/clients/auth"
"github.com/influxdata/influx-cli/v2/pkg/cli/middleware"
"github.com/urfave/cli"
@ -21,9 +23,32 @@ func newAuthCommand() cli.Command {
}
}
func helpText(perm string) struct{ readHelp, writeHelp string } {
var helpOverrides = map[string]struct{ readHelp, writeHelp string }{
"user": {"perform read actions against organization users", "perform mutative actions against organization users"},
"buckets": {"perform read actions against organization buckets", "perform mutative actions against organization buckets"},
"telegrafs": {"read telegraf configs", "create telegraf configs"},
"orgs": {"read organizations", "create organizations"},
"dbrps": {"read database retention policy mappings", "create database retention policy mappings"},
}
help := helpOverrides[perm]
if help.readHelp == "" {
help.readHelp = fmt.Sprintf("read %s", perm)
}
if help.writeHelp == "" {
help.writeHelp = fmt.Sprintf("create or update %s", perm)
}
help.readHelp = "Grants the permission to " + help.readHelp
help.writeHelp = "Grants the permission to " + help.writeHelp
return help
}
func newCreateCommand() cli.Command {
var params auth.CreateParams
flags := append(commonFlags(), getOrgFlags(&params.OrgParams)...)
flags = append(flags,
&cli.StringFlag{
Name: "user, u",
@ -35,27 +60,6 @@ func newCreateCommand() cli.Command {
Usage: "Token description",
Destination: &params.Description,
},
&cli.BoolFlag{
Name: "write-user",
Usage: "Grants the permission to perform mutative actions against organization users",
Destination: &params.WriteUserPermission,
},
&cli.BoolFlag{
Name: "read-user",
Usage: "Grants the permission to perform read actions against organization users",
Destination: &params.ReadUserPermission,
},
&cli.BoolFlag{
Name: "write-buckets",
Usage: "Grants the permission to perform mutative actions against organization buckets",
Destination: &params.WriteBucketsPermission,
},
&cli.BoolFlag{
Name: "read-buckets",
Usage: "Grants the permission to perform read actions against organization buckets",
Destination: &params.ReadBucketsPermission,
},
&cli.StringSliceFlag{
Name: "write-bucket",
Usage: "The bucket id",
@ -65,86 +69,40 @@ func newCreateCommand() cli.Command {
Usage: "The bucket id",
},
&cli.BoolFlag{
Name: "write-tasks",
Usage: "Grants the permission to create tasks",
Destination: &params.WriteTasksPermission,
Name: "operator",
Usage: "Grants all permissions in all organizations",
Destination: &params.OperatorPermission,
},
&cli.BoolFlag{
Name: "read-tasks",
Usage: "Grants the permission to read tasks",
Destination: &params.ReadTasksPermission,
},
&cli.BoolFlag{
Name: "write-telegrafs",
Usage: "Grants the permission to create telegraf configs",
Destination: &params.WriteTelegrafsPermission,
},
&cli.BoolFlag{
Name: "read-telegrafs",
Usage: "Grants the permission to read telegraf configs",
Destination: &params.ReadTelegrafsPermission,
},
&cli.BoolFlag{
Name: "write-orgs",
Usage: "Grants the permission to create organizations",
Destination: &params.WriteOrganizationsPermission,
},
&cli.BoolFlag{
Name: "read-orgs",
Usage: "Grants the permission to read organizations",
Destination: &params.ReadOrganizationsPermission,
},
&cli.BoolFlag{
Name: "write-dashboards",
Usage: "Grants the permission to create dashboards",
Destination: &params.WriteDashboardsPermission,
},
&cli.BoolFlag{
Name: "read-dashboards",
Usage: "Grants the permission to read dashboards",
Destination: &params.ReadDashboardsPermission,
},
&cli.BoolFlag{
Name: "write-checks",
Usage: "Grants the permission to create checks",
Destination: &params.WriteCheckPermission,
},
&cli.BoolFlag{
Name: "read-checks",
Usage: "Grants the permission to read checks",
Destination: &params.ReadCheckPermission,
},
&cli.BoolFlag{
Name: "write-notificationRules",
Usage: "Grants the permission to create notificationRules",
Destination: &params.WriteNotificationRulePermission,
},
&cli.BoolFlag{
Name: "read-notificationRules",
Usage: "Grants the permission to read notificationRules",
Destination: &params.ReadNotificationRulePermission,
},
&cli.BoolFlag{
Name: "write-notificationEndpoints",
Usage: "Grants the permission to create notificationEndpoints",
Destination: &params.WriteNotificationEndpointPermission,
},
&cli.BoolFlag{
Name: "read-notificationEndpoints",
Usage: "Grants the permission to read notificationEndpoints",
Destination: &params.ReadNotificationEndpointPermission,
},
&cli.BoolFlag{
Name: "write-dbrps",
Usage: "Grants the permission to create database retention policy mappings",
Destination: &params.WriteDBRPPermission,
},
&cli.BoolFlag{
Name: "read-dbrps",
Usage: "Grants the permission to read database retention policy mappings",
Destination: &params.ReadDBRPPermission,
Name: "all-access",
Usage: "Grants all permissions in a single organization",
Destination: &params.AllAccess,
},
)
params.ResourcePermissions = auth.BuildResourcePermissions()
for _, perm := range params.ResourcePermissions {
help := helpText(perm.Name)
ossVsCloud := ""
if perm.IsCloud && !perm.IsOss {
ossVsCloud = " (Cloud only)"
}
if !perm.IsCloud && perm.IsOss {
ossVsCloud = " (OSS only)"
}
flags = append(flags,
&cli.BoolFlag{
Name: "read-" + perm.Name,
Usage: help.readHelp + ossVsCloud,
Destination: &perm.Read,
},
&cli.BoolFlag{
Name: "write-" + perm.Name,
Usage: help.writeHelp + ossVsCloud,
Destination: &perm.Write,
})
}
return cli.Command{
Name: "create",
Usage: "Create authorization",
@ -160,6 +118,7 @@ func newCreateCommand() cli.Command {
AuthorizationsApi: api.AuthorizationsApi,
UsersApi: api.UsersApi,
OrganizationsApi: api.OrganizationsApi,
ResourceListApi: api.ResourceListApi,
}
return client.Create(getContext(ctx), &params)
},