2020-05-18 10:06:36 +00:00
|
|
|
package view
|
|
|
|
|
|
|
|
import (
|
2022-04-26 23:01:45 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/errors"
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
|
|
|
|
usr_view "github.com/zitadel/zitadel/internal/user/repository/view"
|
|
|
|
"github.com/zitadel/zitadel/internal/user/repository/view/model"
|
|
|
|
"github.com/zitadel/zitadel/internal/view/repository"
|
2020-05-18 10:06:36 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
tokenTable = "auth.tokens"
|
|
|
|
)
|
|
|
|
|
2022-09-15 12:59:40 +00:00
|
|
|
func (v *View) TokenByIDs(tokenID, userID, instanceID string) (*model.TokenView, error) {
|
|
|
|
return usr_view.TokenByIDs(v.Db, tokenTable, tokenID, userID, instanceID)
|
2020-05-18 10:06:36 +00:00
|
|
|
}
|
|
|
|
|
2022-04-19 06:26:12 +00:00
|
|
|
func (v *View) TokensByUserID(userID, instanceID string) ([]*model.TokenView, error) {
|
|
|
|
return usr_view.TokensByUserID(v.Db, tokenTable, userID, instanceID)
|
2020-05-18 10:06:36 +00:00
|
|
|
}
|
|
|
|
|
2020-12-18 15:47:45 +00:00
|
|
|
func (v *View) PutToken(token *model.TokenView, event *models.Event) 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-18 15:47:45 +00:00
|
|
|
return v.ProcessedTokenSequence(event)
|
2020-05-18 10:06:36 +00:00
|
|
|
}
|
|
|
|
|
2020-12-18 15:47:45 +00:00
|
|
|
func (v *View) PutTokens(token []*model.TokenView, event *models.Event) 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-18 15:47:45 +00:00
|
|
|
return v.ProcessedTokenSequence(event)
|
2020-08-28 07:44:43 +00:00
|
|
|
}
|
|
|
|
|
2022-04-19 06:26:12 +00:00
|
|
|
func (v *View) DeleteToken(tokenID, instanceID string, event *models.Event) error {
|
|
|
|
err := usr_view.DeleteToken(v.Db, tokenTable, tokenID, instanceID)
|
2020-12-21 17:42:34 +00:00
|
|
|
if err != nil && !errors.IsNotFound(err) {
|
|
|
|
return err
|
2020-05-18 10:06:36 +00:00
|
|
|
}
|
2020-12-18 15:47:45 +00:00
|
|
|
return v.ProcessedTokenSequence(event)
|
2020-05-18 10:06:36 +00:00
|
|
|
}
|
|
|
|
|
2022-04-19 06:26:12 +00:00
|
|
|
func (v *View) DeleteSessionTokens(agentID, userID, instanceID string, event *models.Event) error {
|
|
|
|
err := usr_view.DeleteSessionTokens(v.Db, tokenTable, agentID, userID, instanceID)
|
2020-12-21 17:42:34 +00:00
|
|
|
if err != nil && !errors.IsNotFound(err) {
|
|
|
|
return err
|
2020-06-19 12:52:04 +00:00
|
|
|
}
|
2020-12-18 15:47:45 +00:00
|
|
|
return v.ProcessedTokenSequence(event)
|
2020-06-19 12:52:04 +00:00
|
|
|
}
|
|
|
|
|
2022-04-19 06:26:12 +00:00
|
|
|
func (v *View) DeleteUserTokens(userID, instanceID string, event *models.Event) error {
|
|
|
|
err := usr_view.DeleteUserTokens(v.Db, tokenTable, userID, instanceID)
|
2020-12-21 17:42:34 +00:00
|
|
|
if err != nil && !errors.IsNotFound(err) {
|
|
|
|
return err
|
2020-06-19 12:52:04 +00:00
|
|
|
}
|
2020-12-18 15:47:45 +00:00
|
|
|
return v.ProcessedTokenSequence(event)
|
2020-06-19 12:52:04 +00:00
|
|
|
}
|
|
|
|
|
2020-12-18 15:47:45 +00:00
|
|
|
func (v *View) DeleteApplicationTokens(event *models.Event, ids ...string) error {
|
2022-04-19 06:26:12 +00:00
|
|
|
err := usr_view.DeleteApplicationTokens(v.Db, tokenTable, event.InstanceID, ids)
|
2020-12-21 17:42:34 +00:00
|
|
|
if err != nil && !errors.IsNotFound(err) {
|
|
|
|
return err
|
2020-05-18 10:06:36 +00:00
|
|
|
}
|
2020-12-18 15:47:45 +00:00
|
|
|
return v.ProcessedTokenSequence(event)
|
2020-05-18 10:06:36 +00:00
|
|
|
}
|
|
|
|
|
2022-04-19 06:26:12 +00:00
|
|
|
func (v *View) DeleteTokensFromRefreshToken(refreshTokenID, instanceID string, event *models.Event) error {
|
|
|
|
err := usr_view.DeleteTokensFromRefreshToken(v.Db, tokenTable, refreshTokenID, instanceID)
|
2021-11-03 07:35:24 +00:00
|
|
|
if err != nil && !errors.IsNotFound(err) {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return v.ProcessedTokenSequence(event)
|
|
|
|
}
|
|
|
|
|
2022-10-26 13:06:48 +00:00
|
|
|
func (v *View) DeleteInstanceTokens(event *models.Event) error {
|
|
|
|
err := usr_view.DeleteInstanceTokens(v.Db, tokenTable, event.InstanceID)
|
|
|
|
if err != nil && !errors.IsNotFound(err) {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return v.ProcessedTokenSequence(event)
|
|
|
|
}
|
|
|
|
|
2022-11-30 16:01:17 +00:00
|
|
|
func (v *View) DeleteOrgTokens(event *models.Event) error {
|
|
|
|
err := usr_view.DeleteOrgTokens(v.Db, tokenTable, event.InstanceID, event.ResourceOwner)
|
|
|
|
if err != nil && !errors.IsNotFound(err) {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return v.ProcessedTokenSequence(event)
|
|
|
|
}
|
|
|
|
|
2022-04-19 06:26:12 +00:00
|
|
|
func (v *View) GetLatestTokenSequence(instanceID string) (*repository.CurrentSequence, error) {
|
|
|
|
return v.latestSequence(tokenTable, instanceID)
|
|
|
|
}
|
|
|
|
|
2022-11-22 06:36:48 +00:00
|
|
|
func (v *View) GetLatestTokenSequences(instanceIDs []string) ([]*repository.CurrentSequence, error) {
|
|
|
|
return v.latestSequences(tokenTable, instanceIDs)
|
2020-05-18 10:06:36 +00:00
|
|
|
}
|
|
|
|
|
2020-12-18 15:47:45 +00:00
|
|
|
func (v *View) ProcessedTokenSequence(event *models.Event) error {
|
|
|
|
return v.saveCurrentSequence(tokenTable, event)
|
2020-12-02 07:50:59 +00:00
|
|
|
}
|
|
|
|
|
2022-11-22 06:36:48 +00:00
|
|
|
func (v *View) UpdateTokenSpoolerRunTimestamp(instanceIDs []string) error {
|
|
|
|
return v.updateSpoolerRunSequence(tokenTable, instanceIDs)
|
2020-05-18 10:06:36 +00:00
|
|
|
}
|
|
|
|
|
2022-04-19 06:26:12 +00:00
|
|
|
func (v *View) GetLatestTokenFailedEvent(sequence uint64, instanceID string) (*repository.FailedEvent, error) {
|
|
|
|
return v.latestFailedEvent(tokenTable, instanceID, sequence)
|
2020-05-18 10:06:36 +00:00
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
}
|