mirror of
https://github.com/profullstack/agentbbs.git
synced 2026-12-01 09:24:46 +00:00
fix: validate provisioned account kind (#112)
Some checks are pending
CI / build (push) Waiting to run
deploy / deploy (push) Waiting to run
test / test (push) Waiting to run
Some checks are pending
CI / build (push) Waiting to run
deploy / deploy (push) Waiting to run
test / test (push) Waiting to run
This commit is contained in:
parent
bf777a1475
commit
03a2ce3f8b
2 changed files with 44 additions and 1 deletions
|
|
@ -34,6 +34,10 @@ func provisionUser(st store.Store, args []string) {
|
|||
pubkeyFile := fs.String("pubkey-file", "", "read the SSH public key from this file")
|
||||
kind := fs.String("kind", string(auth.Member), "account kind: member | agent")
|
||||
fs.Parse(args)
|
||||
accountKind, ok := parseProvisionKind(*kind)
|
||||
if !ok {
|
||||
fail(`invalid --kind: must be "member" or "agent"`)
|
||||
}
|
||||
|
||||
// Normalize with the same rules the hub uses for self-service joins, so
|
||||
// store-provisioned handles are indistinguishable from join@ ones.
|
||||
|
|
@ -67,7 +71,7 @@ func provisionUser(st store.Store, args []string) {
|
|||
fail(fmt.Sprintf("this key already belongs to member %q (fp %s)", existing.Name, fp))
|
||||
}
|
||||
|
||||
u, err := st.EnsureUser(handle, *kind, fp)
|
||||
u, err := st.EnsureUser(handle, string(accountKind), fp)
|
||||
if err != nil {
|
||||
if errors.Is(err, store.ErrKeyMismatch) {
|
||||
fail(fmt.Sprintf("handle %q is already registered with a different key", handle))
|
||||
|
|
@ -84,6 +88,17 @@ func provisionUser(st store.Store, args []string) {
|
|||
})
|
||||
}
|
||||
|
||||
func parseProvisionKind(value string) (auth.Kind, bool) {
|
||||
switch auth.Kind(strings.ToLower(strings.TrimSpace(value))) {
|
||||
case auth.Member:
|
||||
return auth.Member, true
|
||||
case auth.Agent:
|
||||
return auth.Agent, true
|
||||
default:
|
||||
return "", false
|
||||
}
|
||||
}
|
||||
|
||||
func fail(msg string) {
|
||||
fmt.Fprintln(os.Stderr, "provision-user: "+msg)
|
||||
os.Exit(1)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue