github

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 26, 2022 License: Apache-2.0 Imports: 20 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type OIDCClient

type OIDCClient struct {
	// contains filtered or unexported fields
}

OIDCClient is a client for the GitHub OIDC provider.

func NewOIDCClient

func NewOIDCClient() (*OIDCClient, error)

NewOIDCClient returns new GitHub OIDC provider client.

func NewTestOIDCServer

func NewTestOIDCServer(t *testing.T, now time.Time, token *OIDCToken) (*httptest.Server, *OIDCClient)

NewTestOIDCServer returns an httptest.Server that can be used as the OIDC server, and an OIDClient that will use the test server. The server returns the given token when queried. Now is the time used for token expiration verification by the client.

func (*OIDCClient) Token

func (c *OIDCClient) Token(ctx context.Context, audience []string) (*OIDCToken, error)

Token requests an OIDC token from Github's provider, verifies it, and returns the token.

type OIDCToken

type OIDCToken struct {
	// Issuer is the token issuer.
	Issuer string

	// Audience is the audience for which the token was granted.
	Audience []string

	// Expiry is the expiration date of the token.
	Expiry time.Time

	// JobWorkflowRef is a reference to the current job workflow.
	JobWorkflowRef string `json:"job_workflow_ref"`
}

OIDCToken represents the contents of a Github OIDC JWT token.

type WorkflowContext

type WorkflowContext struct {
	Repository string                 `json:"repository"`
	ActionPath string                 `json:"action_path"`
	Workflow   string                 `json:"workflow"`
	EventName  string                 `json:"event_name"`
	Event      map[string]interface{} `json:"event"`
	SHA        string                 `json:"sha"`
	RefType    string                 `json:"ref_type"`
	Ref        string                 `json:"ref"`
	BaseRef    string                 `json:"base_ref"`
	HeadRef    string                 `json:"head_ref"`
	Actor      string                 `json:"actor"`
	RunNumber  string                 `json:"run_number"`
	ServerURL  string                 `json:"server_url"`
	RunID      string                 `json:"run_id"`
	RunAttempt string                 `json:"run_attempt"`
}

WorkflowContext is the 'github' context given to workflows that contains information about the Github Actions workflow run.

See: https://docs.github.com/en/actions/learn-github-actions/contexts#github-context.

func GetWorkflowContext

func GetWorkflowContext() (WorkflowContext, error)

GetWorkflowContext returns the current Github Actions 'github' context.

func (WorkflowContext) RepositoryURI

func (c WorkflowContext) RepositoryURI() string

RepositoryURI returns a full repository URI for the repo that triggered the workflow.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL