Documentation
¶
Overview ¶
Package client re-exports the authenticated Dynatrace HTTP client from github.com/Dynatrace/dtctl/sdk/session, where the implementation moved: client construction from a context — token resolution, OAuth refresh, the 401 retry — is shared session behavior, and the User-Agent is parameterized there so each consumer ships its own identity. This package pins dtctl's identity (dtctl/<version>) and keeps the CLI-only OTel trace propagation; typed API errors (errors.go) and pagination helpers (pagination.go) also remain here.
Index ¶
- Constants
- func AccountBaseURLForEnvironment(env auth.Environment) string
- func ExitCodeForStatus(statusCode int) int
- func ExtractUserIDFromToken(token string) (string, error)
- func GetTokenForContext(cfg *config.Config, environmentURL, tokenRef string) (string, error)
- func GetTokenWithOAuthSupport(cfg *config.Config, tokenRef string) (string, error)
- func InjectTraceContext(c *Client, ctx context.Context)
- func IsPlatformToken(token string) bool
- func RefreshedTokenForContext(cfg *config.Config, environmentURL, tokenRef, rejected string) (string, error)
- func WrapError(err error, message string) error
- type Client
- type PaginationParams
- type PaginationStyle
- type UserInfo
Constants ¶
const ( ExitSuccess = 0 ExitError = 1 ExitUsageError = 2 ExitAuthError = 3 ExitNotFoundError = 4 ExitPermissionError = 5 )
Error codes matching the CLI error handling spec
Variables ¶
This section is empty.
Functions ¶
func AccountBaseURLForEnvironment ¶
func AccountBaseURLForEnvironment(env auth.Environment) string
AccountBaseURLForEnvironment maps a tier to the account API base URL.
func ExitCodeForStatus ¶
ExitCodeForStatus returns the exit code for an HTTP error status.
func ExtractUserIDFromToken ¶
ExtractUserIDFromToken extracts the user ID (sub claim) from a JWT token.
func GetTokenForContext ¶
GetTokenForContext retrieves a token from config with OAuth token refresh support, detecting the OAuth configuration from the supplied environment URL.
func GetTokenWithOAuthSupport ¶
GetTokenWithOAuthSupport retrieves a token from config with OAuth token refresh support, using the current context's environment to detect the OAuth configuration.
func InjectTraceContext ¶
InjectTraceContext configures the client to inject W3C trace context headers (traceparent / tracestate) on every outgoing HTTP request. It lives here — not in the sdk — so the sdk stays OTel-free; tracing is a dtctl CLI concern.
The provided ctx is captured once at registration time; all subsequent HTTP requests share the same span context (the root CLI span). This means individual API calls do NOT get their own child spans — they all propagate the same trace-id and parent span-id. This is intentional for a short-lived CLI: one invocation = one logical operation.
The propagator is resolved once from the global OTel registry at registration time to avoid per-request mutex overhead from otel.GetTextMapPropagator().
func IsPlatformToken ¶
IsPlatformToken reports whether token is a Dynatrace platform token.
Types ¶
type Client ¶
Client is the authenticated HTTP client for a Dynatrace environment.
func NewForTesting ¶
NewForTesting creates a client with retries disabled, suitable for unit tests that use httptest servers. This avoids the 3×1s retry wait on 500/429 responses.
func NewFromConfig ¶
NewFromConfig creates a client for the config's current context with OAuth-aware token resolution and re-resolution on 401.
func NewFromConfigWithOAuth
deprecated
type PaginationParams ¶
type PaginationParams struct {
// Style determines the pagination variant.
Style PaginationStyle
// PageKeyParam is the query parameter name for the page key
// (e.g. "page-key", "next-page-key", "nextPageKey").
PageKeyParam string
// PageSizeParam is the query parameter name for the page size
// (e.g. "page-size", "pageSize"). May be empty if no page size is used.
PageSizeParam string
// NextPageKey is the current page key (empty string for the first page).
NextPageKey string
// PageSize is the requested page size. Zero means "use API default / no pagination".
PageSize int64
// Filters are additional query parameters (e.g. filter, name, schemaIds, scopes)
// that should be sent according to the pagination style rules.
// For Default and DocumentAPI styles, filters are sent on every request.
// For SettingsAPI style, filters are only sent on the first request (page token embeds them).
Filters map[string]string
}
PaginationParams configures how pagination query parameters are applied to a request.
func (PaginationParams) Apply ¶
func (p PaginationParams) Apply(req *resty.Request) *resty.Request
Apply sets the pagination query parameters on the given resty request. It returns the request for chaining.
This helper encapsulates the three Dynatrace pagination styles so that callers cannot accidentally send page-size alongside page-key on APIs that reject that combination.
type PaginationStyle ¶
type PaginationStyle int
PaginationStyle controls how page-key and page-size interact.
Dynatrace APIs have three distinct pagination behaviors:
Default: page-size must NOT be sent with page-key (HTTP 400). Filter/search params must be resent on every request.
DocumentAPI: page-size CAN be sent with page-key. Filter params must be resent (the page token does not embed them).
SettingsAPI: when nextPageKey is present, NO other params may be sent (pageSize, schemaIds, scopes, and fields are all embedded in the page token).
const ( // PaginationDefault is the standard style used by most Dynatrace APIs. // page-size is only sent on the first request; filter params are sent on every request. PaginationDefault PaginationStyle = iota // PaginationDocumentAPI is used by the Document API (/platform/document/v1/). // page-size and filter params are sent on every request alongside page-key. PaginationDocumentAPI // PaginationSettingsAPI is used by the Settings API (/platform/classic/environment-api/v2/settings/). // When nextPageKey is present, no other query params may be sent (not even fields). PaginationSettingsAPI )