mirror of
https://github.com/openziti/ziti.git
synced 2026-10-13 07:41:17 +00:00
Allow using @name when creating policies. Fixes GH-93
This commit is contained in:
@@ -1,9 +1,16 @@
|
||||
# Release 0.14.2
|
||||
## Theme
|
||||
Ziti 0.14.2 includes the following:
|
||||
|
||||
* [can't create service policy with @ identity name](https://github.com/netfoundry/ziti-cmd/issues/93)
|
||||
* Fixes to connection setup timing
|
||||
|
||||
# Release 0.14.1
|
||||
## Theme
|
||||
Ziti 0.14.1 includes the following:
|
||||
|
||||
### Features
|
||||
* [Enable graceful shutdown of bound connections]https://github.com/netfoundry/ziti-edge/issues/149
|
||||
* [Enable graceful shutdown of bound connections](https://github.com/netfoundry/ziti-edge/issues/149)
|
||||
|
||||
### Fixes
|
||||
* [Enrollments w/ 0 length bodies cause enrollment errors](https://github.com/netfoundry/ziti-edge/issues/150)
|
||||
@@ -1769,4 +1776,4 @@ Errors where there is the potential to report about multiple invalid field value
|
||||
"apiVersion": "0.0.1"
|
||||
}
|
||||
}
|
||||
```
|
||||
```
|
||||
|
||||
@@ -8,7 +8,7 @@ go 1.14
|
||||
|
||||
// replace github.com/netfoundry/ziti-sdk-golang => ../ziti-sdk-golang
|
||||
|
||||
// replace github.com/netfoundry/ziti-edge => ../ziti-edge
|
||||
replace github.com/netfoundry/ziti-edge => ../ziti-edge
|
||||
|
||||
require (
|
||||
github.com/Jeffail/gabs v1.4.0
|
||||
@@ -26,9 +26,9 @@ require (
|
||||
github.com/keybase/go-ps v0.0.0-20190827175125-91aafc93ba19
|
||||
github.com/michaelquigley/pfxlog v0.0.0-20190813191113-2be43bd0dccc
|
||||
github.com/netfoundry/ziti-edge v0.14.8
|
||||
github.com/netfoundry/ziti-fabric v0.11.29
|
||||
github.com/netfoundry/ziti-foundation v0.9.15
|
||||
github.com/netfoundry/ziti-sdk-golang v0.11.30
|
||||
github.com/netfoundry/ziti-fabric v0.11.31
|
||||
github.com/netfoundry/ziti-foundation v0.9.17
|
||||
github.com/netfoundry/ziti-sdk-golang v0.11.33
|
||||
github.com/pborman/uuid v1.2.0
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0
|
||||
|
||||
@@ -230,10 +230,21 @@ github.com/netfoundry/ziti-edge v0.14.8 h1:u4jSKkJ6T6gKmyFWlsRMjsNOuaeOPThH2WvVB
|
||||
github.com/netfoundry/ziti-edge v0.14.8/go.mod h1:KUPJljPUWx0OAXSJzZU+0RS6jTG/R+5McxSRO0+/Sak=
|
||||
github.com/netfoundry/ziti-fabric v0.11.29 h1:cB53VvdL06gyGxs3qOEWV+ATMY3ThSaMSyn2xalXdhs=
|
||||
github.com/netfoundry/ziti-fabric v0.11.29/go.mod h1:SQil5oz1SQgawDm3B4RpJdYQEVc7j8ddLoaocP2Z6gA=
|
||||
github.com/netfoundry/ziti-fabric v0.11.30 h1:Vf9mLMe/rZmyT7iKQlHytBnHBBPIfiV6ORtp/xqENnY=
|
||||
github.com/netfoundry/ziti-fabric v0.11.30/go.mod h1:CejdO9bamBIGbs4wopAUYRu5NcffgjcgFJZrs8FXVeM=
|
||||
github.com/netfoundry/ziti-fabric v0.11.31 h1:otjhKFvxBLJUDP06lHnDOsHwkvVDp3xdhKK/EQyb+Ek=
|
||||
github.com/netfoundry/ziti-fabric v0.11.31/go.mod h1:OkTL8ftDbnWv9BBOGZB5cfOGUOwHz3VF9+dyxBJhHfo=
|
||||
github.com/netfoundry/ziti-foundation v0.9.15 h1:ouP2kJrft+b60JPzoFapWjZJVGdJhkzKOCdxKjmPhDU=
|
||||
github.com/netfoundry/ziti-foundation v0.9.15/go.mod h1:s4O2kYpHcFzeMpS2hkNfD6W7Ce3RhsLw30Ruj4kBRu4=
|
||||
github.com/netfoundry/ziti-foundation v0.9.16/go.mod h1:s4O2kYpHcFzeMpS2hkNfD6W7Ce3RhsLw30Ruj4kBRu4=
|
||||
github.com/netfoundry/ziti-foundation v0.9.17 h1:cBI8oeeZLbZad4nCUe/fjad02h5es4tjbAA9qJID1Bs=
|
||||
github.com/netfoundry/ziti-foundation v0.9.17/go.mod h1:s4O2kYpHcFzeMpS2hkNfD6W7Ce3RhsLw30Ruj4kBRu4=
|
||||
github.com/netfoundry/ziti-sdk-golang v0.11.30 h1:FCg9i1O6GPt7vwOu0fMm0ySV8dicN/s8ITy3ZXwJx9k=
|
||||
github.com/netfoundry/ziti-sdk-golang v0.11.30/go.mod h1:MLXmTe6ldP1S3EL/kA3E3ZLOANIWHHE1sn0mMHcoRzQ=
|
||||
github.com/netfoundry/ziti-sdk-golang v0.11.32 h1:DQIsqeNSQciv1ccPy4Lj/oT29muSsNgQkkHUxSEEpN8=
|
||||
github.com/netfoundry/ziti-sdk-golang v0.11.32/go.mod h1:eyKab+nOpFMIN4gg8YED+/tpbarEnkqd4VRHatSHGNs=
|
||||
github.com/netfoundry/ziti-sdk-golang v0.11.33 h1:QZHYmS8lpOjGwVHlkRHo4Flxs4muNJwDPTl6kI2GQsQ=
|
||||
github.com/netfoundry/ziti-sdk-golang v0.11.33/go.mod h1:5NHKKY44BPh7BVCYBYpqqEHUUE8Tuaka1xJx+p0HQ90=
|
||||
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
|
||||
github.com/oleiade/reflections v1.0.0 h1:0ir4pc6v8/PJ0yw5AEtMddfXpWBXg9cnG7SgSoJuCgY=
|
||||
github.com/oleiade/reflections v1.0.0/go.mod h1:RbATFBbKYkVdqmSFtx13Bb/tVhR0lgOBXunWTZKeL4w=
|
||||
|
||||
@@ -24,21 +24,22 @@ import (
|
||||
)
|
||||
|
||||
func mapNameToID(entityType string, val string) (string, error) {
|
||||
// If we can parse it as a UUID, treat it as such
|
||||
_, err := uuid.Parse(val)
|
||||
if err == nil {
|
||||
list, _, err := filterEntitiesOfType(entityType, fmt.Sprintf("id=\"%s\"", val), false, nil)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if len(list) > 0 {
|
||||
return val, nil
|
||||
}
|
||||
|
||||
// Allow UUID formatted names to be recognized with a name: prefix
|
||||
name := strings.TrimPrefix(val, "name:")
|
||||
list, _, err := filterEntitiesOfType(entityType, fmt.Sprintf("name=\"%s\"", name), false, nil)
|
||||
list, _, err = filterEntitiesOfType(entityType, fmt.Sprintf("name=\"%s\"", val), false, nil)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if len(list) < 1 {
|
||||
return "", errors.Errorf("no %v found for name %v", entityType, val)
|
||||
return "", errors.Errorf("no %v found with id or name %v", entityType, val)
|
||||
}
|
||||
|
||||
if len(list) > 1 {
|
||||
|
||||
@@ -66,11 +66,20 @@ func newCreateEdgeRouterPolicyCmd(f cmdutil.Factory, out io.Writer, errOut io.Wr
|
||||
|
||||
// runCreateEdgeRouterPolicy create a new edgeRouterPolicy on the Ziti Edge Controller
|
||||
func runCreateEdgeRouterPolicy(o *createEdgeRouterPolicyOptions) error {
|
||||
edgeRouterRoles, err := convertNamesToIds(o.edgeRouterRoles, "edge-routers")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
identityRoles, err := convertNamesToIds(o.identityRoles, "identities")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
entityData := gabs.New()
|
||||
setJSONValue(entityData, o.Args[0], "name")
|
||||
setJSONValue(entityData, o.edgeRouterRoles, "edgeRouterRoles")
|
||||
setJSONValue(entityData, o.identityRoles, "identityRoles")
|
||||
setJSONValue(entityData, edgeRouterRoles, "edgeRouterRoles")
|
||||
setJSONValue(entityData, identityRoles, "identityRoles")
|
||||
result, err := createEntityOfType("edge-router-policies", entityData.String(), &o.commonOptions)
|
||||
|
||||
if err != nil {
|
||||
|
||||
@@ -66,11 +66,19 @@ func newCreateServiceEdgeRouterPolicyCmd(f cmdutil.Factory, out io.Writer, errOu
|
||||
|
||||
// runCreateServiceEdgeRouterPolicy create a new edgeRouterPolicy on the Ziti Edge Controller
|
||||
func runCreateServiceEdgeRouterPolicy(o *createServiceEdgeRouterPolicyOptions) error {
|
||||
edgeRouterRoles, err := convertNamesToIds(o.edgeRouterRoles, "edge-routers")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
serviceRoles, err := convertNamesToIds(o.serviceRoles, "identities")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
entityData := gabs.New()
|
||||
setJSONValue(entityData, o.Args[0], "name")
|
||||
setJSONValue(entityData, o.edgeRouterRoles, "edgeRouterRoles")
|
||||
setJSONValue(entityData, o.serviceRoles, "serviceRoles")
|
||||
setJSONValue(entityData, edgeRouterRoles, "edgeRouterRoles")
|
||||
setJSONValue(entityData, serviceRoles, "serviceRoles")
|
||||
result, err := createEntityOfType("service-edge-router-policies", entityData.String(), &o.commonOptions)
|
||||
|
||||
if err != nil {
|
||||
|
||||
@@ -19,6 +19,7 @@ package edge_controller
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
@@ -73,11 +74,21 @@ func runCreateServicePolicy(o *createServicePolicyOptions) error {
|
||||
return errors.Errorf("Invalid policy type '%v'. Valid values: [Bind, Dial]", policyType)
|
||||
}
|
||||
|
||||
serviceRoles, err := convertNamesToIds(o.serviceRoles, "services")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
identityRoles, err := convertNamesToIds(o.identityRoles, "identities")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
entityData := gabs.New()
|
||||
setJSONValue(entityData, o.Args[0], "name")
|
||||
setJSONValue(entityData, o.Args[1], "type")
|
||||
setJSONValue(entityData, o.serviceRoles, "serviceRoles")
|
||||
setJSONValue(entityData, o.identityRoles, "identityRoles")
|
||||
setJSONValue(entityData, serviceRoles, "serviceRoles")
|
||||
setJSONValue(entityData, identityRoles, "identityRoles")
|
||||
result, err := createEntityOfType("service-policies", entityData.String(), &o.commonOptions)
|
||||
|
||||
if err != nil {
|
||||
@@ -92,3 +103,20 @@ func runCreateServicePolicy(o *createServicePolicyOptions) error {
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func convertNamesToIds(roles []string, entityType string) ([]string, error) {
|
||||
var result []string
|
||||
for _, val := range roles {
|
||||
if strings.HasPrefix(val, "@") {
|
||||
idOrName := strings.TrimPrefix(val, "@")
|
||||
id, err := mapNameToID(entityType, idOrName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result = append(result, "@"+id)
|
||||
} else {
|
||||
result = append(result, val)
|
||||
}
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user