Download this file
| 1 | package team |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "database/sql" |
| 6 | "errors" |
| 7 | "time" |
| 8 | ) |
| 9 | |
| 10 | type authorityDenial struct { |
| 11 | cause error |
| 12 | change *GrantChange |
| 13 | scope Scope |
| 14 | } |
| 15 | |
| 16 | func (e *authorityDenial) Error() string { return e.cause.Error() } |
| 17 | func (e *authorityDenial) Unwrap() error { return e.cause } |
| 18 | func (s *Store) observedRevocation(ctx context.Context, scope Scope, err error) error { |
| 19 | if !errors.Is(err, ErrGrantRevoked) { |
| 20 | return err |
| 21 | } |
| 22 | denial := &authorityDenial{cause: err, scope: scope} |
| 23 | if s.bound(ctx) != nil { |
| 24 | return denial |
| 25 | } |
| 26 | return s.commitAuthorityDenial(ctx, denial) |
| 27 | } |
| 28 | func (s *Store) commitAuthorityDenial(ctx context.Context, d *authorityDenial) error { |
| 29 | cleanup, cancel := context.WithTimeout(context.WithoutCancel(ctx), 5*time.Second) |
| 30 | defer cancel() |
| 31 | err := s.WithTransaction(cleanup, func(tx *sql.Tx) error { |
| 32 | if d.change != nil { |
| 33 | return s.FenceGrantsTx(cleanup, tx, []GrantChange{*d.change}) |
| 34 | } |
| 35 | j, err := loadJob(cleanup, tx, d.scope) |
| 36 | if err != nil || j.State.Terminal() { |
| 37 | return err |
| 38 | } |
| 39 | _, err = terminate(cleanup, tx, j, JobCancelled, "authority", "grant revoked", s.clock.Now()) |
| 40 | return err |
| 41 | }) |
| 42 | return errors.Join(d.cause, err) |
| 43 | } |
| 44 | |