Documentation
¶
Overview ¶
Package githubdispatch is the "github-dispatch" sink (spec GithubDispatchSinkConfig, docs/github-dispatch.md): it triggers a repository_dispatch event or a workflow_dispatch run in one GitHub repository, through the netguard client.
repository_dispatch sends event_type (a template) and a flat client_payload of at most 10 top-level keys, the GitHub limit; every string in it is cut to 2048 bytes at a UTF-8 boundary and truncated is true when anything was cut. workflow_dispatch sends ref and inputs, each input a template cut to 1024 bytes. The subscription's template does not apply: the payload is fixed.
The sink never reads the environment or the store: the core resolves token_env and token_ref into sink.Request.Secrets. The token is sent only to api_base_url, the host the core resolved a stored token for, and the sink follows no redirect. It logs nothing, and its errors carry no token, URL path or response body.
Index ¶
- Constants
- func CheckAPIBaseURL(s string) error
- func CheckEventType(s string) error
- func CheckEventTypeTemplate(src string) error
- func CheckInputName(k string) error
- func CheckRef(s string) error
- func CheckTemplate(src string, limit int) error
- func CheckWorkflow(s string) error
- func IsLiteral(src string) bool
- func ValidRepo(s string) bool
- type Config
- type Options
- type Sink
Constants ¶
const ( ModeRepositoryDispatch = "repository_dispatch" ModeWorkflowDispatch = "workflow_dispatch" )
The two GitHub APIs the sink can call (spec GithubDispatchSinkConfig.mode).
const ( DefaultAPIBaseURL = "https://api.github.com" DefaultEventType = "angelia.release.published" DefaultTimeout = 10 * time.Second MinTimeout = time.Second MaxTimeout = 2 * time.Minute // MaxEventTypeTemplate and MaxInputTemplate bound the templates, in bytes. MaxEventTypeTemplate = 1024 MaxInputTemplate = 4096 // MaxInputs is the number of workflow inputs GitHub accepts. MaxInputs = 25 // MaxEventTypeChars is GitHub's limit on a rendered event_type. MaxEventTypeChars = 100 // MaxFieldLen bounds workflow and ref (spec maxLength). MaxFieldLen = 255 )
Defaults and bounds of the configuration (spec GithubDispatchSinkConfig).
const ( TokenPointer = "/token_env" TokenRefPointer = "/token_ref" )
Pointers of the token references in sink.Request.Secrets: the JSON Pointer of token_env or token_ref in the configuration.
const ( // MaxPayloadStringBytes is the longest string of client_payload. MaxPayloadStringBytes = 2048 // MaxInputBytes is the longest workflow input value. MaxInputBytes = 1024 // MaxBodyBytes is the size the sink keeps the JSON body under, below // GitHub's 65535 characters for client_payload. The strings are cut // further, deterministically, when escaping would pass it. MaxBodyBytes = 60000 )
const Kind = "github-dispatch"
Kind is the registry key of this sink.
Variables ¶
This section is empty.
Functions ¶
func CheckAPIBaseURL ¶
CheckAPIBaseURL checks api_base_url: an absolute https URL with no userinfo, query or fragment. The token is sent there and nowhere else. The message never echoes the URL.
func CheckEventType ¶
CheckEventType checks a rendered event_type: 1 to MaxEventTypeChars characters, not blank.
func CheckEventTypeTemplate ¶
CheckEventTypeTemplate checks an event_type template as CheckTemplate does, then renders it on the sample events and checks each result with CheckEventType.
func CheckInputName ¶
CheckInputName checks the name of a workflow input. A name ending in _env or _ref is refused: the core reads every such key of a sink configuration, at any depth, as the name of an environment variable or of a stored secret (ADR 0023 section 4, ADR 0024 section 6).
func CheckTemplate ¶
CheckTemplate compiles an event_type or input template, the way a subscription template is checked at load: the error gives a position and a reason, never the template text. A template with no action is a literal; its length is the caller's concern.
func CheckWorkflow ¶
CheckWorkflow checks the workflow of a workflow_dispatch sink: a numeric id or a file name such as release.yml. It becomes one path segment.
Types ¶
type Config ¶
type Config struct {
Mode string `json:"mode,omitempty"`
Repo string `json:"repo"`
APIBaseURL string `json:"api_base_url,omitempty"`
TokenEnv string `json:"token_env,omitempty"`
TokenRef string `json:"token_ref,omitempty"`
EventType string `json:"event_type,omitempty"`
Workflow string `json:"workflow,omitempty"`
Ref string `json:"ref,omitempty"`
Inputs map[string]string `json:"inputs,omitempty"`
Timeout string `json:"timeout,omitempty"`
}
Config is the configuration of a github-dispatch sink (spec GithubDispatchSinkConfig, docs/github-dispatch.md). It holds the name of the variable or of the stored secret with the token, never the token.
type Options ¶
type Options struct {
// Now is the clock for Retry-After and x-ratelimit-reset. Default
// time.Now.
Now func() time.Time
}
Options configures a Sink.
type Sink ¶
type Sink struct {
// contains filtered or unexported fields
}
Sink is the github-dispatch sink. It is safe for concurrent use.
func New ¶
New returns a github-dispatch sink sending through client, which must be the netguard client (netguard.Client.HTTPClient). The sink uses a copy of it that does not follow redirects. New panics if client is nil.