Documentation
¶
Index ¶
- Constants
- Variables
- func IsAlreadyExists(err error) bool
- func IsNotFound(err error) bool
- func ResolveBaseURL(site string, baseURL string) string
- func ScopesFromNullableList(raw *[]string, isSet bool) *[]string
- type DatadogClient
- func (w *DatadogClient) AddUserToRole(ctx context.Context, roleId string, body datadogV2.RelationshipToUser) (*datadogV2.UsersResponse, error)
- func (w *DatadogClient) CreateAPIKey(ctx context.Context, name string) (*IssuedAPIKey, error)
- func (w *DatadogClient) CreateServiceAccountApplicationKey(ctx context.Context, serviceAccountID, name string, scopes []string) (*IssuedApplicationKey, error)
- func (w *DatadogClient) CreateTeamMembership(ctx context.Context, teamId string, body datadogV2.UserTeamRequest) (*datadogV2.UserTeamResponse, error)
- func (w *DatadogClient) CreateUser(ctx context.Context, req datadogV2.UserCreateRequest) (*datadogV2.UserResponse, error)
- func (w *DatadogClient) DeleteAPIKey(ctx context.Context, id string) error
- func (w *DatadogClient) DeleteServiceAccountApplicationKey(ctx context.Context, serviceAccountID, appKeyID string) error
- func (w *DatadogClient) DeleteTeamMembership(ctx context.Context, teamId string, userId string) error
- func (w *DatadogClient) DisableUser(ctx context.Context, userId string) error
- func (w *DatadogClient) FindAPIKeyByName(ctx context.Context, name string) (*datadogV2.PartialAPIKey, error)
- func (w *DatadogClient) FindApplicationKeyOwner(ctx context.Context, appKeyID string) (string, error)
- func (w *DatadogClient) FindServiceAccountApplicationKeyByName(ctx context.Context, serviceAccountID, name string) (*datadogV2.PartialApplicationKey, error)
- func (w *DatadogClient) GetOfficialClient() *datadog.APIClient
- func (w *DatadogClient) GetRestClient() *DatadogRestClient
- func (w *DatadogClient) GetTeamMemberships(ctx context.Context, teamId string, ...) (*datadogV2.UserTeamsResponse, error)
- func (w *DatadogClient) GetUser(ctx context.Context, userId string) (*datadogV2.UserResponse, error)
- func (w *DatadogClient) ListAPIKeys(ctx context.Context, params *datadogV2.ListAPIKeysOptionalParameters) (*datadogV2.APIKeysResponse, error)
- func (w *DatadogClient) ListRoleUsers(ctx context.Context, roleId string, ...) (*datadogV2.UsersResponse, error)
- func (w *DatadogClient) ListRoles(ctx context.Context, params *datadogV2.ListRolesOptionalParameters) (*datadogV2.RolesResponse, error)
- func (w *DatadogClient) ListServiceAccountApplicationKeys(ctx context.Context, serviceAccountID string, pageNumber, pageSize int64) (*datadogV2.ListApplicationKeysResponse, error)
- func (w *DatadogClient) ListTeams(ctx context.Context, params *datadogV2.ListTeamsOptionalParameters) (*datadogV2.TeamsResponse, error)
- func (w *DatadogClient) ListUsers(ctx context.Context, params *datadogV2.ListUsersOptionalParameters) (*datadogV2.UsersResponse, error)
- func (w *DatadogClient) RemoveUserFromRole(ctx context.Context, roleId string, body datadogV2.RelationshipToUser) (*datadogV2.UsersResponse, error)
- func (w *DatadogClient) UpdateTeamMembership(ctx context.Context, teamId string, userId string, role datadogV2.UserTeamRole) (*datadogV2.UserTeamResponse, error)
- func (w *DatadogClient) UpdateUser(ctx context.Context, userId string, body datadogV2.UserUpdateRequest) (*datadogV2.UserResponse, error)
- func (w *DatadogClient) ValidateCredentials(ctx context.Context) (*datadogV1.AuthenticationValidationResponse, error)
- type DatadogClientInterface
- type DatadogRestClient
- type IssuedAPIKey
- type IssuedApplicationKey
- type OnCallSchedule
- type OnCallScheduleAttributes
- type OnCallSchedulesResponse
- type OnCallUser
- type OnCallUserAttributes
- type OnCallUserResponse
- type PaginationOptions
- type ReqOpt
- type SimpleOnCallScheduleList
Constants ¶
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 ¶
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.
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.
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
IsAlreadyExists reports whether err was returned for a 409 response.
func IsNotFound ¶ added in v0.1.1
IsNotFound reports whether err was returned for a 404 response.
func ResolveBaseURL ¶ added in v0.8.0
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
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 ¶
func (w *DatadogClient) AddUserToRole(ctx context.Context, roleId string, body datadogV2.RelationshipToUser) (*datadogV2.UsersResponse, error)
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
func (w *DatadogClient) CreateUser(ctx context.Context, req datadogV2.UserCreateRequest) (*datadogV2.UserResponse, error)
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 ¶
func (w *DatadogClient) GetTeamMemberships(ctx context.Context, teamId string, params *datadogV2.GetTeamMembershipsOptionalParameters) (*datadogV2.UserTeamsResponse, error)
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 ¶
func (w *DatadogClient) ListAPIKeys(ctx context.Context, params *datadogV2.ListAPIKeysOptionalParameters) (*datadogV2.APIKeysResponse, error)
ListAPIKeys lists API keys using the REST client.
func (*DatadogClient) ListRoleUsers ¶
func (w *DatadogClient) ListRoleUsers(ctx context.Context, roleId string, params *datadogV2.ListRoleUsersOptionalParameters) (*datadogV2.UsersResponse, error)
ListRoleUsers lists users for a specific role and automatically handles HTTP response body closing.
func (*DatadogClient) ListRoles ¶
func (w *DatadogClient) ListRoles(ctx context.Context, params *datadogV2.ListRolesOptionalParameters) (*datadogV2.RolesResponse, error)
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 ¶
func (w *DatadogClient) ListTeams(ctx context.Context, params *datadogV2.ListTeamsOptionalParameters) (*datadogV2.TeamsResponse, error)
ListTeams lists teams using the REST client.
func (*DatadogClient) ListUsers ¶
func (w *DatadogClient) ListUsers(ctx context.Context, params *datadogV2.ListUsersOptionalParameters) (*datadogV2.UsersResponse, error)
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
func (w *DatadogClient) UpdateUser(ctx context.Context, userId string, body datadogV2.UserUpdateRequest) (*datadogV2.UserResponse, error)
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 ¶
func (w *DatadogClient) ValidateCredentials(ctx context.Context) (*datadogV1.AuthenticationValidationResponse, error)
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 ¶
func (c *DatadogRestClient) ListOnCallSchedules(ctx context.Context, opts *PaginationOptions) ([]*OnCallSchedule, string, annotations.Annotations, error)
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 ¶
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 ¶
PaginationOptions contains the options for pagination.
type ReqOpt ¶
ReqOpt represents a request option that can be applied to an HTTP request.
func WithPageSize ¶
WithPageSize adds a page size query parameter to the request.
func WithQueryParam ¶
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.