cmd/uplink Allow use of named accesses in uplink register

Previously uplink register only accepted a fully serialized access grant.
This is kind of annoying, I changed it so that it could also use access names.

Change-Id: If6d4d1baa8d4fb3d87fdedb895d459fa12743f1a
This commit is contained in:
Bill Thorp 2020-11-18 11:07:10 -05:00
parent aeb801604e
commit 5fe3d2dea7

View File

@ -23,6 +23,7 @@ import (
type registerConfig struct {
AuthService string `help:"the address to the service you wish to register your access with" default:"" basic-help:"true"`
AccessConfig
}
var (
@ -155,6 +156,15 @@ func registerAccess(cmd *cobra.Command, args []string) (err error) {
accessRaw := args[0]
// try assuming that accessRaw is a named access
access, err := registerCfg.GetNamedAccess(accessRaw)
if err == nil && access != nil {
accessRaw, err = access.Serialize()
if err != nil {
return fmt.Errorf("error serializing named access '%s'", accessRaw)
}
}
resp, err := http.Post(fmt.Sprintf("%s/v1/access", registerCfg.AuthService), "application/json", strings.NewReader(fmt.Sprintf(`{"access_grant":"%s"}`, accessRaw)))
if err != nil {
return err