Documentation
¶
Overview ¶
Package gitlab provides a wrapper around the GitLab REST API v4 client.
Index ¶
- func DetectScopes(ctx context.Context, client *gl.Client) []string
- func ScopeSatisfied(tokenScopes, requiredScopes []string) bool
- type Client
- func (c *Client) CurrentUser(ctx context.Context) (*CurrentUserInfo, error)
- func (c *Client) CurrentUsername(ctx context.Context) (string, error)deprecated
- func (c *Client) EnableLazyInit()
- func (c *Client) EnsureInitialized(ctx context.Context)
- func (c *Client) GL() *gl.Client
- func (c *Client) Initialize(ctx context.Context) (string, error)
- func (c *Client) IsEnterprise() bool
- func (c *Client) IsInitialized() bool
- func (c *Client) MarkInitialized()
- func (c *Client) Ping(ctx context.Context) (string, error)
- func (c *Client) SetEnterprise(v bool)
- type CurrentUserInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DetectScopes ¶ added in v1.0.6
DetectScopes queries the GitLab PAT self endpoint to retrieve the scopes of the currently authenticated token. Returns nil on failure or when the endpoint is unavailable (GitLab < 16.0), allowing graceful fallback to registering all tools.
func ScopeSatisfied ¶ added in v1.0.6
ScopeSatisfied checks whether requiredScopes are all present in the detected tokenScopes. If tokenScopes is nil (detection failed or disabled), returns true (allow all). If requiredScopes is empty, returns true (no requirement).
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps the official GitLab API client with project-specific configuration. It includes connection resilience: when GitLab is unreachable at startup, the server enters degraded mode and automatically recovers when connectivity is restored.
func NewClient ¶
NewClient creates an authenticated GitLab client from the provided configuration. When cfg.SkipTLSVerify is true, TLS certificate verification is disabled (for self-signed certs). The client includes a resilience transport that enables automatic recovery when GitLab becomes available after being unreachable at startup.
func NewClientWithToken ¶
NewClientWithToken creates an authenticated GitLab client with explicit parameters. Unlike NewClient, it does not require a full config.Config and is designed for use in the server pool where each client has a unique token but shares the same base URL and TLS settings. The client includes a resilience transport that enables automatic recovery when GitLab becomes available after being unreachable.
func (*Client) CurrentUser ¶
func (c *Client) CurrentUser(ctx context.Context) (*CurrentUserInfo, error)
CurrentUser returns the identity of the authenticated GitLab user. It calls the /user API endpoint and returns both the numeric ID and username.
func (*Client) CurrentUsername
deprecated
func (*Client) EnableLazyInit ¶
func (c *Client) EnableLazyInit()
EnableLazyInit enables lazy re-initialization on subsequent API calls. Called when startup Initialize() fails so that the server can recover automatically when GitLab becomes available again.
func (*Client) EnsureInitialized ¶
EnsureInitialized attempts lazy re-initialization if the client was not initialized at startup (e.g. GitLab was down). This allows automatic recovery when GitLab becomes available again. Thread-safe via initMu. Includes a 30-second cooldown between attempts to avoid hammering GitLab. Called automatically by [resilienceTransport] on every SDK request.
func (*Client) Initialize ¶
Initialize validates GitLab connectivity via a direct HTTP health check (bypassing the SDK transport chain to avoid recursion). On success it marks the client as initialized and returns the GitLab version string.
func (*Client) IsEnterprise ¶
IsEnterprise reports whether the GitLab instance is Premium/Ultimate.
func (*Client) IsInitialized ¶
IsInitialized returns true if Initialize() completed successfully.
func (*Client) MarkInitialized ¶
func (c *Client) MarkInitialized()
MarkInitialized sets the initialized flag without running the full Initialize flow. Intended for test setups where the client is preconfigured with a token or mock credentials.
func (*Client) Ping ¶
Ping validates connectivity and authentication by calling the GitLab version endpoint. Returns the GitLab version string on success. Callers should wrap ctx with context.WithTimeout to bound the network round-trip.
func (*Client) SetEnterprise ¶
SetEnterprise marks the client as connected to a Premium/Ultimate instance.
type CurrentUserInfo ¶
CurrentUserInfo holds the identity of the authenticated GitLab user.