Documentation ¶
Overview ¶
Package github provides the ability for Vela to integrate with GitHub or GitHub Enterprise as a scm provider.
Usage:
import "github.com/go-vela/server/scm/github"
Index ¶
- Constants
- func ApplyInstallationPermissions(resource, perm string, perms *github.InstallationPermissions) (*github.InstallationPermissions, error)
- func GetInstallationPermission(resource string, appPermissions *github.InstallationPermissions) (string, error)
- func GetReadWriter(i interface{}) (io.ReadWriter, error)
- func InstallationHasPermission(resource, requiredPerm, actualPerm string) error
- func New(ctx context.Context, opts ...ClientOpt) (*client, error)
- func NewTest(urls ...string) (*client, error)
- type AppsTransport
- type AppsTransportOption
- type Client
- type ClientOpt
- func WithAddress(address string) ClientOpt
- func WithClientID(id string) ClientOpt
- func WithClientSecret(secret string) ClientOpt
- func WithGitHubAppPermissions(permissions []string) ClientOpt
- func WithGithubAppID(id int64) ClientOpt
- func WithGithubPrivateKey(key string) ClientOpt
- func WithGithubPrivateKeyPath(path string) ClientOpt
- func WithOAuthScopes(scopes []string) ClientOpt
- func WithServerAddress(address string) ClientOpt
- func WithServerWebhookAddress(address string) ClientOpt
- func WithStatusContext(context string) ClientOpt
- func WithTracing(tracing *tracing.Client) ClientOpt
- func WithWebUIAddress(address string) ClientOpt
- type RSASigner
- type Signer
- type Transport
Constants ¶
const ( // GitHub App install permission 'none'. AppInstallPermissionNone = "none" // GitHub App install permission 'read'. AppInstallPermissionRead = "read" // GitHub App install permission 'write'. AppInstallPermissionWrite = "write" )
const ( // GitHub App install contents resource. AppInstallResourceContents = "contents" // GitHub App install checks resource. AppInstallResourceChecks = "checks" // GitHub App install packages resource. AppInstallResourcePackages = "packages" )
Variables ¶
This section is empty.
Functions ¶
func ApplyInstallationPermissions ¶ added in v0.26.0
func ApplyInstallationPermissions(resource, perm string, perms *github.InstallationPermissions) (*github.InstallationPermissions, error)
ApplyInstallationPermissions takes permissions and applies a new permission if valid.
func GetInstallationPermission ¶ added in v0.26.0
func GetInstallationPermission(resource string, appPermissions *github.InstallationPermissions) (string, error)
GetInstallationPermission takes permissions and returns the permission level if valid.
func GetReadWriter ¶ added in v0.26.0
func GetReadWriter(i interface{}) (io.ReadWriter, error)
GetReadWriter converts a body interface into an io.ReadWriter object.
func InstallationHasPermission ¶ added in v0.26.0
InstallationHasPermission takes a resource:perm pair and checks if the actual permission matches the expected permission or is supersceded by a higher permission.
Types ¶
type AppsTransport ¶ added in v0.26.0
type AppsTransport struct { BaseURL string // BaseURL is the scheme and host for GitHub API, defaults to https://api.github.com Client Client // Client to use to refresh tokens, defaults to http.Client with provided transport // contains filtered or unexported fields }
AppsTransport provides a http.RoundTripper by wrapping an existing http.RoundTripper and provides GitHub Apps authentication as a GitHub App.
Client can also be overwritten, and is useful to change to one which provides retry logic if you do experience retryable errors.
func NewTestAppsTransport ¶ added in v0.26.0
func NewTestAppsTransport(baseURL string) *AppsTransport
NewTestAppsTransport creates a new AppsTransport for testing purposes.
type AppsTransportOption ¶ added in v0.26.0
type AppsTransportOption func(*AppsTransport)
AppsTransportOption is a func option for configuring an AppsTransport.
func WithSigner ¶ added in v0.26.0
func WithSigner(signer Signer) AppsTransportOption
WithSigner configures the AppsTransport to use the given Signer for generating JWT tokens.
type Client ¶ added in v0.26.0
Client is a HTTP client which sends a http.Request and returns a http.Response or an error.
type ClientOpt ¶
type ClientOpt func(*client) error
ClientOpt represents a configuration option to initialize the scm client for GitHub.
func WithAddress ¶
WithAddress sets the GitHub address in the scm client for GitHub.
func WithClientID ¶
WithClientID sets the OAuth client ID in the scm client for GitHub.
func WithClientSecret ¶
WithClientSecret sets the OAuth client secret in the scm client for GitHub.
func WithGitHubAppPermissions ¶ added in v0.26.0
WithGitHubAppPermissions sets the App permissions in the scm client for GitHub.
func WithGithubAppID ¶ added in v0.26.0
WithGithubAppID sets the ID for the GitHub App in the scm client.
func WithGithubPrivateKey ¶ added in v0.26.0
WithGithubPrivateKey sets the private key for the GitHub App in the scm client.
func WithGithubPrivateKeyPath ¶ added in v0.26.0
WithGithubPrivateKeyPath sets the private key path for the GitHub App in the scm client.
func WithOAuthScopes ¶ added in v0.26.0
WithOAuthScopes sets the OAuth scopes in the scm client for GitHub.
func WithServerAddress ¶
WithServerAddress sets the Vela server address in the scm client for GitHub.
func WithServerWebhookAddress ¶
WithServerWebhookAddress sets the Vela server webhook address in the scm client for GitHub.
func WithStatusContext ¶
WithStatusContext sets the context for commit statuses in the scm client for GitHub.
func WithTracing ¶ added in v0.25.0
WithTracing sets the shared tracing config in the scm client for GitHub.
func WithWebUIAddress ¶
WithWebUIAddress sets the Vela web UI address in the scm client for GitHub.
type RSASigner ¶ added in v0.26.0
type RSASigner struct {
// contains filtered or unexported fields
}
RSASigner signs JWT tokens using RSA keys.
func NewRSASigner ¶ added in v0.26.0
func NewRSASigner(method *jwt.SigningMethodRSA, key *rsa.PrivateKey) *RSASigner
NewRSASigner creates a new RSASigner with the given RSA key.
type Signer ¶ added in v0.26.0
type Signer interface { // sign the given claims and returns a JWT token string, as specified // by [jwt.Token.SignedString] Sign(claims jwt.Claims) (string, error) }
Signer is a JWT token signer. This is a wrapper around jwt.SigningMethod with predetermined key material.
type Transport ¶ added in v0.26.0
type Transport struct { BaseURL string // BaseURL is the scheme and host for GitHub API, defaults to https://api.github.com Client Client // Client to use to refresh tokens, defaults to http.Client with provided transport InstallationTokenOptions *github.InstallationTokenOptions // parameters restrict a token's access // contains filtered or unexported fields }
Transport provides a http.RoundTripper by wrapping an existing http.RoundTripper and provides GitHub Apps authentication as an installation.
Client can also be overwritten, and is useful to change to one which provides retry logic if you do experience retryable errors.
func (*Transport) Expiry ¶ added in v0.26.0
Expiry returns a transport token's expiration time and refresh time. There is a small grace period built in where a token will be refreshed before it expires. expiresAt is the actual token expiry, and refreshAt is when a call to Token() will cause it to be refreshed.