feat: add agent user nodes with access token authentication
Build and Publish Arch Package / build-arch (amd64, x86_64) (push) Successful in 1m50s
Build and Publish Arch Package / build-arch (arm64, aarch64) (push) Successful in 51s
Build and Publish Docker Image / build-apk (amd64, x86_64) (push) Successful in 53s
Build and Publish Docker Image / build-apk (arm64, aarch64) (push) Successful in 48s
Build and Publish Docker Image / build-and-push-docker (push) Successful in 12m50s
Build and Publish Arch Package / build-arch (amd64, x86_64) (push) Successful in 1m50s
Build and Publish Arch Package / build-arch (arm64, aarch64) (push) Successful in 51s
Build and Publish Docker Image / build-apk (amd64, x86_64) (push) Successful in 53s
Build and Publish Docker Image / build-apk (arm64, aarch64) (push) Successful in 48s
Build and Publish Docker Image / build-and-push-docker (push) Successful in 12m50s
This commit is contained in:
@@ -3,7 +3,9 @@ package cmd
|
||||
import (
|
||||
"axolotl/models"
|
||||
"axolotl/service"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
@@ -64,6 +66,9 @@ var addCmd = &cobra.Command{
|
||||
return
|
||||
}
|
||||
|
||||
if n.GetProperty("type") == "agent" {
|
||||
printAgentToken(cmd.OutOrStdout(), n)
|
||||
}
|
||||
PrintNode(cmd.OutOrStdout(), svc, n, jsonFlag)
|
||||
},
|
||||
}
|
||||
@@ -81,3 +86,13 @@ func init() {
|
||||
f.StringArrayVar(&cTags, "tag", nil, "label tag (alias for --rel tagname)")
|
||||
f.StringArrayVar(&cRels, "rel", nil, "relation (prefix::value or relname:target)")
|
||||
}
|
||||
|
||||
func printAgentToken(w io.Writer, n *models.Node) {
|
||||
var c struct {
|
||||
AccessToken string `json:"access_token"`
|
||||
}
|
||||
if err := json.Unmarshal([]byte(n.Content), &c); err == nil && c.AccessToken != "" {
|
||||
fmt.Fprintf(w, "\nAgent access token: %s\n", c.AccessToken)
|
||||
fmt.Fprintln(w, "Save this token — it cannot be retrieved later via the CLI.")
|
||||
}
|
||||
}
|
||||
|
||||
+9
-1
@@ -23,6 +23,14 @@ var serveCmd = &cobra.Command{
|
||||
oidcCfg = &cfg.OIDC
|
||||
}
|
||||
|
||||
agentLookup := func(token string) string {
|
||||
st, err := store.FindOrInitSQLiteStore()
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return service.LookupAgentToken(st, token)
|
||||
}
|
||||
|
||||
handler, err := serve.New(func(user string) (service.NodeService, error) {
|
||||
if user == "" {
|
||||
return nil, fmt.Errorf("user is required")
|
||||
@@ -32,7 +40,7 @@ var serveCmd = &cobra.Command{
|
||||
return nil, err
|
||||
}
|
||||
return service.NewLocalNodeService(st, user), nil
|
||||
}, oidcCfg)
|
||||
}, oidcCfg, agentLookup)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
|
||||
+8
-1
@@ -11,7 +11,7 @@ import (
|
||||
|
||||
var (
|
||||
uTitle, uContent, uDue string
|
||||
uClearDue bool
|
||||
uClearDue, uRegenToken bool
|
||||
uStatus, uPrio, uType string
|
||||
uNamespace, uAssignee string
|
||||
uAddTags, uRmTags, uAddRels, uRmRels []string
|
||||
@@ -83,12 +83,18 @@ var updateCmd = &cobra.Command{
|
||||
}
|
||||
input.RemoveRels = append(input.RemoveRels, ri)
|
||||
}
|
||||
if uRegenToken {
|
||||
input.RegenerateAccessToken = true
|
||||
}
|
||||
|
||||
n, err := svc.Update(args[0], input)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
if uRegenToken {
|
||||
printAgentToken(cmd.OutOrStdout(), n)
|
||||
}
|
||||
PrintNode(cmd.OutOrStdout(), svc, n, jsonFlag)
|
||||
},
|
||||
}
|
||||
@@ -109,4 +115,5 @@ func init() {
|
||||
f.StringArrayVar(&uRmTags, "tag-remove", nil, "remove label tag")
|
||||
f.StringArrayVar(&uAddRels, "rel", nil, "add relation (prefix::value or relname:target)")
|
||||
f.StringArrayVar(&uRmRels, "rel-remove", nil, "remove relation (prefix::value or relname:target)")
|
||||
f.BoolVar(&uRegenToken, "regenerate-access-token", false, "regenerate agent access token")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user