From 4711268651de58c92c1a5378daac0442bf0d0c5b Mon Sep 17 00:00:00 2001 From: Aditya Thebe Date: Mon, 7 Aug 2023 09:54:03 +0545 Subject: [PATCH] chore: address review comment --- agent/controllers.go | 2 +- db/agents.go | 3 +++ db/people.go | 5 +++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/agent/controllers.go b/agent/controllers.go index 93989d19c..bfb3f84d4 100644 --- a/agent/controllers.go +++ b/agent/controllers.go @@ -21,7 +21,7 @@ func GenerateAgent(c echo.Context) error { agent, err := generateAgent(ctx, body) if err != nil { logger.Errorf("failed to generate a new agent: %v", err) - c.JSON(http.StatusInternalServerError, api.HTTPError{Error: err.Error(), Message: "error generating agent"}) + return c.JSON(http.StatusInternalServerError, api.HTTPError{Error: err.Error(), Message: "error generating agent"}) } return c.JSON(http.StatusCreated, agent) diff --git a/db/agents.go b/db/agents.go index 44c2ce465..c87c6c243 100644 --- a/db/agents.go +++ b/db/agents.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" + "github.com/flanksource/commons/collections" "github.com/flanksource/duty/models" "github.com/flanksource/incident-commander/api" "github.com/google/uuid" @@ -53,6 +54,8 @@ func GetOrCreateAgent(ctx *api.Context, name string) (*models.Agent, error) { } func CreateAgent(ctx *api.Context, name string, personID *uuid.UUID, properties map[string]string) error { + properties = collections.MergeMap(properties, map[string]string{"type": "agent"}) + a := models.Agent{ Name: name, PersonID: personID, diff --git a/db/people.go b/db/people.go index 2058b1592..37ca56ffe 100644 --- a/db/people.go +++ b/db/people.go @@ -1,6 +1,7 @@ package db import ( + "fmt" "time" "github.com/flanksource/duty/models" @@ -37,10 +38,10 @@ func CreatePerson(ctx *api.Context, username, hashedPassword string) (*models.Pe } accessToken := models.AccessToken{ - Name: "default", + Name: fmt.Sprintf("agent-%d", time.Now().Unix()), Value: hashedPassword, PersonID: person.ID, - ExpiresAt: time.Now().Add(time.Hour * 24 * 90), // long-lived token + ExpiresAt: time.Now().Add(time.Hour * 24 * 365), // long-lived token } if err := tx.Create(&accessToken).Error; err != nil { return nil, err