Documentation
¶
Overview ¶
Package client provides a client for interacting with GitLab API
Package client provides functionality for interacting with HTTP clients ¶
Package client provides an HTTP client with enhanced logging, tracing, and correlation handling.
Index ¶
- Variables
- func DefaultTransport() http.RoundTripper
- func IsFollowedRedirect(code int) bool
- func IsSystemErrorStatus(code int) bool
- func NewTransport(next http.RoundTripper) http.RoundTripper
- func SignShellJWT(secret, glID string) (string, error)
- type APIError
- type ErrorResponse
- type GitlabNetClient
- func (c *GitlabNetClient) Do(request *http.Request) (*http.Response, error)
- func (c *GitlabNetClient) DoRequest(ctx context.Context, method, path string, data interface{}) (*http.Response, error)
- func (c *GitlabNetClient) Get(ctx context.Context, path string) (*http.Response, error)
- func (c *GitlabNetClient) Post(ctx context.Context, path string, data interface{}) (*http.Response, error)
- func (c *GitlabNetClient) SetUserAgent(ua string)
- func (c *GitlabNetClient) WithHost(host string) *GitlabNetClient
- type HTTPClient
- type HTTPClientOpt
- type OriginalRemoteIPContextKey
- type ShellClaims
Constants ¶
This section is empty.
Variables ¶
var ErrCafileNotFound = errors.New("cafile not found")
ErrCafileNotFound indicates that the specified CA file was not found
Functions ¶
func DefaultTransport ¶ added in v14.21.0
func DefaultTransport() http.RoundTripper
DefaultTransport returns a clone of the default HTTP transport.
func IsFollowedRedirect ¶ added in v14.55.0
IsFollowedRedirect reports whether code is one of the 3xx statuses that Go's http.Client would follow, i.e. the ones a CheckRedirect hook intercepts. A followed redirect downgrades a POST to a GET on 301/302/303 and drops the body, so internal API clients refuse them and treat them as errors.
300 Multiple Choices and 304/305/306 are deliberately excluded: Go does not follow them, and the GitLab internal API uses 300 for custom actions (e.g. Geo) whose body must be parsed normally.
func IsSystemErrorStatus ¶ added in v14.56.0
IsSystemErrorStatus reports whether an HTTP status from the internal API unambiguously indicates a gitlab-shell/infrastructure failure. Transport-layer logging and APIError.System both use this status-only classification.
- Followed redirects (301/302/303/307/308): misroute → system.
- 400 Bad Request: shell-facing internal API endpoints map policy outcomes to 401/403/404/422; a 400 indicates a malformed request from gitlab-shell, such as grape parameter-validation failures or bad_request! on a corrupt gitaly_client_context_bin → system.
- 5xx: server-side failure → system.
Other 4xx responses (401/403/404/422/429) are expected policy responses. parseError reuses this function so that error-level logging and the error-SLI (APIError.System) classification agree.
func NewTransport ¶ added in v14.21.0
func NewTransport(next http.RoundTripper) http.RoundTripper
NewTransport creates a new transport with logging, tracing, and correlation handling.
func SignShellJWT ¶ added in v14.56.0
SignShellJWT creates a Shell JWT token with a gl_id claim, signed with the given secret. This is used for Cells SSH-over-HTTP routing where gitlab-shell authenticates with a remote Cell's Workhorse/Rails.
Types ¶
type APIError ¶ added in v14.36.0
type APIError struct {
Msg string
// StatusCode is the HTTP status returned by the internal API, or 0 when the
// request never produced a response (e.g. a connection failure).
StatusCode int
// System reports whether this is an internal API / transport failure
// (unreachable, a followed redirect, 400, or 5xx) rather than an expected
// policy response from the API (e.g. "You are not allowed to push").
// System errors indicate a gitlab-shell/infrastructure problem and should
// count toward error SLIs; policy responses are expected and should not.
System bool
}
APIError represents an API error
func NewSystemAPIError ¶ added in v14.56.0
NewSystemAPIError creates an APIError that represents an internal API or transport failure (e.g. unreachable host, followed redirect, 400, or 5xx). System errors count toward error SLIs; use a plain APIError for expected policy responses (e.g. access denied).
func NewTransportAPIError ¶ added in v14.56.0
NewTransportAPIError classifies a transport-level failure that produced no HTTP response (nil response and/or a non-nil request error). The StatusCode is always 0, since no response was received. A canceled context means the caller went away mid-request (e.g. the SSH client disconnected), which is a client-side outcome and must not count toward the server-side error SLIs. Every other transport failure (a timeout, connection refused, DNS resolution failure, etc.) is a genuine server-side/infrastructure problem and is marked as a System error.
type ErrorResponse ¶
type ErrorResponse struct {
Message string `json:"message"`
}
ErrorResponse represents an error response from the API
type GitlabNetClient ¶
type GitlabNetClient struct {
// contains filtered or unexported fields
}
GitlabNetClient is a client for interacting with GitLab API
func NewGitlabNetClient ¶
func NewGitlabNetClient( user, password, secret string, httpClient *HTTPClient, ) (*GitlabNetClient, error)
NewGitlabNetClient creates a new GitlabNetClient instance
func (*GitlabNetClient) DoRequest ¶
func (c *GitlabNetClient) DoRequest(ctx context.Context, method, path string, data interface{}) (*http.Response, error)
DoRequest executes a request with the given method, path, and data
func (*GitlabNetClient) Post ¶
func (c *GitlabNetClient) Post(ctx context.Context, path string, data interface{}) (*http.Response, error)
Post makes a POST request
func (*GitlabNetClient) SetUserAgent ¶
func (c *GitlabNetClient) SetUserAgent(ua string)
SetUserAgent overrides the default user agent for the User-Agent header field for subsequent requests for the GitlabNetClient
func (*GitlabNetClient) WithHost ¶ added in v14.50.0
func (c *GitlabNetClient) WithHost(host string) *GitlabNetClient
WithHost returns a shallow copy of the client that sends requests to the specified host instead of the default one. The returned client shares the same HTTP transport, TLS settings, and authentication credentials. This is used for Cells routing where the Topology Service directs requests to a specific cell.
type HTTPClient ¶ added in v14.36.0
type HTTPClient struct {
RetryableHTTP *retryablehttp.Client
Host string
}
HTTPClient provides an HTTP client with retry capabilities. Fields other than Host must be safe to share across shallow copies, because GitlabNetClient.WithHost creates a copy with a different Host while sharing the same RetryableHTTP transport.
func NewHTTPClientWithOpts ¶
func NewHTTPClientWithOpts(gitlabURL, gitlabRelativeURLRoot, caFile, caPath string, readTimeoutSeconds uint64, opts []HTTPClientOpt) (*HTTPClient, error)
NewHTTPClientWithOpts builds an HTTP client using the provided options
type HTTPClientOpt ¶
type HTTPClientOpt func(*httpClientCfg)
HTTPClientOpt provides options for configuring an HttpClient
func WithClientCert ¶
func WithClientCert(certPath, keyPath string) HTTPClientOpt
WithClientCert will configure the HttpClient to provide client certificates when connecting to a server.
func WithHTTPRetryOpts ¶ added in v14.16.0
func WithHTTPRetryOpts(waitMin, waitMax time.Duration, maxAttempts int) HTTPClientOpt
WithHTTPRetryOpts configures HTTP retry options for the HttpClient
type OriginalRemoteIPContextKey ¶
type OriginalRemoteIPContextKey struct{}
OriginalRemoteIPContextKey is used as the key in a Context to set an X-Forwarded-For header in a request
type ShellClaims ¶ added in v14.56.0
type ShellClaims struct {
jwt.RegisteredClaims
GlID string `json:"gl_id,omitempty"`
}
ShellClaims extends RegisteredClaims with the gl_id field needed for Cells SSH-over-HTTP authentication.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package testserver provides test server implementations for testing GitLab Shell client functionality.
|
Package testserver provides test server implementations for testing GitLab Shell client functionality. |