Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrTokenInvalidated = errors.New("oauth token permanently invalidated, re-authentication required")
ErrTokenInvalidated is returned when a token has been permanently invalidated and the user needs to re-authenticate. The tokens have been cleared from the DB.
Functions ¶
func ClearCooldowns ¶ added in v5.3.0
func ClearCooldowns()
ClearCooldowns clears all cooldown state. This is exported for testing purposes.
func RefreshUserForge ¶ added in v5.2.0
func RefreshUserForge(c context.Context, forge Forge, _store store.Store, user *model.User, forgeID int64) error
RefreshUserForge refreshes OAuth tokens for a secondary (non-primary) forge connection. This is similar to Refresh but operates on UserForge records instead of User records. The user parameter is modified in-place with the refreshed tokens.
func TokenExpiryToUnix ¶ added in v5.2.0
TokenExpiryToUnix converts an OAuth2 token expiry time to a Unix timestamp. Returns 0 if the expiry is a zero time (indicating no expiry). This is important because time.Time{}.Unix() returns a large negative number, which would incorrectly be treated as "expired".
Types ¶
type Forge ¶
type Forge interface {
// Name returns the string name of this driver
Name() string
// URL returns the root url of a configured forge
URL() string
// Login authenticates the session and returns the
// forge user details and the URL to redirect to if not authorized yet.
Login(ctx context.Context, r *types.OAuthRequest) (*model.User, string, error)
// Auth authenticates the session and returns the forge user
// login for the given token and secret
Auth(ctx context.Context, token, secret string) (string, error)
// Teams fetches a list of team memberships from the forge.
Teams(ctx context.Context, u *model.User) ([]*model.Team, error)
// Repo fetches the repository from the forge, preferred is using the ID, fallback is owner/name.
Repo(ctx context.Context, u *model.User, remoteID model.ForgeRemoteID, owner, name string) (*model.Repo, error)
// Repos fetches a list of repos from the forge.
Repos(ctx context.Context, u *model.User) ([]*model.Repo, error)
// File fetches a file from the forge repository and returns it in string
// format.
File(ctx context.Context, u *model.User, r *model.Repo, b *model.Pipeline, f string) ([]byte, error)
// Dir fetches a folder from the forge repository
Dir(ctx context.Context, u *model.User, r *model.Repo, b *model.Pipeline, f string) ([]*types.FileMeta, error)
// Status sends the commit status to the forge.
// An example would be the GitHub pull request status.
Status(ctx context.Context, u *model.User, r *model.Repo, b *model.Pipeline, p *model.Workflow) error
// Netrc returns a .netrc file that can be used to clone
// private repositories from a forge.
Netrc(u *model.User, r *model.Repo) (*model.Netrc, error)
// Activate activates a repository by creating the post-commit hook.
Activate(ctx context.Context, u *model.User, r *model.Repo, link string) error
// Deactivate deactivates a repository by removing all previously created
// post-commit hooks matching the given link.
Deactivate(ctx context.Context, u *model.User, r *model.Repo, link string) error
// Branches returns the names of all branches for the named repository.
Branches(ctx context.Context, u *model.User, r *model.Repo, p *model.ListOptions) ([]string, error)
// BranchHead returns the sha of the head (latest commit) of the specified branch
BranchHead(ctx context.Context, u *model.User, r *model.Repo, branch string) (*model.Commit, error)
// PullRequests returns all pull requests for the named repository.
PullRequests(ctx context.Context, u *model.User, r *model.Repo, p *model.ListOptions) ([]*model.PullRequest, error)
// Hook parses the post-commit hook from the Request body and returns the
// required data in a standard format.
Hook(ctx context.Context, r *http.Request) (repo *model.Repo, pipeline *model.Pipeline, err error)
// OrgMembership returns if user is member of organization and if user
// is admin/owner in that organization.
OrgMembership(ctx context.Context, u *model.User, org string) (*model.OrgPerm, error)
// Org fetches the organization from the forge by name. If the name is a user an org with type user is returned.
Org(ctx context.Context, u *model.User, org string) (*model.Org, error)
}