Skip to content

Commit

Permalink
chore: address review comment
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Aug 7, 2023
1 parent 1cab6be commit 4711268
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion agent/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions db/agents.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions db/people.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package db

import (
"fmt"
"time"

"github.com/flanksource/duty/models"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4711268

Please sign in to comment.