Router allow traversal (#619)

* added cli flags to set/unset allow traversal

* Updated some help text

* Refactor allowTraversal to be flipped to noTraversal

* updated dependencies and changelog

* tidied modules

* updated flags to be simpler
This commit is contained in:
Cam Otts
2022-03-04 10:15:03 -06:00
committed by GitHub
parent 8d625043f2
commit 1da8d5af89
7 changed files with 33 additions and 7 deletions
+3
View File
@@ -1,6 +1,9 @@
# Release 0.24.13
* Bug fix: Fixed an issue with the ziti CLI quickstart routine which also affected router and controller config generation leaving many config fields blank or incorrect.
* Enhancement: Added new `noTraversal` field to routers. Configures if a router should allow/disallow traversal. Required on create/update commands.
* Enhancement: `ziti edge update edge-router` now supports either `--no-traversal` flag which will allow/disallow a given router from being used to traverse.
* Enhancement: `ziti fabric list routers` and `ziti edge list routers` will now display the noTraversal flag of associated routers.
# Release 0.24.12
@@ -38,6 +38,7 @@ type createEdgeRouterOptions struct {
tags map[string]string
appData map[string]string
cost uint16
noTraversal bool
}
func newCreateEdgeRouterCmd(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Command {
@@ -70,6 +71,7 @@ func newCreateEdgeRouterCmd(f cmdutil.Factory, out io.Writer, errOut io.Writer)
cmd.Flags().StringToStringVar(&options.tags, "tags", nil, "Custom management tags")
cmd.Flags().StringToStringVar(&options.appData, "app-Data", nil, "Custom application data")
cmd.Flags().Uint16Var(&options.cost, "cost", 0, "Specifies the router cost. Default 0.")
cmd.Flags().BoolVar(&options.noTraversal, "no-traversal", false, "Disallow traversal for this edge router. Default to allowed(false).")
options.AddCommonFlags(cmd)
@@ -85,6 +87,7 @@ func runCreateEdgeRouter(o *createEdgeRouterOptions) error {
api.SetJSONValue(entityData, o.tags, "tags")
api.SetJSONValue(entityData, o.appData, "appData")
api.SetJSONValue(entityData, o.cost, "cost")
api.SetJSONValue(entityData, o.noTraversal, "noTraversal")
result, err := CreateEntityOfType("edge-routers", entityData.String(), &o.Options)
if err := o.LogCreateResult("edge router", result, err); err != nil {
+2 -1
View File
@@ -424,7 +424,8 @@ func outputEdgeRouters(o *api.Options, children []*gabs.Container, pagingInfo *p
isOnline, _ := entity.Path("isOnline").Data().(bool)
cost, _ := entity.Path("cost").Data().(float64)
roleAttributes := entity.Path("roleAttributes").String()
if _, err := fmt.Fprintf(o.Out, "id: %v name: %v isOnline: %v cost: %v role attributes: %v\n", id, name, isOnline, cost, roleAttributes); err != nil {
noTraversal, _ := entity.Path("noTraversal").Data().(bool)
if _, err := fmt.Fprintf(o.Out, "id: %v name: %v isOnline: %v cost: %v noTraversal: %t role attributes: %v\n", id, name, isOnline, cost, noTraversal, roleAttributes); err != nil {
return err
}
}
@@ -40,6 +40,7 @@ type updateEdgeRouterOptions struct {
appData map[string]string
usePut bool
cost uint16
noTraversal bool
}
func newUpdateEdgeRouterCmd(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Command {
@@ -74,6 +75,7 @@ func newUpdateEdgeRouterCmd(f cmdutil.Factory, out io.Writer, errOut io.Writer)
cmd.Flags().StringToStringVar(&options.appData, "app-data", nil, "Custom application data")
cmd.Flags().BoolVar(&options.usePut, "use-put", false, "Use PUT to when making the request")
cmd.Flags().Uint16Var(&options.cost, "cost", 0, "Specifies the router cost. Default 0.")
cmd.Flags().BoolVar(&options.noTraversal, "no-traversal", false, "Disallow traversal for this edge router. Default to allowed(false).")
options.AddCommonFlags(cmd)
@@ -119,6 +121,11 @@ func runUpdateEdgeRouter(o *updateEdgeRouterOptions) error {
change = true
}
if o.Cmd.Flags().Changed("no-traversal") {
api.SetJSONValue(entityData, o.noTraversal, "noTraversal")
change = true
}
if !change {
return errors.New("no change specified. must specify at least one attribute to change")
}
+7 -4
View File
@@ -29,9 +29,10 @@ import (
type createRouterOptions struct {
api.Options
name string
cost uint16
tags map[string]string
name string
cost uint16
tags map[string]string
noTraversal bool
}
// newCreateRouterCmd creates the 'fabric create router' command for the given entity type
@@ -56,6 +57,8 @@ func newCreateRouterCmd(p common.OptionsProvider) *cobra.Command {
cmd.Flags().StringToStringVarP(&options.tags, "tags", "t", nil, "Add tags to router definition")
cmd.Flags().StringVar(&options.name, "name", "", "Specifies the router name. If not specified, the id in the controller cert will be used")
cmd.Flags().Uint16Var(&options.cost, "cost", 0, "Specifies the router cost. Default 0.")
cmd.Flags().BoolVar(&options.noTraversal, "no-traversal", false, "Disallow traversal for this edge router. Default to allowed(false).")
options.AddCommonFlags(cmd)
return cmd
@@ -80,7 +83,7 @@ func (o *createRouterOptions) createRouter(_ *cobra.Command, args []string) erro
api.SetJSONValue(entityData, fingerprint, "fingerprint")
api.SetJSONValue(entityData, o.tags, "tags")
api.SetJSONValue(entityData, o.cost, "cost")
api.SetJSONValue(entityData, o.noTraversal, "noTraversal")
result, err := createEntityOfType("routers", entityData.String(), &o.Options)
if err != nil {
return err
+3 -2
View File
@@ -291,7 +291,7 @@ func outputRouters(o *api.Options, children []*gabs.Container, pagingInfo *api.P
t := table.NewWriter()
t.SetStyle(table.StyleRounded)
t.AppendHeader(table.Row{"ID", "Name", "Online", "Cost", "Version"})
t.AppendHeader(table.Row{"ID", "Name", "Online", "Cost", "No Traversal", "Version"})
for _, entity := range children {
id := entity.Path("id").Data().(string)
@@ -299,6 +299,7 @@ func outputRouters(o *api.Options, children []*gabs.Container, pagingInfo *api.P
connected := entity.Path("connected").Data().(bool)
cost := entity.Path("cost").Data().(float64)
versionInfo := entity.Path("versionInfo")
noTraversal := entity.Path("noTraversal").Data().(bool)
var version string
if versionInfo != nil {
v := versionInfo.Path("version").Data().(string)
@@ -306,7 +307,7 @@ func outputRouters(o *api.Options, children []*gabs.Container, pagingInfo *api.P
arch := versionInfo.Path("arch").Data().(string)
version = fmt.Sprintf("%v on %v/%v", v, os, arch)
}
t.AppendRow(table.Row{id, name, connected, cost, version})
t.AppendRow(table.Row{id, name, connected, cost, noTraversal, version})
}
renderTable(o, t, pagingInfo)
@@ -34,6 +34,7 @@ type updateRouterOptions struct {
name string
fingerprint string
cost uint16
noTraversal bool
}
func newUpdateRouterCmd(p common.OptionsProvider) *cobra.Command {
@@ -59,6 +60,8 @@ func newUpdateRouterCmd(p common.OptionsProvider) *cobra.Command {
cmd.Flags().StringVarP(&options.name, "name", "n", "", "Set the router name")
cmd.Flags().StringVar(&options.fingerprint, "fingerprint", "", "Sets the router fingerprint")
cmd.Flags().Uint16Var(&options.cost, "cost", 0, "Specifies the router cost. Default 0.")
cmd.Flags().BoolVar(&options.noTraversal, "no-traversal", false, "Disallow traversal for this edge router. Default to allowed(false).")
options.AddCommonFlags(cmd)
return cmd
@@ -88,6 +91,11 @@ func runUpdateRouter(o *updateRouterOptions) error {
change = true
}
if o.Cmd.Flags().Changed("no-traversal") {
api.SetJSONValue(entityData, o.noTraversal, "noTraversal")
change = true
}
if !change {
return errors.New("no change specified. must specify at least one attribute to change")
}