mirror of
https://github.com/openziti/ziti.git
synced 2026-10-13 23:59:53 +00:00
Allow specifying entity tags with json. Fixes #916
This commit is contained in:
@@ -17,9 +17,11 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/Jeffail/gabs"
|
||||
gabs2 "github.com/Jeffail/gabs/v2"
|
||||
"github.com/pkg/errors"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -47,6 +49,20 @@ func GetJsonString(container *gabs.Container, path string) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func SetTags(container *gabs.Container, tags map[string]string, tagsJson string, path ...string) {
|
||||
result := map[string]interface{}{}
|
||||
if err := json.Unmarshal([]byte(tagsJson), &result); err != nil {
|
||||
panic(errors.Wrap(err, "invalid tags JSON"))
|
||||
}
|
||||
for k, v := range tags {
|
||||
result[k] = v
|
||||
}
|
||||
|
||||
if _, err := container.Set(result, path...); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func Wrap(c *gabs.Container) *GabsWrapper {
|
||||
return &GabsWrapper{Container: c}
|
||||
}
|
||||
|
||||
@@ -17,9 +17,11 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/Jeffail/gabs"
|
||||
"github.com/openziti/ziti/ziti/cmd/common"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
"io"
|
||||
)
|
||||
@@ -68,3 +70,52 @@ func (options *Options) LogCreateResult(entityType string, result *gabs.Containe
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type EntityOptions struct {
|
||||
Options
|
||||
Tags map[string]string
|
||||
TagsJson string
|
||||
}
|
||||
|
||||
func (self *EntityOptions) AddCommonFlags(cmd *cobra.Command) {
|
||||
self.Options.AddCommonFlags(cmd)
|
||||
if cmd.Flags().ShorthandLookup("t") == nil {
|
||||
cmd.Flags().StringToStringVarP(&self.Tags, "tags", "t", nil, "Add tags to entity definition")
|
||||
} else {
|
||||
cmd.Flags().StringToStringVar(&self.Tags, "tags", nil, "Add tags to entity definition")
|
||||
}
|
||||
cmd.Flags().StringVar(&self.TagsJson, "tags-json", "", "Add tags defined in JSON to entity definition")
|
||||
}
|
||||
|
||||
func (self *EntityOptions) GetTags() map[string]interface{} {
|
||||
result := map[string]interface{}{}
|
||||
if len(self.Tags) > 0 {
|
||||
if err := json.Unmarshal([]byte(self.TagsJson), &result); err != nil {
|
||||
panic(errors.Wrap(err, "invalid tags JSON"))
|
||||
}
|
||||
}
|
||||
for k, v := range self.Tags {
|
||||
result[k] = v
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func (self *EntityOptions) TagsProvided() bool {
|
||||
return self.Cmd.Flags().Changed("tags") || self.Cmd.Flags().Changed("tags-json")
|
||||
}
|
||||
|
||||
func (self *EntityOptions) SetTags(container *gabs.Container) {
|
||||
tags := self.GetTags()
|
||||
SetJSONValue(container, tags, "tags")
|
||||
}
|
||||
|
||||
func NewEntityOptions(out, errOut io.Writer) EntityOptions {
|
||||
return EntityOptions{
|
||||
Options: Options{
|
||||
CommonOptions: common.CommonOptions{
|
||||
Out: out,
|
||||
Err: errOut,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ import (
|
||||
"github.com/openziti/edge/rest_management_api_client/certificate_authority"
|
||||
"github.com/openziti/edge/rest_model"
|
||||
"github.com/openziti/ziti/ziti/cmd/api"
|
||||
"github.com/openziti/ziti/ziti/cmd/common"
|
||||
cmdhelper "github.com/openziti/ziti/ziti/cmd/helpers"
|
||||
"github.com/openziti/ziti/ziti/util"
|
||||
"github.com/spf13/cobra"
|
||||
@@ -30,21 +29,15 @@ import (
|
||||
)
|
||||
|
||||
type createCaOptions struct {
|
||||
api.Options
|
||||
api.EntityOptions
|
||||
Ca rest_model.CaCreate
|
||||
TagsFromFlags map[string]string
|
||||
IdentityRolesFromFlags []string
|
||||
}
|
||||
|
||||
// newCreateCaCmd creates the 'edge controller create ca local' command for the given entity type
|
||||
func newCreateCaCmd(out io.Writer, errOut io.Writer) *cobra.Command {
|
||||
options := &createCaOptions{
|
||||
Options: api.Options{
|
||||
CommonOptions: common.CommonOptions{
|
||||
Out: out,
|
||||
Err: errOut,
|
||||
},
|
||||
},
|
||||
EntityOptions: api.NewEntityOptions(out, errOut),
|
||||
Ca: rest_model.CaCreate{
|
||||
CertPem: S(""),
|
||||
ExternalIDClaim: &rest_model.ExternalIDClaim{
|
||||
@@ -65,7 +58,6 @@ func newCreateCaCmd(out io.Writer, errOut io.Writer) *cobra.Command {
|
||||
SubTags: map[string]interface{}{},
|
||||
},
|
||||
},
|
||||
TagsFromFlags: map[string]string{},
|
||||
}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
@@ -103,7 +95,6 @@ func newCreateCaCmd(out io.Writer, errOut io.Writer) *cobra.Command {
|
||||
|
||||
// allow interspersing positional args and flags
|
||||
cmd.Flags().SetInterspersed(true)
|
||||
cmd.Flags().StringToStringVarP(&options.TagsFromFlags, "tags", "t", nil, "Add tags to service definition")
|
||||
cmd.Flags().BoolVarP(options.Ca.IsAuthEnabled, "auth", "e", false, "Whether the CA can be used for authentication or not")
|
||||
cmd.Flags().BoolVarP(options.Ca.IsOttCaEnrollmentEnabled, "ottca", "o", false, "Whether the CA can be used for one-time-token CA enrollment")
|
||||
cmd.Flags().BoolVarP(options.Ca.IsAutoCaEnrollmentEnabled, "autoca", "u", false, "Whether the CA can be used for auto CA enrollment")
|
||||
@@ -149,7 +140,7 @@ func runCreateCa(options *createCaOptions) (err error) {
|
||||
params.Ca.IdentityRoles = append(params.Ca.IdentityRoles, attr)
|
||||
}
|
||||
|
||||
for k, v := range options.TagsFromFlags {
|
||||
for k, v := range options.GetTags() {
|
||||
params.Ca.Tags.SubTags[k] = v
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/openziti/ziti/ziti/cmd/api"
|
||||
"github.com/openziti/ziti/ziti/cmd/common"
|
||||
cmdhelper "github.com/openziti/ziti/ziti/cmd/helpers"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
@@ -32,16 +31,14 @@ import (
|
||||
)
|
||||
|
||||
type createConfigOptions struct {
|
||||
api.Options
|
||||
api.EntityOptions
|
||||
jsonFile string
|
||||
}
|
||||
|
||||
// newCreateConfigCmd creates the 'edge controller create service-policy' command
|
||||
func newCreateConfigCmd(out io.Writer, errOut io.Writer) *cobra.Command {
|
||||
options := &createConfigOptions{
|
||||
Options: api.Options{
|
||||
CommonOptions: common.CommonOptions{Out: out, Err: errOut},
|
||||
},
|
||||
EntityOptions: api.NewEntityOptions(out, errOut),
|
||||
}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
@@ -104,6 +101,7 @@ func runCreateConfig(o *createConfigOptions) error {
|
||||
api.SetJSONValue(entityData, o.Args[0], "name")
|
||||
api.SetJSONValue(entityData, configTypeId, "configTypeId")
|
||||
api.SetJSONValue(entityData, dataMap, "data")
|
||||
o.SetTags(entityData)
|
||||
result, err := CreateEntityOfType("configs", entityData.String(), &o.Options)
|
||||
return o.LogCreateResult("config", result, err)
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/openziti/ziti/ziti/cmd/api"
|
||||
"github.com/openziti/ziti/ziti/cmd/common"
|
||||
cmdhelper "github.com/openziti/ziti/ziti/cmd/helpers"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
@@ -32,16 +31,14 @@ import (
|
||||
)
|
||||
|
||||
type createConfigTypeOptions struct {
|
||||
api.Options
|
||||
api.EntityOptions
|
||||
schemaFile string
|
||||
}
|
||||
|
||||
// newCreateConfigTypeCmd creates the 'edge controller create service-policy' command
|
||||
func newCreateConfigTypeCmd(out io.Writer, errOut io.Writer) *cobra.Command {
|
||||
options := &createConfigTypeOptions{
|
||||
Options: api.Options{
|
||||
CommonOptions: common.CommonOptions{Out: out, Err: errOut},
|
||||
},
|
||||
EntityOptions: api.NewEntityOptions(out, errOut),
|
||||
}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
@@ -100,6 +97,7 @@ func runCreateConfigType(o *createConfigTypeOptions) error {
|
||||
if schemaMap != nil {
|
||||
api.SetJSONValue(entityData, schemaMap, "schema")
|
||||
}
|
||||
o.SetTags(entityData)
|
||||
|
||||
result, err := CreateEntityOfType("config-types", entityData.String(), &o.Options)
|
||||
return o.LogCreateResult("config type", result, err)
|
||||
|
||||
@@ -20,7 +20,6 @@ import (
|
||||
"fmt"
|
||||
"github.com/Jeffail/gabs"
|
||||
"github.com/openziti/ziti/ziti/cmd/api"
|
||||
"github.com/openziti/ziti/ziti/cmd/common"
|
||||
cmdhelper "github.com/openziti/ziti/ziti/cmd/helpers"
|
||||
"github.com/spf13/cobra"
|
||||
"io"
|
||||
@@ -28,11 +27,10 @@ import (
|
||||
)
|
||||
|
||||
type createEdgeRouterOptions struct {
|
||||
api.Options
|
||||
api.EntityOptions
|
||||
isTunnelerEnabled bool
|
||||
roleAttributes []string
|
||||
jwtOutputFile string
|
||||
tags map[string]string
|
||||
appData map[string]string
|
||||
cost uint16
|
||||
noTraversal bool
|
||||
@@ -40,9 +38,7 @@ type createEdgeRouterOptions struct {
|
||||
|
||||
func newCreateEdgeRouterCmd(out io.Writer, errOut io.Writer) *cobra.Command {
|
||||
options := &createEdgeRouterOptions{
|
||||
Options: api.Options{
|
||||
CommonOptions: common.CommonOptions{Out: out, Err: errOut},
|
||||
},
|
||||
EntityOptions: api.NewEntityOptions(out, errOut),
|
||||
}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
@@ -65,7 +61,6 @@ func newCreateEdgeRouterCmd(out io.Writer, errOut io.Writer) *cobra.Command {
|
||||
cmd.Flags().StringSliceVarP(&options.roleAttributes, "role-attributes", "a", nil, "Role attributes of the new edge router")
|
||||
cmd.Flags().BoolVarP(&options.isTunnelerEnabled, "tunneler-enabled", "t", false, "Can this edge router be used as a tunneler")
|
||||
cmd.Flags().StringVarP(&options.jwtOutputFile, "jwt-output-file", "o", "", "File to which to output the JWT used for enrolling the edge router")
|
||||
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).")
|
||||
@@ -81,10 +76,10 @@ func runCreateEdgeRouter(o *createEdgeRouterOptions) error {
|
||||
api.SetJSONValue(entityData, o.Args[0], "name")
|
||||
api.SetJSONValue(entityData, o.isTunnelerEnabled, "isTunnelerEnabled")
|
||||
api.SetJSONValue(entityData, o.roleAttributes, "roleAttributes")
|
||||
api.SetJSONValue(entityData, o.tags, "tags")
|
||||
api.SetJSONValue(entityData, o.appData, "appData")
|
||||
api.SetJSONValue(entityData, o.cost, "cost")
|
||||
api.SetJSONValue(entityData, o.noTraversal, "noTraversal")
|
||||
o.SetTags(entityData)
|
||||
|
||||
result, err := CreateEntityOfType("edge-routers", entityData.String(), &o.Options)
|
||||
if err := o.LogCreateResult("edge router", result, err); err != nil {
|
||||
|
||||
@@ -18,7 +18,6 @@ package edge
|
||||
|
||||
import (
|
||||
"github.com/openziti/ziti/ziti/cmd/api"
|
||||
"github.com/openziti/ziti/ziti/cmd/common"
|
||||
cmdhelper "github.com/openziti/ziti/ziti/cmd/helpers"
|
||||
"io"
|
||||
|
||||
@@ -27,7 +26,7 @@ import (
|
||||
)
|
||||
|
||||
type createEdgeRouterPolicyOptions struct {
|
||||
api.Options
|
||||
api.EntityOptions
|
||||
edgeRouterRoles []string
|
||||
identityRoles []string
|
||||
semantic string
|
||||
@@ -36,9 +35,7 @@ type createEdgeRouterPolicyOptions struct {
|
||||
// newCreateEdgeRouterPolicyCmd creates the 'edge controller create edge-router-policy' command
|
||||
func newCreateEdgeRouterPolicyCmd(out io.Writer, errOut io.Writer) *cobra.Command {
|
||||
options := &createEdgeRouterPolicyOptions{
|
||||
Options: api.Options{
|
||||
CommonOptions: common.CommonOptions{Out: out, Err: errOut},
|
||||
},
|
||||
EntityOptions: api.NewEntityOptions(out, errOut),
|
||||
}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
@@ -85,6 +82,7 @@ func runCreateEdgeRouterPolicy(o *createEdgeRouterPolicyOptions) error {
|
||||
if o.semantic != "" {
|
||||
api.SetJSONValue(entityData, o.semantic, "semantic")
|
||||
}
|
||||
o.SetTags(entityData)
|
||||
|
||||
result, err := CreateEntityOfType("edge-router-policies", entityData.String(), &o.Options)
|
||||
return o.LogCreateResult("edge router policy", result, err)
|
||||
|
||||
@@ -19,12 +19,11 @@ package edge
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/openziti/ziti/ziti/cmd/api"
|
||||
"github.com/openziti/ziti/ziti/cmd/common"
|
||||
cmdhelper "github.com/openziti/ziti/ziti/cmd/helpers"
|
||||
"github.com/pkg/errors"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"math"
|
||||
"os"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
@@ -33,7 +32,7 @@ import (
|
||||
)
|
||||
|
||||
type createIdentityOptions struct {
|
||||
api.Options
|
||||
api.EntityOptions
|
||||
isAdmin bool
|
||||
roleAttributes []string
|
||||
jwtOutputFile string
|
||||
@@ -42,7 +41,6 @@ type createIdentityOptions struct {
|
||||
defaultHostingCost uint16
|
||||
serviceCosts map[string]int
|
||||
servicePrecedences map[string]string
|
||||
tags map[string]string
|
||||
appData map[string]string
|
||||
externalId string
|
||||
}
|
||||
@@ -51,9 +49,7 @@ type createIdentityOptions struct {
|
||||
func newCreateIdentityCmd(out io.Writer, errOut io.Writer) *cobra.Command {
|
||||
newOptions := func() *createIdentityOptions {
|
||||
return &createIdentityOptions{
|
||||
Options: api.Options{
|
||||
CommonOptions: common.CommonOptions{Out: out, Err: errOut},
|
||||
},
|
||||
EntityOptions: api.NewEntityOptions(out, errOut),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,7 +92,6 @@ func newCreateIdentityOfTypeCmd(idType string, options *createIdentityOptions) *
|
||||
cmd.Flags().Uint16VarP(&options.defaultHostingCost, "default-hosting-cost", "c", 0, "Default cost to use when hosting services using this identity")
|
||||
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.tags, "tags", nil, "Custom management tags")
|
||||
cmd.Flags().StringToStringVar(&options.appData, "app-data", nil, "Custom application data")
|
||||
|
||||
options.AddCommonFlags(cmd)
|
||||
@@ -117,7 +112,6 @@ func runCreateIdentity(idType string, o *createIdentityOptions) error {
|
||||
}
|
||||
api.SetJSONValue(entityData, o.isAdmin, "isAdmin")
|
||||
api.SetJSONValue(entityData, o.roleAttributes, "roleAttributes")
|
||||
api.SetJSONValue(entityData, o.tags, "tags")
|
||||
api.SetJSONValue(entityData, o.appData, "appData")
|
||||
|
||||
if o.externalId != "" {
|
||||
@@ -163,6 +157,7 @@ func runCreateIdentity(idType string, o *createIdentityOptions) error {
|
||||
o.servicePrecedences[id] = prec
|
||||
}
|
||||
api.SetJSONValue(entityData, o.servicePrecedences, "serviceHostingPrecedences")
|
||||
o.SetTags(entityData)
|
||||
|
||||
result, err := CreateEntityOfType("identities", entityData.String(), &o.Options)
|
||||
if err := o.LogCreateResult("identity", result, err); err != nil {
|
||||
@@ -207,7 +202,7 @@ func getIdentityJwt(o *createIdentityOptions, id string, timeout int, verbose bo
|
||||
return fmt.Errorf("enrollment JWT not present for new identity")
|
||||
}
|
||||
|
||||
if err := ioutil.WriteFile(o.jwtOutputFile, []byte(jwt), 0600); err != nil {
|
||||
if err := os.WriteFile(o.jwtOutputFile, []byte(jwt), 0600); err != nil {
|
||||
fmt.Printf("Failed to write JWT to file(%v)\n", o.jwtOutputFile)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ import (
|
||||
"github.com/openziti/edge/rest_management_api_client/posture_checks"
|
||||
"github.com/openziti/edge/rest_model"
|
||||
"github.com/openziti/ziti/ziti/cmd/api"
|
||||
"github.com/openziti/ziti/ziti/cmd/common"
|
||||
cmdhelper "github.com/openziti/ziti/ziti/cmd/helpers"
|
||||
"github.com/openziti/ziti/ziti/util"
|
||||
"github.com/spf13/cobra"
|
||||
@@ -48,9 +47,8 @@ func newCreatePostureCheckCmd(out io.Writer, errOut io.Writer) *cobra.Command {
|
||||
}
|
||||
|
||||
type createPostureCheckOptions struct {
|
||||
api.Options
|
||||
api.EntityOptions
|
||||
name string
|
||||
tags map[string]string
|
||||
roleAttributes []string
|
||||
}
|
||||
|
||||
@@ -102,20 +100,13 @@ type createPostureCheckProcessMultiOptions struct {
|
||||
func (options *createPostureCheckOptions) addPostureFlags(cmd *cobra.Command) {
|
||||
// allow interspersing positional args and flags
|
||||
cmd.Flags().SetInterspersed(true)
|
||||
cmd.Flags().StringToStringVarP(&options.tags, "tags", "t", nil, "Add tags to service definition")
|
||||
cmd.Flags().StringSliceVarP(&options.roleAttributes, "role-attributes", "a", nil, "Role attributes of the new service")
|
||||
}
|
||||
|
||||
func newCreatePostureCheckMacCmd(out io.Writer, errOut io.Writer) *cobra.Command {
|
||||
options := &createPostureCheckMacOptions{
|
||||
createPostureCheckOptions: createPostureCheckOptions{
|
||||
Options: api.Options{
|
||||
CommonOptions: common.CommonOptions{
|
||||
Out: out,
|
||||
Err: errOut,
|
||||
},
|
||||
},
|
||||
tags: make(map[string]string),
|
||||
EntityOptions: api.NewEntityOptions(out, errOut),
|
||||
},
|
||||
addresses: nil,
|
||||
}
|
||||
@@ -148,13 +139,7 @@ func newCreatePostureCheckMacCmd(out io.Writer, errOut io.Writer) *cobra.Command
|
||||
func newCreatePostureCheckDomainCmd(out io.Writer, errOut io.Writer) *cobra.Command {
|
||||
options := &createPostureCheckDomainOptions{
|
||||
createPostureCheckOptions: createPostureCheckOptions{
|
||||
Options: api.Options{
|
||||
CommonOptions: common.CommonOptions{
|
||||
Out: out,
|
||||
Err: errOut,
|
||||
},
|
||||
},
|
||||
tags: make(map[string]string),
|
||||
EntityOptions: api.NewEntityOptions(out, errOut),
|
||||
},
|
||||
domains: nil,
|
||||
}
|
||||
@@ -187,13 +172,7 @@ func newCreatePostureCheckDomainCmd(out io.Writer, errOut io.Writer) *cobra.Comm
|
||||
func newCreatePostureCheckProcessCmd(out io.Writer, errOut io.Writer) *cobra.Command {
|
||||
options := &createPostureCheckProcessOptions{
|
||||
createPostureCheckOptions: createPostureCheckOptions{
|
||||
Options: api.Options{
|
||||
CommonOptions: common.CommonOptions{
|
||||
Out: out,
|
||||
Err: errOut,
|
||||
},
|
||||
},
|
||||
tags: make(map[string]string),
|
||||
EntityOptions: api.NewEntityOptions(out, errOut),
|
||||
},
|
||||
hashes: nil,
|
||||
signer: "",
|
||||
@@ -240,13 +219,7 @@ func newCreatePostureCheckProcessCmd(out io.Writer, errOut io.Writer) *cobra.Com
|
||||
func newCreatePostureCheckProcessMultiCmd(out io.Writer, errOut io.Writer) *cobra.Command {
|
||||
options := &createPostureCheckProcessMultiOptions{
|
||||
createPostureCheckOptions: createPostureCheckOptions{
|
||||
Options: api.Options{
|
||||
CommonOptions: common.CommonOptions{
|
||||
Out: out,
|
||||
Err: errOut,
|
||||
},
|
||||
},
|
||||
tags: make(map[string]string),
|
||||
EntityOptions: api.NewEntityOptions(out, errOut),
|
||||
},
|
||||
rawBinaryFileHashes: nil,
|
||||
rawBinarySigners: nil,
|
||||
@@ -517,8 +490,8 @@ func runCreatePostureCheckProcessMulti(options *createPostureCheckProcessMultiOp
|
||||
func setPostureCheckEntityValues(entity *gabs.Container, options *createPostureCheckOptions, typeId string) {
|
||||
api.SetJSONValue(entity, options.Args[0], "name")
|
||||
api.SetJSONValue(entity, options.roleAttributes, "roleAttributes")
|
||||
api.SetJSONValue(entity, options.tags, "tags")
|
||||
api.SetJSONValue(entity, typeId, "typeId")
|
||||
options.SetTags(entity)
|
||||
}
|
||||
|
||||
func cleanMacAddresses(inAddresses []string) ([]string, error) {
|
||||
@@ -622,16 +595,9 @@ func runCreatePostureCheckDomain(o *createPostureCheckDomainOptions) (err error)
|
||||
}
|
||||
|
||||
func newCreatePostureCheckOsCmd(out io.Writer, errOut io.Writer) *cobra.Command {
|
||||
|
||||
options := &createPostureCheckOsOptions{
|
||||
createPostureCheckOptions: createPostureCheckOptions{
|
||||
Options: api.Options{
|
||||
CommonOptions: common.CommonOptions{
|
||||
Out: out,
|
||||
Err: errOut,
|
||||
},
|
||||
},
|
||||
tags: make(map[string]string),
|
||||
EntityOptions: api.NewEntityOptions(out, errOut),
|
||||
},
|
||||
os: nil,
|
||||
}
|
||||
@@ -729,13 +695,7 @@ func parseOsSpec(osSpecStr string) (*osSpec, error) {
|
||||
func newCreatePostureCheckMfaCmd(out io.Writer, errOut io.Writer) *cobra.Command {
|
||||
options := createPostureCheckMfaOptions{
|
||||
createPostureCheckOptions: createPostureCheckOptions{
|
||||
Options: api.Options{
|
||||
CommonOptions: common.CommonOptions{
|
||||
Out: out,
|
||||
Err: errOut,
|
||||
},
|
||||
},
|
||||
tags: make(map[string]string),
|
||||
EntityOptions: api.NewEntityOptions(out, errOut),
|
||||
},
|
||||
timeoutSeconds: 0,
|
||||
promptOnWake: false,
|
||||
|
||||
@@ -19,16 +19,14 @@ package edge
|
||||
import (
|
||||
"github.com/Jeffail/gabs"
|
||||
"github.com/openziti/ziti/ziti/cmd/api"
|
||||
"github.com/openziti/ziti/ziti/cmd/common"
|
||||
cmdhelper "github.com/openziti/ziti/ziti/cmd/helpers"
|
||||
"github.com/spf13/cobra"
|
||||
"io"
|
||||
)
|
||||
|
||||
type createServiceOptions struct {
|
||||
api.Options
|
||||
api.EntityOptions
|
||||
terminatorStrategy string
|
||||
tags map[string]string
|
||||
roleAttributes []string
|
||||
configs []string
|
||||
requireEncryption bool
|
||||
@@ -38,13 +36,7 @@ type createServiceOptions struct {
|
||||
// newCreateServiceCmd creates the 'edge controller create service local' command for the given entity type
|
||||
func newCreateServiceCmd(out io.Writer, errOut io.Writer) *cobra.Command {
|
||||
options := &createServiceOptions{
|
||||
Options: api.Options{
|
||||
CommonOptions: common.CommonOptions{
|
||||
Out: out,
|
||||
Err: errOut,
|
||||
},
|
||||
},
|
||||
tags: make(map[string]string),
|
||||
EntityOptions: api.NewEntityOptions(out, errOut),
|
||||
}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
@@ -63,7 +55,6 @@ func newCreateServiceCmd(out io.Writer, errOut io.Writer) *cobra.Command {
|
||||
|
||||
// allow interspersing positional args and flags
|
||||
cmd.Flags().SetInterspersed(true)
|
||||
cmd.Flags().StringToStringVarP(&options.tags, "tags", "t", nil, "Add tags to service definition")
|
||||
cmd.Flags().StringSliceVarP(&options.roleAttributes, "role-attributes", "a", nil, "Role attributes of the new service")
|
||||
cmd.Flags().StringSliceVarP(&options.configs, "configs", "c", nil, "Configuration id or names to be associated with the new service")
|
||||
cmd.Flags().StringVar(&options.terminatorStrategy, "terminator-strategy", "", "Specifies the terminator strategy for the service")
|
||||
@@ -88,10 +79,9 @@ func runCreateService(o *createServiceOptions) (err error) {
|
||||
}
|
||||
|
||||
api.SetJSONValue(entityData, o.encryption.Get(), "encryptionRequired")
|
||||
|
||||
api.SetJSONValue(entityData, o.roleAttributes, "roleAttributes")
|
||||
api.SetJSONValue(entityData, configs, "configs")
|
||||
api.SetJSONValue(entityData, o.tags, "tags")
|
||||
o.SetTags(entityData)
|
||||
|
||||
result, err := CreateEntityOfType("services", entityData.String(), &o.Options)
|
||||
return o.LogCreateResult("service", result, err)
|
||||
|
||||
@@ -18,7 +18,6 @@ package edge
|
||||
|
||||
import (
|
||||
"github.com/openziti/ziti/ziti/cmd/api"
|
||||
"github.com/openziti/ziti/ziti/cmd/common"
|
||||
cmdhelper "github.com/openziti/ziti/ziti/cmd/helpers"
|
||||
"io"
|
||||
|
||||
@@ -27,7 +26,7 @@ import (
|
||||
)
|
||||
|
||||
type createServiceEdgeRouterPolicyOptions struct {
|
||||
api.Options
|
||||
api.EntityOptions
|
||||
edgeRouterRoles []string
|
||||
serviceRoles []string
|
||||
semantic string
|
||||
@@ -36,9 +35,7 @@ type createServiceEdgeRouterPolicyOptions struct {
|
||||
// newCreateServiceEdgeRouterPolicyCmd creates the 'edge controller create service-edge-router-policy' command
|
||||
func newCreateServiceEdgeRouterPolicyCmd(out io.Writer, errOut io.Writer) *cobra.Command {
|
||||
options := &createServiceEdgeRouterPolicyOptions{
|
||||
Options: api.Options{
|
||||
CommonOptions: common.CommonOptions{Out: out, Err: errOut},
|
||||
},
|
||||
EntityOptions: api.NewEntityOptions(out, errOut),
|
||||
}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
@@ -84,6 +81,7 @@ func runCreateServiceEdgeRouterPolicy(o *createServiceEdgeRouterPolicyOptions) e
|
||||
if o.semantic != "" {
|
||||
api.SetJSONValue(entityData, o.semantic, "semantic")
|
||||
}
|
||||
o.SetTags(entityData)
|
||||
|
||||
result, err := CreateEntityOfType("service-edge-router-policies", entityData.String(), &o.Options)
|
||||
return o.LogCreateResult("service edge router policy", result, err)
|
||||
|
||||
@@ -18,7 +18,6 @@ package edge
|
||||
|
||||
import (
|
||||
"github.com/openziti/ziti/ziti/cmd/api"
|
||||
"github.com/openziti/ziti/ziti/cmd/common"
|
||||
cmdhelper "github.com/openziti/ziti/ziti/cmd/helpers"
|
||||
"io"
|
||||
"strings"
|
||||
@@ -30,7 +29,7 @@ import (
|
||||
)
|
||||
|
||||
type createServicePolicyOptions struct {
|
||||
api.Options
|
||||
api.EntityOptions
|
||||
serviceRoles []string
|
||||
identityRoles []string
|
||||
postureCheckRoles []string
|
||||
@@ -40,9 +39,7 @@ type createServicePolicyOptions struct {
|
||||
// newCreateServicePolicyCmd creates the 'edge controller create service-policy' command
|
||||
func newCreateServicePolicyCmd(out io.Writer, errOut io.Writer) *cobra.Command {
|
||||
options := &createServicePolicyOptions{
|
||||
Options: api.Options{
|
||||
CommonOptions: common.CommonOptions{Out: out, Err: errOut},
|
||||
},
|
||||
EntityOptions: api.NewEntityOptions(out, errOut),
|
||||
}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
@@ -99,10 +96,11 @@ func runCreateServicePolicy(o *createServicePolicyOptions) error {
|
||||
api.SetJSONValue(entityData, serviceRoles, "serviceRoles")
|
||||
api.SetJSONValue(entityData, identityRoles, "identityRoles")
|
||||
api.SetJSONValue(entityData, postureCheckRoles, "postureCheckRoles")
|
||||
|
||||
if o.semantic != "" {
|
||||
api.SetJSONValue(entityData, o.semantic, "semantic")
|
||||
}
|
||||
o.SetTags(entityData)
|
||||
|
||||
result, err := CreateEntityOfType("service-policies", entityData.String(), &o.Options)
|
||||
return o.LogCreateResult("service policy", result, err)
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ import (
|
||||
"github.com/openziti/edge/router/xgress_edge_transport"
|
||||
"github.com/openziti/foundation/v2/stringz"
|
||||
"github.com/openziti/ziti/ziti/cmd/api"
|
||||
"github.com/openziti/ziti/ziti/cmd/common"
|
||||
cmdhelper "github.com/openziti/ziti/ziti/cmd/helpers"
|
||||
"github.com/spf13/cobra"
|
||||
"io"
|
||||
@@ -30,7 +29,7 @@ import (
|
||||
)
|
||||
|
||||
type createTerminatorOptions struct {
|
||||
api.Options
|
||||
api.EntityOptions
|
||||
binding string
|
||||
cost int32
|
||||
precedence string
|
||||
@@ -40,12 +39,7 @@ type createTerminatorOptions struct {
|
||||
// newCreateTerminatorCmd creates the 'edge controller create Terminator local' command for the given entity type
|
||||
func newCreateTerminatorCmd(out io.Writer, errOut io.Writer) *cobra.Command {
|
||||
options := &createTerminatorOptions{
|
||||
Options: api.Options{
|
||||
CommonOptions: common.CommonOptions{
|
||||
Out: out,
|
||||
Err: errOut,
|
||||
},
|
||||
},
|
||||
EntityOptions: api.NewEntityOptions(out, errOut),
|
||||
}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
@@ -110,6 +104,7 @@ func runCreateTerminator(o *createTerminatorOptions) (err error) {
|
||||
}
|
||||
api.SetJSONValue(entityData, o.precedence, "precedence")
|
||||
}
|
||||
o.SetTags(entityData)
|
||||
|
||||
result, err := CreateEntityOfType("terminators", entityData.String(), &o.Options)
|
||||
if err != nil {
|
||||
|
||||
@@ -19,7 +19,6 @@ package edge
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/openziti/ziti/ziti/cmd/api"
|
||||
"github.com/openziti/ziti/ziti/cmd/common"
|
||||
cmdhelper "github.com/openziti/ziti/ziti/cmd/helpers"
|
||||
"io"
|
||||
"os"
|
||||
@@ -29,19 +28,15 @@ import (
|
||||
)
|
||||
|
||||
type createTransitRouterOptions struct {
|
||||
api.Options
|
||||
api.EntityOptions
|
||||
jwtOutputFile string
|
||||
tags map[string]string
|
||||
cost uint16
|
||||
noTraversal bool
|
||||
}
|
||||
|
||||
func newCreateTransitRouterCmd(out io.Writer, errOut io.Writer) *cobra.Command {
|
||||
options := &createTransitRouterOptions{
|
||||
Options: api.Options{
|
||||
CommonOptions: common.CommonOptions{Out: out, Err: errOut},
|
||||
},
|
||||
}
|
||||
EntityOptions: api.NewEntityOptions(out, errOut)}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "transit-router <name>",
|
||||
@@ -60,7 +55,6 @@ func newCreateTransitRouterCmd(out io.Writer, errOut io.Writer) *cobra.Command {
|
||||
// allow interspersing positional args and flags
|
||||
cmd.Flags().SetInterspersed(true)
|
||||
cmd.Flags().StringVarP(&options.jwtOutputFile, "jwt-output-file", "o", "", "File to which to output the JWT used for enrolling the edge router")
|
||||
cmd.Flags().StringToStringVar(&options.tags, "tags", nil, "Custom management tags")
|
||||
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).")
|
||||
|
||||
@@ -73,9 +67,9 @@ func newCreateTransitRouterCmd(out io.Writer, errOut io.Writer) *cobra.Command {
|
||||
func runCreateTransitRouter(o *createTransitRouterOptions) error {
|
||||
entityData := gabs.New()
|
||||
api.SetJSONValue(entityData, o.Args[0], "name")
|
||||
api.SetJSONValue(entityData, o.tags, "tags")
|
||||
api.SetJSONValue(entityData, o.cost, "cost")
|
||||
api.SetJSONValue(entityData, o.noTraversal, "noTraversal")
|
||||
o.SetTags(entityData)
|
||||
|
||||
result, err := CreateEntityOfType("transit-routers", entityData.String(), &o.Options)
|
||||
if err := o.LogCreateResult("transit router", result, err); err != nil {
|
||||
|
||||
@@ -21,18 +21,17 @@ import (
|
||||
"github.com/openziti/edge/rest_management_api_client/certificate_authority"
|
||||
"github.com/openziti/edge/rest_model"
|
||||
"github.com/openziti/ziti/ziti/cmd/api"
|
||||
"github.com/openziti/ziti/ziti/cmd/common"
|
||||
"github.com/openziti/ziti/ziti/cmd/helpers"
|
||||
"github.com/openziti/ziti/ziti/util"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
"gopkg.in/resty.v1"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
)
|
||||
|
||||
type updateCaOptions struct {
|
||||
api.Options
|
||||
api.EntityOptions
|
||||
verify bool
|
||||
verifyCertPath string
|
||||
verifyCertBytes []byte
|
||||
@@ -43,7 +42,6 @@ type updateCaOptions struct {
|
||||
authEnabled bool
|
||||
identityAttributes []string
|
||||
identityNameFormat string
|
||||
tags map[string]string
|
||||
|
||||
externalIDClaim rest_model.ExternalIDClaimPatch
|
||||
}
|
||||
@@ -51,11 +49,8 @@ type updateCaOptions struct {
|
||||
// newUpdateAuthenticatorCmd creates the 'edge controller update authenticator' command
|
||||
func newUpdateCaCmd(out io.Writer, errOut io.Writer) *cobra.Command {
|
||||
options := updateCaOptions{
|
||||
Options: api.Options{
|
||||
CommonOptions: common.CommonOptions{Out: out, Err: errOut},
|
||||
OutputJSONResponse: false,
|
||||
},
|
||||
verify: false,
|
||||
EntityOptions: api.NewEntityOptions(out, errOut),
|
||||
verify: false,
|
||||
externalIDClaim: rest_model.ExternalIDClaimPatch{
|
||||
Index: I64(0),
|
||||
Location: S(""),
|
||||
@@ -86,7 +81,7 @@ func newUpdateCaCmd(out io.Writer, errOut io.Writer) *cobra.Command {
|
||||
}
|
||||
|
||||
var err error
|
||||
options.verifyCertBytes, err = ioutil.ReadFile(options.verifyCertPath)
|
||||
options.verifyCertBytes, err = os.ReadFile(options.verifyCertPath)
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not read --cert file: %s", err)
|
||||
@@ -124,7 +119,6 @@ func newUpdateCaCmd(out io.Writer, errOut io.Writer) *cobra.Command {
|
||||
cmd.Flags().StringVarP(options.externalIDClaim.MatcherCriteria, "matcher-criteria", "x", "", "criteria used with the given matcher")
|
||||
cmd.Flags().StringVarP(options.externalIDClaim.Parser, "parser", "p", "", "the parser to use on found external ids")
|
||||
cmd.Flags().StringVarP(options.externalIDClaim.ParserCriteria, "parser-criteria", "z", "", "criteria used with the given parser")
|
||||
cmd.Flags().StringToStringVar(&options.tags, "tags", nil, "Custom management tags")
|
||||
|
||||
options.AddCommonFlags(cmd)
|
||||
return cmd
|
||||
@@ -211,11 +205,11 @@ func runUpdateCa(options updateCaOptions) error {
|
||||
changed = true
|
||||
}
|
||||
|
||||
if options.Cmd.Flags().Changed("tags") {
|
||||
if options.TagsProvided() {
|
||||
ca.Tags = &rest_model.Tags{
|
||||
SubTags: rest_model.SubTags{},
|
||||
}
|
||||
for k, v := range options.tags {
|
||||
for k, v := range options.GetTags() {
|
||||
ca.Tags.SubTags[k] = v
|
||||
}
|
||||
changed = true
|
||||
|
||||
@@ -20,7 +20,6 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/openziti/ziti/ziti/cmd/api"
|
||||
"github.com/openziti/ziti/ziti/cmd/common"
|
||||
cmdhelper "github.com/openziti/ziti/ziti/cmd/helpers"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
@@ -32,19 +31,16 @@ import (
|
||||
)
|
||||
|
||||
type updateConfigOptions struct {
|
||||
api.Options
|
||||
api.EntityOptions
|
||||
name string
|
||||
data string
|
||||
jsonFile string
|
||||
tags map[string]string
|
||||
}
|
||||
|
||||
// newUpdateConfigCmd updates the 'edge controller update service-policy' command
|
||||
func newUpdateConfigCmd(out io.Writer, errOut io.Writer) *cobra.Command {
|
||||
options := &updateConfigOptions{
|
||||
Options: api.Options{
|
||||
CommonOptions: common.CommonOptions{Out: out, Err: errOut},
|
||||
},
|
||||
EntityOptions: api.NewEntityOptions(out, errOut),
|
||||
}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
@@ -66,7 +62,6 @@ func newUpdateConfigCmd(out io.Writer, errOut io.Writer) *cobra.Command {
|
||||
cmd.Flags().StringVarP(&options.name, "name", "n", "", "Set the name of the config")
|
||||
cmd.Flags().StringVarP(&options.data, "data", "d", "", "Set the data of the config")
|
||||
cmd.Flags().StringVarP(&options.jsonFile, "json-file", "f", "", "Read config JSON from a file instead of the command line")
|
||||
cmd.Flags().StringToStringVar(&options.tags, "tags", nil, "Custom management tags")
|
||||
|
||||
options.AddCommonFlags(cmd)
|
||||
|
||||
@@ -103,8 +98,8 @@ func runUpdateConfig(o *updateConfigOptions) error {
|
||||
}
|
||||
}
|
||||
|
||||
if o.Cmd.Flags().Changed("tags") {
|
||||
api.SetJSONValue(entityData, o.tags, "tags")
|
||||
if o.TagsProvided() {
|
||||
o.SetTags(entityData)
|
||||
change = true
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/openziti/ziti/ziti/cmd/api"
|
||||
"github.com/openziti/ziti/ziti/cmd/common"
|
||||
cmdhelper "github.com/openziti/ziti/ziti/cmd/helpers"
|
||||
"io"
|
||||
"os"
|
||||
@@ -32,18 +31,15 @@ import (
|
||||
)
|
||||
|
||||
type updateConfigTypeAction struct {
|
||||
api.Options
|
||||
api.EntityOptions
|
||||
name string
|
||||
data string
|
||||
jsonFile string
|
||||
tags map[string]string
|
||||
}
|
||||
|
||||
func newUpdateConfigTypeCmd(out io.Writer, errOut io.Writer) *cobra.Command {
|
||||
action := &updateConfigTypeAction{
|
||||
Options: api.Options{
|
||||
CommonOptions: common.CommonOptions{Out: out, Err: errOut},
|
||||
},
|
||||
EntityOptions: api.NewEntityOptions(out, errOut),
|
||||
}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
@@ -64,7 +60,6 @@ func newUpdateConfigTypeCmd(out io.Writer, errOut io.Writer) *cobra.Command {
|
||||
cmd.Flags().StringVarP(&action.name, "name", "n", "", "Set the name of the config")
|
||||
cmd.Flags().StringVarP(&action.data, "data", "d", "", "Set the data of the config")
|
||||
cmd.Flags().StringVarP(&action.jsonFile, "json-file", "f", "", "Read config JSON from a file instead of the command line")
|
||||
cmd.Flags().StringToStringVar(&action.tags, "tags", nil, "Custom management tags")
|
||||
|
||||
action.AddCommonFlags(cmd)
|
||||
|
||||
@@ -101,8 +96,8 @@ func (self *updateConfigTypeAction) run() error {
|
||||
}
|
||||
}
|
||||
|
||||
if self.Cmd.Flags().Changed("tags") {
|
||||
api.SetJSONValue(entityData, self.tags, "tags")
|
||||
if self.TagsProvided() {
|
||||
self.SetTags(entityData)
|
||||
change = true
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ package edge
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/openziti/ziti/ziti/cmd/api"
|
||||
"github.com/openziti/ziti/ziti/cmd/common"
|
||||
cmdhelper "github.com/openziti/ziti/ziti/cmd/helpers"
|
||||
"io"
|
||||
|
||||
@@ -30,11 +29,10 @@ import (
|
||||
)
|
||||
|
||||
type updateEdgeRouterOptions struct {
|
||||
api.Options
|
||||
api.EntityOptions
|
||||
name string
|
||||
isTunnelerEnabled bool
|
||||
roleAttributes []string
|
||||
tags map[string]string
|
||||
appData map[string]string
|
||||
usePut bool
|
||||
cost uint16
|
||||
@@ -43,9 +41,7 @@ type updateEdgeRouterOptions struct {
|
||||
|
||||
func newUpdateEdgeRouterCmd(out io.Writer, errOut io.Writer) *cobra.Command {
|
||||
options := &updateEdgeRouterOptions{
|
||||
Options: api.Options{
|
||||
CommonOptions: common.CommonOptions{Out: out, Err: errOut},
|
||||
},
|
||||
EntityOptions: api.NewEntityOptions(out, errOut),
|
||||
}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
@@ -69,7 +65,6 @@ func newUpdateEdgeRouterCmd(out io.Writer, errOut io.Writer) *cobra.Command {
|
||||
cmd.Flags().BoolVarP(&options.isTunnelerEnabled, "tunneler-enabled", "t", false, "Can this edge router be used as a tunneler")
|
||||
cmd.Flags().StringSliceVarP(&options.roleAttributes, "role-attributes", "a", nil,
|
||||
"Set role attributes of the edge router. Use --role-attributes '' to set an empty list")
|
||||
cmd.Flags().StringToStringVar(&options.tags, "tags", nil, "Custom management tags")
|
||||
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.")
|
||||
@@ -104,8 +99,8 @@ func runUpdateEdgeRouter(o *updateEdgeRouterOptions) error {
|
||||
change = true
|
||||
}
|
||||
|
||||
if o.Cmd.Flags().Changed("tags") {
|
||||
api.SetJSONValue(entityData, o.tags, "tags")
|
||||
if o.TagsProvided() {
|
||||
o.SetTags(entityData)
|
||||
change = true
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ package edge
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/openziti/ziti/ziti/cmd/api"
|
||||
"github.com/openziti/ziti/ziti/cmd/common"
|
||||
cmdhelper "github.com/openziti/ziti/ziti/cmd/helpers"
|
||||
"io"
|
||||
|
||||
@@ -30,18 +29,15 @@ import (
|
||||
)
|
||||
|
||||
type updateEdgeRouterPolicyOptions struct {
|
||||
api.Options
|
||||
api.EntityOptions
|
||||
name string
|
||||
edgeRouterRoles []string
|
||||
identityRoles []string
|
||||
tags map[string]string
|
||||
}
|
||||
|
||||
func newUpdateEdgeRouterPolicyCmd(out io.Writer, errOut io.Writer) *cobra.Command {
|
||||
options := &updateEdgeRouterPolicyOptions{
|
||||
Options: api.Options{
|
||||
CommonOptions: common.CommonOptions{Out: out, Err: errOut},
|
||||
},
|
||||
EntityOptions: api.NewEntityOptions(out, errOut),
|
||||
}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
@@ -64,7 +60,6 @@ func newUpdateEdgeRouterPolicyCmd(out io.Writer, errOut io.Writer) *cobra.Comman
|
||||
cmd.Flags().StringVarP(&options.name, "name", "n", "", "Set the name of the edge router policy")
|
||||
cmd.Flags().StringSliceVar(&options.edgeRouterRoles, "edge-router-roles", nil, "Edge router roles of the edge router policy")
|
||||
cmd.Flags().StringSliceVar(&options.identityRoles, "identity-roles", nil, "Identity roles of the edge router policy")
|
||||
cmd.Flags().StringToStringVar(&options.tags, "tags", nil, "Custom management tags")
|
||||
|
||||
options.AddCommonFlags(cmd)
|
||||
|
||||
@@ -105,8 +100,8 @@ func runUpdateEdgeRouterPolicy(o *updateEdgeRouterPolicyOptions) error {
|
||||
change = true
|
||||
}
|
||||
|
||||
if o.Cmd.Flags().Changed("tags") {
|
||||
api.SetJSONValue(entityData, o.tags, "tags")
|
||||
if o.TagsProvided() {
|
||||
o.SetTags(entityData)
|
||||
change = true
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@ import (
|
||||
"fmt"
|
||||
"github.com/openziti/sdk-golang/ziti"
|
||||
"github.com/openziti/ziti/ziti/cmd/api"
|
||||
"github.com/openziti/ziti/ziti/cmd/common"
|
||||
cmdhelper "github.com/openziti/ziti/ziti/cmd/helpers"
|
||||
"io"
|
||||
"math"
|
||||
@@ -33,23 +32,20 @@ import (
|
||||
)
|
||||
|
||||
type updateIdentityOptions struct {
|
||||
api.Options
|
||||
api.EntityOptions
|
||||
name string
|
||||
roleAttributes []string
|
||||
defaultHostingPrecedence string
|
||||
defaultHostingCost uint16
|
||||
serviceCosts map[string]int
|
||||
servicePrecedences map[string]string
|
||||
tags map[string]string
|
||||
appData map[string]string
|
||||
externalId string
|
||||
}
|
||||
|
||||
func newUpdateIdentityCmd(out io.Writer, errOut io.Writer) *cobra.Command {
|
||||
options := &updateIdentityOptions{
|
||||
Options: api.Options{
|
||||
CommonOptions: common.CommonOptions{Out: out, Err: errOut},
|
||||
},
|
||||
EntityOptions: api.NewEntityOptions(out, errOut),
|
||||
}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
@@ -77,7 +73,6 @@ func newUpdateIdentityCmd(out io.Writer, errOut io.Writer) *cobra.Command {
|
||||
cmd.Flags().Uint16VarP(&options.defaultHostingCost, "default-hosting-cost", "c", 0, "Default cost to use when hosting services using this identity")
|
||||
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.tags, "tags", nil, "Custom management tags")
|
||||
cmd.Flags().StringToStringVar(&options.appData, "app-data", nil, "Custom application data")
|
||||
|
||||
return cmd
|
||||
@@ -156,8 +151,8 @@ func runUpdateIdentity(o *updateIdentityOptions) error {
|
||||
change = true
|
||||
}
|
||||
|
||||
if o.Cmd.Flags().Changed("tags") {
|
||||
api.SetJSONValue(entityData, o.tags, "tags")
|
||||
if o.TagsProvided() {
|
||||
o.SetTags(entityData)
|
||||
change = true
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ package edge
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/openziti/ziti/ziti/cmd/api"
|
||||
"github.com/openziti/ziti/ziti/cmd/common"
|
||||
cmdhelper "github.com/openziti/ziti/ziti/cmd/helpers"
|
||||
"io"
|
||||
|
||||
@@ -45,9 +44,8 @@ func newUpdatePostureCheckCmd(out io.Writer, errOut io.Writer) *cobra.Command {
|
||||
}
|
||||
|
||||
type updatePostureCheckOptions struct {
|
||||
api.Options
|
||||
api.EntityOptions
|
||||
name string
|
||||
tags map[string]string
|
||||
roleAttributes []string
|
||||
}
|
||||
|
||||
@@ -85,9 +83,7 @@ type updatePostureCheckOsOptions struct {
|
||||
func newUpdatePostureCheckMacCmd(out io.Writer, errOut io.Writer) *cobra.Command {
|
||||
options := &updatePostureCheckMacOptions{
|
||||
updatePostureCheckOptions: updatePostureCheckOptions{
|
||||
Options: api.Options{
|
||||
CommonOptions: common.CommonOptions{Out: out, Err: errOut},
|
||||
},
|
||||
EntityOptions: api.NewEntityOptions(out, errOut),
|
||||
},
|
||||
addresses: nil,
|
||||
}
|
||||
@@ -113,7 +109,6 @@ func newUpdatePostureCheckMacCmd(out io.Writer, errOut io.Writer) *cobra.Command
|
||||
"Set role attributes of the posture check. Use --role-attributes '' to set an empty list")
|
||||
cmd.Flags().StringSliceVarP(&options.addresses, "mac-addresses", "m", nil,
|
||||
"Set MAC addresses of the posture check")
|
||||
cmd.Flags().StringToStringVar(&options.tags, "tags", nil, "Custom management tags")
|
||||
|
||||
return cmd
|
||||
}
|
||||
@@ -142,8 +137,8 @@ func runUpdatePostureCheckMac(o *updatePostureCheckMacOptions) error {
|
||||
change = true
|
||||
}
|
||||
|
||||
if o.Cmd.Flags().Changed("tags") {
|
||||
api.SetJSONValue(entityData, o.tags, "tags")
|
||||
if o.TagsProvided() {
|
||||
o.SetTags(entityData)
|
||||
change = true
|
||||
}
|
||||
|
||||
@@ -160,9 +155,7 @@ func runUpdatePostureCheckMac(o *updatePostureCheckMacOptions) error {
|
||||
func newUpdatePostureCheckDomainCmd(out io.Writer, errOut io.Writer) *cobra.Command {
|
||||
options := &updatePostureCheckDomainOptions{
|
||||
updatePostureCheckOptions: updatePostureCheckOptions{
|
||||
Options: api.Options{
|
||||
CommonOptions: common.CommonOptions{Out: out, Err: errOut},
|
||||
},
|
||||
EntityOptions: api.NewEntityOptions(out, errOut),
|
||||
},
|
||||
domains: nil,
|
||||
}
|
||||
@@ -194,9 +187,7 @@ func newUpdatePostureCheckDomainCmd(out io.Writer, errOut io.Writer) *cobra.Comm
|
||||
func newUpdatePostureCheckMfaCmd(out io.Writer, errOut io.Writer) *cobra.Command {
|
||||
options := &updatePostureCheckMfaOptions{
|
||||
updatePostureCheckOptions: updatePostureCheckOptions{
|
||||
Options: api.Options{
|
||||
CommonOptions: common.CommonOptions{Out: out, Err: errOut},
|
||||
},
|
||||
EntityOptions: api.NewEntityOptions(out, errOut),
|
||||
},
|
||||
timeoutSeconds: -1,
|
||||
promptOnWake: false,
|
||||
@@ -289,6 +280,11 @@ func runUpdatePostureCheckMfa(o *updatePostureCheckMfaOptions) error {
|
||||
change = true
|
||||
}
|
||||
|
||||
if o.TagsProvided() {
|
||||
o.SetTags(entityData)
|
||||
change = true
|
||||
}
|
||||
|
||||
if !change {
|
||||
return errors.New("no change specified. must specify at least one attribute to change")
|
||||
}
|
||||
@@ -327,6 +323,11 @@ func runUpdatePostureCheckDomain(o *updatePostureCheckDomainOptions) error {
|
||||
change = true
|
||||
}
|
||||
|
||||
if o.TagsProvided() {
|
||||
o.SetTags(entityData)
|
||||
change = true
|
||||
}
|
||||
|
||||
if !change {
|
||||
return errors.New("no change specified. must specify at least one attribute to change")
|
||||
}
|
||||
@@ -342,9 +343,7 @@ func runUpdatePostureCheckDomain(o *updatePostureCheckDomainOptions) error {
|
||||
func newUpdatePostureCheckProcessCmd(out io.Writer, errOut io.Writer) *cobra.Command {
|
||||
options := &updatePostureCheckProcessOptions{
|
||||
updatePostureCheckOptions: updatePostureCheckOptions{
|
||||
Options: api.Options{
|
||||
CommonOptions: common.CommonOptions{Out: out, Err: errOut},
|
||||
},
|
||||
EntityOptions: api.NewEntityOptions(out, errOut),
|
||||
},
|
||||
hashes: nil,
|
||||
signer: "",
|
||||
@@ -435,6 +434,11 @@ func runUpdatePostureCheckProcess(o *updatePostureCheckProcessOptions) error {
|
||||
change = true
|
||||
}
|
||||
|
||||
if o.TagsProvided() {
|
||||
o.SetTags(entityData)
|
||||
change = true
|
||||
}
|
||||
|
||||
if !change {
|
||||
return errors.New("no change specified. must specify at least one attribute to change")
|
||||
}
|
||||
@@ -449,9 +453,7 @@ func runUpdatePostureCheckProcess(o *updatePostureCheckProcessOptions) error {
|
||||
func newUpdatePostureCheckOsCmd(out io.Writer, errOut io.Writer) *cobra.Command {
|
||||
options := &updatePostureCheckOsOptions{
|
||||
updatePostureCheckOptions: updatePostureCheckOptions{
|
||||
Options: api.Options{
|
||||
CommonOptions: common.CommonOptions{Out: out, Err: errOut},
|
||||
},
|
||||
EntityOptions: api.NewEntityOptions(out, errOut),
|
||||
},
|
||||
os: nil,
|
||||
}
|
||||
@@ -512,6 +514,11 @@ func runUpdatePostureCheckOs(o *updatePostureCheckOsOptions) error {
|
||||
change = true
|
||||
}
|
||||
|
||||
if o.TagsProvided() {
|
||||
o.SetTags(entityData)
|
||||
change = true
|
||||
}
|
||||
|
||||
if !change {
|
||||
return errors.New("no change specified. must specify at least one attribute to change")
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ package edge
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/openziti/ziti/ziti/cmd/api"
|
||||
"github.com/openziti/ziti/ziti/cmd/common"
|
||||
cmdhelper "github.com/openziti/ziti/ziti/cmd/helpers"
|
||||
"io"
|
||||
|
||||
@@ -30,20 +29,17 @@ import (
|
||||
)
|
||||
|
||||
type updateServiceOptions struct {
|
||||
api.Options
|
||||
api.EntityOptions
|
||||
name string
|
||||
terminatorStrategy string
|
||||
roleAttributes []string
|
||||
encryption encryptionVar
|
||||
configs []string
|
||||
tags map[string]string
|
||||
}
|
||||
|
||||
func newUpdateServiceCmd(out io.Writer, errOut io.Writer) *cobra.Command {
|
||||
options := &updateServiceOptions{
|
||||
Options: api.Options{
|
||||
CommonOptions: common.CommonOptions{Out: out, Err: errOut},
|
||||
},
|
||||
EntityOptions: api.NewEntityOptions(out, errOut),
|
||||
}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
@@ -69,7 +65,6 @@ func newUpdateServiceCmd(out io.Writer, errOut io.Writer) *cobra.Command {
|
||||
options.encryption.Set("ON")
|
||||
cmd.Flags().VarP(&options.encryption, "encryption", "e", "Controls end-to-end encryption for the service")
|
||||
cmd.Flags().StringSliceVarP(&options.configs, "configs", "c", nil, "Configuration id or names to be associated with the new service")
|
||||
cmd.Flags().StringToStringVar(&options.tags, "tags", nil, "Custom management tags")
|
||||
|
||||
options.AddCommonFlags(cmd)
|
||||
|
||||
@@ -114,8 +109,8 @@ func runUpdateService(o *updateServiceOptions) error {
|
||||
change = true
|
||||
}
|
||||
|
||||
if o.Cmd.Flags().Changed("tags") {
|
||||
api.SetJSONValue(entityData, o.tags, "tags")
|
||||
if o.TagsProvided() {
|
||||
o.SetTags(entityData)
|
||||
change = true
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ package edge
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/openziti/ziti/ziti/cmd/api"
|
||||
"github.com/openziti/ziti/ziti/cmd/common"
|
||||
cmdhelper "github.com/openziti/ziti/ziti/cmd/helpers"
|
||||
"io"
|
||||
|
||||
@@ -30,18 +29,15 @@ import (
|
||||
)
|
||||
|
||||
type updateServiceEdgeRouterPolicyOptions struct {
|
||||
api.Options
|
||||
api.EntityOptions
|
||||
name string
|
||||
edgeRouterRoles []string
|
||||
serviceRoles []string
|
||||
tags map[string]string
|
||||
}
|
||||
|
||||
func newUpdateServiceEdgeRouterPolicyCmd(out io.Writer, errOut io.Writer) *cobra.Command {
|
||||
options := &updateServiceEdgeRouterPolicyOptions{
|
||||
Options: api.Options{
|
||||
CommonOptions: common.CommonOptions{Out: out, Err: errOut},
|
||||
},
|
||||
EntityOptions: api.NewEntityOptions(out, errOut),
|
||||
}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
@@ -64,7 +60,6 @@ func newUpdateServiceEdgeRouterPolicyCmd(out io.Writer, errOut io.Writer) *cobra
|
||||
cmd.Flags().StringVarP(&options.name, "name", "n", "", "Set the name of the edge router policy")
|
||||
cmd.Flags().StringSliceVar(&options.edgeRouterRoles, "edge-router-roles", nil, "Edge router roles of the service edge router policy")
|
||||
cmd.Flags().StringSliceVar(&options.serviceRoles, "service-roles", nil, "Service roles of the service edge router policy")
|
||||
cmd.Flags().StringToStringVar(&options.tags, "tags", nil, "Custom management tags")
|
||||
|
||||
options.AddCommonFlags(cmd)
|
||||
|
||||
@@ -105,8 +100,8 @@ func runUpdateServiceEdgeRouterPolicy(o *updateServiceEdgeRouterPolicyOptions) e
|
||||
change = true
|
||||
}
|
||||
|
||||
if o.Cmd.Flags().Changed("tags") {
|
||||
api.SetJSONValue(entityData, o.tags, "tags")
|
||||
if o.TagsProvided() {
|
||||
o.SetTags(entityData)
|
||||
change = true
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ package edge
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/openziti/ziti/ziti/cmd/api"
|
||||
"github.com/openziti/ziti/ziti/cmd/common"
|
||||
cmdhelper "github.com/openziti/ziti/ziti/cmd/helpers"
|
||||
"io"
|
||||
|
||||
@@ -30,19 +29,16 @@ import (
|
||||
)
|
||||
|
||||
type updateServicePolicyOptions struct {
|
||||
api.Options
|
||||
api.EntityOptions
|
||||
name string
|
||||
serviceRoles []string
|
||||
identityRoles []string
|
||||
postureCheckRoles []string
|
||||
tags map[string]string
|
||||
}
|
||||
|
||||
func newUpdateServicePolicyCmd(out io.Writer, errOut io.Writer) *cobra.Command {
|
||||
options := &updateServicePolicyOptions{
|
||||
Options: api.Options{
|
||||
CommonOptions: common.CommonOptions{Out: out, Err: errOut},
|
||||
},
|
||||
EntityOptions: api.NewEntityOptions(out, errOut),
|
||||
}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
@@ -66,7 +62,6 @@ func newUpdateServicePolicyCmd(out io.Writer, errOut io.Writer) *cobra.Command {
|
||||
cmd.Flags().StringSliceVar(&options.serviceRoles, "service-roles", nil, "Service roles of the service policy")
|
||||
cmd.Flags().StringSliceVar(&options.identityRoles, "identity-roles", nil, "Identity roles of the service policy")
|
||||
cmd.Flags().StringSliceVarP(&options.postureCheckRoles, "posture-check-roles", "p", nil, "Posture Check roles of the service policy")
|
||||
cmd.Flags().StringToStringVar(&options.tags, "tags", nil, "Custom management tags")
|
||||
|
||||
options.AddCommonFlags(cmd)
|
||||
|
||||
@@ -117,8 +112,8 @@ func runUpdateServicePolicy(o *updateServicePolicyOptions) error {
|
||||
change = true
|
||||
}
|
||||
|
||||
if o.Cmd.Flags().Changed("tags") {
|
||||
api.SetJSONValue(entityData, o.tags, "tags")
|
||||
if o.TagsProvided() {
|
||||
o.SetTags(entityData)
|
||||
change = true
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@ import (
|
||||
"github.com/Jeffail/gabs"
|
||||
"github.com/openziti/foundation/v2/stringz"
|
||||
"github.com/openziti/ziti/ziti/cmd/api"
|
||||
"github.com/openziti/ziti/ziti/cmd/common"
|
||||
cmdhelper "github.com/openziti/ziti/ziti/cmd/helpers"
|
||||
errors2 "github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
@@ -31,23 +30,17 @@ import (
|
||||
)
|
||||
|
||||
type updateTerminatorOptions struct {
|
||||
api.Options
|
||||
api.EntityOptions
|
||||
router string
|
||||
address string
|
||||
binding string
|
||||
cost int32
|
||||
precedence string
|
||||
tags map[string]string
|
||||
}
|
||||
|
||||
func newUpdateTerminatorCmd(out io.Writer, errOut io.Writer) *cobra.Command {
|
||||
options := &updateTerminatorOptions{
|
||||
Options: api.Options{
|
||||
CommonOptions: common.CommonOptions{
|
||||
Out: out,
|
||||
Err: errOut,
|
||||
},
|
||||
},
|
||||
EntityOptions: api.NewEntityOptions(out, errOut),
|
||||
}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
@@ -70,7 +63,6 @@ func newUpdateTerminatorCmd(out io.Writer, errOut io.Writer) *cobra.Command {
|
||||
cmd.Flags().StringVar(&options.binding, "binding", "", "Set the terminator binding")
|
||||
cmd.Flags().Int32VarP(&options.cost, "cost", "c", 0, "Set the terminator cost")
|
||||
cmd.Flags().StringVarP(&options.precedence, "precedence", "p", "", "Set the terminator precedence ('default', 'required' or 'failed')")
|
||||
cmd.Flags().StringToStringVar(&options.tags, "tags", nil, "Custom management tags")
|
||||
|
||||
options.AddCommonFlags(cmd)
|
||||
|
||||
@@ -119,8 +111,8 @@ func runUpdateTerminator(o *updateTerminatorOptions) (err error) {
|
||||
change = true
|
||||
}
|
||||
|
||||
if o.Cmd.Flags().Changed("tags") {
|
||||
api.SetJSONValue(entityData, o.tags, "tags")
|
||||
if o.TagsProvided() {
|
||||
o.SetTags(entityData)
|
||||
change = true
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user