Skip to content

Commit

Permalink
fix: remove unnecessary transaction (#3029)
Browse files Browse the repository at this point in the history
  • Loading branch information
mitar authored Mar 11, 2022
1 parent 849af9f commit d4b2696
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions persistence/sql/persister_oauth2.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,26 +175,26 @@ func (p *Persister) ClientAssertionJWTValid(ctx context.Context, jti string) err
}

func (p *Persister) SetClientAssertionJWT(ctx context.Context, jti string, exp time.Time) error {
return p.transaction(ctx, func(ctx context.Context, c *pop.Connection) error {
// delete expired
now := "now()"
if c.Dialect.Name() == "sqlite3" {
now = "CURRENT_TIMESTAMP"
}
/* #nosec G201 table is static */
if err := c.RawQuery(fmt.Sprintf("DELETE FROM %s WHERE expires_at < %s", oauth2.BlacklistedJTI{}.TableName(), now)).Exec(); err != nil {
return sqlcon.HandleError(err)
}
// delete expired
c := p.Connection(ctx)
now := "now()"
if c.Dialect.Name() == "sqlite3" {
now = "CURRENT_TIMESTAMP"
}
/* #nosec G201 table is static */
if err := c.RawQuery(fmt.Sprintf("DELETE FROM %s WHERE expires_at < %s", oauth2.BlacklistedJTI{}.TableName(), now)).Exec(); err != nil {
return sqlcon.HandleError(err)
}

if err := p.SetClientAssertionJWTRaw(ctx, oauth2.NewBlacklistedJTI(jti, exp)); errors.Is(err, sqlcon.ErrUniqueViolation) {
// found a jti
return errorsx.WithStack(fosite.ErrJTIKnown)
} else if err != nil {
return err
}
// setting worked without a problem
return nil
})
if err := p.SetClientAssertionJWTRaw(ctx, oauth2.NewBlacklistedJTI(jti, exp)); errors.Is(err, sqlcon.ErrUniqueViolation) {
// found a jti
return errorsx.WithStack(fosite.ErrJTIKnown)
} else if err != nil {
return err
}

// setting worked without a problem
return nil
}

func (p *Persister) GetClientAssertionJWT(ctx context.Context, j string) (*oauth2.BlacklistedJTI, error) {
Expand Down

0 comments on commit d4b2696

Please sign in to comment.