gitlab

package
v16.11.10 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2024 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var File_internal_gitlab_gitlab_proto protoreflect.FileDescriptor

Functions

func IsBadRequest added in v16.9.0

func IsBadRequest(err error) bool

func IsForbidden

func IsForbidden(err error) bool

func IsNotFound

func IsNotFound(err error) bool

func IsUnauthorized

func IsUnauthorized(err error) bool

Types

type Client

type Client struct {
	Backend           *url.URL
	HTTPClient        HTTPClient
	HTTPClientNoRetry HTTPClient
	UserAgent         string
}

func NewClient

func NewClient(backend *url.URL, authSecret []byte, opts ...ClientOption) *Client

func (*Client) Do

func (c *Client) Do(ctx context.Context, opts ...DoOption) error

type ClientError

type ClientError struct {
	StatusCode int32  `protobuf:"varint,1,opt,name=status_code,json=statusCode,proto3" json:"status_code,omitempty"`
	Path       string `protobuf:"bytes,2,opt,name=path,proto3" json:"path,omitempty"`
	Reason     string `protobuf:"bytes,3,opt,name=reason,proto3" json:"reason,omitempty"`
	// contains filtered or unexported fields
}

func (*ClientError) Descriptor deprecated

func (*ClientError) Descriptor() ([]byte, []int)

Deprecated: Use ClientError.ProtoReflect.Descriptor instead.

func (*ClientError) Error

func (x *ClientError) Error() string

func (*ClientError) GetPath

func (x *ClientError) GetPath() string

func (*ClientError) GetReason added in v16.2.0

func (x *ClientError) GetReason() string

func (*ClientError) GetStatusCode

func (x *ClientError) GetStatusCode() int32

func (*ClientError) ProtoMessage

func (*ClientError) ProtoMessage()

func (*ClientError) ProtoReflect

func (x *ClientError) ProtoReflect() protoreflect.Message

func (*ClientError) Reset

func (x *ClientError) Reset()

func (*ClientError) String

func (x *ClientError) String() string

type ClientInterface

type ClientInterface interface {
	Do(ctx context.Context, opts ...DoOption) error
}

type ClientOption

type ClientOption func(*clientConfig)

ClientOption to configure the client.

func WithMeterProvider added in v16.5.0

func WithMeterProvider(meterProvider otelmetric.MeterProvider) ClientOption

WithMeterProvider sets a custom meter provider to be used, otherwise the OTEL's global MeterProvider is used.

func WithRateLimiter

func WithRateLimiter(limiter httpz.Limiter) ClientOption

WithRateLimiter sets the rate limiter to use.

func WithRetryConfig

func WithRetryConfig(retryConfig RetryConfig) ClientOption

WithRetryConfig configures retry behavior.

func WithTLSConfig

func WithTLSConfig(tlsConfig *tls.Config) ClientOption

WithTLSConfig sets the TLS config to use.

func WithTextMapPropagator

func WithTextMapPropagator(p propagation.TextMapPropagator) ClientOption

WithTextMapPropagator sets a custom trace propagator to be used, otherwise the OTEL's global TextMapPropagator is used.

func WithTracerProvider added in v16.5.0

func WithTracerProvider(traceProvider trace.TracerProvider) ClientOption

WithTracerProvider sets a custom trace provider to be used, otherwise the OTEL's global TracerProvider is used.

func WithUserAgent

func WithUserAgent(userAgent string) ClientOption

WithUserAgent configures the User-Agent header on the http client.

type DefaultApiError added in v16.2.0

type DefaultApiError struct {
	Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"`
	// contains filtered or unexported fields
}

func (*DefaultApiError) Descriptor deprecated added in v16.2.0

func (*DefaultApiError) Descriptor() ([]byte, []int)

Deprecated: Use DefaultApiError.ProtoReflect.Descriptor instead.

func (*DefaultApiError) GetMessage added in v16.2.0

func (x *DefaultApiError) GetMessage() string

func (*DefaultApiError) ProtoMessage added in v16.2.0

func (*DefaultApiError) ProtoMessage()

func (*DefaultApiError) ProtoReflect added in v16.2.0

func (x *DefaultApiError) ProtoReflect() protoreflect.Message

func (*DefaultApiError) Reset added in v16.2.0

func (x *DefaultApiError) Reset()

func (*DefaultApiError) String added in v16.2.0

func (x *DefaultApiError) String() string

type DoOption

type DoOption func(*doConfig) error

DoOption to configure the Do call of the client.

func WithAgentToken

func WithAgentToken(agentToken api.AgentToken) DoOption

func WithBearerToken added in v16.6.0

func WithBearerToken(token string) DoOption

WithBearerToken sets the bearer token to authenticate this API request. See https://docs.gitlab.com/ee/api/rest/#personalprojectgroup-access-tokens. Some endpoints also support GitLab Agent for Kubernetes tokens for authentication.

func WithHeader

func WithHeader(header http.Header) DoOption

func WithJSONRequestBody added in v16.9.0

func WithJSONRequestBody(body interface{}) DoOption

WithJSONRequestBody specifies the object to marshal to JSON and use as request body. Do NOT use this method with proto messages, use WithProtoJSONRequestBody instead.

func WithJWT

func WithJWT(withJWT bool) DoOption

func WithJobToken

func WithJobToken(jobToken string) DoOption

WithJobToken sets the CI job token to authenticate this API request. See https://docs.gitlab.com/ee/api/rest/#job-tokens.

func WithMethod

func WithMethod(method string) DoOption

func WithPath

func WithPath(path string) DoOption

func WithProtoJSONRequestBody added in v16.9.0

func WithProtoJSONRequestBody(body ValidatableMessage) DoOption

WithProtoJSONRequestBody specifies the object to marshal to JSON and use as request body. Use this method with proto messages.

func WithQuery

func WithQuery(query url.Values) DoOption

func WithRequestBody

func WithRequestBody(body io.Reader, contentType string) DoOption

WithRequestBody sets the request body and HTTP Content-Type header if contentType is not empty.

func WithResponseHandler

func WithResponseHandler(handler ResponseHandler) DoOption

func WithoutRetries

func WithoutRetries() DoOption

type ErrHandler added in v16.2.0

type ErrHandler func(resp *http.Response) error

type HTTPClient

type HTTPClient interface {
	Do(*retryablehttp.Request) (*http.Response, error)
}

type ResponseHandler

type ResponseHandler interface {
	// Handle is invoked with HTTP client's response and error values.
	Handle(*http.Response, error) error
	// Accept returns the value to send in the Accept HTTP header.
	// Empty string means no value should be sent.
	Accept() string
}

func NakedResponseHandler

func NakedResponseHandler(response **http.Response) ResponseHandler

func NoContentResponseHandler

func NoContentResponseHandler() ResponseHandler

NoContentResponseHandler can be used when no response is expected or response must be discarded.

func ProtoJSONResponseHandler added in v16.9.0

func ProtoJSONResponseHandler(response ValidatableMessage) ResponseHandler

func ProtoJSONResponseHandlerWithErr added in v16.9.0

func ProtoJSONResponseHandlerWithErr(response ValidatableMessage, errHandler ErrHandler) ResponseHandler

func ProtoJSONResponseHandlerWithStructuredErrReason added in v16.9.0

func ProtoJSONResponseHandlerWithStructuredErrReason(response ValidatableMessage) ResponseHandler

type ResponseHandlerStruct

type ResponseHandlerStruct struct {
	AcceptHeader string
	HandleFunc   func(*http.Response, error) error
}

func (ResponseHandlerStruct) Accept

func (r ResponseHandlerStruct) Accept() string

func (ResponseHandlerStruct) Handle

func (r ResponseHandlerStruct) Handle(resp *http.Response, err error) error

type RetryConfig

type RetryConfig struct {
	// Logger instance. Can be either retryablehttp.Logger or retryablehttp.LeveledLogger
	Logger interface{}

	RetryWaitMin time.Duration // Minimum time to wait
	RetryWaitMax time.Duration // Maximum time to wait
	RetryMax     int           // Maximum number of retries

	// RequestLogHook allows a user-supplied function to be called
	// before each retry.
	RequestLogHook retryablehttp.RequestLogHook

	// ResponseLogHook allows a user-supplied function to be called
	// with the response from each HTTP request executed.
	ResponseLogHook retryablehttp.ResponseLogHook

	// CheckRetry specifies the policy for handling retries, and is called
	// after each request. The default policy is retryablehttp.DefaultRetryPolicy.
	CheckRetry retryablehttp.CheckRetry

	// Backoff specifies the policy for how long to wait between retries.
	// retryablehttp.DefaultBackoff is used by default.
	Backoff retryablehttp.Backoff
}

type ValidatableMessage

type ValidatableMessage interface {
	proto.Message
	ValidateAll() error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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