Skip to main content

personal_access_token.go

personal_access_token.go - Overview

Defines the data structures for personal access tokens (PATs) and related functionalities, including creation and storage.

Detailed Documentation

GettablePAT

  • Purpose: Represents a personal access token that can be retrieved, including information about the users who created and updated it.
  • Fields:
    • CreatedByUser: PatUser - User who created the PAT.
    • UpdatedByUser: PatUser - User who last updated the PAT.
    • StorablePersonalAccessToken: StorablePersonalAccessToken - Embedded struct containing the token's storable data.

PatUser

  • Purpose: Represents a user with an additional flag indicating if the user was not found.
  • Fields:
    • User: types.User - Embedded user information.
    • NotFound: bool - Indicates whether the user was found.

NewGettablePAT

  • Purpose: Creates a new GettablePAT instance.
  • Parameters:
    • name: string - Name of the token.
    • role: string - Role associated with the token.
    • userID: string - ID of the user associated with the token.
    • expiresAt: int64 - Expiry timestamp of the token.
  • Returns:
    • GettablePAT: A new GettablePAT instance.

StorablePersonalAccessToken

  • Purpose: Represents a personal access token that can be stored in a database.
  • Fields:
    • bun.BaseModel: bun.BaseModel - Base model for bun ORM.
    • types.Identifiable: types.Identifiable - Embedded struct providing a unique ID.
    • types.TimeAuditable: types.TimeAuditable - Embedded struct providing CreatedAt and UpdatedAt timestamps.
    • OrgID: string - Organization ID.
    • Role: string - Role associated with the token (default: 'ADMIN').
    • UserID: string - ID of the user associated with the token.
    • Token: string - The actual token string.
    • Name: string - Name of the token.
    • ExpiresAt: int64 - Expiry timestamp of the token.
    • LastUsed: int64 - Last used timestamp of the token.
    • Revoked: bool - Indicates whether the token has been revoked (default: false).
    • UpdatedByUserID: string - ID of the user who last updated the token (default: '').

NewStorablePersonalAccessToken

  • Purpose: Creates a new StorablePersonalAccessToken instance, generating a random token and setting the expiry time.
  • Parameters:
    • name: string - Name of the token.
    • role: string - Role associated with the token.
    • userID: string - ID of the user associated with the token.
    • expiresAt: int64 - Expiry time in days. If 0, token does not expire.
  • Returns:
    • StorablePersonalAccessToken: A new StorablePersonalAccessToken instance with a generated token and set expiry time.

Code Examples

None

Clarity and Accuracy

The documentation is based on the code provided and aims for clarity and accuracy.

Getting Started Relevance: YES