2020-05-18 10:06:36 +00:00
|
|
|
package view
|
|
|
|
|
|
|
|
import (
|
2020-10-15 11:52:41 +00:00
|
|
|
usr_view "github.com/caos/zitadel/internal/user/repository/view"
|
|
|
|
"github.com/caos/zitadel/internal/user/repository/view/model"
|
2020-06-25 06:01:13 +00:00
|
|
|
"github.com/caos/zitadel/internal/view/repository"
|
2020-12-02 07:50:59 +00:00
|
|
|
"time"
|
2020-05-18 10:06:36 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
tokenTable = "auth.tokens"
|
|
|
|
)
|
|
|
|
|
2020-10-15 11:52:41 +00:00
|
|
|
func (v *View) TokenByID(tokenID string) (*model.TokenView, error) {
|
|
|
|
return usr_view.TokenByID(v.Db, tokenTable, tokenID)
|
2020-05-18 10:06:36 +00:00
|
|
|
}
|
|
|
|
|
2020-10-15 11:52:41 +00:00
|
|
|
func (v *View) TokensByUserID(userID string) ([]*model.TokenView, error) {
|
|
|
|
return usr_view.TokensByUserID(v.Db, tokenTable, userID)
|
2020-05-18 10:06:36 +00:00
|
|
|
}
|
|
|
|
|
2020-12-02 07:50:59 +00:00
|
|
|
func (v *View) PutToken(token *model.TokenView, eventTimestamp time.Time) error {
|
2020-10-15 11:52:41 +00:00
|
|
|
err := usr_view.PutToken(v.Db, tokenTable, token)
|
2020-05-18 10:06:36 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-12-02 07:50:59 +00:00
|
|
|
return v.ProcessedTokenSequence(token.Sequence, eventTimestamp)
|
2020-05-18 10:06:36 +00:00
|
|
|
}
|
|
|
|
|
2020-12-02 07:50:59 +00:00
|
|
|
func (v *View) PutTokens(token []*model.TokenView, sequence uint64, eventTimestamp time.Time) error {
|
2020-10-15 11:52:41 +00:00
|
|
|
err := usr_view.PutTokens(v.Db, tokenTable, token...)
|
2020-08-28 07:44:43 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-12-02 07:50:59 +00:00
|
|
|
return v.ProcessedTokenSequence(sequence, eventTimestamp)
|
2020-08-28 07:44:43 +00:00
|
|
|
}
|
|
|
|
|
2020-12-02 07:50:59 +00:00
|
|
|
func (v *View) DeleteToken(tokenID string, eventSequence uint64, eventTimestamp time.Time) error {
|
2020-10-15 11:52:41 +00:00
|
|
|
err := usr_view.DeleteToken(v.Db, tokenTable, tokenID)
|
2020-05-18 10:06:36 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil
|
|
|
|
}
|
2020-12-02 07:50:59 +00:00
|
|
|
return v.ProcessedTokenSequence(eventSequence, eventTimestamp)
|
2020-05-18 10:06:36 +00:00
|
|
|
}
|
|
|
|
|
2020-12-02 07:50:59 +00:00
|
|
|
func (v *View) DeleteSessionTokens(agentID, userID string, eventSequence uint64, eventTimestamp time.Time) error {
|
2020-10-15 11:52:41 +00:00
|
|
|
err := usr_view.DeleteSessionTokens(v.Db, tokenTable, agentID, userID)
|
2020-06-19 12:52:04 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil
|
|
|
|
}
|
2020-12-02 07:50:59 +00:00
|
|
|
return v.ProcessedTokenSequence(eventSequence, eventTimestamp)
|
2020-06-19 12:52:04 +00:00
|
|
|
}
|
|
|
|
|
2020-12-02 07:50:59 +00:00
|
|
|
func (v *View) DeleteUserTokens(userID string, eventSequence uint64, eventTimestamp time.Time) error {
|
2020-10-15 11:52:41 +00:00
|
|
|
err := usr_view.DeleteUserTokens(v.Db, tokenTable, userID)
|
2020-06-19 12:52:04 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil
|
|
|
|
}
|
2020-12-02 07:50:59 +00:00
|
|
|
return v.ProcessedTokenSequence(eventSequence, eventTimestamp)
|
2020-06-19 12:52:04 +00:00
|
|
|
}
|
|
|
|
|
2020-12-02 07:50:59 +00:00
|
|
|
func (v *View) DeleteApplicationTokens(eventSequence uint64, eventTimestamp time.Time, ids ...string) error {
|
2020-10-15 11:52:41 +00:00
|
|
|
err := usr_view.DeleteApplicationTokens(v.Db, tokenTable, ids)
|
2020-05-18 10:06:36 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil
|
|
|
|
}
|
2020-12-02 07:50:59 +00:00
|
|
|
return v.ProcessedTokenSequence(eventSequence, eventTimestamp)
|
2020-05-18 10:06:36 +00:00
|
|
|
}
|
|
|
|
|
2020-07-15 11:24:36 +00:00
|
|
|
func (v *View) GetLatestTokenSequence() (*repository.CurrentSequence, error) {
|
2020-05-18 10:06:36 +00:00
|
|
|
return v.latestSequence(tokenTable)
|
|
|
|
}
|
|
|
|
|
2020-12-02 07:50:59 +00:00
|
|
|
func (v *View) ProcessedTokenSequence(eventSequence uint64, eventTimestamp time.Time) error {
|
|
|
|
return v.saveCurrentSequence(tokenTable, eventSequence, eventTimestamp)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *View) UpdateTokenSpoolerRunTimestamp() error {
|
|
|
|
return v.updateSpoolerRunSequence(tokenTable)
|
2020-05-18 10:06:36 +00:00
|
|
|
}
|
|
|
|
|
2020-06-25 06:01:13 +00:00
|
|
|
func (v *View) GetLatestTokenFailedEvent(sequence uint64) (*repository.FailedEvent, error) {
|
2020-05-18 10:06:36 +00:00
|
|
|
return v.latestFailedEvent(tokenTable, sequence)
|
|
|
|
}
|
|
|
|
|
2020-06-25 06:01:13 +00:00
|
|
|
func (v *View) ProcessedTokenFailedEvent(failedEvent *repository.FailedEvent) error {
|
2020-05-18 10:06:36 +00:00
|
|
|
return v.saveFailedEvent(failedEvent)
|
|
|
|
}
|