client

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: Apache-2.0 Imports: 16 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	DefaultBaseURL          = "https://api.%s"
	OnCallSchedulesEndpoint = "/api/v2/on-call/schedules"
	OnCallUserEndpoint      = "/api/v2/on-call/schedules/%s/on-call"

	// PageSize is the page size for pagination.
	// note: (docs stand that the maximum allowed by Datadog API is 100, but we can only get pages with 50 elements).
	PageSize = 50
)

Variables

View Source
var ErrAlreadyExists = errors.New("baton-datadog: already exists")

ErrAlreadyExists is joined onto errors returned from wrapper methods when the Datadog API responds with HTTP 409. Grant callers use IsAlreadyExists to treat a duplicate membership as success without depending on the SDK error message.

View Source
var ErrApplicationKeyOwnerUnknown = errors.New("baton-datadog: application key owner unknown")

ErrApplicationKeyOwnerUnknown is joined onto the errors FindApplicationKeyOwner returns when the provider answered successfully and its answer names no owner for the key. That is the one owner-lookup failure a retry cannot fix, so callers branch on it -- with errors.Is, not with a gRPC code -- to refuse permanently.

A gRPC code cannot carry this. These errors reach a caller as codes.Unknown, but so does anything wrapOfficialClientError classifies through uhttp.GrpcCodeFromHTTPStatus's default arm, which is every status outside 4xx/5xx -- including a 2xx or 3xx whose body the generated Datadog client could not unmarshal. Treating that code as "no owner exists" would turn a retryable transport failure into a permanent refusal.

View Source
var ErrNotFound = errors.New("baton-datadog: not found")

ErrNotFound is joined onto errors returned from wrapper methods when the Datadog API responds with HTTP 404. Callers use IsNotFound to detect this without depending on the SDK error message format.

Functions

func IsAlreadyExists added in v0.3.2

func IsAlreadyExists(err error) bool

IsAlreadyExists reports whether err was returned for a 409 response.

func IsNotFound added in v0.1.1

func IsNotFound(err error) bool

IsNotFound reports whether err was returned for a 404 response.

func ResolveBaseURL added in v0.8.0

func ResolveBaseURL(site string, baseURL string) string

ResolveBaseURL is the Datadog API endpoint for a site: the base-url override when set, otherwise the endpoint the site implies.

func ScopesFromNullableList added in v0.3.0

func ScopesFromNullableList(raw *[]string, isSet bool) *[]string

ScopesFromNullableList reads Datadog's three-state nullable scopes list into two states a caller can act on. Datadog distinguishes unset (field absent from the response), explicit null (the documented shape for an unscoped key) and a list. Explicit null and a list both mean "Datadog told us the scopes", so they collapse to a non-nil slice -- empty for unscoped. Unset stays nil so callers can tell "no scope restrictions" from "the provider did not say".

Types

type DatadogClient

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

DatadogClient wraps the Datadog REST client to provide a clean interface for all endpoints. This client delegates to the DatadogRestClient which already handles HTTP response body closing correctly.

func NewDatadogClient

func NewDatadogClient(restClient *DatadogRestClient, officialClient *datadog.APIClient, site, apiKey, appKey string) *DatadogClient

NewDatadogClient creates a new client that uses the custom REST client.

func (*DatadogClient) AddUserToRole

AddUserToRole adds a user to a role and automatically handles HTTP response body closing.

func (*DatadogClient) CreateAPIKey added in v0.3.0

func (w *DatadogClient) CreateAPIKey(ctx context.Context, name string) (*IssuedAPIKey, error)

func (*DatadogClient) CreateServiceAccountApplicationKey added in v0.3.0

func (w *DatadogClient) CreateServiceAccountApplicationKey(ctx context.Context, serviceAccountID, name string, scopes []string) (*IssuedApplicationKey, error)

CreateServiceAccountApplicationKey issues a new application key scoped to and owned by the given Datadog service account. Scopes may be empty (an unscoped application key).

func (*DatadogClient) CreateTeamMembership

func (w *DatadogClient) CreateTeamMembership(ctx context.Context, teamId string, body datadogV2.UserTeamRequest) (*datadogV2.UserTeamResponse, error)

CreateTeamMembership creates a team membership and automatically handles HTTP response body closing.

func (*DatadogClient) CreateUser added in v0.1.0

CreateUser creates a Datadog user using the official V2 API client and closes the HTTP response body.

func (*DatadogClient) DeleteAPIKey added in v0.3.0

func (w *DatadogClient) DeleteAPIKey(ctx context.Context, id string) error

func (*DatadogClient) DeleteServiceAccountApplicationKey added in v0.3.0

func (w *DatadogClient) DeleteServiceAccountApplicationKey(ctx context.Context, serviceAccountID, appKeyID string) error

DeleteServiceAccountApplicationKey deletes an application key owned by the given service account. Unlike DeleteAPIKey, Datadog's API requires both the owning service-account id and the key id -- there is no delete-by-key-id-alone form for this credential type.

func (*DatadogClient) DeleteTeamMembership

func (w *DatadogClient) DeleteTeamMembership(ctx context.Context, teamId string, userId string) error

DeleteTeamMembership deletes a team membership and automatically handles HTTP response body closing.

func (*DatadogClient) DisableUser added in v0.1.1

func (w *DatadogClient) DisableUser(ctx context.Context, userId string) error

DisableUser soft-disables a Datadog user. DELETE /api/v2/users/{user_id}. Requires the user_access_manage permission. Datadog has no hard delete; this sets attributes.disabled = true.

func (*DatadogClient) FindAPIKeyByName added in v0.3.0

func (w *DatadogClient) FindAPIKeyByName(ctx context.Context, name string) (*datadogV2.PartialAPIKey, error)

FindAPIKeyByName returns an exact name match, if one exists. Datadog's filter is a substring search, so compare the returned name exactly before treating it as an existing issuance.

One request, not a paged walk. The name searched for is always "c1-<request id>", so only a key whose own name contains that whole string can come back -- a page of 100 cannot fill with them. A full page therefore means the filter did not narrow the way this depends on, which is refused: reporting "no existing key" from a page that may not contain it would mint a duplicate, and Datadog cannot re-issue plaintext for the one that already exists.

func (*DatadogClient) FindApplicationKeyOwner added in v0.3.0

func (w *DatadogClient) FindApplicationKeyOwner(ctx context.Context, appKeyID string) (string, error)

FindApplicationKeyOwner returns the id of the service account that owns an application key. Datadog carries it as the key's owned_by relationship, so a caller holding only the key id can still reach the service-account-scoped endpoints, which take both ids.

func (*DatadogClient) FindServiceAccountApplicationKeyByName added in v0.3.0

func (w *DatadogClient) FindServiceAccountApplicationKeyByName(ctx context.Context, serviceAccountID, name string) (*datadogV2.PartialApplicationKey, error)

FindServiceAccountApplicationKeyByName returns an exact name match among a single service account's application keys, if one exists. Mirrors FindAPIKeyByName, including its single-request shape and its refusal of a full page, scoped to one service account instead of the whole org.

func (*DatadogClient) GetOfficialClient

func (w *DatadogClient) GetOfficialClient() *datadog.APIClient

GetOfficialClient returns the underlying official Datadog API client for operations that need it.

func (*DatadogClient) GetRestClient

func (w *DatadogClient) GetRestClient() *DatadogRestClient

GetRestClient returns the underlying REST client.

func (*DatadogClient) GetTeamMemberships

GetTeamMemberships gets team memberships and automatically handles HTTP response body closing.

func (*DatadogClient) GetUser

func (w *DatadogClient) GetUser(ctx context.Context, userId string) (*datadogV2.UserResponse, error)

GetUser gets a user by ID and automatically handles HTTP response body closing.

func (*DatadogClient) ListAPIKeys

ListAPIKeys lists API keys using the REST client.

func (*DatadogClient) ListRoleUsers

ListRoleUsers lists users for a specific role and automatically handles HTTP response body closing.

func (*DatadogClient) ListRoles

ListRoles lists roles using the REST client.

func (*DatadogClient) ListServiceAccountApplicationKeys added in v0.3.0

func (w *DatadogClient) ListServiceAccountApplicationKeys(ctx context.Context, serviceAccountID string, pageNumber, pageSize int64) (*datadogV2.ListApplicationKeysResponse, error)

ListServiceAccountApplicationKeys lists every application key owned by the given service account, one page at a time via pageNumber/pageSize.

func (*DatadogClient) ListTeams

ListTeams lists teams using the REST client.

func (*DatadogClient) ListUsers

ListUsers lists users using the REST client.

func (*DatadogClient) RemoveUserFromRole

func (w *DatadogClient) RemoveUserFromRole(ctx context.Context, roleId string, body datadogV2.RelationshipToUser) (*datadogV2.UsersResponse, error)

RemoveUserFromRole removes a user from a role and automatically handles HTTP response body closing.

func (*DatadogClient) UpdateTeamMembership added in v0.3.2

func (w *DatadogClient) UpdateTeamMembership(ctx context.Context, teamId string, userId string, role datadogV2.UserTeamRole) (*datadogV2.UserTeamResponse, error)

UpdateTeamMembership updates a user's role on a team and automatically handles HTTP response body closing.

func (*DatadogClient) UpdateUser added in v0.1.1

UpdateUser updates a Datadog user. PATCH /api/v2/users/{user_id}. Requires the user_access_manage permission. UserUpdateAttributes exposes name, email, and disabled.

func (*DatadogClient) ValidateCredentials

ValidateCredentials validates API credentials and automatically handles HTTP response body closing.

type DatadogClientInterface

type DatadogClientInterface interface {
	ListOnCallSchedules(ctx context.Context, opts *PaginationOptions) ([]*OnCallSchedule, string, annotations.Annotations, error)
	GetScheduleOnCallUser(ctx context.Context, scheduleID string) (*OnCallUserResponse, annotations.Annotations, error)
}

DatadogClientInterface defines the interface for Datadog client operations.

type DatadogRestClient

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

DatadogRestClient is a client for Datadog REST API. that is not available in the official client library.

func NewDatadogRestClient

func NewDatadogRestClient(ctx context.Context, site string, apiKey string, appKey string, baseURL string) (*DatadogRestClient, error)

NewDatadogRestClient creates a new instance of the REST client. If baseURL is empty, it will be constructed from site using DefaultBaseURL.

func (*DatadogRestClient) GetScheduleOnCallUser

func (c *DatadogRestClient) GetScheduleOnCallUser(ctx context.Context, scheduleID string) (*OnCallUserResponse, annotations.Annotations, error)

GetScheduleOnCallUser gets the user who is currently on-call for a specific schedule.

func (*DatadogRestClient) ListOnCallSchedules

ListOnCallSchedules lists on-call schedules with optional pagination.

type IssuedAPIKey added in v0.3.0

type IssuedAPIKey struct {
	ID     string
	Secret string
	// CreatedByUserID is the Datadog user id from the create response's
	// relationships.created_by, when the provider reported one. Empty means
	// Datadog did not report a creator for this creation call -- the create
	// call authenticates as this connector's configured principal, not as
	// whichever identity the key is being vended to, so callers must not
	// substitute the recipient identity when this is empty. Mirrors how
	// apiTokenBuilder.List reads the same relationship on sync.
	CreatedByUserID string
}

type IssuedApplicationKey added in v0.3.0

type IssuedApplicationKey struct {
	ID               string
	Secret           string
	ServiceAccountID string
	// Scopes is what the provider echoed back for the created key, which is
	// authoritative over what was requested: Datadog is free to normalize the
	// list. nil means Datadog did not report scopes at all, which is distinct
	// from a non-nil empty slice -- Datadog represents an unscoped key (one
	// carrying its owner's full permissions) as an explicit JSON null, and
	// collapsing "not reported" into "unscoped" would assert something the
	// response never said. See scopesFromNullableList.
	Scopes *[]string
}

IssuedApplicationKey is the result of issuing a Datadog service-account application key: the provider handle (ID), the one-time plaintext secret, and the service-account id that owns it. ServiceAccountID is required at delete time -- DeleteServiceAccountApplicationKey has no lookup-by-id-alone form -- so callers must retain it (see application_key.go's Delete doc comment: it travels via ResourceDeleterV2Limited.Delete's parentResourceID parameter, not a packed handle string).

type OnCallSchedule

type OnCallSchedule struct {
	ID         string                   `json:"id"`
	Type       string                   `json:"type"`
	Attributes OnCallScheduleAttributes `json:"attributes"`
}

OnCallSchedule represents an on-call schedule in Datadog.

type OnCallScheduleAttributes

type OnCallScheduleAttributes struct {
	Name     string `json:"name"`
	TimeZone string `json:"time_zone"`
}

OnCallScheduleAttributes represents the attributes of an on-call schedule.

type OnCallSchedulesResponse

type OnCallSchedulesResponse struct {
	Data []*OnCallSchedule `json:"data"`
	Meta struct {
		Page struct {
			Type        string `json:"type"`
			Number      int    `json:"number"`
			Size        int    `json:"size"`
			Total       int    `json:"total"`
			FirstNumber int    `json:"first_number"`
			PrevNumber  *int   `json:"prev_number"`
			NextNumber  *int   `json:"next_number"`
			LastNumber  int    `json:"last_number"`
		} `json:"page"`
	} `json:"meta"`
}

OnCallSchedulesResponse represents the response of the on-call schedules API.

type OnCallUser

type OnCallUser struct {
	ID         string               `json:"id"`
	Type       string               `json:"type"`
	Attributes OnCallUserAttributes `json:"attributes"`
}

OnCallUser represents an on-call user in Datadog.

type OnCallUserAttributes

type OnCallUserAttributes struct {
	Name  string `json:"name"`
	Email string `json:"email"`
}

OnCallUserAttributes represents the attributes of an on-call user.

type OnCallUserResponse

type OnCallUserResponse struct {
	Data OnCallUser `json:"data"`
}

OnCallUserResponse represents the response of the on-call user API.

type PaginationOptions

type PaginationOptions struct {
	PageSize   int
	PageNumber int
}

PaginationOptions contains the options for pagination.

type ReqOpt

type ReqOpt func(*http.Request) *http.Request

ReqOpt represents a request option that can be applied to an HTTP request.

func WithPage

func WithPage(page int) ReqOpt

WithPage adds a page number query parameter to the request.

func WithPageSize

func WithPageSize(pageSize int) ReqOpt

WithPageSize adds a page size query parameter to the request.

func WithQueryParam

func WithQueryParam(key, value string) ReqOpt

WithQueryParam adds a query parameter to the request.

type SimpleOnCallScheduleList

type SimpleOnCallScheduleList struct {
	Schedules []OnCallSchedule `json:"schedules"`
}

SimpleOnCallScheduleList represents a simple list of schedules without pagination metadata.

Jump to

Keyboard shortcuts

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