providers

package
v0.0.45 Latest Latest
Warning

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

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

Documentation

Overview

Package providers contains general utilities for interacting with providers.

Index

Constants

View Source
const (
	// InstallationEventKey is the key for the event in the message metadata (e.g. removed)
	InstallationEventKey = "event"
	// ClassKey is the key for the provider class in the message metadata
	ClassKey = "class"
)
View Source
const (
	// ProviderInstallationTopic is the topic for when a provider installation is removed
	ProviderInstallationTopic = "internal.provider.installation.removed.event"
)
View Source
const TypeGitHubOrganization = "Organization"

TypeGitHubOrganization is the type returned from the GitHub API when the owner is an organization

Variables

View Source
var ErrInvalidCredential = errors.New("invalid credential type")

ErrInvalidCredential is returned when the credential is not of the required type

View Source
var ErrInvalidTokenIdentity = errors.New("invalid token identity")

ErrInvalidTokenIdentity is returned when the user identity in the token does not match the expected user identity from the state

Functions

func DBToPBAuthFlow added in v0.0.35

func DBToPBAuthFlow(t db.AuthorizationFlow) (minderv1.AuthorizationFlow, bool)

DBToPBAuthFlow converts a database authorization flow to a protobuf authorization flow.

func DBToPBType added in v0.0.30

func DBToPBType(t db.ProviderType) (minderv1.ProviderType, bool)

DBToPBType converts a database provider type to a protobuf provider type.

func GetCredentialStateForProvider added in v0.0.37

func GetCredentialStateForProvider(
	ctx context.Context,
	prov db.Provider,
	s db.Store,
	cryptoEngine crypto.Engine,
	provCfg *serverconfig.ProviderConfig,
) string

GetCredentialStateForProvider returns the credential state for the given provider.

func GetProviderClassString added in v0.0.38

func GetProviderClassString(prov db.Provider) string

GetProviderClassString returns the string representation of the provider class.

func ListProviderClasses added in v0.0.38

func ListProviderClasses() []string

ListProviderClasses returns a list of provider classes.

func ProviderInstanceRemovedMessage added in v0.0.39

func ProviderInstanceRemovedMessage(
	msg *message.Message,
	providerClass db.ProviderClass,
	payload []byte,
)

ProviderInstanceRemovedMessage returns the provider installation event from the message

Types

type ErrProviderNotFoundBy added in v0.0.43

type ErrProviderNotFoundBy struct {
	Name  string
	Trait string
}

ErrProviderNotFoundBy is an error type which is returned when a provider is not found

func (ErrProviderNotFoundBy) Error added in v0.0.43

func (e ErrProviderNotFoundBy) Error() string

type GitHubAppInstallationDeletedPayload added in v0.0.39

type GitHubAppInstallationDeletedPayload struct {
	InstallationID int64 `json:"installation_id"`
}

GitHubAppInstallationDeletedPayload represents the payload of a GitHub App installation deleted event

type InstallationManager added in v0.0.39

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

InstallationManager is a struct representing the installation manager

func NewInstallationManager added in v0.0.39

func NewInstallationManager(
	svc ProviderService,
) *InstallationManager

NewInstallationManager creates a new installation manager

func (*InstallationManager) Register added in v0.0.39

func (im *InstallationManager) Register(reg events.Registrar)

Register implements the Consumer interface.

type ProjectFactory added in v0.0.39

type ProjectFactory func(
	ctx context.Context, qtx db.Querier, name string, user int64) (*db.Project, error)

ProjectFactory may create a project named name for the specified userid if present in the system. If a db.Project is returned, it should be used as the location to create a Provider corresponding to the GitHub App installation.

type ProviderBuilder

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

ProviderBuilder is a utility struct which allows for the creation of provider clients.

func GetProviderBuilder

func GetProviderBuilder(
	ctx context.Context,
	prov db.Provider,
	store db.Store,
	crypteng crypto.Engine,
	provCfg *serverconfig.ProviderConfig,
	fallbackTokenClient *gogithub.Client,
	opts ...ProviderBuilderOption,
) (*ProviderBuilder, error)

GetProviderBuilder is a utility function which allows for the creation of a provider factory.

func NewProviderBuilder

func NewProviderBuilder(
	p *db.Provider,
	ownerFilter sql.NullString,
	isOrg bool,
	credential provinfv1.Credential,
	cfg *serverconfig.ProviderConfig,
	fallbackTokenClient *gogithub.Client,
	opts ...ProviderBuilderOption,
) *ProviderBuilder

NewProviderBuilder creates a new provider builder.

func (*ProviderBuilder) GetGit

func (pb *ProviderBuilder) GetGit() (provinfv1.Git, error)

GetGit returns a git client for the provider.

func (*ProviderBuilder) GetGitHub

func (pb *ProviderBuilder) GetGitHub() (provinfv1.GitHub, error)

GetGitHub returns a github client for the provider.

func (*ProviderBuilder) GetHTTP

func (pb *ProviderBuilder) GetHTTP() (provinfv1.REST, error)

GetHTTP returns a github client for the provider.

func (*ProviderBuilder) GetName

func (pb *ProviderBuilder) GetName() string

GetName returns the name of the provider instance as defined in the database.

func (*ProviderBuilder) GetRepoLister

func (pb *ProviderBuilder) GetRepoLister() (provinfv1.RepoLister, error)

GetRepoLister returns a repo lister for the provider.

func (*ProviderBuilder) Implements

func (pb *ProviderBuilder) Implements(impl db.ProviderType) bool

Implements returns true if the provider implements the given type.

type ProviderBuilderOption

type ProviderBuilderOption func(*ProviderBuilder)

ProviderBuilderOption is a function which can be used to set options on the ProviderBuilder.

func WithProviderMetrics

func WithProviderMetrics(metrics telemetry.ProviderMetrics) ProviderBuilderOption

WithProviderMetrics sets the metrics for the ProviderBuilder

func WithRestClientCache added in v0.0.31

func WithRestClientCache(cache ratecache.RestClientCache) ProviderBuilderOption

WithRestClientCache sets the rest client cache for the ProviderBuilder

type ProviderClassDefinition added in v0.0.38

type ProviderClassDefinition struct {
	Traits             []db.ProviderType
	AuthorizationFlows []db.AuthorizationFlow
}

ProviderClassDefinition contains the static fields needed when creating a provider

func GetProviderClassDefinition added in v0.0.38

func GetProviderClassDefinition(class string) (ProviderClassDefinition, error)

GetProviderClassDefinition returns the provider definition for the given provider class

type ProviderInstallationEvent added in v0.0.39

type ProviderInstallationEvent string

ProviderInstallationEvent is an event that occurs when a provider installation changes

const (
	// ProviderInstanceRemovedEvent is an event that occurs when a provider instance is removed
	ProviderInstanceRemovedEvent ProviderInstallationEvent = "provider_instance_removed"
)

type ProviderService added in v0.0.38

type ProviderService interface {
	// CreateGitHubOAuthProvider creates a GitHub OAuth provider with an access token credential
	CreateGitHubOAuthProvider(ctx context.Context, providerName string, providerClass db.ProviderClass,
		token oauth2.Token, stateData db.GetProjectIDBySessionStateRow, state string) (*db.Provider, error)
	// CreateGitHubAppProvider creates a GitHub App provider with an installation ID in a known project
	CreateGitHubAppProvider(ctx context.Context, token oauth2.Token, stateData db.GetProjectIDBySessionStateRow,
		installationID int64, state string) (*db.Provider, error)
	// CreateGitHubAppWithoutInvitation either creates a new project for the selected app, or stores
	// the installation in preparation for creating a new project when the authorizing user logs in.
	//
	// Note that this function may return nil, nil if the installation user is not known to Minder.
	CreateGitHubAppWithoutInvitation(ctx context.Context, qtx db.Querier, userID int64,
		installationID int64) (*db.Project, error)
	// ValidateGitHubInstallationId checks if the supplied GitHub token has access to the installation ID
	ValidateGitHubInstallationId(ctx context.Context, token *oauth2.Token, installationID int64) error
	// DeleteGitHubAppInstallation deletes the GitHub App installation and provider from the database.
	DeleteGitHubAppInstallation(ctx context.Context, installationID int64) error
	// ValidateGitHubAppWebhookPayload validates the payload of a GitHub App webhook.
	ValidateGitHubAppWebhookPayload(r *http.Request) (payload []byte, err error)
	DeleteProvider(ctx context.Context, provider *db.Provider) error
}

ProviderService encapsulates methods for creating and updating providers

func NewProviderService added in v0.0.38

func NewProviderService(store db.Store, cryptoEngine crypto.Engine, mt metrics.Metrics,
	provMt provtelemetry.ProviderMetrics, config *server.ProviderConfig,
	projectFactory ProjectFactory, restClientCache ratecache.RestClientCache, fallbackTokenClient *github.Client) ProviderService

NewProviderService creates an instance of ProviderService

type ProviderStore added in v0.0.39

type ProviderStore interface {
	// GetByID returns the provider identified by its UUID primary key.
	// It is assumed that the caller carries out some kind of validation to
	// ensure that whoever made the request is authorized to access this
	// provider.
	GetByID(ctx context.Context, providerID uuid.UUID) (*db.Provider, error)
	// GetByName returns the provider instance in the database as
	// identified by its project ID and name. All parent projects of the
	// specified project are included in the search.
	GetByName(ctx context.Context, projectID uuid.UUID, name string) (*db.Provider, error)
	// GetByNameInSpecificProject returns the provider instance in the database as
	// identified by its project ID and name. Unlike `GetByName` it will only
	// search in the specified project, and ignore the project hierarchy.
	GetByNameInSpecificProject(ctx context.Context, projectID uuid.UUID, name string) (*db.Provider, error)
	// GetByNameAndTrait returns the providers in the project which match the
	// specified trait. All parent projects of the specified project are
	// included in the search.
	// Note that if error is nil, there will always be at least one element
	// in the list of providers which is returned.
	GetByNameAndTrait(
		ctx context.Context,
		projectID uuid.UUID,
		name string,
		trait db.ProviderType,
	) ([]db.Provider, error)
}

ProviderStore provides methods for retrieving Providers from the database

func NewProviderStore added in v0.0.39

func NewProviderStore(store db.Store) ProviderStore

NewProviderStore returns a new instance of ProviderStore.

Directories

Path Synopsis
Package credentials provides the implementations for the credentials
Package credentials provides the implementations for the credentials
Package git provides a client for interacting with Git providers
Package git provides a client for interacting with Git providers
Package github provides a client for interacting with the GitHub API
Package github provides a client for interacting with the GitHub API
app
Package app provides the GitHub App specific operations
Package app provides the GitHub App specific operations
common
Package common provides common utilities for the GitHub provider
Package common provides common utilities for the GitHub provider
mock
Package mockgh is a generated GoMock package.
Package mockgh is a generated GoMock package.
oauth
Package oauth provides a client for interacting with the GitHub API using OAuth 2.0 authorization
Package oauth provides a client for interacting with the GitHub API using OAuth 2.0 authorization
Package http implements an HTTP client for interacting with an HTTP API.
Package http implements an HTTP client for interacting with an HTTP API.
Package mockprofsvc is a generated GoMock package.
Package mockprofsvc is a generated GoMock package.
Package ratecache provides a cache for the REST clients
Package ratecache provides a cache for the REST clients
mock
Package mockratecache is a generated GoMock package.
Package mockratecache is a generated GoMock package.
Package telemetry provides the telemetry interfaces and implementations for providers
Package telemetry provides the telemetry interfaces and implementations for providers

Jump to

Keyboard shortcuts

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