mirror of
https://github.com/openziti/ziti.git
synced 2026-10-13 15:51:21 +00:00
Merge pull request #1065 from openziti/fix.1064.allow.authpolicy.assignment
fixes #1064 support auth policy on identities for CLI
This commit is contained in:
@@ -43,6 +43,7 @@ type createIdentityOptions struct {
|
||||
servicePrecedences map[string]string
|
||||
appData map[string]string
|
||||
externalId string
|
||||
authPolicyNameOrId string
|
||||
}
|
||||
|
||||
// newCreateIdentityCmd creates the 'edge controller create identity' command
|
||||
@@ -93,6 +94,7 @@ func newCreateIdentityOfTypeCmd(idType string, options *createIdentityOptions) *
|
||||
cmd.Flags().StringToIntVar(&options.serviceCosts, "service-costs", map[string]int{}, "Per-service hosting costs")
|
||||
cmd.Flags().StringToStringVar(&options.servicePrecedences, "service-precedences", map[string]string{}, "Per-service hosting precedences")
|
||||
cmd.Flags().StringToStringVar(&options.appData, "app-data", nil, "Custom application data")
|
||||
cmd.Flags().StringVarP(&options.authPolicyNameOrId, "auth-policy", "P", "default", "The name or id of the auth policy to assign to the identity")
|
||||
|
||||
options.AddCommonFlags(cmd)
|
||||
|
||||
@@ -156,7 +158,21 @@ func runCreateIdentity(idType string, o *createIdentityOptions) error {
|
||||
delete(o.servicePrecedences, k)
|
||||
o.servicePrecedences[id] = prec
|
||||
}
|
||||
|
||||
api.SetJSONValue(entityData, o.servicePrecedences, "serviceHostingPrecedences")
|
||||
|
||||
authPolicyId, err := mapNameToID("auth-policies", o.authPolicyNameOrId, o.Options)
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not fetch auth policy by name or id: %w", err)
|
||||
}
|
||||
|
||||
if authPolicyId == "" {
|
||||
return fmt.Errorf("authentication policy id or name '%s' is not found", o.authPolicyNameOrId)
|
||||
}
|
||||
|
||||
api.SetJSONValue(entityData, authPolicyId, "authPolicyId")
|
||||
|
||||
o.SetTags(entityData)
|
||||
|
||||
result, err := CreateEntityOfType("identities", entityData.String(), &o.Options)
|
||||
|
||||
@@ -979,7 +979,7 @@ func outputIdentities(o *api.Options, children []*gabs.Container, pagingInfo *ap
|
||||
|
||||
t := table.NewWriter()
|
||||
t.SetStyle(table.StyleRounded)
|
||||
t.AppendHeader(table.Row{"ID", "Name", "Type", "Attributes"})
|
||||
t.AppendHeader(table.Row{"ID", "Name", "Type", "Attributes", "Auth-Policy"})
|
||||
|
||||
for _, entity := range children {
|
||||
wrapper := api.Wrap(entity)
|
||||
@@ -987,7 +987,8 @@ func outputIdentities(o *api.Options, children []*gabs.Container, pagingInfo *ap
|
||||
wrapper.String("id"),
|
||||
wrapper.String("name"),
|
||||
wrapper.String("type.name"),
|
||||
strings.Join(wrapper.StringSlice("roleAttributes"), ",")})
|
||||
strings.Join(wrapper.StringSlice("roleAttributes"), ","),
|
||||
wrapper.String("authPolicyId")})
|
||||
}
|
||||
api.RenderTable(o, t, pagingInfo)
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@ type updateIdentityOptions struct {
|
||||
servicePrecedences map[string]string
|
||||
appData map[string]string
|
||||
externalId string
|
||||
authPolicyIdOrName string
|
||||
}
|
||||
|
||||
func newUpdateIdentityCmd(out io.Writer, errOut io.Writer) *cobra.Command {
|
||||
@@ -74,6 +75,7 @@ func newUpdateIdentityCmd(out io.Writer, errOut io.Writer) *cobra.Command {
|
||||
cmd.Flags().StringToIntVar(&options.serviceCosts, "service-costs", map[string]int{}, "Per-service hosting costs")
|
||||
cmd.Flags().StringToStringVar(&options.servicePrecedences, "service-precedences", map[string]string{}, "Per-service hosting precedences")
|
||||
cmd.Flags().StringToStringVar(&options.appData, "app-data", nil, "Custom application data")
|
||||
cmd.Flags().StringVarP(&options.authPolicyIdOrName, "auth-policy", "P", "", "The auth policy id or name to assign to the identity")
|
||||
|
||||
return cmd
|
||||
}
|
||||
@@ -116,6 +118,19 @@ func runUpdateIdentity(o *updateIdentityOptions) error {
|
||||
change = true
|
||||
}
|
||||
|
||||
if o.Cmd.Flags().Changed("auth-policy") {
|
||||
authPolicyId, err := mapNameToID("auth-policies", o.authPolicyIdOrName, o.Options)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not fetch auth policy by name or id: %w", err)
|
||||
}
|
||||
|
||||
if authPolicyId == "" {
|
||||
return fmt.Errorf("authentication policy id or name '%s' is not found", o.authPolicyIdOrName)
|
||||
}
|
||||
api.SetJSONValue(entityData, authPolicyId, "authPolicyId")
|
||||
change = true
|
||||
}
|
||||
|
||||
if o.Cmd.Flags().Changed("service-costs") {
|
||||
for k, v := range o.serviceCosts {
|
||||
if v < 0 || v > math.MaxUint16 {
|
||||
|
||||
Reference in New Issue
Block a user