(ctx context.Context, userID uuid.UUID, lifetime time.Duration)
| 518 | } |
| 519 | |
| 520 | func (api *API) validateAPIKeyLifetime(ctx context.Context, userID uuid.UUID, lifetime time.Duration) error { |
| 521 | if lifetime <= 0 { |
| 522 | return xerrors.New("lifetime must be positive number greater than 0") |
| 523 | } |
| 524 | |
| 525 | maxLifetime, err := api.getMaxTokenLifetime(ctx, userID) |
| 526 | if err != nil { |
| 527 | return xerrors.Errorf("failed to get max token lifetime: %w", err) |
| 528 | } |
| 529 | |
| 530 | if lifetime > maxLifetime { |
| 531 | return xerrors.Errorf( |
| 532 | "lifetime must be less than %v", |
| 533 | maxLifetime, |
| 534 | ) |
| 535 | } |
| 536 | |
| 537 | return nil |
| 538 | } |
| 539 | |
| 540 | // getMaxTokenLifetime returns the maximum allowed token lifetime for a user. |
| 541 | // It distinguishes between regular users and owners. |
no test coverage detected