Documentation
¶
Index ¶
- func AppTokenTestAPIURL() (string, error)
- func ConfigureRepository(ctx context.Context, run *params.Run, req *http.Request, payload string, ...) (bool, bool, error)
- func ListRepos(ctx context.Context, v *Provider) ([]string, error)
- func MakeClient(ctx context.Context, apiURL, token string, retryOpts ...*retryhttp.Options) (*github.Client, string, *string, error)
- func MatchEventURLRepo(ctx context.Context, cs *params.Run, event *info.Event, ns string) (*v1alpha1.Repository, error)
- func ScopeTokenToListOfRepos(ctx context.Context, vcx provider.Interface, pacInfo *info.PacOpts, ...) (string, error)
- type APIEndpoint
- type Payload
- type Provider
- func (v *Provider) CheckPolicyAllowing(ctx context.Context, event *info.Event, allowedTeams []string) (bool, string)
- func (v *Provider) Client() *github.Client
- func (v *Provider) CreateComment(ctx context.Context, event *info.Event, commit, updateMarker string) error
- func (v *Provider) CreateStatus(ctx context.Context, runevent *info.Event, ...) error
- func (v *Provider) CreateToken(ctx context.Context, repository []string, event *info.Event) (string, error)
- func (v *Provider) Detect(req *http.Request, payload string, logger *zap.SugaredLogger) (bool, bool, *zap.SugaredLogger, string, error)
- func (v *Provider) GenerateJWT(ctx context.Context, ns string, kube kubernetes.Interface) (string, error)
- func (v *Provider) GetAppIDAndPrivateKey(ctx context.Context, ns string, kube kubernetes.Interface) (int64, []byte, error)
- func (v *Provider) GetAppToken(ctx context.Context, kube kubernetes.Interface, gheURL string, ...) (string, error)
- func (v *Provider) GetCommitInfo(ctx context.Context, runevent *info.Event) error
- func (v *Provider) GetCommitStatuses(ctx context.Context, event *info.Event) ([]provider.CommitStatusInfo, error)
- func (v *Provider) GetConfig() *info.ProviderConfig
- func (v *Provider) GetFileInsideRepo(ctx context.Context, runevent *info.Event, path, target string) (string, error)
- func (v *Provider) GetFiles(ctx context.Context, runevent *info.Event) (changedfiles.ChangedFiles, error)
- func (v *Provider) GetStringPullRequestComment(ctx context.Context, runevent *info.Event) ([]*github.IssueComment, error)
- func (v *Provider) GetTaskURI(ctx context.Context, event *info.Event, uri string) (bool, string, error)
- func (v *Provider) GetTektonDir(ctx context.Context, runevent *info.Event, path, provenance string) (string, error)
- func (v *Provider) GetTemplate(commentType provider.CommentType) string
- func (v *Provider) InitAppClient(ctx context.Context, kube kubernetes.Interface, event *info.Event) error
- func (v *Provider) IsAllowed(ctx context.Context, event *info.Event) (bool, error)
- func (v *Provider) IsAllowedOwnersFile(ctx context.Context, event *info.Event) (bool, error)
- func (v *Provider) MakeClient(ctx context.Context, apiURL, token string) (*github.Client, string, *string, error)
- func (v *Provider) ParsePayload(ctx context.Context, run *params.Run, request *http.Request, payload string) (*info.Event, error)
- func (v *Provider) SetClient(ctx context.Context, run *params.Run, event *info.Event, ...) error
- func (v *Provider) SetGithubClient(client *github.Client)
- func (v *Provider) SetLogger(logger *zap.SugaredLogger)
- func (v *Provider) SetPacInfo(pacInfo *info.PacOpts)
- func (v *Provider) UsePreauthenticatedClient(client *github.Client)
- func (v *Provider) Validate(_ context.Context, _ *params.Run, event *info.Event) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppTokenTestAPIURL ¶ added in v0.51.0
func ConfigureRepository ¶ added in v0.13.0
func MakeClient ¶ added in v0.27.1
func MatchEventURLRepo ¶ added in v0.44.0
func ScopeTokenToListOfRepos ¶ added in v0.19.0
Types ¶
type APIEndpoint ¶ added in v0.51.0
APIEndpoint holds the API locations to use for a given GitHub host.
func TrustedAPIEndpointForRepository ¶ added in v0.51.0
func TrustedAPIEndpointForRepository(ctx context.Context, run *params.Run, repositoryURL string) (APIEndpoint, error)
TrustedAPIEndpointForRepository resolves the endpoint for a Repository CR URL through the controller allowlist.
func (APIEndpoint) BaseURLForClient ¶ added in v0.51.0
func (e APIEndpoint) BaseURLForClient() (string, error)
BaseURLForClient returns the base URL a client must be built against.
It is the endpoint base URL, except when the loopback override the unit tests use is set: authentication and API then live on two different servers, and every caller has to prefer the override the same way.
type Provider ¶
type Provider struct {
Logger *zap.SugaredLogger
Run *params.Run
Token, APIURL *string
ApplicationID *int64
RepositoryIDs []int64
RepositoryNames []string
PaginedNumber int
// contains filtered or unexported fields
}
func (*Provider) CheckPolicyAllowing ¶ added in v0.20.0
func (v *Provider) CheckPolicyAllowing(ctx context.Context, event *info.Event, allowedTeams []string) (bool, string)
CheckPolicyAllowing check that policy is allowing the event to be processed we check the membership of the team allowed if the team is not found we explicitly disallow the policy, user have to correct the setting.
func (*Provider) CreateComment ¶ added in v0.34.0
func (v *Provider) CreateComment(ctx context.Context, event *info.Event, commit, updateMarker string) error
CreateComment creates a comment on a Pull Request.
func (*Provider) CreateStatus ¶
func (v *Provider) CreateStatus(ctx context.Context, runevent *info.Event, statusOpts providerstatus.StatusOpts) error
func (*Provider) CreateToken ¶ added in v0.19.0
func (*Provider) Detect ¶
func (v *Provider) Detect(req *http.Request, payload string, logger *zap.SugaredLogger) (bool, bool, *zap.SugaredLogger, string, error)
Detect processes event and detect if it is a github event, whether to process or reject it returns (if is a GH event, whether to process or reject, error if any occurred).
func (*Provider) GenerateJWT ¶ added in v0.43.0
func (v *Provider) GenerateJWT(ctx context.Context, ns string, kube kubernetes.Interface) (string, error)
GenerateJWT generates a JWT token for GitHub App. It retrieves the application ID and private key, sets the claims, and signs the token.
func (*Provider) GetAppIDAndPrivateKey ¶ added in v0.24.2
func (v *Provider) GetAppIDAndPrivateKey(ctx context.Context, ns string, kube kubernetes.Interface) (int64, []byte, error)
GetAppIDAndPrivateKey retrieves the GitHub application ID and private key from a secret in the specified namespace. It takes a context, namespace, and Kubernetes client as input parameters. It returns the application ID (int64), private key ([]byte), and an error if any.
func (*Provider) GetAppToken ¶ added in v0.15.0
func (*Provider) GetCommitInfo ¶
GetCommitInfo get info (url and title) on a commit in runevent, this needs to be run after sewebhook while we already matched a token.
func (*Provider) GetCommitStatuses ¶ added in v0.44.0
func (*Provider) GetConfig ¶
func (v *Provider) GetConfig() *info.ProviderConfig
func (*Provider) GetFileInsideRepo ¶
func (v *Provider) GetFileInsideRepo(ctx context.Context, runevent *info.Event, path, target string) (string, error)
GetFileInsideRepo Get a file via Github API using the runinfo information, we branch is true, the user the branch as ref instead of the SHA TODO: merge GetFileInsideRepo amd GetTektonDir.
func (*Provider) GetFiles ¶ added in v0.12.0
func (v *Provider) GetFiles(ctx context.Context, runevent *info.Event) (changedfiles.ChangedFiles, error)
GetFiles gets and caches the list of files changed by a given event.
func (*Provider) GetStringPullRequestComment ¶
func (v *Provider) GetStringPullRequestComment(ctx context.Context, runevent *info.Event) ([]*github.IssueComment, error)
GetStringPullRequestComment return the comment if we find an /ok-to-test comment in one of the comments text of a pull request.
func (*Provider) GetTaskURI ¶ added in v0.13.0
func (*Provider) GetTektonDir ¶
func (v *Provider) GetTektonDir(ctx context.Context, runevent *info.Event, path, provenance string) (string, error)
GetTektonDir retrieves all YAML files from the .tekton directory and returns them as a single concatenated multi-document YAML file.
func (*Provider) GetTemplate ¶ added in v0.34.0
func (v *Provider) GetTemplate(commentType provider.CommentType) string
func (*Provider) InitAppClient ¶
func (*Provider) IsAllowedOwnersFile ¶ added in v0.22.1
IsAllowedOwnersFile get the owner files (OWNERS, OWNERS_ALIASES) from main branch and check if we have explicitly allowed the user in there.
func (*Provider) MakeClient ¶ added in v0.51.0
func (v *Provider) MakeClient(ctx context.Context, apiURL, token string) (*github.Client, string, *string, error)
MakeClient creates a GitHub API client using the provider retry settings.
func (*Provider) ParsePayload ¶
func (v *Provider) ParsePayload(ctx context.Context, run *params.Run, request *http.Request, payload string) (*info.Event, error)
ParsePayload will parse the payload and return the event it generate the github app token targeting the installation id this pieces of code is a bit messy because we need first getting a token to before parsing the payload.
We need to get the token at first because in some case when coming from pull request comment (or recheck from the UI) we will use that token to get information about the PR that is not part of the payload.
We then regenerate a second time the token scoped to the repo where the payload come from so we can avoid the scenario where an admin install the app on a github org which has a mixed of private and public repos and some of the public users should not have access to the private repos.
Validate the webhook signature before generating an app token because the token request signs a GitHub App JWT locally and sends it to the selected API host.
func (*Provider) SetGithubClient ¶ added in v0.34.0
func (*Provider) SetLogger ¶
func (v *Provider) SetLogger(logger *zap.SugaredLogger)
func (*Provider) SetPacInfo ¶ added in v0.26.0
func (*Provider) UsePreauthenticatedClient ¶ added in v0.51.0
UsePreauthenticatedClient installs a client the caller built itself and opts the provider out of the trusted hostname gate in SetClient.
The gate exists to stop a credential the controller owns from being sent to a host that a payload, or a Repository CR sharing a token from another namespace, asked for. It is the origin of the host that matters: a caller that picked the URL itself, the end to end harness taking it from its own configuration, has already made that decision and there is nothing left here to protect, whether the token is its own or one it minted from the App. It follows that the URL must never come from a payload. Nothing in the controller may use this.