mirror of
https://github.com/openziti/ziti.git
synced 2026-10-12 23:32:02 +00:00
fix admin authenticator crud ops
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
# Release 0.20.11
|
||||
|
||||
* Bug fix: CLI Admin create/update/delete for UPDB authenticators now function properly
|
||||
|
||||
# Release 0.20.10
|
||||
|
||||
## What's New
|
||||
|
||||
@@ -29,7 +29,7 @@ require (
|
||||
github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d
|
||||
github.com/keybase/go-ps v0.0.0-20190827175125-91aafc93ba19
|
||||
github.com/michaelquigley/pfxlog v0.3.7
|
||||
github.com/openziti/edge v0.19.145
|
||||
github.com/openziti/edge v0.19.146
|
||||
github.com/openziti/fabric v0.16.71
|
||||
github.com/openziti/foundation v0.15.56
|
||||
github.com/openziti/sdk-golang v0.15.57
|
||||
|
||||
@@ -622,8 +622,8 @@ github.com/openziti/bbolt v1.3.6-0.20210317142109-547da822475e h1:ST9+54UtCr96S5
|
||||
github.com/openziti/bbolt v1.3.6-0.20210317142109-547da822475e/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ=
|
||||
github.com/openziti/dilithium v0.3.3 h1:PLgQ6PMNLSTzCFbX/h98cmudgz/cU6TmjdSv5NAPD8k=
|
||||
github.com/openziti/dilithium v0.3.3/go.mod h1:vsCjI2AU/hon9e+dLhUFbCNGesJDj2ASgkySOcpmvjo=
|
||||
github.com/openziti/edge v0.19.145 h1:YVvTg+2iNuoqpnwVbID9AqYkhxdRrx3Z4o5P4/wrbq0=
|
||||
github.com/openziti/edge v0.19.145/go.mod h1:+Rav15D9soV8grHd/UOM3deA7T1HvN4obeYnKNYfvBY=
|
||||
github.com/openziti/edge v0.19.146 h1:ff5erVcZzyXPh+Pd2jI0yTQxytQVTndvCyuzoNwvh84=
|
||||
github.com/openziti/edge v0.19.146/go.mod h1:+Rav15D9soV8grHd/UOM3deA7T1HvN4obeYnKNYfvBY=
|
||||
github.com/openziti/fabric v0.16.71 h1:5y66bJYXXOI2xdCfD79KCBlW3g638Vx80VVrnyq9kRc=
|
||||
github.com/openziti/fabric v0.16.71/go.mod h1:RhooR5KtpxSpesOa/L9VelwlkhaToBTwzwT1QiGDB/4=
|
||||
github.com/openziti/foundation v0.15.56 h1:St4FLcaBD8ER1QyO/P0enyIRw+ErOKayHc3zY6aY6aU=
|
||||
|
||||
@@ -17,11 +17,14 @@
|
||||
package edge_controller
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/Jeffail/gabs"
|
||||
"github.com/openziti/edge/rest_management_api_client/authenticator"
|
||||
"github.com/openziti/foundation/util/term"
|
||||
"github.com/openziti/ziti/ziti/cmd/ziti/cmd/helpers"
|
||||
"github.com/openziti/ziti/ziti/cmd/ziti/util"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@@ -78,24 +81,55 @@ func runCreateIdentityPassword(idType string, options *createAuthenticatorUpdb)
|
||||
return errors.New("an identity must be specified")
|
||||
}
|
||||
|
||||
id, err := mapIdentityNameToID(options.idOrName, options.edgeOptions)
|
||||
identityId, err := mapIdentityNameToID(options.idOrName, options.edgeOptions)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
client, err := util.DefaultEdgeManagementClient()
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
filter := fmt.Sprintf(`identity="%s" and method="updb"`, identityId)
|
||||
|
||||
result, err := client.Authenticator.ListAuthenticators(&authenticator.ListAuthenticatorsParams{
|
||||
Filter: &filter,
|
||||
Context: context.Background(),
|
||||
}, nil)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(result.Payload.Data) != 0 {
|
||||
return fmt.Errorf("updb authentictor already exists, update or remove it instead")
|
||||
}
|
||||
|
||||
if options.password == "" {
|
||||
if options.password, err = term.PromptPassword("Enter password: ", false); err != nil {
|
||||
return err
|
||||
}
|
||||
verifyPassword := ""
|
||||
if verifyPassword, err = term.PromptPassword("Enter password again: ", false); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if verifyPassword != options.password {
|
||||
return errors.New("passwords did not match")
|
||||
}
|
||||
}
|
||||
|
||||
passwordData := gabs.New()
|
||||
setJSONValue(passwordData, options.password, "password")
|
||||
setJSONValue(passwordData, options.username, "username")
|
||||
authenticatorData := gabs.New()
|
||||
setJSONValue(authenticatorData, identityId, "identityId")
|
||||
setJSONValue(authenticatorData, options.password, "password")
|
||||
setJSONValue(authenticatorData, options.username, "username")
|
||||
setJSONValue(authenticatorData, "updb", "method")
|
||||
|
||||
if _, err = createEntityOfType(fmt.Sprintf("identities/%s/updb", id), passwordData.String(), &options.edgeOptions); err != nil {
|
||||
if _, err = createEntityOfType("authenticators", authenticatorData.String(), &options.edgeOptions); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -17,7 +17,10 @@
|
||||
package edge_controller
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/openziti/edge/rest_management_api_client/authenticator"
|
||||
"github.com/openziti/ziti/ziti/cmd/ziti/util"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
import cmdhelper "github.com/openziti/ziti/ziti/cmd/ziti/cmd/helpers"
|
||||
@@ -52,13 +55,43 @@ func newDeleteAuthenticatorUpdb(idType string, options *edgeOptions) *cobra.Comm
|
||||
}
|
||||
|
||||
func runDeleteUpdb(idOrName string, options *deleteUpdbOptions) error {
|
||||
|
||||
id, err := mapIdentityNameToID(idOrName, options.edgeOptions)
|
||||
identityId, err := mapIdentityNameToID(idOrName, options.edgeOptions)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = deleteEntityOfType(fmt.Sprintf("identities/%s/updb/password", id), "", &options.edgeOptions)
|
||||
|
||||
client, err := util.DefaultEdgeManagementClient()
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
filter := fmt.Sprintf(`identity="%s" and method="updb"`, identityId)
|
||||
|
||||
result, err := client.Authenticator.ListAuthenticators(&authenticator.ListAuthenticatorsParams{
|
||||
Filter: &filter,
|
||||
Context: context.Background(),
|
||||
}, nil)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(result.Payload.Data) != 1 {
|
||||
return fmt.Errorf("incorrect number of results, expected 1, got %d", len(result.Payload.Data))
|
||||
}
|
||||
|
||||
if result.Payload.Data[0].ID == nil {
|
||||
return fmt.Errorf("authenticator contained a nil id")
|
||||
}
|
||||
|
||||
if *result.Payload.Data[0].ID == "" {
|
||||
return fmt.Errorf("authenticator contained an empty id")
|
||||
}
|
||||
|
||||
authenticatorId := *result.Payload.Data[0].ID
|
||||
|
||||
_, err = deleteEntityOfType(fmt.Sprintf("authenticators/%s", authenticatorId), "", &options.edgeOptions)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -17,9 +17,11 @@
|
||||
package edge_controller
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/Jeffail/gabs"
|
||||
"github.com/openziti/edge/rest_management_api_client/authenticator"
|
||||
"github.com/openziti/foundation/util/term"
|
||||
"github.com/openziti/ziti/ziti/cmd/ziti/util"
|
||||
"github.com/spf13/cobra"
|
||||
@@ -134,16 +136,55 @@ func setIdentityPassword(identity, password string, options edgeOptions) error {
|
||||
return err
|
||||
}
|
||||
|
||||
client, err := util.DefaultEdgeManagementClient()
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
filter := fmt.Sprintf(`identity="%s" and method="updb"`, id)
|
||||
|
||||
result, err := client.Authenticator.ListAuthenticators(&authenticator.ListAuthenticatorsParams{
|
||||
Filter: &filter,
|
||||
Context: context.Background(),
|
||||
}, nil)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(result.Payload.Data) != 1 {
|
||||
return fmt.Errorf("incorrect number of results, expected 1, got %d", len(result.Payload.Data))
|
||||
}
|
||||
|
||||
if result.Payload.Data[0].ID == nil {
|
||||
return fmt.Errorf("authenticator contained a nil id")
|
||||
}
|
||||
|
||||
if *result.Payload.Data[0].ID == "" {
|
||||
return fmt.Errorf("authenticator contained an empty id")
|
||||
}
|
||||
|
||||
authenticatorId := result.Payload.Data[0].ID
|
||||
|
||||
if password == "" {
|
||||
if password, err = term.PromptPassword("Enter the identity's new password : ", false); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
verifyPassword := ""
|
||||
if verifyPassword, err = term.PromptPassword("Enter password again: ", false); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if verifyPassword != password {
|
||||
return errors.New("passwords did not match")
|
||||
}
|
||||
}
|
||||
|
||||
passwordData := gabs.New()
|
||||
setJSONValue(passwordData, password, "password")
|
||||
|
||||
_, err = putEntityOfType(fmt.Sprintf("identities/%s/updb/password", id), passwordData.String(), &options)
|
||||
_, err = patchEntityOfType(fmt.Sprintf("authenticators/%s", *authenticatorId), passwordData.String(), &options)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user