Documentation
¶
Index ¶
- Constants
- Variables
- func PublicError(err error) error
- func ScrubOAuthCallbackURL(request *http.Request) (code, state string, err error)
- type AuthorizedGitHubRepository
- func (r *AuthorizedGitHubRepository) CreateBranchRef(ctx context.Context, branch, oid string) error
- func (r *AuthorizedGitHubRepository) CreateCommitOnBranch(ctx context.Context, branch, expectedHeadOID, message string, ...) (GitHubCommit, error)
- func (r *AuthorizedGitHubRepository) CreatePullRequest(ctx context.Context, title, body, head, base string) (GitHubPullRequest, error)
- func (r *AuthorizedGitHubRepository) DeleteBranchIfHead(ctx context.Context, branch, expected string) error
- func (r *AuthorizedGitHubRepository) FindPullRequest(ctx context.Context, head, base string, marker string) (GitHubPullRequest, error)
- func (r *AuthorizedGitHubRepository) GetBlob(ctx context.Context, blobOID string) ([]byte, error)
- func (r *AuthorizedGitHubRepository) GetCommit(ctx context.Context, oid string) (GitHubCommit, error)
- func (r *AuthorizedGitHubRepository) GetPullRequest(ctx context.Context, number int64, head, base string) (GitHubPullRequest, error)
- func (r *AuthorizedGitHubRepository) GetRef(ctx context.Context, branch string) (GitHubRef, error)
- func (r *AuthorizedGitHubRepository) GetTree(ctx context.Context, treeOID string) ([]GitHubTreeEntry, error)
- func (r *AuthorizedGitHubRepository) ListBranches(ctx context.Context) ([]GitHubBranch, error)
- func (r *AuthorizedGitHubRepository) Scope() RepositoryScope
- func (r *AuthorizedGitHubRepository) UpdateRefs(ctx context.Context, updates []GitHubRefUpdate) error
- type CredentialStore
- type GitHubActor
- type GitHubAppClient
- func (c *GitHubAppClient) AuthorizationURL(state, codeChallenge string, repositoryID int64) (string, error)
- func (c *GitHubAppClient) Exchange(ctx context.Context, code, verifier string) (OAuthTokens, error)
- func (c *GitHubAppClient) Refresh(ctx context.Context, refreshToken string) (OAuthTokens, error)
- func (c *GitHubAppClient) ScopedHTTPClient(tokens OAuthTokens, repo RepositoryRef, nodeID string, ...) *http.Client
- func (c *GitHubAppClient) String() string
- func (c *GitHubAppClient) UserClient(tokens OAuthTokens) repositoryUserClient
- type GitHubAppConfig
- type GitHubAppInstallationAuthorizer
- type GitHubAppRepositoryAccess
- type GitHubBranch
- type GitHubCommit
- type GitHubFileChange
- type GitHubOAuthAppClient
- func (c *GitHubOAuthAppClient) AuthorizationURL(state, challenge string, repositoryID int64) (string, error)
- func (c *GitHubOAuthAppClient) AuthorizationURLWithScopes(state, challenge string, repositoryID int64, scopes []string) (string, error)
- func (c *GitHubOAuthAppClient) Exchange(ctx context.Context, code, verifier string) (OAuthTokens, error)
- func (c *GitHubOAuthAppClient) Refresh(ctx context.Context, token string) (OAuthTokens, error)
- func (c *GitHubOAuthAppClient) ScopedHTTPClient(tokens OAuthTokens, repo RepositoryRef, nodeID string, ...) *http.Client
- func (c *GitHubOAuthAppClient) UserClient(tokens OAuthTokens) repositoryUserClient
- type GitHubOAuthAppConfig
- type GitHubPullRequest
- type GitHubRef
- type GitHubRefUpdate
- type GitHubRepository
- type GitHubRepositoryPermissions
- type GitHubTreeEntry
- type InstallationAuthorizer
- type OAuthTokens
- type Provider
- func (p *Provider) AuthorizeRepository(ctx context.Context, firebaseUID string, repoRef RepositoryRef, ...) (*AuthorizedGitHubRepository, error)
- func (p *Provider) AuthorizeRepositoryWithScopes(ctx context.Context, firebaseUID string, repoRef RepositoryRef, ...) (*AuthorizedGitHubRepository, error)
- func (p *Provider) BeginAuthorization(ctx context.Context, firebaseUID string) (string, error)
- func (p *Provider) BeginAuthorizationWithScopes(ctx context.Context, firebaseUID string, scopes []string) (string, error)
- func (p *Provider) BeginProjectAuthorization(ctx context.Context, firebaseUID, operationID string, scopes []string) (string, error)
- func (p *Provider) BeginRepositoryAuthorization(ctx context.Context, firebaseUID string, repo RepositoryRef) (string, error)
- func (p *Provider) CompleteAuthorization(ctx context.Context, firebaseUID, state, code string) error
- func (p *Provider) CompleteProjectAuthorization(ctx context.Context, firebaseUID, state, code, operationID string) error
- func (p *Provider) CurrentActorScopes(ctx context.Context, firebaseUID string) (GitHubActor, []string, error)
- func (p *Provider) ListRepositories(ctx context.Context, firebaseUID string) ([]GitHubRepository, error)
- func (p *Provider) ResolveRepositoryByName(ctx context.Context, firebaseUID, owner, name string) (GitHubRepository, error)
- func (p *Provider) String() string
- type ProviderOptions
- type ProviderSet
- type RepositoryOperation
- type RepositoryRef
- type RepositoryScope
- type RequestFailure
Constants ¶
const ( DataTugGitHubAppSlug = "datatug" DataTugGitHubAppID = int64(5223634) )
Variables ¶
var ( ErrCredentialMissing = errors.New("GitHub connection is missing") ErrCredentialChanged = errors.New("GitHub connection changed during refresh") ErrRefreshInProgress = errors.New("GitHub token refresh is in progress") ErrOAuthStateInvalid = errors.New("GitHub OAuth state is invalid or expired") )
var ( ErrGitHubAppNotConfigured = errors.New("DataTug GitHub App authorization is not configured") ErrGitHubActorMismatch = errors.New("GitHub account does not match the connected Firebase user") ErrGitHubRepositoryDenied = errors.New("GitHub repository is not authorized") ErrGitHubPermissionDenied = errors.New("GitHub user does not have the required repository permission") ErrGitHubScopesDenied = errors.New("GitHub OAuth App is missing required repository workflow scopes") ErrGitHubOAuthAppNotConfigured = errors.New("DataTug GitHub OAuth App authorization is not configured") )
Functions ¶
func PublicError ¶ added in v0.59.1
PublicError reads only explicit replacement boundaries. Original causes are still available to errors.Is/As and private, sanitized diagnostics.
func ScrubOAuthCallbackURL ¶
ScrubOAuthCallbackURL must be the first callback-handler operation. It extracts the one-time code/state in memory, then removes every query value from both URL representations before application logging or routing.
Types ¶
type AuthorizedGitHubRepository ¶
type AuthorizedGitHubRepository struct {
// contains filtered or unexported fields
}
AuthorizedGitHubRepository is an ephemeral, actor-bound API client. The underlying user token remains private in the transport and the client is restricted to the selected repository and operation permission.
func (*AuthorizedGitHubRepository) CreateBranchRef ¶ added in v0.59.1
func (r *AuthorizedGitHubRepository) CreateBranchRef(ctx context.Context, branch, oid string) error
func (*AuthorizedGitHubRepository) CreateCommitOnBranch ¶
func (r *AuthorizedGitHubRepository) CreateCommitOnBranch(ctx context.Context, branch, expectedHeadOID, message string, changes []GitHubFileChange) (GitHubCommit, error)
func (*AuthorizedGitHubRepository) CreatePullRequest ¶ added in v0.59.1
func (r *AuthorizedGitHubRepository) CreatePullRequest(ctx context.Context, title, body, head, base string) (GitHubPullRequest, error)
func (*AuthorizedGitHubRepository) DeleteBranchIfHead ¶ added in v0.59.1
func (r *AuthorizedGitHubRepository) DeleteBranchIfHead(ctx context.Context, branch, expected string) error
func (*AuthorizedGitHubRepository) FindPullRequest ¶ added in v0.59.1
func (r *AuthorizedGitHubRepository) FindPullRequest(ctx context.Context, head, base string, marker string) (GitHubPullRequest, error)
func (*AuthorizedGitHubRepository) GetCommit ¶
func (r *AuthorizedGitHubRepository) GetCommit(ctx context.Context, oid string) (GitHubCommit, error)
func (*AuthorizedGitHubRepository) GetPullRequest ¶ added in v0.59.1
func (r *AuthorizedGitHubRepository) GetPullRequest(ctx context.Context, number int64, head, base string) (GitHubPullRequest, error)
func (*AuthorizedGitHubRepository) GetTree ¶
func (r *AuthorizedGitHubRepository) GetTree(ctx context.Context, treeOID string) ([]GitHubTreeEntry, error)
GetTree returns all descendants of treeOID, recursively. A truncated GitHub response is an error.
func (*AuthorizedGitHubRepository) ListBranches ¶
func (r *AuthorizedGitHubRepository) ListBranches(ctx context.Context) ([]GitHubBranch, error)
func (*AuthorizedGitHubRepository) Scope ¶
func (r *AuthorizedGitHubRepository) Scope() RepositoryScope
func (*AuthorizedGitHubRepository) UpdateRefs ¶
func (r *AuthorizedGitHubRepository) UpdateRefs(ctx context.Context, updates []GitHubRefUpdate) error
type CredentialStore ¶
type CredentialStore struct {
// contains filtered or unexported fields
}
CredentialStore persists only purpose-encrypted GitHub tokens. Refresh state is updated in DAL transactions so concurrent Cloud API instances cannot both consume the same rotating refresh token.
type GitHubActor ¶
type GitHubAppClient ¶
type GitHubAppClient struct {
// contains filtered or unexported fields
}
func NewGitHubAppClient ¶
func NewGitHubAppClient(config GitHubAppConfig, client *http.Client) (*GitHubAppClient, error)
func (*GitHubAppClient) AuthorizationURL ¶
func (c *GitHubAppClient) AuthorizationURL(state, codeChallenge string, repositoryID int64) (string, error)
func (*GitHubAppClient) Exchange ¶
func (c *GitHubAppClient) Exchange(ctx context.Context, code, verifier string) (OAuthTokens, error)
func (*GitHubAppClient) Refresh ¶
func (c *GitHubAppClient) Refresh(ctx context.Context, refreshToken string) (OAuthTokens, error)
func (*GitHubAppClient) ScopedHTTPClient ¶
func (c *GitHubAppClient) ScopedHTTPClient(tokens OAuthTokens, repo RepositoryRef, nodeID string, operation RepositoryOperation) *http.Client
func (*GitHubAppClient) String ¶
func (c *GitHubAppClient) String() string
func (*GitHubAppClient) UserClient ¶
func (c *GitHubAppClient) UserClient(tokens OAuthTokens) repositoryUserClient
type GitHubAppConfig ¶
type GitHubAppConfig struct {
AppID int64
ClientID string
ClientSecret string
PrivateKeyPEM []byte
CallbackURL string
}
GitHubAppConfig contains server-side settings for the existing DataTug GitHub App. Secret values are accepted only by the server and are never persisted by this package.
type GitHubAppInstallationAuthorizer ¶
type GitHubAppInstallationAuthorizer struct {
// contains filtered or unexported fields
}
GitHubAppInstallationAuthorizer checks the dedicated DataTug App's current installation for the selected repository. Provider first verifies the immutable repository ID, owner, and name with the GitHub user actor token; this App-JWT request then proves that the same owner/repository path is in the App installation and returns its effective Contents permission.
func NewGitHubAppInstallationAuthorizer ¶
func NewGitHubAppInstallationAuthorizer(appID int64, privateKeyPEM []byte) (*GitHubAppInstallationAuthorizer, error)
func (*GitHubAppInstallationAuthorizer) AuthorizeDataTugAppRepository ¶
func (a *GitHubAppInstallationAuthorizer) AuthorizeDataTugAppRepository(ctx context.Context, repo RepositoryRef) (GitHubAppRepositoryAccess, error)
type GitHubBranch ¶
GitHubBranch is a branch name and its current immutable commit identifier.
type GitHubCommit ¶
type GitHubFileChange ¶
GitHubFileChange adds/replaces a file with raw bytes, or deletes it when Delete is true.
type GitHubOAuthAppClient ¶ added in v0.59.1
type GitHubOAuthAppClient struct {
// contains filtered or unexported fields
}
GitHubOAuthAppClient uses the existing DataTug OAuth App identity. It does not depend on a GitHub App installation and requests classic repo+workflow scopes together at the create-submit consent step.
func NewGitHubOAuthAppClient ¶ added in v0.59.1
func NewGitHubOAuthAppClient(config GitHubOAuthAppConfig, client *http.Client) (*GitHubOAuthAppClient, error)
func (*GitHubOAuthAppClient) AuthorizationURL ¶ added in v0.59.1
func (c *GitHubOAuthAppClient) AuthorizationURL(state, challenge string, repositoryID int64) (string, error)
func (*GitHubOAuthAppClient) AuthorizationURLWithScopes ¶ added in v0.59.1
func (*GitHubOAuthAppClient) Exchange ¶ added in v0.59.1
func (c *GitHubOAuthAppClient) Exchange(ctx context.Context, code, verifier string) (OAuthTokens, error)
func (*GitHubOAuthAppClient) Refresh ¶ added in v0.59.1
func (c *GitHubOAuthAppClient) Refresh(ctx context.Context, token string) (OAuthTokens, error)
func (*GitHubOAuthAppClient) ScopedHTTPClient ¶ added in v0.59.1
func (c *GitHubOAuthAppClient) ScopedHTTPClient(tokens OAuthTokens, repo RepositoryRef, nodeID string, operation RepositoryOperation) *http.Client
func (*GitHubOAuthAppClient) UserClient ¶ added in v0.59.1
func (c *GitHubOAuthAppClient) UserClient(tokens OAuthTokens) repositoryUserClient
type GitHubOAuthAppConfig ¶ added in v0.59.1
GitHubOAuthAppConfig is deliberately separate from GitHubAppConfig: OAuth App credentials and GitHub App credentials are different provider modes.
type GitHubPullRequest ¶ added in v0.59.1
type GitHubPullRequest struct {
Number int64
URL string
State string
Merged bool
MergeCommitSHA string
HeadBranch string
HeadSHA string
HeadRepositoryID int64
BaseBranch string
BaseRepositoryID int64
Body string
}
GitHubPullRequest is a verified repository-scoped PR snapshot.
type GitHubRefUpdate ¶
GitHubRefUpdate is an atomic compare-and-swap update for one branch ref.
type GitHubRepository ¶
type GitHubRepository struct {
ID int64
NodeID string
Owner string
Name string
DefaultBranch string
Permissions GitHubRepositoryPermissions
EffectivePermission RepositoryOperation
}
type GitHubTreeEntry ¶
GitHubTreeEntry identifies one path in a complete recursive repository tree.
type InstallationAuthorizer ¶
type InstallationAuthorizer interface {
AuthorizeDataTugAppRepository(context.Context, RepositoryRef) (GitHubAppRepositoryAccess, error)
}
InstallationAuthorizer proves that the existing DataTug GitHub App's selected-repository installation currently includes a project repository. Its adapter may use App authentication, but an installation token is never returned as the project actor.
type OAuthTokens ¶
type OAuthTokens struct {
// contains filtered or unexported fields
}
OAuthTokens exists only in memory. Its string representations and default JSON representation intentionally omit token material.
func (OAuthTokens) GoString ¶
func (OAuthTokens) GoString() string
func (OAuthTokens) MarshalJSON ¶
func (OAuthTokens) MarshalJSON() ([]byte, error)
func (OAuthTokens) String ¶
func (OAuthTokens) String() string
type Provider ¶
type Provider struct {
// contains filtered or unexported fields
}
func NewOAuthAppProvider ¶ added in v0.59.1
func NewOAuthAppProvider(db dal.DB, config GitHubOAuthAppConfig, platformCryptoRoot []byte, options ProviderOptions) (*Provider, error)
NewOAuthAppProvider configures the existing DataTug OAuth App identity for submit-time repository write consent. It never constructs an App installation authorizer and uses a separate encrypted credential record.
func NewProvider ¶
func NewProvider(db dal.DB, config GitHubAppConfig, platformCryptoRoot []byte, installation InstallationAuthorizer, options ProviderOptions) (*Provider, error)
func (*Provider) AuthorizeRepository ¶
func (p *Provider) AuthorizeRepository(ctx context.Context, firebaseUID string, repoRef RepositoryRef, operation RepositoryOperation) (*AuthorizedGitHubRepository, error)
AuthorizeRepository rechecks Firebase UID to GitHub actor binding, selected App installation membership, repository identity, and the requested current permission on every read or write.
func (*Provider) AuthorizeRepositoryWithScopes ¶ added in v0.59.1
func (p *Provider) AuthorizeRepositoryWithScopes(ctx context.Context, firebaseUID string, repoRef RepositoryRef, operation RepositoryOperation, requiredScopes []string) (*AuthorizedGitHubRepository, error)
AuthorizeRepositoryWithScopes revalidates only the OAuth scopes required by the exact planned mutation. Legacy GitHub App mode still always checks its installation permissions independently.
func (*Provider) BeginAuthorization ¶
BeginAuthorization connects a GitHub actor before repository selection. The returned URL contains only short-lived state and a PKCE challenge.
func (*Provider) BeginAuthorizationWithScopes ¶ added in v0.59.1
func (p *Provider) BeginAuthorizationWithScopes(ctx context.Context, firebaseUID string, scopes []string) (string, error)
BeginAuthorizationWithScopes starts OAuth App consent for an exact scope set.
func (*Provider) BeginProjectAuthorization ¶ added in v0.59.1
func (*Provider) BeginRepositoryAuthorization ¶
func (p *Provider) BeginRepositoryAuthorization(ctx context.Context, firebaseUID string, repo RepositoryRef) (string, error)
BeginRepositoryAuthorization starts a repository-bound reconnection for an already selected project. Initial connection uses BeginAuthorization.
func (*Provider) CompleteAuthorization ¶
func (p *Provider) CompleteAuthorization(ctx context.Context, firebaseUID, state, code string) error
CompleteAuthorization consumes the actor-bound one-time state before exchanging the callback code. Callers must scrub code and state from the callback URL before routing, logging, or analytics.
func (*Provider) CompleteProjectAuthorization ¶ added in v0.59.1
func (*Provider) CurrentActorScopes ¶ added in v0.59.1
func (*Provider) ListRepositories ¶
func (p *Provider) ListRepositories(ctx context.Context, firebaseUID string) ([]GitHubRepository, error)
ListRepositories returns only repositories the connected actor can read and the dedicated DataTug App currently has installed. It conveys no mutation authority; project operations still call AuthorizeRepository every time.
func (*Provider) ResolveRepositoryByName ¶ added in v0.17.1
func (p *Provider) ResolveRepositoryByName(ctx context.Context, firebaseUID, owner, name string) (GitHubRepository, error)
ResolveRepositoryByName resolves a selected owner/name through the current connected actor token. The caller must still run the fresh App and operation authorization path using the returned immutable ID.
type ProviderOptions ¶
type ProviderSet ¶ added in v0.59.1
ProviderSet selects mode from server-owned credential presence. A damaged, revoked or stale OAuth credential fails closed; only its genuine absence permits the legacy App mode.
type RepositoryOperation ¶
type RepositoryOperation string
const ( RepositoryRead RepositoryOperation = "read" RepositoryWrite RepositoryOperation = "write" )
type RepositoryRef ¶
type RepositoryRef struct {
ID int64 `json:"id" firestore:"id"`
Owner string `json:"owner" firestore:"owner"`
Name string `json:"name" firestore:"name"`
}
func (RepositoryRef) Validate ¶
func (r RepositoryRef) Validate() error
type RepositoryScope ¶
type RepositoryScope struct {
FirebaseUID string
Actor GitHubActor
Repository GitHubRepository
Permission RepositoryOperation
}
RepositoryScope returns a value snapshot of the verified actor and immutable repository identity. Mutating the returned value cannot widen the client.
type RequestFailure ¶ added in v0.59.1
type RequestFailure struct {
Stage string
Status int
Cause error
// contains filtered or unexported fields
}
RequestFailure retains the original provider failure without exposing its URL/body through diagnostics or changing the established public sentinel.
func (*RequestFailure) Error ¶ added in v0.59.1
func (e *RequestFailure) Error() string
func (*RequestFailure) PublicClassification ¶ added in v0.59.1
func (e *RequestFailure) PublicClassification() error
func (*RequestFailure) Unwrap ¶ added in v0.59.1
func (e *RequestFailure) Unwrap() error