client

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2021 License: Apache-2.0 Imports: 21 Imported by: 1

Documentation

Index

Constants

View Source
const (
	OAuth2KeyAccessToken = "accessToken"

	AuthHeaderAuthorization = "Authorization"

	AuthPrefixBearer = "Bearer"

	// OAuth2ClientIDKey is the key of the clientID for AuthTypeOAuth2 secrets
	OAuth2ClientIDKey = "clientID"
	// OAuth2ClientSecretKey is the key of the clientSecret for AuthTypeOAuth2 secrets
	OAuth2ClientSecretKey = "clientSecret"
	// OAuth2CodeKey is the key of the code for AuthTypeOAuth2 secrets
	OAuth2CodeKey = "code"
	// OAuth2AccessTokenKeyKey is the key of the accessTokenKey for AuthTypeOAuth2 secrets
	OAuth2AccessTokenKeyKey = "accessTokenKey"
	// OAuth2AccessTokenKey is the key of the accessToken for AuthTypeOAuth2 secrets
	OAuth2AccessTokenKey = "accessToken"
	// OAuth2ScopeKey is the key of the scope for AuthTypeOAuth2 secrets
	OAuth2ScopeKey = "scope"
	// OAuth2RefreshTokenKey is the key of the refreshToken for AuthTypeOAuth2 secrets
	OAuth2RefreshTokenKey = "refreshToken"
	// OAuth2ExpiresInKey is the key of the expiresIn for AuthTypeOAuth2 secrets
	OAuth2CreatedAtKey = "createdAt"
	// OAuth2ExpiresInKey is the key of the expiresIn for AuthTypeOAuth2 secrets
	OAuth2ExpiresInKey = "expiresIn"
	// OAuth2RedirectURLKey is the key of the redirectURL for AuthTypeOAuth2 secrets
	OAuth2RedirectURLKey = "redirectURL"
)
View Source
const (
	// PluginAuthHeader header for auth type (kubernetes secret type)
	PluginAuthHeader = "X-Plugin-Auth"
	// PluginSecretHeader header to store data part of the secret
	PluginSecretHeader = "X-Plugin-Secret"
)
View Source
const (
	// PluginMetaHeader header to store metadata for the plugin
	PluginMetaHeader = "X-Plugin-Meta"
)

Variables

This section is empty.

Functions

func AuthFilter

func AuthFilter(req *restful.Request, resp *restful.Response, chain *restful.FilterChain)

AuthFilter auth filter for go restful, parsing plugin auth

func GetDefaultTransport

func GetDefaultTransport() http.RoundTripper

func MetaFilter

func MetaFilter(req *restful.Request, resp *restful.Response, chain *restful.FilterChain)

MetaFilter meta filter for go restful, parsing plugin meta

func NewHTTPClient

func NewHTTPClient() *http.Client

Types

type ArtifactDeleter

type ArtifactDeleter interface {
	Interface
	DeleteArtifact(ctx context.Context, params metav1alpha1.ArtifactOptions) error
}

ArtifactDeleter delete artifact

type ArtifactGetter

type ArtifactGetter interface {
	Interface
	GetArtifact(ctx context.Context, params metav1alpha1.ArtifactOptions) (*metav1alpha1.Artifact, error)
}

ArtifactGetter get artifact detail

type ArtifactLister

type ArtifactLister interface {
	Interface
	ListArtifacts(ctx context.Context, params metav1alpha1.ArtifactOptions, option metav1alpha1.ListOptions) (*metav1alpha1.ArtifactList, error)
}

ArtifactLister list artifact

type Auth

type Auth struct {
	// Type secret type as in kubernetes secret.type
	Type v1alpha1.AuthType `json:"type"`
	// Secret 's data value extracted from kubernetes
	Secret map[string][]byte `json:"data"`
}

Auth plugin auth

func ExtractAuth

func ExtractAuth(ctx context.Context) *Auth

ExtractAuth extract auth from a specific context

func FromSecret

func FromSecret(secret corev1.Secret) *Auth

FromSecret generate auth from secret

func (*Auth) Basic

func (a *Auth) Basic() (AuthMethod, error)

Basic return a Basic auth function

func (*Auth) BearerToken

func (a *Auth) BearerToken(attribute string) (AuthMethod, error)

BearerToken return an bearer token auth method

func (*Auth) Get

func (a *Auth) Get(attribute string) (string, error)

Get get specific attribute from secret

func (*Auth) GetBasicInfo

func (a *Auth) GetBasicInfo() (userName string, password string, err error)

GetBasicInfo get basic auth username and password

func (*Auth) GetOAuth2Token

func (a *Auth) GetOAuth2Token() (string, error)

GetOAuth2Token get oauth2 access token

func (*Auth) Header

func (a *Auth) Header(attribute string, header string) (AuthMethod, error)

Header return an auth method which could append to header with specific attribute

func (*Auth) HeaderWithPrefix

func (a *Auth) HeaderWithPrefix(attribute string, header string, prefix string) (AuthMethod, error)

HeaderWithPrefix return an auth method which could append to header with specific attribute and prefix

func (*Auth) IsBasic

func (a *Auth) IsBasic() bool

IsBasic check auth is basic

func (*Auth) IsOAuth2

func (a *Auth) IsOAuth2() bool

IsOAuth2 check auth is oauth2

func (*Auth) OAuth2

func (a *Auth) OAuth2() (AuthMethod, error)

OAuth2 return an oauth2 auth method

func (*Auth) Query

func (a *Auth) Query(attribute string, query string) (AuthMethod, error)

Query return an auth method which could append to query with specific attribute

func (*Auth) WithContext

func (a *Auth) WithContext(ctx context.Context) context.Context

WithContext returns a copy of parent include with the auth

type AuthMethod

type AuthMethod func(request *resty.Request)

type BuildOptions

type BuildOptions func(client *PluginClient)

BuildOptions Options to build the plugin client

func ClientOpts

func ClientOpts(clt *resty.Client) BuildOptions

ClientOpts adds a custom client build options for plugin client

type Client

type Client interface {
	Get(ctx context.Context, baseURL *duckv1.Addressable, uri string, options ...OptionFunc) error
	Post(ctx context.Context, baseURL *duckv1.Addressable, uri string, options ...OptionFunc) error
	Put(ctx context.Context, baseURL *duckv1.Addressable, uri string, options ...OptionFunc) error
	Delete(ctx context.Context, baseURL *duckv1.Addressable, uri string, options ...OptionFunc) error
}

Client inteface for PluginClient, client code shoud use the interface as dependency

type ClientGitBranch

type ClientGitBranch interface {
	List(ctx context.Context, baseURL *duckv1.Addressable, repo metav1alpha1.GitBranchOption, options ...OptionFunc) (*metav1alpha1.GitBranchList, error)
	Create(ctx context.Context, baseURL *duckv1.Addressable, payload metav1alpha1.CreateBranchPayload, options ...OptionFunc) (*metav1alpha1.GitBranch, error)
	Get(ctx context.Context, baseURL *duckv1.Addressable, repo metav1alpha1.GitRepo, branch string, options ...OptionFunc) (*metav1alpha1.GitBranch, error)
}

ClientGitBranch client for branch

type ClientGitCommit

type ClientGitCommit interface {
	Get(ctx context.Context, baseURL *duckv1.Addressable, option metav1alpha1.GitCommitOption, options ...OptionFunc) (*metav1alpha1.GitCommit, error)
}

ClientGitCommit client for commit

type ClientGitCommitComment

type ClientGitCommitComment interface {
	List(ctx context.Context, baseURL *duckv1.Addressable, option metav1alpha1.GitCommitOption, options ...OptionFunc) (*metav1alpha1.GitCommitCommentList, error)
	Create(ctx context.Context, baseURL *duckv1.Addressable, payload metav1alpha1.CreateCommitCommentPayload, options ...OptionFunc) (*metav1alpha1.GitCommitComment, error)
}

type ClientGitCommitStatus

type ClientGitCommitStatus interface {
	List(ctx context.Context, baseURL *duckv1.Addressable, option metav1alpha1.GitCommitOption, options ...OptionFunc) (*metav1alpha1.GitCommitStatusList, error)
	Create(ctx context.Context, baseURL *duckv1.Addressable, payload metav1alpha1.CreateCommitStatusPayload, options ...OptionFunc) (*metav1alpha1.GitCommitStatus, error)
}

type ClientGitContent

type ClientGitContent interface {
	Get(ctx context.Context, baseURL *duckv1.Addressable, option metav1alpha1.GitRepoFileOption, options ...OptionFunc) (*metav1alpha1.GitRepoFile, error)
	Create(ctx context.Context, baseURL *duckv1.Addressable, payload metav1alpha1.CreateRepoFilePayload, options ...OptionFunc) (*metav1alpha1.GitCommit, error)
}

type ClientGitRepository

type ClientGitRepository interface {
	List(ctx context.Context, baseURL *duckv1.Addressable, project, keyword string, options ...OptionFunc) (*metav1alpha1.GitRepositoryList, error)
	Get(ctx context.Context, baseURL *duckv1.Addressable, project, repo string, options ...OptionFunc) (*metav1alpha1.GitRepository, error)
}

ClientGitRepository client for repo

type ClientProject

type ClientProject interface {
	List(ctx context.Context, baseURL *duckv1.Addressable, options ...OptionFunc) (*metav1alpha1.ProjectList, error)
	Create(ctx context.Context, baseURL *duckv1.Addressable, project *metav1alpha1.Project, options ...OptionFunc) (*metav1alpha1.Project, error)
	Get(ctx context.Context, baseURL *duckv1.Addressable, id string, options ...OptionFunc) (*metav1alpha1.Project, error)
}

type ClientProjectGetter

type ClientProjectGetter interface {
	Project(meta Meta, secret corev1.Secret) ClientProject
}

type GitBranchCreator

type GitBranchCreator interface {
	Interface
	CreateGitBranch(ctx context.Context, payload metav1alpha1.CreateBranchPayload) (metav1alpha1.GitBranch, error)
}

GitBranchCreator create git branch,github, gogs don't support create branch

type GitBranchGetter

type GitBranchGetter interface {
	Interface
	GetGitBranch(ctx context.Context, repoOption metav1alpha1.GitRepo, branch string) (metav1alpha1.GitBranch, error)
}

GitBranchGetter get git branch

type GitBranchLister

type GitBranchLister interface {
	Interface
	ListGitBranch(ctx context.Context, branchOption metav1alpha1.GitBranchOption, option metav1alpha1.ListOptions) (metav1alpha1.GitBranchList, error)
}

GitBranchLister List git branch

type GitCommitCommentCreator

type GitCommitCommentCreator interface {
	Interface
	CreateGitCommitComment(ctx context.Context, payload metav1alpha1.CreateCommitCommentPayload) (metav1alpha1.GitCommitComment, error)
}

GitRepositoryLister create git commit comment

type GitCommitCommentLister

type GitCommitCommentLister interface {
	Interface
	ListGitCommitComment(ctx context.Context, option metav1alpha1.GitCommitOption, listOption metav1alpha1.ListOptions) (metav1alpha1.GitCommitCommentList, error)
}

GitRepositoryLister list git commit comment

type GitCommitGetter

type GitCommitGetter interface {
	Interface
	GetGitCommit(ctx context.Context, option metav1alpha1.GitCommitOption) (metav1alpha1.GitCommit, error)
}

GitCommitGetter get git commit

type GitCommitStatusCreator

type GitCommitStatusCreator interface {
	Interface
	CreateGitCommitStatus(ctx context.Context, payload metav1alpha1.CreateCommitStatusPayload) (metav1alpha1.GitCommitStatus, error)
}

GitCommitStatusCreator create git commit status

type GitCommitStatusLister

type GitCommitStatusLister interface {
	Interface
	ListGitCommitStatus(ctx context.Context, option metav1alpha1.GitCommitOption, listOption metav1alpha1.ListOptions) (metav1alpha1.GitCommitStatusList, error)
}

GitCommitStatusLister list git commit status

type GitPullRequestCommentCreator

type GitPullRequestCommentCreator interface {
	Interface
	CreatePullRequestComment(ctx context.Context, option metav1alpha1.CreatePullRequestCommentPayload) (metav1alpha1.GitPullRequestNote, error)
}

GitPullRequestCommentCreator create pull request comment functions

type GitPullRequestCommentLister

type GitPullRequestCommentLister interface {
	Interface
	ListPullRequestComment(ctx context.Context, option metav1alpha1.GitPullRequestOption, listOption metav1alpha1.ListOptions) (metav1alpha1.GitPullRequestNoteList, error)
}

GitPullRequestCommentLister list pull request comment functions

type GitPullRequestHandler

GitPullRequestHandler list, get and create pr function

type GitRepoFileCreator

type GitRepoFileCreator interface {
	Interface
	CreateGitRepoFile(ctx context.Context, payload metav1alpha1.CreateRepoFilePayload) (metav1alpha1.GitCommit, error)
}

GitRepoFileCreator used to create a file, gogs don't support

type GitRepoFileGetter

type GitRepoFileGetter interface {
	Interface
	GetGitRepoFile(ctx context.Context, option metav1alpha1.GitRepoFileOption) (metav1alpha1.GitRepoFile, error)
}

GitRepoFileGetter used to get a file content

type GitRepositoryGetter

type GitRepositoryGetter interface {
	Interface
	GetGitRepository(ctx context.Context, repoOption metav1alpha1.GitRepo) (metav1alpha1.GitRepository, error)
}

GitRepositoryGetter get git repository

type GitRepositoryLister

type GitRepositoryLister interface {
	Interface
	ListGitRepository(ctx context.Context, id, keyword string, listOption metav1alpha1.ListOptions) (metav1alpha1.GitRepositoryList, error)
}

GitRepositoryLister list git repository

type GitTriggerRegister

type GitTriggerRegister interface {
	GetIntegrationClassName() string

	// cloud event type of pull request hook that will match
	PullRequestEventType() string

	// cloud event type of push hook that will match
	PushEventType() string

	// cloud event type of push hook that will match
	TagEventType() string
}

GitTriggerRegister used to register GitTrigger TODO: need refactor: maybe integration plugin should decided how to generate cloudevents filters up to now, it is not a better solution that relying on plugins to give some events type to GitTriggerReconcile.

PullRequestCloudEventFilter() CloudEventFilters
BranchCloudEventFilter() CloudEventFilters
TagCloudEventFilter() CloudEventFilters
WebHook() WebHook

type Interface

type Interface interface {
	Path() string
	Setup(context.Context, *zap.SugaredLogger) error
}

Interface base interface for plugins

type Meta

type Meta struct {
	Version string `json:"version,omitempty"`
	BaseURL string `json:"baseURL,omitempty"`
}

Meta Plugin meta with base url and version info, for calling plugin api

func ExtraMeta

func ExtraMeta(ctx context.Context) *Meta

ExtraMeta extract meta from a specific context

func (*Meta) WithContext

func (p *Meta) WithContext(ctx context.Context) context.Context

WithContext returns a copy of parent include with the plugin meta

type OptionFunc

type OptionFunc func(request *resty.Request)

OptionFunc options for requests

func BodyOpts

func BodyOpts(body interface{}) OptionFunc

BodyOpts request body

func ErrorOpts

func ErrorOpts(err interface{}) OptionFunc

ErrorOpts error response object

func HeaderOpts

func HeaderOpts(key, value string) OptionFunc

HeaderOpts sets a header

func ListOpts

func ListOpts(opts metav1alpha1.ListOptions) OptionFunc

ListOpts options for lists

func MetaOpts

func MetaOpts(meta Meta) OptionFunc

MetaOpts provides metadata for the request

func QueryOpts

func QueryOpts(params map[string]string) OptionFunc

QueryOpts query parameters for the request

func ResultOpts

func ResultOpts(dest interface{}) OptionFunc

ResultOpts request result automatically marshalled into object

func SecretOpts

func SecretOpts(secret corev1.Secret) OptionFunc

SecretOpts provides a secret to be assigned to the request in the header

type PluginClient

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

PluginClient client for plugins

func NewPluginClient

func NewPluginClient(opts ...BuildOptions) *PluginClient

NewPluginClient creates a new plugin client

func (*PluginClient) Body

func (p *PluginClient) Body(body interface{}) OptionFunc

Body request body

func (*PluginClient) Delete

func (p *PluginClient) Delete(ctx context.Context, baseURL *duckv1.Addressable, path string, options ...OptionFunc) error

Delete performs a DELETE request with the given parameters

func (*PluginClient) Dest

func (p *PluginClient) Dest(dest interface{}) OptionFunc

Dest request result automatically marshalled into object

func (*PluginClient) Error

func (p *PluginClient) Error(err interface{}) OptionFunc

Error error response object

func (*PluginClient) Get

func (p *PluginClient) Get(ctx context.Context, baseURL *duckv1.Addressable, path string, options ...OptionFunc) error

Get performs a GET request using defined options

func (*PluginClient) GitBranch

func (p *PluginClient) GitBranch(meta Meta, secret corev1.Secret) ClientGitBranch

GitBranch get branch client

func (*PluginClient) GitCommit

func (p *PluginClient) GitCommit(meta Meta, secret corev1.Secret) ClientGitCommit

GitPullRequest get pr client

func (*PluginClient) GitCommitComment

func (p *PluginClient) GitCommitComment(meta Meta, secret corev1.Secret) ClientGitCommitComment

GitCommitComment get commit comment client

func (*PluginClient) GitCommitStatus

func (p *PluginClient) GitCommitStatus(meta Meta, secret corev1.Secret) ClientGitCommitStatus

GitCommitStatus get commit comment client

func (*PluginClient) GitContent

func (p *PluginClient) GitContent(meta Meta, secret corev1.Secret) ClientGitContent

GitContent get content client

func (*PluginClient) GitPullRequest

func (p *PluginClient) GitPullRequest(meta Meta, secret corev1.Secret) ClientGitPullRequest

GitPullRequest get pr client

func (*PluginClient) GitRepository

func (p *PluginClient) GitRepository(meta Meta, secret corev1.Secret) ClientGitRepository

GitRepository get repo client

func (*PluginClient) HandleError

func (p *PluginClient) HandleError(response *resty.Response, err error) error

func (*PluginClient) Header

func (p *PluginClient) Header(key, value string) OptionFunc

Header sets a header

func (*PluginClient) ListOptions

func (p *PluginClient) ListOptions(opts metav1alpha1.ListOptions) OptionFunc

ListOptions options for lists

func (*PluginClient) Meta

func (p *PluginClient) Meta(meta Meta) OptionFunc

Meta provides metadata for the request

func (*PluginClient) Post

func (p *PluginClient) Post(ctx context.Context, baseURL *duckv1.Addressable, path string, options ...OptionFunc) error

Post performs a POST request with the given parameters

func (*PluginClient) Project

func (p *PluginClient) Project(meta Meta, secret corev1.Secret) ClientProject

Project get project client

func (*PluginClient) Put

func (p *PluginClient) Put(ctx context.Context, baseURL *duckv1.Addressable, path string, options ...OptionFunc) error

Put performs a PUT request with the given parameters

func (*PluginClient) Query

func (p *PluginClient) Query(params map[string]string) OptionFunc

Query query parameters for the request

func (*PluginClient) R

func (p *PluginClient) R(ctx context.Context, baseURL *duckv1.Addressable, options ...OptionFunc) *resty.Request

R prepares a request based on the given information

func (*PluginClient) Secret

func (p *PluginClient) Secret(secret corev1.Secret) OptionFunc

Secret provides a secret to be assigned to the request in the header

type PluginRegister

type PluginRegister interface {
	Interface
	GetIntegrationClassName() string
	// Returns its own plugin access URL
	GetAddressURL() *apis.URL
	// Returns a Webhook accessible URL for external tools
	// If not supported return nil, false
	GetWebhookURL() (*apis.URL, bool)
	// Returns a list of supported versions by the plugin
	// For SaaS platform plugins use a "online" version.
	GetSupportedVersions() []string
	// Returns all secret types supported by the plugin
	GetSecretTypes() []string
	// GetReplicationPolicyTypes return replication policy types for ClusterIntegration
	GetReplicationPolicyTypes() []string
	// Returns a list of Resource types that can be used in ClusterIntegration and Integration
	GetResourceTypes() []string
}

PluginRegister plugin registration methods to update IntegationClass status

type ProjectCreator

type ProjectCreator interface {
	Interface
	CreateProject(ctx context.Context, project *metav1alpha1.Project) (*metav1alpha1.Project, error)
}

ProjectCreator create project api

type ProjectGetter

type ProjectGetter interface {
	Interface
	GetProject(ctx context.Context, id string) (*metav1alpha1.Project, error)
}

ProjectGetter list project api

type ProjectLister

type ProjectLister interface {
	Interface
	ListProjects(ctx context.Context, option metav1alpha1.ListOptions) (*metav1alpha1.ProjectList, error)
}

ProjectLister list project api

type RepositoryLister

type RepositoryLister interface {
	Interface
	ListRepositories(ctx context.Context, params metav1alpha1.RepositoryOptions, option metav1alpha1.ListOptions) (*metav1alpha1.RepositoryList, error)
}

RepositoryLister list repository

type ResourceLister

type ResourceLister interface {
	Interface
	ListResources(ctx context.Context, option metav1alpha1.ListOptions) (*metav1alpha1.ResourceList, error)
}

ResourceLister list resource api

type ScanImage

type ScanImage interface {
	Interface
	ScanImage(ctx context.Context, params metav1alpha1.ArtifactOptions) error
}

ScanImage scan image

type WebhookReceiver

type WebhookReceiver interface {
	Interface
	ReceiveWebhook(ctx context.Context, req *restful.Request, secret string) (cloudevent.Event, error)
}

WebhookReceiver receives a webhook request with validation and transform it into a cloud event

type WebhookRegister

type WebhookRegister interface {
	// Use the methods below to manage webhooks in the target platform
	CreateWebhook(ctx context.Context, spec metav1alpha1.WebhookRegisterSpec, secret corev1.Secret) (metav1alpha1.WebhookRegisterStatus, error)
	UpdateWebhook(ctx context.Context, spec metav1alpha1.WebhookRegisterSpec, secret corev1.Secret) (metav1alpha1.WebhookRegisterStatus, error)
	DeleteWebhook(ctx context.Context, spec metav1alpha1.WebhookRegisterSpec, secret corev1.Secret) error
	ListWebhooks(ctx context.Context, uri apis.URL, secret corev1.Secret) ([]metav1alpha1.WebhookRegisterStatus, error)
}

WebhookRegister used to register and manage webhooks

type WebhookResourceDiffer

type WebhookResourceDiffer interface {
	// IsSameResource will provide two ResourceURI
	// the plugin should discern if they are the same.
	// If this method is not implemented a standard comparisons will be used
	IsSameResource(ctx context.Context, i, j metav1alpha1.ResourceURI) bool
}

WebhookResourceDiffer used to compare different webhook resources in order to provide a way to merge webhook registration requests. If not provided, the resource's URI will be directly compared

Jump to

Keyboard shortcuts

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