MCPcopy Index your code
hub / github.com/coder/coder / validateAPIKeyLifetime

Method validateAPIKeyLifetime

coderd/apikey.go:520–538  ·  view source on GitHub ↗
(ctx context.Context, userID uuid.UUID, lifetime time.Duration)

Source from the content-addressed store, hash-verified

518}
519
520func (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.

Callers 1

postTokenMethod · 0.95

Calls 3

getMaxTokenLifetimeMethod · 0.95
NewMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected