clients

package
v0.0.80 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Package clients contains github client logic

Index

Constants

View Source
const Github = "github"

Github is the string that represents the GitHubOAuth provider

View Source
const GithubApp = "github-app"

GithubApp is the string that represents the GitHubApp provider

Variables

AppAuthorizationFlows is the list of authorization flows that the GitHubOAuth provider supports

AppImplements is the list of provider types that the GitHubOAuth provider implements

OAuthAuthorizationFlows is the list of authorization flows that the GitHubOAuth provider supports

OAuthImplements is the list of provider types that the GitHubOAuth provider implements

Functions

func MarshalV1AppConfig

func MarshalV1AppConfig(rawCfg json.RawMessage) (json.RawMessage, error)

MarshalV1AppConfig unmarshalls and then marshalls back to get rid of unknown keys before storing

func MarshalV1OAuthConfig

func MarshalV1OAuthConfig(rawCfg json.RawMessage) (json.RawMessage, error)

MarshalV1OAuthConfig marshals the GitHubConfig struct into a raw config

func NewGitHubAppProvider

func NewGitHubAppProvider(
	cfg *minderv1.GitHubAppProviderConfig,
	appConfig *server.ProviderConfig,
	whcfg *server.WebhookConfig,
	restClientCache ratecache.RestClientCache,
	credential provifv1.GitHubCredential,
	packageListingClient *gogithub.Client,
	ghClientFactory GitHubClientFactory,
	propertyFetchers properties.GhPropertyFetcherFactory,
	isOrg bool,
) (*github.GitHub, error)

NewGitHubAppProvider creates a new GitHub App API client BaseURL defaults to the public GitHub API, if needing to use a customer domain endpoint (as is the case with GitHub Enterprise), set the Endpoint field in the GitHubConfig struct

func NewRestClient

func NewRestClient(
	cfg *minderv1.GitHubProviderConfig,
	providerCfg *server.ProviderConfig,
	whcfg *server.WebhookConfig,
	restClientCache ratecache.RestClientCache,
	credential provifv1.GitHubCredential,
	ghClientFactory GitHubClientFactory,
	propertyFetchers properties.GhPropertyFetcherFactory,
	owner string,
) (*github.GitHub, error)

NewRestClient creates a new GitHub REST API client BaseURL defaults to the public GitHub API, if needing to use a customer domain endpoint (as is the case with GitHub Enterprise), set the Endpoint field in the GitHubConfig struct

func ParseAndMergeV1AppConfig

func ParseAndMergeV1AppConfig(rawCfg json.RawMessage) (
	*minderv1.ProviderConfig,
	*minderv1.GitHubAppProviderConfig,
	error,
)

ParseAndMergeV1AppConfig parses the raw config into a GitHubAppProviderConfig struct

func ParseAndMergeV1OAuthConfig

func ParseAndMergeV1OAuthConfig(rawCfg json.RawMessage) (*minderv1.GitHubProviderConfig, error)

ParseAndMergeV1OAuthConfig parses the raw config into a GitHubConfig struct

Types

type GitHubAppDelegate

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

GitHubAppDelegate is the struct that contains the GitHub App specific operations

func NewAppDelegate

func NewAppDelegate(
	client *gogithub.Client,
	credential provifv1.GitHubCredential,
	appName string,
	defaultUserId int64,
	isOrg bool,
) *GitHubAppDelegate

NewAppDelegate creates a GitHubOAuthDelegate from a GitHub client This exists as a separate function to allow the provider creation code to use its methods without instantiating a full provider.

func (*GitHubAppDelegate) GetCredential

func (g *GitHubAppDelegate) GetCredential() provifv1.GitHubCredential

GetCredential returns the GitHub App installation credential

func (*GitHubAppDelegate) GetLogin

func (g *GitHubAppDelegate) GetLogin(ctx context.Context) (string, error)

GetLogin returns the username for the GitHub App user

func (*GitHubAppDelegate) GetName

func (g *GitHubAppDelegate) GetName(_ context.Context) (string, error)

GetName returns the username for the GitHub App user

func (*GitHubAppDelegate) GetOwner

func (_ *GitHubAppDelegate) GetOwner() string

GetOwner returns the owner filter

func (*GitHubAppDelegate) GetPrimaryEmail

func (g *GitHubAppDelegate) GetPrimaryEmail(ctx context.Context) (string, error)

GetPrimaryEmail returns the email for the GitHub App user

func (*GitHubAppDelegate) GetUserId

func (g *GitHubAppDelegate) GetUserId(ctx context.Context) (int64, error)

GetUserId returns the user id for the GitHub App user

func (*GitHubAppDelegate) IsOrg

func (g *GitHubAppDelegate) IsOrg() bool

IsOrg returns true if the owner is an organization

func (*GitHubAppDelegate) ListAllRepositories

func (g *GitHubAppDelegate) ListAllRepositories(ctx context.Context) ([]*minderv1.Repository, error)

ListAllRepositories returns a list of all repositories accessible to the GitHub App installation

type GitHubClientFactory

type GitHubClientFactory interface {
	// BuildOAuthClient creates an instance of the GitHub Client and the OAuthDelegate
	// `baseURL` should be set to the empty string if there is no need to
	// override the default GitHub URL
	BuildOAuthClient(
		baseURL string,
		credential provifv1.GitHubCredential,
		owner string,
	) (*gogithub.Client, github.Delegate, error)
	// BuildAppClient creates an instance of the GitHub Client and the AppDelegate
	// `baseURL` should be set to the empty string if there is no need to
	// override the default GitHub URL
	BuildAppClient(
		baseURL string,
		credential provifv1.GitHubCredential,
		appName string,
		userID int64,
		isOrg bool,
	) (*gogithub.Client, github.Delegate, error)
}

GitHubClientFactory creates instances of the GitHub API client

func NewGitHubClientFactory

func NewGitHubClientFactory(metrics telemetry.HttpClientMetrics) GitHubClientFactory

NewGitHubClientFactory creates a new instance of GitHubClientFactory

type GitHubOAuthDelegate

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

GitHubOAuthDelegate is the struct that contains the GitHub access token specifc operations

func NewOAuthDelegate

func NewOAuthDelegate(
	client *gogithub.Client,
	credential provifv1.GitHubCredential,
	owner string,
) *GitHubOAuthDelegate

NewOAuthDelegate creates a GitHubOAuthDelegate from a GitHub client This exists as a separate function to allow the provider creation code to use its methods without instantiating a full provider.

func (*GitHubOAuthDelegate) GetCredential

func (o *GitHubOAuthDelegate) GetCredential() provifv1.GitHubCredential

GetCredential returns the GitHub OAuth credential

func (*GitHubOAuthDelegate) GetLogin

func (o *GitHubOAuthDelegate) GetLogin(ctx context.Context) (string, error)

GetLogin returns the login for the authenticated user

func (*GitHubOAuthDelegate) GetName

func (o *GitHubOAuthDelegate) GetName(ctx context.Context) (string, error)

GetName returns the username for the authenticated user

func (*GitHubOAuthDelegate) GetOwner

func (o *GitHubOAuthDelegate) GetOwner() string

GetOwner returns the owner filter

func (*GitHubOAuthDelegate) GetPrimaryEmail

func (o *GitHubOAuthDelegate) GetPrimaryEmail(ctx context.Context) (string, error)

GetPrimaryEmail returns the primary email for the authenticated user.

func (*GitHubOAuthDelegate) GetUserId

func (o *GitHubOAuthDelegate) GetUserId(ctx context.Context) (int64, error)

GetUserId returns the user id for the authenticated user

func (*GitHubOAuthDelegate) IsOrg

func (o *GitHubOAuthDelegate) IsOrg() bool

IsOrg returns true if the owner is an organization

func (*GitHubOAuthDelegate) ListAllRepositories

func (o *GitHubOAuthDelegate) ListAllRepositories(ctx context.Context) ([]*minderv1.Repository, error)

ListAllRepositories returns a list of all repositories for the authenticated user Two APIs are available, contigent on whether the token is for a user or an organization

Directories

Path Synopsis
Package mock_clients is a generated GoMock package.
Package mock_clients is a generated GoMock package.

Jump to

Keyboard shortcuts

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