mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-13 03:24:26 +00:00
fix: save creation and change date of auth requests in db (#2429)
* fix: save creation and change date of auth requests in db (prepare for cleanup) * Update cache.go
This commit is contained in:
parent
583b1c42d4
commit
b96291ec8d
14
internal/auth_request/repository/cache/cache.go
vendored
14
internal/auth_request/repository/cache/cache.go
vendored
@ -6,9 +6,10 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"time"
|
||||
|
||||
"github.com/caos/zitadel/internal/config/types"
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
caos_errs "github.com/caos/zitadel/internal/errors"
|
||||
)
|
||||
|
||||
@ -43,11 +44,14 @@ func (c *AuthRequestCache) GetAuthRequestByCode(_ context.Context, code string)
|
||||
}
|
||||
|
||||
func (c *AuthRequestCache) SaveAuthRequest(_ context.Context, request *domain.AuthRequest) error {
|
||||
return c.saveAuthRequest(request, "INSERT INTO auth.auth_requests (id, request, request_type) VALUES($1, $2, $3)", request.Request.Type())
|
||||
return c.saveAuthRequest(request, "INSERT INTO auth.auth_requests (id, request, creation_date, change_date, request_type) VALUES($1, $2, $3, $3, $4)", request.CreationDate, request.Request.Type())
|
||||
}
|
||||
|
||||
func (c *AuthRequestCache) UpdateAuthRequest(_ context.Context, request *domain.AuthRequest) error {
|
||||
return c.saveAuthRequest(request, "UPDATE auth.auth_requests SET request = $2, code = $3 WHERE id = $1", request.Code)
|
||||
if request.ChangeDate.IsZero() {
|
||||
request.ChangeDate = time.Now()
|
||||
}
|
||||
return c.saveAuthRequest(request, "UPDATE auth.auth_requests SET request = $2, change_date = $3, code = $4 WHERE id = $1", request.ChangeDate, request.Code)
|
||||
}
|
||||
|
||||
func (c *AuthRequestCache) DeleteAuthRequest(_ context.Context, id string) error {
|
||||
@ -79,7 +83,7 @@ func (c *AuthRequestCache) getAuthRequest(key, value string) (*domain.AuthReques
|
||||
return request, nil
|
||||
}
|
||||
|
||||
func (c *AuthRequestCache) saveAuthRequest(request *domain.AuthRequest, query string, param interface{}) error {
|
||||
func (c *AuthRequestCache) saveAuthRequest(request *domain.AuthRequest, query string, date time.Time, param interface{}) error {
|
||||
b, err := json.Marshal(request)
|
||||
if err != nil {
|
||||
return caos_errs.ThrowInternal(err, "CACHE-os0GH", "Errors.Internal")
|
||||
@ -88,7 +92,7 @@ func (c *AuthRequestCache) saveAuthRequest(request *domain.AuthRequest, query st
|
||||
if err != nil {
|
||||
return caos_errs.ThrowInternal(err, "CACHE-su3GK", "Errors.Internal")
|
||||
}
|
||||
_, err = stmt.Exec(request.ID, b, param)
|
||||
_, err = stmt.Exec(request.ID, b, date, param)
|
||||
if err != nil {
|
||||
return caos_errs.ThrowInternal(err, "CACHE-sj8iS", "Errors.Internal")
|
||||
}
|
||||
|
2
migrations/cockroach/V1.73__auth_request_times.sql
Normal file
2
migrations/cockroach/V1.73__auth_request_times.sql
Normal file
@ -0,0 +1,2 @@
|
||||
ALTER TABLE auth.auth_requests ADD COLUMN creation_data TIMESTAMPTZ;
|
||||
ALTER TABLE auth.auth_requests ADD COLUMN change_data TIMESTAMPTZ;
|
Loading…
Reference in New Issue
Block a user