mirror of
https://github.com/absmach/magistrala.git
synced 2026-06-23 04:10:28 +00:00
SMQ-2869 - Switch to UTC time on backends (#2870)
Signed-off-by: Dusan Borovcanin <borovcanindusan1@gmail.com>
This commit is contained in:
@@ -88,7 +88,7 @@ func (pr *patRepo) RetrieveAll(ctx context.Context, userID string, pm auth.PATSP
|
||||
Name: pm.Name,
|
||||
ID: pm.ID,
|
||||
Status: pm.Status,
|
||||
Timestamp: time.Now(),
|
||||
Timestamp: time.Now().UTC(),
|
||||
}
|
||||
|
||||
rows, err := pr.db.NamedQueryContext(ctx, q, dbPage)
|
||||
@@ -160,7 +160,7 @@ func (pr *patRepo) RetrieveSecretAndRevokeStatus(ctx context.Context, userID, pa
|
||||
dbPage := dbPagemeta{
|
||||
User: userID,
|
||||
PatID: patID,
|
||||
Timestamp: time.Now(),
|
||||
Timestamp: time.Now().UTC(),
|
||||
}
|
||||
|
||||
rows, err := pr.db.NamedQueryContext(ctx, q, dbPage)
|
||||
@@ -181,7 +181,7 @@ func (pr *patRepo) RetrieveSecretAndRevokeStatus(ctx context.Context, userID, pa
|
||||
return "", true, true, postgres.HandleError(repoerr.ErrNotFound, err)
|
||||
}
|
||||
|
||||
expired := time.Now().After(expiresAt)
|
||||
expired := time.Now().UTC().After(expiresAt)
|
||||
return secret, revoked, expired, nil
|
||||
}
|
||||
|
||||
@@ -197,7 +197,7 @@ func (pr *patRepo) UpdateName(ctx context.Context, userID, patID, name string) (
|
||||
ID: patID,
|
||||
Name: name,
|
||||
UpdatedAt: sql.NullTime{
|
||||
Time: time.Now(),
|
||||
Time: time.Now().UTC(),
|
||||
Valid: true,
|
||||
},
|
||||
}
|
||||
@@ -230,7 +230,7 @@ func (pr *patRepo) UpdateDescription(ctx context.Context, userID, patID, descrip
|
||||
User: userID,
|
||||
ID: patID,
|
||||
UpdatedAt: sql.NullTime{
|
||||
Time: time.Now(),
|
||||
Time: time.Now().UTC(),
|
||||
Valid: true,
|
||||
},
|
||||
Description: description,
|
||||
@@ -264,7 +264,7 @@ func (pr *patRepo) UpdateTokenHash(ctx context.Context, userID, patID, tokenHash
|
||||
User: userID,
|
||||
ID: patID,
|
||||
UpdatedAt: sql.NullTime{
|
||||
Time: time.Now(),
|
||||
Time: time.Now().UTC(),
|
||||
Valid: true,
|
||||
},
|
||||
ExpiresAt: expiryAt,
|
||||
@@ -298,7 +298,7 @@ func (pr *patRepo) Revoke(ctx context.Context, userID, patID string) error {
|
||||
User: userID,
|
||||
ID: patID,
|
||||
RevokedAt: sql.NullTime{
|
||||
Time: time.Now(),
|
||||
Time: time.Now().UTC(),
|
||||
Valid: true,
|
||||
},
|
||||
}
|
||||
@@ -653,7 +653,7 @@ func (pr *patRepo) retrievePATFromDB(ctx context.Context, userID, patID string)
|
||||
dbp := dbPagemeta{
|
||||
ID: patID,
|
||||
User: userID,
|
||||
Timestamp: time.Now(),
|
||||
Timestamp: time.Now().UTC(),
|
||||
}
|
||||
|
||||
rows, err := pr.db.NamedQueryContext(ctx, q, dbp)
|
||||
|
||||
+8
-8
@@ -260,7 +260,7 @@ func (svc service) PolicyValidation(pr policies.Policy) error {
|
||||
}
|
||||
|
||||
func (svc service) tmpKey(ctx context.Context, duration time.Duration, key Key) (Token, error) {
|
||||
key.ExpiresAt = time.Now().Add(duration)
|
||||
key.ExpiresAt = time.Now().UTC().Add(duration)
|
||||
if err := svc.checkUserRole(ctx, key); err != nil {
|
||||
return Token{}, errors.Wrap(errIssueTmp, err)
|
||||
}
|
||||
@@ -275,7 +275,7 @@ func (svc service) tmpKey(ctx context.Context, duration time.Duration, key Key)
|
||||
func (svc service) accessKey(ctx context.Context, key Key) (Token, error) {
|
||||
var err error
|
||||
key.Type = AccessKey
|
||||
key.ExpiresAt = time.Now().Add(svc.loginDuration)
|
||||
key.ExpiresAt = time.Now().UTC().Add(svc.loginDuration)
|
||||
|
||||
if err := svc.checkUserRole(ctx, key); err != nil {
|
||||
return Token{}, errors.Wrap(errIssueUser, err)
|
||||
@@ -286,7 +286,7 @@ func (svc service) accessKey(ctx context.Context, key Key) (Token, error) {
|
||||
return Token{}, errors.Wrap(errIssueTmp, err)
|
||||
}
|
||||
|
||||
key.ExpiresAt = time.Now().Add(svc.refreshDuration)
|
||||
key.ExpiresAt = time.Now().UTC().Add(svc.refreshDuration)
|
||||
key.Type = RefreshKey
|
||||
refresh, err := svc.tokenizer.Issue(key)
|
||||
if err != nil {
|
||||
@@ -299,7 +299,7 @@ func (svc service) accessKey(ctx context.Context, key Key) (Token, error) {
|
||||
func (svc service) invitationKey(ctx context.Context, key Key) (Token, error) {
|
||||
var err error
|
||||
key.Type = InvitationKey
|
||||
key.ExpiresAt = time.Now().Add(svc.invitationDuration)
|
||||
key.ExpiresAt = time.Now().UTC().Add(svc.invitationDuration)
|
||||
|
||||
if err := svc.checkUserRole(ctx, key); err != nil {
|
||||
return Token{}, errors.Wrap(errIssueTmp, err)
|
||||
@@ -330,13 +330,13 @@ func (svc service) refreshKey(ctx context.Context, token string, key Key) (Token
|
||||
}
|
||||
key.Role = k.Role
|
||||
|
||||
key.ExpiresAt = time.Now().Add(svc.loginDuration)
|
||||
key.ExpiresAt = time.Now().UTC().Add(svc.loginDuration)
|
||||
access, err := svc.tokenizer.Issue(key)
|
||||
if err != nil {
|
||||
return Token{}, errors.Wrap(errIssueTmp, err)
|
||||
}
|
||||
|
||||
key.ExpiresAt = time.Now().Add(svc.refreshDuration)
|
||||
key.ExpiresAt = time.Now().UTC().Add(svc.refreshDuration)
|
||||
key.Type = RefreshKey
|
||||
refresh, err := svc.tokenizer.Issue(key)
|
||||
if err != nil {
|
||||
@@ -478,7 +478,7 @@ func (svc service) CreatePAT(ctx context.Context, token, name, description strin
|
||||
return PAT{}, errors.Wrap(svcerr.ErrCreateEntity, err)
|
||||
}
|
||||
|
||||
now := time.Now()
|
||||
now := time.Now().UTC()
|
||||
pat := PAT{
|
||||
ID: id,
|
||||
User: key.Subject,
|
||||
@@ -570,7 +570,7 @@ func (svc service) ResetPATSecret(ctx context.Context, token, patID string, dura
|
||||
return PAT{}, errors.Wrap(svcerr.ErrUpdateEntity, err)
|
||||
}
|
||||
|
||||
pat, err := svc.pats.UpdateTokenHash(ctx, key.Subject, patID, hash, time.Now().Add(duration))
|
||||
pat, err := svc.pats.UpdateTokenHash(ctx, key.Subject, patID, hash, time.Now().UTC().Add(duration))
|
||||
if err != nil {
|
||||
return PAT{}, errors.Wrap(svcerr.ErrUpdateEntity, err)
|
||||
}
|
||||
|
||||
+1
-1
@@ -107,7 +107,7 @@ func (cs *certsService) RevokeCert(ctx context.Context, domainID, token, clientI
|
||||
if err != nil {
|
||||
return revoke, errors.Wrap(ErrFailedCertRevocation, err)
|
||||
}
|
||||
revoke.RevocationTime = time.Now()
|
||||
revoke.RevocationTime = time.Now().UTC()
|
||||
}
|
||||
|
||||
return revoke, nil
|
||||
|
||||
+7
-7
@@ -70,7 +70,7 @@ func (svc service) CreateChannels(ctx context.Context, session authn.Session, ch
|
||||
return []Channel{}, []roles.RoleProvision{}, svcerr.ErrInvalidStatus
|
||||
}
|
||||
c.Domain = session.DomainID
|
||||
c.CreatedAt = time.Now()
|
||||
c.CreatedAt = time.Now().UTC()
|
||||
reChs = append(reChs, c)
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ func (svc service) UpdateChannel(ctx context.Context, session authn.Session, ch
|
||||
ID: ch.ID,
|
||||
Name: ch.Name,
|
||||
Metadata: ch.Metadata,
|
||||
UpdatedAt: time.Now(),
|
||||
UpdatedAt: time.Now().UTC(),
|
||||
UpdatedBy: session.UserID,
|
||||
}
|
||||
channel, err := svc.repo.Update(ctx, channel)
|
||||
@@ -134,7 +134,7 @@ func (svc service) UpdateChannelTags(ctx context.Context, session authn.Session,
|
||||
channel := Channel{
|
||||
ID: ch.ID,
|
||||
Tags: ch.Tags,
|
||||
UpdatedAt: time.Now(),
|
||||
UpdatedAt: time.Now().UTC(),
|
||||
UpdatedBy: session.UserID,
|
||||
}
|
||||
channel, err := svc.repo.UpdateTags(ctx, channel)
|
||||
@@ -148,7 +148,7 @@ func (svc service) EnableChannel(ctx context.Context, session authn.Session, id
|
||||
channel := Channel{
|
||||
ID: id,
|
||||
Status: EnabledStatus,
|
||||
UpdatedAt: time.Now(),
|
||||
UpdatedAt: time.Now().UTC(),
|
||||
}
|
||||
ch, err := svc.changeChannelStatus(ctx, session.UserID, channel)
|
||||
if err != nil {
|
||||
@@ -162,7 +162,7 @@ func (svc service) DisableChannel(ctx context.Context, session authn.Session, id
|
||||
channel := Channel{
|
||||
ID: id,
|
||||
Status: DisabledStatus,
|
||||
UpdatedAt: time.Now(),
|
||||
UpdatedAt: time.Now().UTC(),
|
||||
}
|
||||
ch, err := svc.changeChannelStatus(ctx, session.UserID, channel)
|
||||
if err != nil {
|
||||
@@ -432,7 +432,7 @@ func (svc service) SetParentGroup(ctx context.Context, session authn.Session, pa
|
||||
}
|
||||
}
|
||||
}()
|
||||
ch = Channel{ID: id, ParentGroup: parentGroupID, UpdatedBy: session.UserID, UpdatedAt: time.Now()}
|
||||
ch = Channel{ID: id, ParentGroup: parentGroupID, UpdatedBy: session.UserID, UpdatedAt: time.Now().UTC()}
|
||||
|
||||
if err := svc.repo.SetParentGroup(ctx, ch); err != nil {
|
||||
return errors.Wrap(svcerr.ErrUpdateEntity, err)
|
||||
@@ -468,7 +468,7 @@ func (svc service) RemoveParentGroup(ctx context.Context, session authn.Session,
|
||||
}
|
||||
}()
|
||||
|
||||
ch := Channel{ID: id, UpdatedBy: session.UserID, UpdatedAt: time.Now()}
|
||||
ch := Channel{ID: id, UpdatedBy: session.UserID, UpdatedAt: time.Now().UTC()}
|
||||
|
||||
if err := svc.repo.RemoveParentGroup(ctx, ch); err != nil {
|
||||
return err
|
||||
|
||||
+8
-8
@@ -73,7 +73,7 @@ func (svc service) CreateClients(ctx context.Context, session authn.Session, cls
|
||||
return []Client{}, []roles.RoleProvision{}, svcerr.ErrInvalidStatus
|
||||
}
|
||||
c.Domain = session.DomainID
|
||||
c.CreatedAt = time.Now()
|
||||
c.CreatedAt = time.Now().UTC()
|
||||
clients = append(clients, c)
|
||||
}
|
||||
|
||||
@@ -166,7 +166,7 @@ func (svc service) Update(ctx context.Context, session authn.Session, cli Client
|
||||
ID: cli.ID,
|
||||
Name: cli.Name,
|
||||
Metadata: cli.Metadata,
|
||||
UpdatedAt: time.Now(),
|
||||
UpdatedAt: time.Now().UTC(),
|
||||
UpdatedBy: session.UserID,
|
||||
}
|
||||
client, err := svc.repo.Update(ctx, client)
|
||||
@@ -180,7 +180,7 @@ func (svc service) UpdateTags(ctx context.Context, session authn.Session, cli Cl
|
||||
client := Client{
|
||||
ID: cli.ID,
|
||||
Tags: cli.Tags,
|
||||
UpdatedAt: time.Now(),
|
||||
UpdatedAt: time.Now().UTC(),
|
||||
UpdatedBy: session.UserID,
|
||||
}
|
||||
client, err := svc.repo.UpdateTags(ctx, client)
|
||||
@@ -196,7 +196,7 @@ func (svc service) UpdateSecret(ctx context.Context, session authn.Session, id,
|
||||
Credentials: Credentials{
|
||||
Secret: key,
|
||||
},
|
||||
UpdatedAt: time.Now(),
|
||||
UpdatedAt: time.Now().UTC(),
|
||||
UpdatedBy: session.UserID,
|
||||
Status: EnabledStatus,
|
||||
}
|
||||
@@ -211,7 +211,7 @@ func (svc service) Enable(ctx context.Context, session authn.Session, id string)
|
||||
client := Client{
|
||||
ID: id,
|
||||
Status: EnabledStatus,
|
||||
UpdatedAt: time.Now(),
|
||||
UpdatedAt: time.Now().UTC(),
|
||||
}
|
||||
client, err := svc.changeClientStatus(ctx, session, client)
|
||||
if err != nil {
|
||||
@@ -225,7 +225,7 @@ func (svc service) Disable(ctx context.Context, session authn.Session, id string
|
||||
client := Client{
|
||||
ID: id,
|
||||
Status: DisabledStatus,
|
||||
UpdatedAt: time.Now(),
|
||||
UpdatedAt: time.Now().UTC(),
|
||||
}
|
||||
client, err := svc.changeClientStatus(ctx, session, client)
|
||||
if err != nil {
|
||||
@@ -285,7 +285,7 @@ func (svc service) SetParentGroup(ctx context.Context, session authn.Session, pa
|
||||
}
|
||||
}
|
||||
}()
|
||||
cli = Client{ID: id, ParentGroup: parentGroupID, UpdatedBy: session.UserID, UpdatedAt: time.Now()}
|
||||
cli = Client{ID: id, ParentGroup: parentGroupID, UpdatedBy: session.UserID, UpdatedAt: time.Now().UTC()}
|
||||
|
||||
if err := svc.repo.SetParentGroup(ctx, cli); err != nil {
|
||||
return errors.Wrap(svcerr.ErrUpdateEntity, err)
|
||||
@@ -321,7 +321,7 @@ func (svc service) RemoveParentGroup(ctx context.Context, session authn.Session,
|
||||
}
|
||||
}()
|
||||
|
||||
cli := Client{ID: id, UpdatedBy: session.UserID, UpdatedAt: time.Now()}
|
||||
cli := Client{ID: id, UpdatedBy: session.UserID, UpdatedAt: time.Now().UTC()}
|
||||
|
||||
if err := svc.repo.RemoveParentGroup(ctx, cli); err != nil {
|
||||
return err
|
||||
|
||||
+2
-2
@@ -317,8 +317,8 @@ func createAdmin(ctx context.Context, c config, repo users.Repository, hsr users
|
||||
Metadata: users.Metadata{
|
||||
"role": "admin",
|
||||
},
|
||||
CreatedAt: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
CreatedAt: time.Now().UTC(),
|
||||
UpdatedAt: time.Now().UTC(),
|
||||
Role: users.AdminRole,
|
||||
Status: users.EnabledStatus,
|
||||
}
|
||||
|
||||
@@ -402,7 +402,7 @@ func (repo domainRepo) UpdateDomain(ctx context.Context, id string, dr domains.D
|
||||
query = append(query, "status = :status")
|
||||
d.Status = *dr.Status
|
||||
}
|
||||
d.UpdatedAt = time.Now()
|
||||
d.UpdatedAt = time.Now().UTC()
|
||||
if dr.UpdatedAt != nil {
|
||||
query = append(query, "updated_at = :updated_at")
|
||||
d.UpdatedAt = *dr.UpdatedAt
|
||||
|
||||
+5
-6
@@ -61,7 +61,7 @@ func (svc service) CreateDomain(ctx context.Context, session authn.Session, d Do
|
||||
return Domain{}, []roles.RoleProvision{}, svcerr.ErrInvalidStatus
|
||||
}
|
||||
|
||||
d.CreatedAt = time.Now()
|
||||
d.CreatedAt = time.Now().UTC()
|
||||
|
||||
// Domain is created in repo first, because Roles table have foreign key relation with Domain ID
|
||||
dom, err := svc.repo.SaveDomain(ctx, d)
|
||||
@@ -119,7 +119,7 @@ func (svc service) RetrieveDomain(ctx context.Context, session authn.Session, id
|
||||
}
|
||||
|
||||
func (svc service) UpdateDomain(ctx context.Context, session authn.Session, id string, d DomainReq) (Domain, error) {
|
||||
updatedAt := time.Now()
|
||||
updatedAt := time.Now().UTC()
|
||||
d.UpdatedAt = &updatedAt
|
||||
d.UpdatedBy = &session.UserID
|
||||
dom, err := svc.repo.UpdateDomain(ctx, id, d)
|
||||
@@ -131,7 +131,7 @@ func (svc service) UpdateDomain(ctx context.Context, session authn.Session, id s
|
||||
|
||||
func (svc service) EnableDomain(ctx context.Context, session authn.Session, id string) (Domain, error) {
|
||||
status := EnabledStatus
|
||||
updatedAt := time.Now()
|
||||
updatedAt := time.Now().UTC()
|
||||
dom, err := svc.repo.UpdateDomain(ctx, id, DomainReq{Status: &status, UpdatedBy: &session.UserID, UpdatedAt: &updatedAt})
|
||||
if err != nil {
|
||||
return Domain{}, errors.Wrap(svcerr.ErrUpdateEntity, err)
|
||||
@@ -145,7 +145,7 @@ func (svc service) EnableDomain(ctx context.Context, session authn.Session, id s
|
||||
|
||||
func (svc service) DisableDomain(ctx context.Context, session authn.Session, id string) (Domain, error) {
|
||||
status := DisabledStatus
|
||||
updatedAt := time.Now()
|
||||
updatedAt := time.Now().UTC()
|
||||
dom, err := svc.repo.UpdateDomain(ctx, id, DomainReq{Status: &status, UpdatedBy: &session.UserID, UpdatedAt: &updatedAt})
|
||||
if err != nil {
|
||||
return Domain{}, errors.Wrap(svcerr.ErrUpdateEntity, err)
|
||||
@@ -160,7 +160,7 @@ func (svc service) DisableDomain(ctx context.Context, session authn.Session, id
|
||||
// Only SuperAdmin can freeze the domain.
|
||||
func (svc service) FreezeDomain(ctx context.Context, session authn.Session, id string) (Domain, error) {
|
||||
status := FreezeStatus
|
||||
updatedAt := time.Now()
|
||||
updatedAt := time.Now().UTC()
|
||||
dom, err := svc.repo.UpdateDomain(ctx, id, DomainReq{Status: &status, UpdatedBy: &session.UserID, UpdatedAt: &updatedAt})
|
||||
if err != nil {
|
||||
return Domain{}, errors.Wrap(svcerr.ErrUpdateEntity, err)
|
||||
@@ -190,7 +190,6 @@ func (svc *service) SendInvitation(ctx context.Context, session authn.Session, i
|
||||
return errors.Wrap(svcerr.ErrInvalidRole, err)
|
||||
}
|
||||
invitation.InvitedBy = session.UserID
|
||||
|
||||
invitation.CreatedAt = time.Now().UTC()
|
||||
|
||||
if invitation.Resend {
|
||||
|
||||
+4
-4
@@ -57,7 +57,7 @@ func (svc service) CreateGroup(ctx context.Context, session smqauthn.Session, g
|
||||
}
|
||||
|
||||
g.ID = groupID
|
||||
g.CreatedAt = time.Now()
|
||||
g.CreatedAt = time.Now().UTC()
|
||||
g.Domain = session.DomainID
|
||||
|
||||
saved, err := svc.repo.Save(ctx, g)
|
||||
@@ -148,7 +148,7 @@ func (svc service) ListUserGroups(ctx context.Context, session smqauthn.Session,
|
||||
}
|
||||
|
||||
func (svc service) UpdateGroup(ctx context.Context, session smqauthn.Session, g Group) (Group, error) {
|
||||
g.UpdatedAt = time.Now()
|
||||
g.UpdatedAt = time.Now().UTC()
|
||||
g.UpdatedBy = session.UserID
|
||||
|
||||
group, err := svc.repo.Update(ctx, g)
|
||||
@@ -162,7 +162,7 @@ func (svc service) EnableGroup(ctx context.Context, session smqauthn.Session, id
|
||||
group := Group{
|
||||
ID: id,
|
||||
Status: EnabledStatus,
|
||||
UpdatedAt: time.Now(),
|
||||
UpdatedAt: time.Now().UTC(),
|
||||
}
|
||||
group, err := svc.changeGroupStatus(ctx, session, group)
|
||||
if err != nil {
|
||||
@@ -175,7 +175,7 @@ func (svc service) DisableGroup(ctx context.Context, session smqauthn.Session, i
|
||||
group := Group{
|
||||
ID: id,
|
||||
Status: DisabledStatus,
|
||||
UpdatedAt: time.Now(),
|
||||
UpdatedAt: time.Now().UTC(),
|
||||
}
|
||||
group, err := svc.changeGroupStatus(ctx, session, group)
|
||||
if err != nil {
|
||||
|
||||
@@ -136,7 +136,7 @@ type dbJournal struct {
|
||||
|
||||
func toDBJournal(j journal.Journal) (dbJournal, error) {
|
||||
if j.OccurredAt.IsZero() {
|
||||
j.OccurredAt = time.Now()
|
||||
j.OccurredAt = time.Now().UTC()
|
||||
}
|
||||
|
||||
attributes := []byte("{}")
|
||||
|
||||
@@ -5,6 +5,7 @@ package postgres
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/absmach/supermq/pkg/errors"
|
||||
_ "github.com/jackc/pgx/v5/stdlib" // required for SQL access
|
||||
@@ -60,6 +61,9 @@ func Connect(cfg Config) (*sqlx.DB, error) {
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(errConnect, err)
|
||||
}
|
||||
|
||||
db.SetConnMaxLifetime(time.Hour)
|
||||
db.SetConnMaxIdleTime(time.Minute)
|
||||
db.SetMaxIdleConns(10)
|
||||
db.SetMaxOpenConns(20)
|
||||
return db, nil
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/jmoiron/sqlx"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
@@ -48,6 +49,9 @@ type Database interface {
|
||||
|
||||
// NewDatabase creates a Clients'Database instance.
|
||||
func NewDatabase(db *sqlx.DB, config Config, tracer trace.Tracer) Database {
|
||||
db.SetMaxIdleConns(10)
|
||||
db.SetConnMaxIdleTime(5 * time.Minute)
|
||||
db.SetMaxOpenConns(1000)
|
||||
database := &database{
|
||||
Config: config,
|
||||
db: db,
|
||||
|
||||
@@ -166,7 +166,7 @@ func (r ProvisionManageService) AddNewEntitiesRoles(ctx context.Context, domainI
|
||||
ID: id,
|
||||
Name: defaultRole.String(),
|
||||
EntityID: entityID,
|
||||
CreatedAt: time.Now(),
|
||||
CreatedAt: time.Now().UTC(),
|
||||
CreatedBy: userID,
|
||||
},
|
||||
OptionalActions: caps,
|
||||
@@ -236,7 +236,7 @@ func (r ProvisionManageService) AddRole(ctx context.Context, session authn.Sessi
|
||||
ID: id,
|
||||
Name: roleName,
|
||||
EntityID: entityID,
|
||||
CreatedAt: time.Now(),
|
||||
CreatedAt: time.Now().UTC(),
|
||||
CreatedBy: session.UserID,
|
||||
},
|
||||
OptionalActions: optionalActions,
|
||||
@@ -321,7 +321,7 @@ func (r ProvisionManageService) UpdateRoleName(ctx context.Context, session auth
|
||||
EntityID: entityID,
|
||||
Name: newRoleName,
|
||||
UpdatedBy: session.UserID,
|
||||
UpdatedAt: time.Now(),
|
||||
UpdatedAt: time.Now().UTC(),
|
||||
})
|
||||
if err != nil {
|
||||
return Role{}, errors.Wrap(svcerr.ErrUpdateEntity, err)
|
||||
@@ -391,7 +391,7 @@ func (r ProvisionManageService) RoleAddActions(ctx context.Context, session auth
|
||||
}
|
||||
}()
|
||||
|
||||
ro.UpdatedAt = time.Now()
|
||||
ro.UpdatedAt = time.Now().UTC()
|
||||
ro.UpdatedBy = session.UserID
|
||||
|
||||
resActs, err := r.repo.RoleAddActions(ctx, ro, actions)
|
||||
@@ -452,7 +452,7 @@ func (r ProvisionManageService) RoleRemoveActions(ctx context.Context, session a
|
||||
if err := r.policy.DeletePolicies(ctx, prs); err != nil {
|
||||
return errors.Wrap(svcerr.ErrDeletePolicies, err)
|
||||
}
|
||||
ro.UpdatedAt = time.Now()
|
||||
ro.UpdatedAt = time.Now().UTC()
|
||||
ro.UpdatedBy = session.UserID
|
||||
if err := r.repo.RoleRemoveActions(ctx, ro, actions); err != nil {
|
||||
return errors.Wrap(svcerr.ErrRemoveEntity, err)
|
||||
@@ -475,7 +475,7 @@ func (r ProvisionManageService) RoleRemoveAllActions(ctx context.Context, sessio
|
||||
return errors.Wrap(svcerr.ErrDeletePolicies, err)
|
||||
}
|
||||
|
||||
ro.UpdatedAt = time.Now()
|
||||
ro.UpdatedAt = time.Now().UTC()
|
||||
ro.UpdatedBy = session.UserID
|
||||
|
||||
if err := r.repo.RoleRemoveAllActions(ctx, ro); err != nil {
|
||||
@@ -517,7 +517,7 @@ func (r ProvisionManageService) RoleAddMembers(ctx context.Context, session auth
|
||||
}
|
||||
}()
|
||||
|
||||
ro.UpdatedAt = time.Now()
|
||||
ro.UpdatedAt = time.Now().UTC()
|
||||
ro.UpdatedBy = session.UserID
|
||||
|
||||
mems, err := r.repo.RoleAddMembers(ctx, ro, members)
|
||||
@@ -578,7 +578,7 @@ func (r ProvisionManageService) RoleRemoveMembers(ctx context.Context, session a
|
||||
return errors.Wrap(svcerr.ErrDeletePolicies, err)
|
||||
}
|
||||
|
||||
ro.UpdatedAt = time.Now()
|
||||
ro.UpdatedAt = time.Now().UTC()
|
||||
ro.UpdatedBy = session.UserID
|
||||
if err := r.repo.RoleRemoveMembers(ctx, ro, members); err != nil {
|
||||
return errors.Wrap(svcerr.ErrRemoveEntity, err)
|
||||
@@ -602,7 +602,7 @@ func (r ProvisionManageService) RoleRemoveAllMembers(ctx context.Context, sessio
|
||||
return errors.Wrap(svcerr.ErrDeletePolicies, err)
|
||||
}
|
||||
|
||||
ro.UpdatedAt = time.Now()
|
||||
ro.UpdatedAt = time.Now().UTC()
|
||||
ro.UpdatedBy = session.UserID
|
||||
|
||||
if err := r.repo.RoleRemoveAllMembers(ctx, ro); err != nil {
|
||||
|
||||
@@ -185,7 +185,7 @@ func (repo *userRepo) UpdateUsername(ctx context.Context, user users.User) (user
|
||||
dbu = DBUser{
|
||||
ID: user.ID,
|
||||
Username: stringToNullString(user.Credentials.Username),
|
||||
UpdatedAt: sql.NullTime{Time: time.Now(), Valid: true},
|
||||
UpdatedAt: sql.NullTime{Time: time.Now().UTC(), Valid: true},
|
||||
}
|
||||
|
||||
if ok := row.Next(); !ok {
|
||||
|
||||
+11
-11
@@ -73,7 +73,7 @@ func (svc service) Register(ctx context.Context, session authn.Session, u User,
|
||||
return User{}, errors.Wrap(svcerr.ErrMalformedEntity, svcerr.ErrInvalidRole)
|
||||
}
|
||||
u.ID = userID
|
||||
u.CreatedAt = time.Now()
|
||||
u.CreatedAt = time.Now().UTC()
|
||||
|
||||
if err := svc.addUserPolicy(ctx, u.ID, u.Role); err != nil {
|
||||
return User{}, err
|
||||
@@ -207,7 +207,7 @@ func (svc service) Update(ctx context.Context, session authn.Session, usr User)
|
||||
LastName: usr.LastName,
|
||||
Metadata: usr.Metadata,
|
||||
Role: AllRole,
|
||||
UpdatedAt: time.Now(),
|
||||
UpdatedAt: time.Now().UTC(),
|
||||
UpdatedBy: session.UserID,
|
||||
}
|
||||
|
||||
@@ -229,7 +229,7 @@ func (svc service) UpdateTags(ctx context.Context, session authn.Session, usr Us
|
||||
ID: usr.ID,
|
||||
Tags: usr.Tags,
|
||||
Role: AllRole,
|
||||
UpdatedAt: time.Now(),
|
||||
UpdatedAt: time.Now().UTC(),
|
||||
UpdatedBy: session.UserID,
|
||||
}
|
||||
user, err := svc.users.Update(ctx, user)
|
||||
@@ -274,7 +274,7 @@ func (svc service) UpdateEmail(ctx context.Context, session authn.Session, userI
|
||||
ID: userID,
|
||||
Email: email,
|
||||
Role: AllRole,
|
||||
UpdatedAt: time.Now(),
|
||||
UpdatedAt: time.Now().UTC(),
|
||||
UpdatedBy: session.UserID,
|
||||
}
|
||||
user, err := svc.users.Update(ctx, user)
|
||||
@@ -317,7 +317,7 @@ func (svc service) ResetSecret(ctx context.Context, session authn.Session, secre
|
||||
Credentials: Credentials{
|
||||
Secret: secret,
|
||||
},
|
||||
UpdatedAt: time.Now(),
|
||||
UpdatedAt: time.Now().UTC(),
|
||||
UpdatedBy: session.UserID,
|
||||
}
|
||||
if _, err := svc.users.UpdateSecret(ctx, u); err != nil {
|
||||
@@ -339,7 +339,7 @@ func (svc service) UpdateSecret(ctx context.Context, session authn.Session, oldS
|
||||
return User{}, errors.Wrap(svcerr.ErrMalformedEntity, err)
|
||||
}
|
||||
dbUser.Credentials.Secret = newSecret
|
||||
dbUser.UpdatedAt = time.Now()
|
||||
dbUser.UpdatedAt = time.Now().UTC()
|
||||
dbUser.UpdatedBy = session.UserID
|
||||
|
||||
dbUser, err = svc.users.UpdateSecret(ctx, dbUser)
|
||||
@@ -362,7 +362,7 @@ func (svc service) UpdateUsername(ctx context.Context, session authn.Session, id
|
||||
Credentials: Credentials{
|
||||
Username: username,
|
||||
},
|
||||
UpdatedAt: time.Now(),
|
||||
UpdatedAt: time.Now().UTC(),
|
||||
UpdatedBy: session.UserID,
|
||||
}
|
||||
updatedUser, err := svc.users.UpdateUsername(ctx, usr)
|
||||
@@ -384,7 +384,7 @@ func (svc service) UpdateRole(ctx context.Context, session authn.Session, usr Us
|
||||
user := User{
|
||||
ID: usr.ID,
|
||||
Role: usr.Role,
|
||||
UpdatedAt: time.Now(),
|
||||
UpdatedAt: time.Now().UTC(),
|
||||
UpdatedBy: session.UserID,
|
||||
}
|
||||
|
||||
@@ -406,7 +406,7 @@ func (svc service) UpdateRole(ctx context.Context, session authn.Session, usr Us
|
||||
func (svc service) Enable(ctx context.Context, session authn.Session, id string) (User, error) {
|
||||
u := User{
|
||||
ID: id,
|
||||
UpdatedAt: time.Now(),
|
||||
UpdatedAt: time.Now().UTC(),
|
||||
Status: EnabledStatus,
|
||||
}
|
||||
user, err := svc.changeUserStatus(ctx, session, u)
|
||||
@@ -420,7 +420,7 @@ func (svc service) Enable(ctx context.Context, session authn.Session, id string)
|
||||
func (svc service) Disable(ctx context.Context, session authn.Session, id string) (User, error) {
|
||||
user := User{
|
||||
ID: id,
|
||||
UpdatedAt: time.Now(),
|
||||
UpdatedAt: time.Now().UTC(),
|
||||
Status: DisabledStatus,
|
||||
}
|
||||
user, err := svc.changeUserStatus(ctx, session, user)
|
||||
@@ -456,7 +456,7 @@ func (svc service) changeUserStatus(ctx context.Context, session authn.Session,
|
||||
func (svc service) Delete(ctx context.Context, session authn.Session, id string) error {
|
||||
user := User{
|
||||
ID: id,
|
||||
UpdatedAt: time.Now(),
|
||||
UpdatedAt: time.Now().UTC(),
|
||||
Status: DeletedStatus,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user