diff --git a/.generator/schemas/v2/openapi.yaml b/.generator/schemas/v2/openapi.yaml index c2b306a7c45..b4cbd81ddfa 100644 --- a/.generator/schemas/v2/openapi.yaml +++ b/.generator/schemas/v2/openapi.yaml @@ -1784,6 +1784,21 @@ components: required: true schema: type: string + WebhooksAuthMethodIDPathParameter: + description: The UUID of the auth method. + in: path + name: auth_method_id + required: true + schema: + type: string + WebhooksAuthMethodInclude: + description: Comma-separated list of relationships to include in the response. + explode: true + in: query + name: include + required: false + schema: + $ref: "#/components/schemas/WebhooksAuthMethodProtocol" WorkflowId: description: The ID of the workflow. in: path @@ -96332,6 +96347,277 @@ components: $ref: "#/components/schemas/WebIntegrationAccountResponseData" type: array type: object + WebhooksAuthMethodAttributes: + description: Attributes of a webhooks auth method. + properties: + protocol: + $ref: "#/components/schemas/WebhooksAuthMethodProtocol" + type: object + WebhooksAuthMethodProtocol: + description: Authentication protocol used by the auth method. + enum: + - oauth2-client-credentials + example: oauth2-client-credentials + type: string + x-enum-varnames: + - OAUTH2_CLIENT_CREDENTIALS + WebhooksAuthMethodRelationships: + description: Relationships of a webhooks auth method to its protocol-specific resource. + properties: + oauth2-client-credentials: + $ref: "#/components/schemas/WebhooksOAuth2ClientCredentialsRelationship" + type: object + WebhooksAuthMethodResponseData: + description: Webhooks auth method data from a response. + properties: + attributes: + $ref: "#/components/schemas/WebhooksAuthMethodAttributes" + id: + description: The ID of the auth method. + example: "596da4af-0563-4097-90ff-07230c3f9db3" + type: string + relationships: + $ref: "#/components/schemas/WebhooksAuthMethodRelationships" + type: + $ref: "#/components/schemas/WebhooksAuthMethodType" + required: + - id + - type + - attributes + type: object + WebhooksAuthMethodType: + default: webhooks-auth-method + description: Webhooks auth method resource type. + enum: + - webhooks-auth-method + example: webhooks-auth-method + type: string + x-enum-varnames: + - WEBHOOKS_AUTH_METHOD + WebhooksAuthMethodsResponse: + description: Response containing a list of webhooks auth methods. + properties: + data: + description: An array of webhooks auth methods. + items: + $ref: "#/components/schemas/WebhooksAuthMethodResponseData" + type: array + included: + description: Resources related to the auth methods, included when requested via the `include` query parameter. + items: + $ref: "#/components/schemas/WebhooksOAuth2ClientCredentialsResponseData" + type: array + required: + - data + type: object + WebhooksOAuth2ClientCredentialsCreateAttributes: + description: OAuth2 client credentials attributes for a create request. + properties: + access_token_url: + description: URL of the OAuth2 access token endpoint. + example: "https://example.com/oauth/token" + maxLength: 2048 + minLength: 1 + type: string + audience: + description: The intended audience for the OAuth2 access token. + example: "https://api.example.com" + maxLength: 2048 + minLength: 1 + nullable: true + type: string + client_id: + description: The OAuth2 client ID issued by the authorization server. + example: "my-client-id" + maxLength: 2048 + minLength: 1 + type: string + client_secret: + description: |- + The OAuth2 client secret issued by the authorization server. + Write-only; never returned by the API. + example: "my-client-secret" + maxLength: 2048 + minLength: 1 + type: string + name: + description: Human-readable name for this auth method. Must be unique within your organization. + example: "my-oauth2-auth" + maxLength: 100 + minLength: 1 + type: string + scope: + description: Space-separated list of OAuth2 scopes to request. + example: "read:webhooks write:webhooks" + maxLength: 2048 + minLength: 1 + nullable: true + type: string + required: + - name + - access_token_url + - client_id + - client_secret + type: object + WebhooksOAuth2ClientCredentialsCreateData: + description: OAuth2 client credentials data for a create request. + properties: + attributes: + $ref: "#/components/schemas/WebhooksOAuth2ClientCredentialsCreateAttributes" + type: + $ref: "#/components/schemas/WebhooksOAuth2ClientCredentialsType" + required: + - type + - attributes + type: object + WebhooksOAuth2ClientCredentialsCreateRequest: + description: Create request for an OAuth2 client credentials auth method. + properties: + data: + $ref: "#/components/schemas/WebhooksOAuth2ClientCredentialsCreateData" + required: + - data + type: object + WebhooksOAuth2ClientCredentialsRelationship: + description: Relationship pointing to the OAuth2 client credentials resource for this auth method. + properties: + data: + $ref: "#/components/schemas/WebhooksOAuth2ClientCredentialsRelationshipData" + type: object + WebhooksOAuth2ClientCredentialsRelationshipData: + description: Relationship data referencing an OAuth2 client credentials resource. + properties: + id: + description: The ID of the OAuth2 client credentials resource. + example: "596da4af-0563-4097-90ff-07230c3f9db3" + type: string + type: + $ref: "#/components/schemas/WebhooksOAuth2ClientCredentialsType" + type: object + WebhooksOAuth2ClientCredentialsResponse: + description: Response containing an OAuth2 client credentials auth method. + properties: + data: + $ref: "#/components/schemas/WebhooksOAuth2ClientCredentialsResponseData" + required: + - data + type: object + WebhooksOAuth2ClientCredentialsResponseAttributes: + description: OAuth2 client credentials attributes returned by the API. The `client_secret` is never echoed. + properties: + access_token_url: + description: URL of the OAuth2 access token endpoint. + example: "https://example.com/oauth/token" + type: string + audience: + description: The intended audience for the OAuth2 access token. + example: "https://api.example.com" + nullable: true + type: string + client_id: + description: The OAuth2 client ID issued by the authorization server. + example: "my-client-id" + type: string + name: + description: Human-readable name for this auth method. + example: "my-oauth2-auth" + type: string + protocol: + $ref: "#/components/schemas/WebhooksAuthMethodProtocol" + scope: + description: Space-separated list of OAuth2 scopes to request. + example: "read:webhooks write:webhooks" + nullable: true + type: string + type: object + WebhooksOAuth2ClientCredentialsResponseData: + description: OAuth2 client credentials data from a response. + properties: + attributes: + $ref: "#/components/schemas/WebhooksOAuth2ClientCredentialsResponseAttributes" + id: + description: The ID of the OAuth2 client credentials auth method. + example: "596da4af-0563-4097-90ff-07230c3f9db3" + type: string + type: + $ref: "#/components/schemas/WebhooksOAuth2ClientCredentialsType" + required: + - id + - type + - attributes + type: object + WebhooksOAuth2ClientCredentialsType: + default: webhooks-auth-method-oauth2-client-credentials + description: OAuth2 client credentials resource type. + enum: + - webhooks-auth-method-oauth2-client-credentials + example: webhooks-auth-method-oauth2-client-credentials + type: string + x-enum-varnames: + - WEBHOOKS_AUTH_METHOD_OAUTH2_CLIENT_CREDENTIALS + WebhooksOAuth2ClientCredentialsUpdateAttributes: + description: OAuth2 client credentials attributes for an update request. + properties: + access_token_url: + description: URL of the OAuth2 access token endpoint. + example: "https://example.com/oauth/token" + maxLength: 2048 + minLength: 1 + type: string + audience: + description: The intended audience for the OAuth2 access token. + example: "https://api.example.com" + maxLength: 2048 + minLength: 1 + nullable: true + type: string + client_id: + description: The OAuth2 client ID issued by the authorization server. + example: "my-client-id" + maxLength: 2048 + minLength: 1 + type: string + client_secret: + description: |- + The OAuth2 client secret issued by the authorization server. + Write-only; never returned by the API. + example: "my-client-secret" + maxLength: 2048 + minLength: 1 + type: string + name: + description: Human-readable name for this auth method. + example: "my-oauth2-auth" + maxLength: 100 + minLength: 1 + type: string + scope: + description: Space-separated list of OAuth2 scopes to request. + example: "read:webhooks write:webhooks" + maxLength: 2048 + minLength: 1 + nullable: true + type: string + type: object + WebhooksOAuth2ClientCredentialsUpdateData: + description: OAuth2 client credentials data for an update request. + properties: + attributes: + $ref: "#/components/schemas/WebhooksOAuth2ClientCredentialsUpdateAttributes" + type: + $ref: "#/components/schemas/WebhooksOAuth2ClientCredentialsType" + required: + - type + - attributes + type: object + WebhooksOAuth2ClientCredentialsUpdateRequest: + description: Update request for an OAuth2 client credentials auth method. + properties: + data: + $ref: "#/components/schemas/WebhooksOAuth2ClientCredentialsUpdateData" + required: + - data + type: object Weekday: description: A day of the week. enum: @@ -127140,6 +127426,223 @@ paths: operator: OR permissions: - manage_integrations + /api/v2/integration/webhooks/configuration/auth-method: + get: + description: |- + Get a list of all auth methods configured for the Webhooks integration in + your organization. + operationId: GetAllAuthMethods + parameters: + - $ref: "#/components/parameters/WebhooksAuthMethodInclude" + responses: + "200": + content: + application/json: + examples: + default: + value: + data: + - attributes: + protocol: oauth2-client-credentials + id: 00000000-0000-0000-0000-000000000001 + relationships: + oauth2-client-credentials: + data: + id: 00000000-0000-0000-0000-000000000001 + type: webhooks-auth-method-oauth2-client-credentials + type: webhooks-auth-method + schema: + $ref: "#/components/schemas/WebhooksAuthMethodsResponse" + description: OK + "403": + $ref: "#/components/responses/ForbiddenResponse" + "429": + $ref: "#/components/responses/TooManyRequestsResponse" + summary: Get all auth methods + tags: + - Webhooks Integration + "x-permission": + operator: OR + permissions: + - integrations_read + /api/v2/integration/webhooks/configuration/auth-method/oauth2-client-credentials: + post: + description: |- + Create a new OAuth2 client credentials auth method for the Webhooks + integration. The `client_secret` is stored securely and never returned. + operationId: CreateOAuth2ClientCredentials + requestBody: + content: + application/json: + examples: + default: + value: + data: + attributes: + access_token_url: https://example.com/oauth/token + audience: https://api.example.com + client_id: my-client-id + client_secret: my-client-secret + name: my-oauth2-auth + scope: read:webhooks write:webhooks + type: webhooks-auth-method-oauth2-client-credentials + schema: + $ref: "#/components/schemas/WebhooksOAuth2ClientCredentialsCreateRequest" + description: OAuth2 client credentials payload. + required: true + responses: + "201": + content: + application/json: + examples: + default: + value: + data: + attributes: + access_token_url: https://example.com/oauth/token + audience: https://api.example.com + client_id: my-client-id + name: my-oauth2-auth + protocol: oauth2-client-credentials + scope: read:webhooks write:webhooks + id: 00000000-0000-0000-0000-000000000002 + type: webhooks-auth-method-oauth2-client-credentials + schema: + $ref: "#/components/schemas/WebhooksOAuth2ClientCredentialsResponse" + description: CREATED + "400": + $ref: "#/components/responses/BadRequestResponse" + "403": + $ref: "#/components/responses/ForbiddenResponse" + "409": + $ref: "#/components/responses/ConflictResponse" + "429": + $ref: "#/components/responses/TooManyRequestsResponse" + summary: Create an OAuth2 client credentials auth method + tags: + - Webhooks Integration + x-codegen-request-body-name: body + "x-permission": + operator: OR + permissions: + - manage_integrations + /api/v2/integration/webhooks/configuration/auth-method/oauth2-client-credentials/{auth_method_id}: + delete: + description: Delete an OAuth2 client credentials auth method by ID. + operationId: DeleteOAuth2ClientCredentials + parameters: + - $ref: "#/components/parameters/WebhooksAuthMethodIDPathParameter" + responses: + "204": + description: OK + "403": + $ref: "#/components/responses/ForbiddenResponse" + "404": + $ref: "#/components/responses/NotFoundResponse" + "429": + $ref: "#/components/responses/TooManyRequestsResponse" + summary: Delete an OAuth2 client credentials auth method + tags: + - Webhooks Integration + "x-permission": + operator: OR + permissions: + - manage_integrations + get: + description: Get a single OAuth2 client credentials auth method by ID. + operationId: GetOAuth2ClientCredentials + parameters: + - $ref: "#/components/parameters/WebhooksAuthMethodIDPathParameter" + responses: + "200": + content: + application/json: + examples: + default: + value: + data: + attributes: + access_token_url: https://example.com/oauth/token + audience: https://api.example.com + client_id: my-client-id + name: my-oauth2-auth + protocol: oauth2-client-credentials + scope: read:webhooks write:webhooks + id: 00000000-0000-0000-0000-000000000003 + type: webhooks-auth-method-oauth2-client-credentials + schema: + $ref: "#/components/schemas/WebhooksOAuth2ClientCredentialsResponse" + description: OK + "403": + $ref: "#/components/responses/ForbiddenResponse" + "404": + $ref: "#/components/responses/NotFoundResponse" + "429": + $ref: "#/components/responses/TooManyRequestsResponse" + summary: Get an OAuth2 client credentials auth method + tags: + - Webhooks Integration + "x-permission": + operator: OR + permissions: + - integrations_read + patch: + description: Update an existing OAuth2 client credentials auth method. + operationId: UpdateOAuth2ClientCredentials + parameters: + - $ref: "#/components/parameters/WebhooksAuthMethodIDPathParameter" + requestBody: + content: + application/json: + examples: + default: + value: + data: + attributes: + name: my-oauth2-auth-renamed + type: webhooks-auth-method-oauth2-client-credentials + schema: + $ref: "#/components/schemas/WebhooksOAuth2ClientCredentialsUpdateRequest" + description: OAuth2 client credentials payload. + required: true + responses: + "200": + content: + application/json: + examples: + default: + value: + data: + attributes: + access_token_url: https://example.com/oauth/token + audience: https://api.example.com + client_id: my-client-id + name: my-oauth2-auth-renamed + protocol: oauth2-client-credentials + scope: read:webhooks write:webhooks + id: 00000000-0000-0000-0000-000000000004 + type: webhooks-auth-method-oauth2-client-credentials + schema: + $ref: "#/components/schemas/WebhooksOAuth2ClientCredentialsResponse" + description: OK + "400": + $ref: "#/components/responses/BadRequestResponse" + "403": + $ref: "#/components/responses/ForbiddenResponse" + "404": + $ref: "#/components/responses/NotFoundResponse" + "409": + $ref: "#/components/responses/ConflictResponse" + "429": + $ref: "#/components/responses/TooManyRequestsResponse" + summary: Update an OAuth2 client credentials auth method + tags: + - Webhooks Integration + x-codegen-request-body-name: body + "x-permission": + operator: OR + permissions: + - manage_integrations /api/v2/integrations: get: operationId: ListIntegrations @@ -172595,6 +173098,12 @@ tags: Manage web integration accounts programmatically through the Datadog API. See the [Web Integrations page](https://app.datadoghq.com/integrations) for more information. name: Web Integrations + - description: |- + Configure your [Datadog Webhooks integration](https://docs.datadoghq.com/integrations/webhooks/) + directly through the Datadog API. + externalDocs: + url: https://docs.datadoghq.com/api/latest/webhooks-integration + name: Webhooks Integration - description: |- Create, read, update, and delete saved widgets. Widgets are reusable visualization components stored independently from any dashboard or notebook, diff --git a/api/datadogV2/api_webhooks_integration.go b/api/datadogV2/api_webhooks_integration.go new file mode 100644 index 00000000000..3899e64a4cf --- /dev/null +++ b/api/datadogV2/api_webhooks_integration.go @@ -0,0 +1,437 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. + +package datadogV2 + +import ( + _context "context" + _nethttp "net/http" + _neturl "net/url" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// WebhooksIntegrationApi service type +type WebhooksIntegrationApi datadog.Service + +// CreateOAuth2ClientCredentials Create an OAuth2 client credentials auth method. +// Create a new OAuth2 client credentials auth method for the Webhooks +// integration. The `client_secret` is stored securely and never returned. +func (a *WebhooksIntegrationApi) CreateOAuth2ClientCredentials(ctx _context.Context, body WebhooksOAuth2ClientCredentialsCreateRequest) (WebhooksOAuth2ClientCredentialsResponse, *_nethttp.Response, error) { + var ( + localVarHTTPMethod = _nethttp.MethodPost + localVarPostBody interface{} + localVarReturnValue WebhooksOAuth2ClientCredentialsResponse + ) + + localBasePath, err := a.Client.Cfg.ServerURLWithContext(ctx, "v2.WebhooksIntegrationApi.CreateOAuth2ClientCredentials") + if err != nil { + return localVarReturnValue, nil, datadog.GenericOpenAPIError{ErrorMessage: err.Error()} + } + + localVarPath := localBasePath + "/api/v2/integration/webhooks/configuration/auth-method/oauth2-client-credentials" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := _neturl.Values{} + localVarFormParams := _neturl.Values{} + localVarHeaderParams["Content-Type"] = "application/json" + localVarHeaderParams["Accept"] = "application/json" + + // body params + localVarPostBody = &body + if a.Client.Cfg.DelegatedTokenConfig != nil { + err = datadog.UseDelegatedTokenAuth(ctx, &localVarHeaderParams, a.Client.Cfg.DelegatedTokenConfig) + if err != nil { + return localVarReturnValue, nil, err + } + } else { + datadog.SetAuthKeys( + ctx, + &localVarHeaderParams, + [2]string{"apiKeyAuth", "DD-API-KEY"}, + [2]string{"appKeyAuth", "DD-APPLICATION-KEY"}, + ) + } + req, err := a.Client.PrepareRequest(ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, nil) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.Client.CallAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := datadog.ReadBody(localVarHTTPResponse) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := datadog.GenericOpenAPIError{ + ErrorBody: localVarBody, + ErrorMessage: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 || localVarHTTPResponse.StatusCode == 403 || localVarHTTPResponse.StatusCode == 409 || localVarHTTPResponse.StatusCode == 429 { + var v APIErrorResponse + err = a.Client.Decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.ErrorModel = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.Client.Decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := datadog.GenericOpenAPIError{ + ErrorBody: localVarBody, + ErrorMessage: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +// DeleteOAuth2ClientCredentials Delete an OAuth2 client credentials auth method. +// Delete an OAuth2 client credentials auth method by ID. +func (a *WebhooksIntegrationApi) DeleteOAuth2ClientCredentials(ctx _context.Context, authMethodId string) (*_nethttp.Response, error) { + var ( + localVarHTTPMethod = _nethttp.MethodDelete + localVarPostBody interface{} + ) + + localBasePath, err := a.Client.Cfg.ServerURLWithContext(ctx, "v2.WebhooksIntegrationApi.DeleteOAuth2ClientCredentials") + if err != nil { + return nil, datadog.GenericOpenAPIError{ErrorMessage: err.Error()} + } + + localVarPath := localBasePath + "/api/v2/integration/webhooks/configuration/auth-method/oauth2-client-credentials/{auth_method_id}" + localVarPath = datadog.ReplacePathParameter(localVarPath, "{auth_method_id}", _neturl.PathEscape(datadog.ParameterToString(authMethodId, ""))) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := _neturl.Values{} + localVarFormParams := _neturl.Values{} + localVarHeaderParams["Accept"] = "*/*" + + if a.Client.Cfg.DelegatedTokenConfig != nil { + err = datadog.UseDelegatedTokenAuth(ctx, &localVarHeaderParams, a.Client.Cfg.DelegatedTokenConfig) + if err != nil { + return nil, err + } + } else { + datadog.SetAuthKeys( + ctx, + &localVarHeaderParams, + [2]string{"apiKeyAuth", "DD-API-KEY"}, + [2]string{"appKeyAuth", "DD-APPLICATION-KEY"}, + ) + } + req, err := a.Client.PrepareRequest(ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, nil) + if err != nil { + return nil, err + } + + localVarHTTPResponse, err := a.Client.CallAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarHTTPResponse, err + } + + localVarBody, err := datadog.ReadBody(localVarHTTPResponse) + if err != nil { + return localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := datadog.GenericOpenAPIError{ + ErrorBody: localVarBody, + ErrorMessage: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 403 || localVarHTTPResponse.StatusCode == 404 || localVarHTTPResponse.StatusCode == 429 { + var v APIErrorResponse + err = a.Client.Decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + return localVarHTTPResponse, newErr + } + newErr.ErrorModel = v + } + return localVarHTTPResponse, newErr + } + + return localVarHTTPResponse, nil +} + +// GetAllAuthMethodsOptionalParameters holds optional parameters for GetAllAuthMethods. +type GetAllAuthMethodsOptionalParameters struct { + Include *WebhooksAuthMethodProtocol +} + +// NewGetAllAuthMethodsOptionalParameters creates an empty struct for parameters. +func NewGetAllAuthMethodsOptionalParameters() *GetAllAuthMethodsOptionalParameters { + this := GetAllAuthMethodsOptionalParameters{} + return &this +} + +// WithInclude sets the corresponding parameter name and returns the struct. +func (r *GetAllAuthMethodsOptionalParameters) WithInclude(include WebhooksAuthMethodProtocol) *GetAllAuthMethodsOptionalParameters { + r.Include = &include + return r +} + +// GetAllAuthMethods Get all auth methods. +// Get a list of all auth methods configured for the Webhooks integration in +// your organization. +func (a *WebhooksIntegrationApi) GetAllAuthMethods(ctx _context.Context, o ...GetAllAuthMethodsOptionalParameters) (WebhooksAuthMethodsResponse, *_nethttp.Response, error) { + var ( + localVarHTTPMethod = _nethttp.MethodGet + localVarPostBody interface{} + localVarReturnValue WebhooksAuthMethodsResponse + optionalParams GetAllAuthMethodsOptionalParameters + ) + + if len(o) > 1 { + return localVarReturnValue, nil, datadog.ReportError("only one argument of type GetAllAuthMethodsOptionalParameters is allowed") + } + if len(o) == 1 { + optionalParams = o[0] + } + + localBasePath, err := a.Client.Cfg.ServerURLWithContext(ctx, "v2.WebhooksIntegrationApi.GetAllAuthMethods") + if err != nil { + return localVarReturnValue, nil, datadog.GenericOpenAPIError{ErrorMessage: err.Error()} + } + + localVarPath := localBasePath + "/api/v2/integration/webhooks/configuration/auth-method" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := _neturl.Values{} + localVarFormParams := _neturl.Values{} + if optionalParams.Include != nil { + localVarQueryParams.Add("include", datadog.ParameterToString(*optionalParams.Include, "")) + } + localVarHeaderParams["Accept"] = "application/json" + + if a.Client.Cfg.DelegatedTokenConfig != nil { + err = datadog.UseDelegatedTokenAuth(ctx, &localVarHeaderParams, a.Client.Cfg.DelegatedTokenConfig) + if err != nil { + return localVarReturnValue, nil, err + } + } else { + datadog.SetAuthKeys( + ctx, + &localVarHeaderParams, + [2]string{"apiKeyAuth", "DD-API-KEY"}, + [2]string{"appKeyAuth", "DD-APPLICATION-KEY"}, + ) + } + req, err := a.Client.PrepareRequest(ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, nil) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.Client.CallAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := datadog.ReadBody(localVarHTTPResponse) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := datadog.GenericOpenAPIError{ + ErrorBody: localVarBody, + ErrorMessage: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 403 || localVarHTTPResponse.StatusCode == 429 { + var v APIErrorResponse + err = a.Client.Decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.ErrorModel = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.Client.Decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := datadog.GenericOpenAPIError{ + ErrorBody: localVarBody, + ErrorMessage: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +// GetOAuth2ClientCredentials Get an OAuth2 client credentials auth method. +// Get a single OAuth2 client credentials auth method by ID. +func (a *WebhooksIntegrationApi) GetOAuth2ClientCredentials(ctx _context.Context, authMethodId string) (WebhooksOAuth2ClientCredentialsResponse, *_nethttp.Response, error) { + var ( + localVarHTTPMethod = _nethttp.MethodGet + localVarPostBody interface{} + localVarReturnValue WebhooksOAuth2ClientCredentialsResponse + ) + + localBasePath, err := a.Client.Cfg.ServerURLWithContext(ctx, "v2.WebhooksIntegrationApi.GetOAuth2ClientCredentials") + if err != nil { + return localVarReturnValue, nil, datadog.GenericOpenAPIError{ErrorMessage: err.Error()} + } + + localVarPath := localBasePath + "/api/v2/integration/webhooks/configuration/auth-method/oauth2-client-credentials/{auth_method_id}" + localVarPath = datadog.ReplacePathParameter(localVarPath, "{auth_method_id}", _neturl.PathEscape(datadog.ParameterToString(authMethodId, ""))) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := _neturl.Values{} + localVarFormParams := _neturl.Values{} + localVarHeaderParams["Accept"] = "application/json" + + if a.Client.Cfg.DelegatedTokenConfig != nil { + err = datadog.UseDelegatedTokenAuth(ctx, &localVarHeaderParams, a.Client.Cfg.DelegatedTokenConfig) + if err != nil { + return localVarReturnValue, nil, err + } + } else { + datadog.SetAuthKeys( + ctx, + &localVarHeaderParams, + [2]string{"apiKeyAuth", "DD-API-KEY"}, + [2]string{"appKeyAuth", "DD-APPLICATION-KEY"}, + ) + } + req, err := a.Client.PrepareRequest(ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, nil) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.Client.CallAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := datadog.ReadBody(localVarHTTPResponse) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := datadog.GenericOpenAPIError{ + ErrorBody: localVarBody, + ErrorMessage: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 403 || localVarHTTPResponse.StatusCode == 404 || localVarHTTPResponse.StatusCode == 429 { + var v APIErrorResponse + err = a.Client.Decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.ErrorModel = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.Client.Decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := datadog.GenericOpenAPIError{ + ErrorBody: localVarBody, + ErrorMessage: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +// UpdateOAuth2ClientCredentials Update an OAuth2 client credentials auth method. +// Update an existing OAuth2 client credentials auth method. +func (a *WebhooksIntegrationApi) UpdateOAuth2ClientCredentials(ctx _context.Context, authMethodId string, body WebhooksOAuth2ClientCredentialsUpdateRequest) (WebhooksOAuth2ClientCredentialsResponse, *_nethttp.Response, error) { + var ( + localVarHTTPMethod = _nethttp.MethodPatch + localVarPostBody interface{} + localVarReturnValue WebhooksOAuth2ClientCredentialsResponse + ) + + localBasePath, err := a.Client.Cfg.ServerURLWithContext(ctx, "v2.WebhooksIntegrationApi.UpdateOAuth2ClientCredentials") + if err != nil { + return localVarReturnValue, nil, datadog.GenericOpenAPIError{ErrorMessage: err.Error()} + } + + localVarPath := localBasePath + "/api/v2/integration/webhooks/configuration/auth-method/oauth2-client-credentials/{auth_method_id}" + localVarPath = datadog.ReplacePathParameter(localVarPath, "{auth_method_id}", _neturl.PathEscape(datadog.ParameterToString(authMethodId, ""))) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := _neturl.Values{} + localVarFormParams := _neturl.Values{} + localVarHeaderParams["Content-Type"] = "application/json" + localVarHeaderParams["Accept"] = "application/json" + + // body params + localVarPostBody = &body + if a.Client.Cfg.DelegatedTokenConfig != nil { + err = datadog.UseDelegatedTokenAuth(ctx, &localVarHeaderParams, a.Client.Cfg.DelegatedTokenConfig) + if err != nil { + return localVarReturnValue, nil, err + } + } else { + datadog.SetAuthKeys( + ctx, + &localVarHeaderParams, + [2]string{"apiKeyAuth", "DD-API-KEY"}, + [2]string{"appKeyAuth", "DD-APPLICATION-KEY"}, + ) + } + req, err := a.Client.PrepareRequest(ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, nil) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.Client.CallAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := datadog.ReadBody(localVarHTTPResponse) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := datadog.GenericOpenAPIError{ + ErrorBody: localVarBody, + ErrorMessage: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 || localVarHTTPResponse.StatusCode == 403 || localVarHTTPResponse.StatusCode == 404 || localVarHTTPResponse.StatusCode == 409 || localVarHTTPResponse.StatusCode == 429 { + var v APIErrorResponse + err = a.Client.Decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.ErrorModel = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.Client.Decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := datadog.GenericOpenAPIError{ + ErrorBody: localVarBody, + ErrorMessage: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +// NewWebhooksIntegrationApi Returns NewWebhooksIntegrationApi. +func NewWebhooksIntegrationApi(client *datadog.APIClient) *WebhooksIntegrationApi { + return &WebhooksIntegrationApi{ + Client: client, + } +} diff --git a/api/datadogV2/doc.go b/api/datadogV2/doc.go index db887c8c2ff..4cc44369057 100644 --- a/api/datadogV2/doc.go +++ b/api/datadogV2/doc.go @@ -1227,6 +1227,11 @@ // - [WebIntegrationsApi.GetWebIntegrationAccount] // - [WebIntegrationsApi.ListWebIntegrationAccounts] // - [WebIntegrationsApi.UpdateWebIntegrationAccount] +// - [WebhooksIntegrationApi.CreateOAuth2ClientCredentials] +// - [WebhooksIntegrationApi.DeleteOAuth2ClientCredentials] +// - [WebhooksIntegrationApi.GetAllAuthMethods] +// - [WebhooksIntegrationApi.GetOAuth2ClientCredentials] +// - [WebhooksIntegrationApi.UpdateOAuth2ClientCredentials] // - [WidgetsApi.CreateWidget] // - [WidgetsApi.DeleteWidget] // - [WidgetsApi.GetWidget] diff --git a/api/datadogV2/model_webhooks_auth_method_attributes.go b/api/datadogV2/model_webhooks_auth_method_attributes.go new file mode 100644 index 00000000000..c63cf3792d7 --- /dev/null +++ b/api/datadogV2/model_webhooks_auth_method_attributes.go @@ -0,0 +1,112 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. + +package datadogV2 + +import ( + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// WebhooksAuthMethodAttributes Attributes of a webhooks auth method. +type WebhooksAuthMethodAttributes struct { + // Authentication protocol used by the auth method. + Protocol *WebhooksAuthMethodProtocol `json:"protocol,omitempty"` + // UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct + UnparsedObject map[string]interface{} `json:"-"` + AdditionalProperties map[string]interface{} `json:"-"` +} + +// NewWebhooksAuthMethodAttributes instantiates a new WebhooksAuthMethodAttributes object. +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed. +func NewWebhooksAuthMethodAttributes() *WebhooksAuthMethodAttributes { + this := WebhooksAuthMethodAttributes{} + return &this +} + +// NewWebhooksAuthMethodAttributesWithDefaults instantiates a new WebhooksAuthMethodAttributes object. +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set. +func NewWebhooksAuthMethodAttributesWithDefaults() *WebhooksAuthMethodAttributes { + this := WebhooksAuthMethodAttributes{} + return &this +} + +// GetProtocol returns the Protocol field value if set, zero value otherwise. +func (o *WebhooksAuthMethodAttributes) GetProtocol() WebhooksAuthMethodProtocol { + if o == nil || o.Protocol == nil { + var ret WebhooksAuthMethodProtocol + return ret + } + return *o.Protocol +} + +// GetProtocolOk returns a tuple with the Protocol field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *WebhooksAuthMethodAttributes) GetProtocolOk() (*WebhooksAuthMethodProtocol, bool) { + if o == nil || o.Protocol == nil { + return nil, false + } + return o.Protocol, true +} + +// HasProtocol returns a boolean if a field has been set. +func (o *WebhooksAuthMethodAttributes) HasProtocol() bool { + return o != nil && o.Protocol != nil +} + +// SetProtocol gets a reference to the given WebhooksAuthMethodProtocol and assigns it to the Protocol field. +func (o *WebhooksAuthMethodAttributes) SetProtocol(v WebhooksAuthMethodProtocol) { + o.Protocol = &v +} + +// MarshalJSON serializes the struct using spec logic. +func (o WebhooksAuthMethodAttributes) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + if o.Protocol != nil { + toSerialize["protocol"] = o.Protocol + } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *WebhooksAuthMethodAttributes) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + Protocol *WebhooksAuthMethodProtocol `json:"protocol,omitempty"` + }{} + if err = datadog.Unmarshal(bytes, &all); err != nil { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + additionalProperties := make(map[string]interface{}) + if err = datadog.UnmarshalUseNumber(bytes, &additionalProperties); err == nil { + datadog.DeleteKeys(additionalProperties, &[]string{"protocol"}) + } else { + return err + } + + hasInvalidField := false + if all.Protocol != nil && !all.Protocol.IsValid() { + hasInvalidField = true + } else { + o.Protocol = all.Protocol + } + + if len(additionalProperties) > 0 { + o.AdditionalProperties = additionalProperties + } + + if hasInvalidField { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + + return nil +} diff --git a/api/datadogV2/model_webhooks_auth_method_protocol.go b/api/datadogV2/model_webhooks_auth_method_protocol.go new file mode 100644 index 00000000000..6ce3aa01020 --- /dev/null +++ b/api/datadogV2/model_webhooks_auth_method_protocol.go @@ -0,0 +1,64 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. + +package datadogV2 + +import ( + "fmt" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// WebhooksAuthMethodProtocol Authentication protocol used by the auth method. +type WebhooksAuthMethodProtocol string + +// List of WebhooksAuthMethodProtocol. +const ( + WEBHOOKSAUTHMETHODPROTOCOL_OAUTH2_CLIENT_CREDENTIALS WebhooksAuthMethodProtocol = "oauth2-client-credentials" +) + +var allowedWebhooksAuthMethodProtocolEnumValues = []WebhooksAuthMethodProtocol{ + WEBHOOKSAUTHMETHODPROTOCOL_OAUTH2_CLIENT_CREDENTIALS, +} + +// GetAllowedValues reeturns the list of possible values. +func (v *WebhooksAuthMethodProtocol) GetAllowedValues() []WebhooksAuthMethodProtocol { + return allowedWebhooksAuthMethodProtocolEnumValues +} + +// UnmarshalJSON deserializes the given payload. +func (v *WebhooksAuthMethodProtocol) UnmarshalJSON(src []byte) error { + var value string + err := datadog.Unmarshal(src, &value) + if err != nil { + return err + } + *v = WebhooksAuthMethodProtocol(value) + return nil +} + +// NewWebhooksAuthMethodProtocolFromValue returns a pointer to a valid WebhooksAuthMethodProtocol +// for the value passed as argument, or an error if the value passed is not allowed by the enum. +func NewWebhooksAuthMethodProtocolFromValue(v string) (*WebhooksAuthMethodProtocol, error) { + ev := WebhooksAuthMethodProtocol(v) + if ev.IsValid() { + return &ev, nil + } + return nil, fmt.Errorf("invalid value '%v' for WebhooksAuthMethodProtocol: valid values are %v", v, allowedWebhooksAuthMethodProtocolEnumValues) +} + +// IsValid return true if the value is valid for the enum, false otherwise. +func (v WebhooksAuthMethodProtocol) IsValid() bool { + for _, existing := range allowedWebhooksAuthMethodProtocolEnumValues { + if existing == v { + return true + } + } + return false +} + +// Ptr returns reference to WebhooksAuthMethodProtocol value. +func (v WebhooksAuthMethodProtocol) Ptr() *WebhooksAuthMethodProtocol { + return &v +} diff --git a/api/datadogV2/model_webhooks_auth_method_relationships.go b/api/datadogV2/model_webhooks_auth_method_relationships.go new file mode 100644 index 00000000000..62f93700279 --- /dev/null +++ b/api/datadogV2/model_webhooks_auth_method_relationships.go @@ -0,0 +1,111 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. + +package datadogV2 + +import ( + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// WebhooksAuthMethodRelationships Relationships of a webhooks auth method to its protocol-specific resource. +type WebhooksAuthMethodRelationships struct { + // Relationship pointing to the OAuth2 client credentials resource for this auth method. + Oauth2ClientCredentials *WebhooksOAuth2ClientCredentialsRelationship `json:"oauth2-client-credentials,omitempty"` + // UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct + UnparsedObject map[string]interface{} `json:"-"` + AdditionalProperties map[string]interface{} `json:"-"` +} + +// NewWebhooksAuthMethodRelationships instantiates a new WebhooksAuthMethodRelationships object. +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed. +func NewWebhooksAuthMethodRelationships() *WebhooksAuthMethodRelationships { + this := WebhooksAuthMethodRelationships{} + return &this +} + +// NewWebhooksAuthMethodRelationshipsWithDefaults instantiates a new WebhooksAuthMethodRelationships object. +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set. +func NewWebhooksAuthMethodRelationshipsWithDefaults() *WebhooksAuthMethodRelationships { + this := WebhooksAuthMethodRelationships{} + return &this +} + +// GetOauth2ClientCredentials returns the Oauth2ClientCredentials field value if set, zero value otherwise. +func (o *WebhooksAuthMethodRelationships) GetOauth2ClientCredentials() WebhooksOAuth2ClientCredentialsRelationship { + if o == nil || o.Oauth2ClientCredentials == nil { + var ret WebhooksOAuth2ClientCredentialsRelationship + return ret + } + return *o.Oauth2ClientCredentials +} + +// GetOauth2ClientCredentialsOk returns a tuple with the Oauth2ClientCredentials field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *WebhooksAuthMethodRelationships) GetOauth2ClientCredentialsOk() (*WebhooksOAuth2ClientCredentialsRelationship, bool) { + if o == nil || o.Oauth2ClientCredentials == nil { + return nil, false + } + return o.Oauth2ClientCredentials, true +} + +// HasOauth2ClientCredentials returns a boolean if a field has been set. +func (o *WebhooksAuthMethodRelationships) HasOauth2ClientCredentials() bool { + return o != nil && o.Oauth2ClientCredentials != nil +} + +// SetOauth2ClientCredentials gets a reference to the given WebhooksOAuth2ClientCredentialsRelationship and assigns it to the Oauth2ClientCredentials field. +func (o *WebhooksAuthMethodRelationships) SetOauth2ClientCredentials(v WebhooksOAuth2ClientCredentialsRelationship) { + o.Oauth2ClientCredentials = &v +} + +// MarshalJSON serializes the struct using spec logic. +func (o WebhooksAuthMethodRelationships) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + if o.Oauth2ClientCredentials != nil { + toSerialize["oauth2-client-credentials"] = o.Oauth2ClientCredentials + } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *WebhooksAuthMethodRelationships) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + Oauth2ClientCredentials *WebhooksOAuth2ClientCredentialsRelationship `json:"oauth2-client-credentials,omitempty"` + }{} + if err = datadog.Unmarshal(bytes, &all); err != nil { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + additionalProperties := make(map[string]interface{}) + if err = datadog.UnmarshalUseNumber(bytes, &additionalProperties); err == nil { + datadog.DeleteKeys(additionalProperties, &[]string{"oauth2-client-credentials"}) + } else { + return err + } + + hasInvalidField := false + if all.Oauth2ClientCredentials != nil && all.Oauth2ClientCredentials.UnparsedObject != nil && o.UnparsedObject == nil { + hasInvalidField = true + } + o.Oauth2ClientCredentials = all.Oauth2ClientCredentials + + if len(additionalProperties) > 0 { + o.AdditionalProperties = additionalProperties + } + + if hasInvalidField { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + + return nil +} diff --git a/api/datadogV2/model_webhooks_auth_method_response_data.go b/api/datadogV2/model_webhooks_auth_method_response_data.go new file mode 100644 index 00000000000..a7c800471a1 --- /dev/null +++ b/api/datadogV2/model_webhooks_auth_method_response_data.go @@ -0,0 +1,218 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. + +package datadogV2 + +import ( + "fmt" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// WebhooksAuthMethodResponseData Webhooks auth method data from a response. +type WebhooksAuthMethodResponseData struct { + // Attributes of a webhooks auth method. + Attributes WebhooksAuthMethodAttributes `json:"attributes"` + // The ID of the auth method. + Id string `json:"id"` + // Relationships of a webhooks auth method to its protocol-specific resource. + Relationships *WebhooksAuthMethodRelationships `json:"relationships,omitempty"` + // Webhooks auth method resource type. + Type WebhooksAuthMethodType `json:"type"` + // UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct + UnparsedObject map[string]interface{} `json:"-"` + AdditionalProperties map[string]interface{} `json:"-"` +} + +// NewWebhooksAuthMethodResponseData instantiates a new WebhooksAuthMethodResponseData object. +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed. +func NewWebhooksAuthMethodResponseData(attributes WebhooksAuthMethodAttributes, id string, typeVar WebhooksAuthMethodType) *WebhooksAuthMethodResponseData { + this := WebhooksAuthMethodResponseData{} + this.Attributes = attributes + this.Id = id + this.Type = typeVar + return &this +} + +// NewWebhooksAuthMethodResponseDataWithDefaults instantiates a new WebhooksAuthMethodResponseData object. +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set. +func NewWebhooksAuthMethodResponseDataWithDefaults() *WebhooksAuthMethodResponseData { + this := WebhooksAuthMethodResponseData{} + var typeVar WebhooksAuthMethodType = WEBHOOKSAUTHMETHODTYPE_WEBHOOKS_AUTH_METHOD + this.Type = typeVar + return &this +} + +// GetAttributes returns the Attributes field value. +func (o *WebhooksAuthMethodResponseData) GetAttributes() WebhooksAuthMethodAttributes { + if o == nil { + var ret WebhooksAuthMethodAttributes + return ret + } + return o.Attributes +} + +// GetAttributesOk returns a tuple with the Attributes field value +// and a boolean to check if the value has been set. +func (o *WebhooksAuthMethodResponseData) GetAttributesOk() (*WebhooksAuthMethodAttributes, bool) { + if o == nil { + return nil, false + } + return &o.Attributes, true +} + +// SetAttributes sets field value. +func (o *WebhooksAuthMethodResponseData) SetAttributes(v WebhooksAuthMethodAttributes) { + o.Attributes = v +} + +// GetId returns the Id field value. +func (o *WebhooksAuthMethodResponseData) GetId() string { + if o == nil { + var ret string + return ret + } + return o.Id +} + +// GetIdOk returns a tuple with the Id field value +// and a boolean to check if the value has been set. +func (o *WebhooksAuthMethodResponseData) GetIdOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Id, true +} + +// SetId sets field value. +func (o *WebhooksAuthMethodResponseData) SetId(v string) { + o.Id = v +} + +// GetRelationships returns the Relationships field value if set, zero value otherwise. +func (o *WebhooksAuthMethodResponseData) GetRelationships() WebhooksAuthMethodRelationships { + if o == nil || o.Relationships == nil { + var ret WebhooksAuthMethodRelationships + return ret + } + return *o.Relationships +} + +// GetRelationshipsOk returns a tuple with the Relationships field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *WebhooksAuthMethodResponseData) GetRelationshipsOk() (*WebhooksAuthMethodRelationships, bool) { + if o == nil || o.Relationships == nil { + return nil, false + } + return o.Relationships, true +} + +// HasRelationships returns a boolean if a field has been set. +func (o *WebhooksAuthMethodResponseData) HasRelationships() bool { + return o != nil && o.Relationships != nil +} + +// SetRelationships gets a reference to the given WebhooksAuthMethodRelationships and assigns it to the Relationships field. +func (o *WebhooksAuthMethodResponseData) SetRelationships(v WebhooksAuthMethodRelationships) { + o.Relationships = &v +} + +// GetType returns the Type field value. +func (o *WebhooksAuthMethodResponseData) GetType() WebhooksAuthMethodType { + if o == nil { + var ret WebhooksAuthMethodType + return ret + } + return o.Type +} + +// GetTypeOk returns a tuple with the Type field value +// and a boolean to check if the value has been set. +func (o *WebhooksAuthMethodResponseData) GetTypeOk() (*WebhooksAuthMethodType, bool) { + if o == nil { + return nil, false + } + return &o.Type, true +} + +// SetType sets field value. +func (o *WebhooksAuthMethodResponseData) SetType(v WebhooksAuthMethodType) { + o.Type = v +} + +// MarshalJSON serializes the struct using spec logic. +func (o WebhooksAuthMethodResponseData) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + toSerialize["attributes"] = o.Attributes + toSerialize["id"] = o.Id + if o.Relationships != nil { + toSerialize["relationships"] = o.Relationships + } + toSerialize["type"] = o.Type + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *WebhooksAuthMethodResponseData) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + Attributes *WebhooksAuthMethodAttributes `json:"attributes"` + Id *string `json:"id"` + Relationships *WebhooksAuthMethodRelationships `json:"relationships,omitempty"` + Type *WebhooksAuthMethodType `json:"type"` + }{} + if err = datadog.Unmarshal(bytes, &all); err != nil { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + if all.Attributes == nil { + return fmt.Errorf("required field attributes missing") + } + if all.Id == nil { + return fmt.Errorf("required field id missing") + } + if all.Type == nil { + return fmt.Errorf("required field type missing") + } + additionalProperties := make(map[string]interface{}) + if err = datadog.UnmarshalUseNumber(bytes, &additionalProperties); err == nil { + datadog.DeleteKeys(additionalProperties, &[]string{"attributes", "id", "relationships", "type"}) + } else { + return err + } + + hasInvalidField := false + if all.Attributes.UnparsedObject != nil && o.UnparsedObject == nil { + hasInvalidField = true + } + o.Attributes = *all.Attributes + o.Id = *all.Id + if all.Relationships != nil && all.Relationships.UnparsedObject != nil && o.UnparsedObject == nil { + hasInvalidField = true + } + o.Relationships = all.Relationships + if !all.Type.IsValid() { + hasInvalidField = true + } else { + o.Type = *all.Type + } + + if len(additionalProperties) > 0 { + o.AdditionalProperties = additionalProperties + } + + if hasInvalidField { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + + return nil +} diff --git a/api/datadogV2/model_webhooks_auth_method_type.go b/api/datadogV2/model_webhooks_auth_method_type.go new file mode 100644 index 00000000000..fdecc70e11f --- /dev/null +++ b/api/datadogV2/model_webhooks_auth_method_type.go @@ -0,0 +1,64 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. + +package datadogV2 + +import ( + "fmt" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// WebhooksAuthMethodType Webhooks auth method resource type. +type WebhooksAuthMethodType string + +// List of WebhooksAuthMethodType. +const ( + WEBHOOKSAUTHMETHODTYPE_WEBHOOKS_AUTH_METHOD WebhooksAuthMethodType = "webhooks-auth-method" +) + +var allowedWebhooksAuthMethodTypeEnumValues = []WebhooksAuthMethodType{ + WEBHOOKSAUTHMETHODTYPE_WEBHOOKS_AUTH_METHOD, +} + +// GetAllowedValues reeturns the list of possible values. +func (v *WebhooksAuthMethodType) GetAllowedValues() []WebhooksAuthMethodType { + return allowedWebhooksAuthMethodTypeEnumValues +} + +// UnmarshalJSON deserializes the given payload. +func (v *WebhooksAuthMethodType) UnmarshalJSON(src []byte) error { + var value string + err := datadog.Unmarshal(src, &value) + if err != nil { + return err + } + *v = WebhooksAuthMethodType(value) + return nil +} + +// NewWebhooksAuthMethodTypeFromValue returns a pointer to a valid WebhooksAuthMethodType +// for the value passed as argument, or an error if the value passed is not allowed by the enum. +func NewWebhooksAuthMethodTypeFromValue(v string) (*WebhooksAuthMethodType, error) { + ev := WebhooksAuthMethodType(v) + if ev.IsValid() { + return &ev, nil + } + return nil, fmt.Errorf("invalid value '%v' for WebhooksAuthMethodType: valid values are %v", v, allowedWebhooksAuthMethodTypeEnumValues) +} + +// IsValid return true if the value is valid for the enum, false otherwise. +func (v WebhooksAuthMethodType) IsValid() bool { + for _, existing := range allowedWebhooksAuthMethodTypeEnumValues { + if existing == v { + return true + } + } + return false +} + +// Ptr returns reference to WebhooksAuthMethodType value. +func (v WebhooksAuthMethodType) Ptr() *WebhooksAuthMethodType { + return &v +} diff --git a/api/datadogV2/model_webhooks_auth_methods_response.go b/api/datadogV2/model_webhooks_auth_methods_response.go new file mode 100644 index 00000000000..47068d6c809 --- /dev/null +++ b/api/datadogV2/model_webhooks_auth_methods_response.go @@ -0,0 +1,136 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. + +package datadogV2 + +import ( + "fmt" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// WebhooksAuthMethodsResponse Response containing a list of webhooks auth methods. +type WebhooksAuthMethodsResponse struct { + // An array of webhooks auth methods. + Data []WebhooksAuthMethodResponseData `json:"data"` + // Resources related to the auth methods, included when requested via the `include` query parameter. + Included []WebhooksOAuth2ClientCredentialsResponseData `json:"included,omitempty"` + // UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct + UnparsedObject map[string]interface{} `json:"-"` + AdditionalProperties map[string]interface{} `json:"-"` +} + +// NewWebhooksAuthMethodsResponse instantiates a new WebhooksAuthMethodsResponse object. +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed. +func NewWebhooksAuthMethodsResponse(data []WebhooksAuthMethodResponseData) *WebhooksAuthMethodsResponse { + this := WebhooksAuthMethodsResponse{} + this.Data = data + return &this +} + +// NewWebhooksAuthMethodsResponseWithDefaults instantiates a new WebhooksAuthMethodsResponse object. +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set. +func NewWebhooksAuthMethodsResponseWithDefaults() *WebhooksAuthMethodsResponse { + this := WebhooksAuthMethodsResponse{} + return &this +} + +// GetData returns the Data field value. +func (o *WebhooksAuthMethodsResponse) GetData() []WebhooksAuthMethodResponseData { + if o == nil { + var ret []WebhooksAuthMethodResponseData + return ret + } + return o.Data +} + +// GetDataOk returns a tuple with the Data field value +// and a boolean to check if the value has been set. +func (o *WebhooksAuthMethodsResponse) GetDataOk() (*[]WebhooksAuthMethodResponseData, bool) { + if o == nil { + return nil, false + } + return &o.Data, true +} + +// SetData sets field value. +func (o *WebhooksAuthMethodsResponse) SetData(v []WebhooksAuthMethodResponseData) { + o.Data = v +} + +// GetIncluded returns the Included field value if set, zero value otherwise. +func (o *WebhooksAuthMethodsResponse) GetIncluded() []WebhooksOAuth2ClientCredentialsResponseData { + if o == nil || o.Included == nil { + var ret []WebhooksOAuth2ClientCredentialsResponseData + return ret + } + return o.Included +} + +// GetIncludedOk returns a tuple with the Included field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *WebhooksAuthMethodsResponse) GetIncludedOk() (*[]WebhooksOAuth2ClientCredentialsResponseData, bool) { + if o == nil || o.Included == nil { + return nil, false + } + return &o.Included, true +} + +// HasIncluded returns a boolean if a field has been set. +func (o *WebhooksAuthMethodsResponse) HasIncluded() bool { + return o != nil && o.Included != nil +} + +// SetIncluded gets a reference to the given []WebhooksOAuth2ClientCredentialsResponseData and assigns it to the Included field. +func (o *WebhooksAuthMethodsResponse) SetIncluded(v []WebhooksOAuth2ClientCredentialsResponseData) { + o.Included = v +} + +// MarshalJSON serializes the struct using spec logic. +func (o WebhooksAuthMethodsResponse) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + toSerialize["data"] = o.Data + if o.Included != nil { + toSerialize["included"] = o.Included + } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *WebhooksAuthMethodsResponse) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + Data *[]WebhooksAuthMethodResponseData `json:"data"` + Included []WebhooksOAuth2ClientCredentialsResponseData `json:"included,omitempty"` + }{} + if err = datadog.Unmarshal(bytes, &all); err != nil { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + if all.Data == nil { + return fmt.Errorf("required field data missing") + } + additionalProperties := make(map[string]interface{}) + if err = datadog.UnmarshalUseNumber(bytes, &additionalProperties); err == nil { + datadog.DeleteKeys(additionalProperties, &[]string{"data", "included"}) + } else { + return err + } + o.Data = *all.Data + o.Included = all.Included + + if len(additionalProperties) > 0 { + o.AdditionalProperties = additionalProperties + } + + return nil +} diff --git a/api/datadogV2/model_webhooks_o_auth2_client_credentials_create_attributes.go b/api/datadogV2/model_webhooks_o_auth2_client_credentials_create_attributes.go new file mode 100644 index 00000000000..098a7274c03 --- /dev/null +++ b/api/datadogV2/model_webhooks_o_auth2_client_credentials_create_attributes.go @@ -0,0 +1,290 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. + +package datadogV2 + +import ( + "fmt" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// WebhooksOAuth2ClientCredentialsCreateAttributes OAuth2 client credentials attributes for a create request. +type WebhooksOAuth2ClientCredentialsCreateAttributes struct { + // URL of the OAuth2 access token endpoint. + AccessTokenUrl string `json:"access_token_url"` + // The intended audience for the OAuth2 access token. + Audience datadog.NullableString `json:"audience,omitempty"` + // The OAuth2 client ID issued by the authorization server. + ClientId string `json:"client_id"` + // The OAuth2 client secret issued by the authorization server. + // Write-only; never returned by the API. + ClientSecret string `json:"client_secret"` + // Human-readable name for this auth method. Must be unique within your organization. + Name string `json:"name"` + // Space-separated list of OAuth2 scopes to request. + Scope datadog.NullableString `json:"scope,omitempty"` + // UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct + UnparsedObject map[string]interface{} `json:"-"` + AdditionalProperties map[string]interface{} `json:"-"` +} + +// NewWebhooksOAuth2ClientCredentialsCreateAttributes instantiates a new WebhooksOAuth2ClientCredentialsCreateAttributes object. +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed. +func NewWebhooksOAuth2ClientCredentialsCreateAttributes(accessTokenUrl string, clientId string, clientSecret string, name string) *WebhooksOAuth2ClientCredentialsCreateAttributes { + this := WebhooksOAuth2ClientCredentialsCreateAttributes{} + this.AccessTokenUrl = accessTokenUrl + this.ClientId = clientId + this.ClientSecret = clientSecret + this.Name = name + return &this +} + +// NewWebhooksOAuth2ClientCredentialsCreateAttributesWithDefaults instantiates a new WebhooksOAuth2ClientCredentialsCreateAttributes object. +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set. +func NewWebhooksOAuth2ClientCredentialsCreateAttributesWithDefaults() *WebhooksOAuth2ClientCredentialsCreateAttributes { + this := WebhooksOAuth2ClientCredentialsCreateAttributes{} + return &this +} + +// GetAccessTokenUrl returns the AccessTokenUrl field value. +func (o *WebhooksOAuth2ClientCredentialsCreateAttributes) GetAccessTokenUrl() string { + if o == nil { + var ret string + return ret + } + return o.AccessTokenUrl +} + +// GetAccessTokenUrlOk returns a tuple with the AccessTokenUrl field value +// and a boolean to check if the value has been set. +func (o *WebhooksOAuth2ClientCredentialsCreateAttributes) GetAccessTokenUrlOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.AccessTokenUrl, true +} + +// SetAccessTokenUrl sets field value. +func (o *WebhooksOAuth2ClientCredentialsCreateAttributes) SetAccessTokenUrl(v string) { + o.AccessTokenUrl = v +} + +// GetAudience returns the Audience field value if set, zero value otherwise (both if not set or set to explicit null). +func (o *WebhooksOAuth2ClientCredentialsCreateAttributes) GetAudience() string { + if o == nil || o.Audience.Get() == nil { + var ret string + return ret + } + return *o.Audience.Get() +} + +// GetAudienceOk returns a tuple with the Audience field value if set, nil otherwise +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned. +func (o *WebhooksOAuth2ClientCredentialsCreateAttributes) GetAudienceOk() (*string, bool) { + if o == nil { + return nil, false + } + return o.Audience.Get(), o.Audience.IsSet() +} + +// HasAudience returns a boolean if a field has been set. +func (o *WebhooksOAuth2ClientCredentialsCreateAttributes) HasAudience() bool { + return o != nil && o.Audience.IsSet() +} + +// SetAudience gets a reference to the given datadog.NullableString and assigns it to the Audience field. +func (o *WebhooksOAuth2ClientCredentialsCreateAttributes) SetAudience(v string) { + o.Audience.Set(&v) +} + +// SetAudienceNil sets the value for Audience to be an explicit nil. +func (o *WebhooksOAuth2ClientCredentialsCreateAttributes) SetAudienceNil() { + o.Audience.Set(nil) +} + +// UnsetAudience ensures that no value is present for Audience, not even an explicit nil. +func (o *WebhooksOAuth2ClientCredentialsCreateAttributes) UnsetAudience() { + o.Audience.Unset() +} + +// GetClientId returns the ClientId field value. +func (o *WebhooksOAuth2ClientCredentialsCreateAttributes) GetClientId() string { + if o == nil { + var ret string + return ret + } + return o.ClientId +} + +// GetClientIdOk returns a tuple with the ClientId field value +// and a boolean to check if the value has been set. +func (o *WebhooksOAuth2ClientCredentialsCreateAttributes) GetClientIdOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.ClientId, true +} + +// SetClientId sets field value. +func (o *WebhooksOAuth2ClientCredentialsCreateAttributes) SetClientId(v string) { + o.ClientId = v +} + +// GetClientSecret returns the ClientSecret field value. +func (o *WebhooksOAuth2ClientCredentialsCreateAttributes) GetClientSecret() string { + if o == nil { + var ret string + return ret + } + return o.ClientSecret +} + +// GetClientSecretOk returns a tuple with the ClientSecret field value +// and a boolean to check if the value has been set. +func (o *WebhooksOAuth2ClientCredentialsCreateAttributes) GetClientSecretOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.ClientSecret, true +} + +// SetClientSecret sets field value. +func (o *WebhooksOAuth2ClientCredentialsCreateAttributes) SetClientSecret(v string) { + o.ClientSecret = v +} + +// GetName returns the Name field value. +func (o *WebhooksOAuth2ClientCredentialsCreateAttributes) GetName() string { + if o == nil { + var ret string + return ret + } + return o.Name +} + +// GetNameOk returns a tuple with the Name field value +// and a boolean to check if the value has been set. +func (o *WebhooksOAuth2ClientCredentialsCreateAttributes) GetNameOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Name, true +} + +// SetName sets field value. +func (o *WebhooksOAuth2ClientCredentialsCreateAttributes) SetName(v string) { + o.Name = v +} + +// GetScope returns the Scope field value if set, zero value otherwise (both if not set or set to explicit null). +func (o *WebhooksOAuth2ClientCredentialsCreateAttributes) GetScope() string { + if o == nil || o.Scope.Get() == nil { + var ret string + return ret + } + return *o.Scope.Get() +} + +// GetScopeOk returns a tuple with the Scope field value if set, nil otherwise +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned. +func (o *WebhooksOAuth2ClientCredentialsCreateAttributes) GetScopeOk() (*string, bool) { + if o == nil { + return nil, false + } + return o.Scope.Get(), o.Scope.IsSet() +} + +// HasScope returns a boolean if a field has been set. +func (o *WebhooksOAuth2ClientCredentialsCreateAttributes) HasScope() bool { + return o != nil && o.Scope.IsSet() +} + +// SetScope gets a reference to the given datadog.NullableString and assigns it to the Scope field. +func (o *WebhooksOAuth2ClientCredentialsCreateAttributes) SetScope(v string) { + o.Scope.Set(&v) +} + +// SetScopeNil sets the value for Scope to be an explicit nil. +func (o *WebhooksOAuth2ClientCredentialsCreateAttributes) SetScopeNil() { + o.Scope.Set(nil) +} + +// UnsetScope ensures that no value is present for Scope, not even an explicit nil. +func (o *WebhooksOAuth2ClientCredentialsCreateAttributes) UnsetScope() { + o.Scope.Unset() +} + +// MarshalJSON serializes the struct using spec logic. +func (o WebhooksOAuth2ClientCredentialsCreateAttributes) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + toSerialize["access_token_url"] = o.AccessTokenUrl + if o.Audience.IsSet() { + toSerialize["audience"] = o.Audience.Get() + } + toSerialize["client_id"] = o.ClientId + toSerialize["client_secret"] = o.ClientSecret + toSerialize["name"] = o.Name + if o.Scope.IsSet() { + toSerialize["scope"] = o.Scope.Get() + } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *WebhooksOAuth2ClientCredentialsCreateAttributes) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + AccessTokenUrl *string `json:"access_token_url"` + Audience datadog.NullableString `json:"audience,omitempty"` + ClientId *string `json:"client_id"` + ClientSecret *string `json:"client_secret"` + Name *string `json:"name"` + Scope datadog.NullableString `json:"scope,omitempty"` + }{} + if err = datadog.Unmarshal(bytes, &all); err != nil { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + if all.AccessTokenUrl == nil { + return fmt.Errorf("required field access_token_url missing") + } + if all.ClientId == nil { + return fmt.Errorf("required field client_id missing") + } + if all.ClientSecret == nil { + return fmt.Errorf("required field client_secret missing") + } + if all.Name == nil { + return fmt.Errorf("required field name missing") + } + additionalProperties := make(map[string]interface{}) + if err = datadog.UnmarshalUseNumber(bytes, &additionalProperties); err == nil { + datadog.DeleteKeys(additionalProperties, &[]string{"access_token_url", "audience", "client_id", "client_secret", "name", "scope"}) + } else { + return err + } + o.AccessTokenUrl = *all.AccessTokenUrl + o.Audience = all.Audience + o.ClientId = *all.ClientId + o.ClientSecret = *all.ClientSecret + o.Name = *all.Name + o.Scope = all.Scope + + if len(additionalProperties) > 0 { + o.AdditionalProperties = additionalProperties + } + + return nil +} diff --git a/api/datadogV2/model_webhooks_o_auth2_client_credentials_create_data.go b/api/datadogV2/model_webhooks_o_auth2_client_credentials_create_data.go new file mode 100644 index 00000000000..71a81ababc0 --- /dev/null +++ b/api/datadogV2/model_webhooks_o_auth2_client_credentials_create_data.go @@ -0,0 +1,148 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. + +package datadogV2 + +import ( + "fmt" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// WebhooksOAuth2ClientCredentialsCreateData OAuth2 client credentials data for a create request. +type WebhooksOAuth2ClientCredentialsCreateData struct { + // OAuth2 client credentials attributes for a create request. + Attributes WebhooksOAuth2ClientCredentialsCreateAttributes `json:"attributes"` + // OAuth2 client credentials resource type. + Type WebhooksOAuth2ClientCredentialsType `json:"type"` + // UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct + UnparsedObject map[string]interface{} `json:"-"` + AdditionalProperties map[string]interface{} `json:"-"` +} + +// NewWebhooksOAuth2ClientCredentialsCreateData instantiates a new WebhooksOAuth2ClientCredentialsCreateData object. +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed. +func NewWebhooksOAuth2ClientCredentialsCreateData(attributes WebhooksOAuth2ClientCredentialsCreateAttributes, typeVar WebhooksOAuth2ClientCredentialsType) *WebhooksOAuth2ClientCredentialsCreateData { + this := WebhooksOAuth2ClientCredentialsCreateData{} + this.Attributes = attributes + this.Type = typeVar + return &this +} + +// NewWebhooksOAuth2ClientCredentialsCreateDataWithDefaults instantiates a new WebhooksOAuth2ClientCredentialsCreateData object. +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set. +func NewWebhooksOAuth2ClientCredentialsCreateDataWithDefaults() *WebhooksOAuth2ClientCredentialsCreateData { + this := WebhooksOAuth2ClientCredentialsCreateData{} + var typeVar WebhooksOAuth2ClientCredentialsType = WEBHOOKSOAUTH2CLIENTCREDENTIALSTYPE_WEBHOOKS_AUTH_METHOD_OAUTH2_CLIENT_CREDENTIALS + this.Type = typeVar + return &this +} + +// GetAttributes returns the Attributes field value. +func (o *WebhooksOAuth2ClientCredentialsCreateData) GetAttributes() WebhooksOAuth2ClientCredentialsCreateAttributes { + if o == nil { + var ret WebhooksOAuth2ClientCredentialsCreateAttributes + return ret + } + return o.Attributes +} + +// GetAttributesOk returns a tuple with the Attributes field value +// and a boolean to check if the value has been set. +func (o *WebhooksOAuth2ClientCredentialsCreateData) GetAttributesOk() (*WebhooksOAuth2ClientCredentialsCreateAttributes, bool) { + if o == nil { + return nil, false + } + return &o.Attributes, true +} + +// SetAttributes sets field value. +func (o *WebhooksOAuth2ClientCredentialsCreateData) SetAttributes(v WebhooksOAuth2ClientCredentialsCreateAttributes) { + o.Attributes = v +} + +// GetType returns the Type field value. +func (o *WebhooksOAuth2ClientCredentialsCreateData) GetType() WebhooksOAuth2ClientCredentialsType { + if o == nil { + var ret WebhooksOAuth2ClientCredentialsType + return ret + } + return o.Type +} + +// GetTypeOk returns a tuple with the Type field value +// and a boolean to check if the value has been set. +func (o *WebhooksOAuth2ClientCredentialsCreateData) GetTypeOk() (*WebhooksOAuth2ClientCredentialsType, bool) { + if o == nil { + return nil, false + } + return &o.Type, true +} + +// SetType sets field value. +func (o *WebhooksOAuth2ClientCredentialsCreateData) SetType(v WebhooksOAuth2ClientCredentialsType) { + o.Type = v +} + +// MarshalJSON serializes the struct using spec logic. +func (o WebhooksOAuth2ClientCredentialsCreateData) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + toSerialize["attributes"] = o.Attributes + toSerialize["type"] = o.Type + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *WebhooksOAuth2ClientCredentialsCreateData) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + Attributes *WebhooksOAuth2ClientCredentialsCreateAttributes `json:"attributes"` + Type *WebhooksOAuth2ClientCredentialsType `json:"type"` + }{} + if err = datadog.Unmarshal(bytes, &all); err != nil { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + if all.Attributes == nil { + return fmt.Errorf("required field attributes missing") + } + if all.Type == nil { + return fmt.Errorf("required field type missing") + } + additionalProperties := make(map[string]interface{}) + if err = datadog.UnmarshalUseNumber(bytes, &additionalProperties); err == nil { + datadog.DeleteKeys(additionalProperties, &[]string{"attributes", "type"}) + } else { + return err + } + + hasInvalidField := false + if all.Attributes.UnparsedObject != nil && o.UnparsedObject == nil { + hasInvalidField = true + } + o.Attributes = *all.Attributes + if !all.Type.IsValid() { + hasInvalidField = true + } else { + o.Type = *all.Type + } + + if len(additionalProperties) > 0 { + o.AdditionalProperties = additionalProperties + } + + if hasInvalidField { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + + return nil +} diff --git a/api/datadogV2/model_webhooks_o_auth2_client_credentials_create_request.go b/api/datadogV2/model_webhooks_o_auth2_client_credentials_create_request.go new file mode 100644 index 00000000000..bc7b4771446 --- /dev/null +++ b/api/datadogV2/model_webhooks_o_auth2_client_credentials_create_request.go @@ -0,0 +1,110 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. + +package datadogV2 + +import ( + "fmt" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// WebhooksOAuth2ClientCredentialsCreateRequest Create request for an OAuth2 client credentials auth method. +type WebhooksOAuth2ClientCredentialsCreateRequest struct { + // OAuth2 client credentials data for a create request. + Data WebhooksOAuth2ClientCredentialsCreateData `json:"data"` + // UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct + UnparsedObject map[string]interface{} `json:"-"` + AdditionalProperties map[string]interface{} `json:"-"` +} + +// NewWebhooksOAuth2ClientCredentialsCreateRequest instantiates a new WebhooksOAuth2ClientCredentialsCreateRequest object. +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed. +func NewWebhooksOAuth2ClientCredentialsCreateRequest(data WebhooksOAuth2ClientCredentialsCreateData) *WebhooksOAuth2ClientCredentialsCreateRequest { + this := WebhooksOAuth2ClientCredentialsCreateRequest{} + this.Data = data + return &this +} + +// NewWebhooksOAuth2ClientCredentialsCreateRequestWithDefaults instantiates a new WebhooksOAuth2ClientCredentialsCreateRequest object. +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set. +func NewWebhooksOAuth2ClientCredentialsCreateRequestWithDefaults() *WebhooksOAuth2ClientCredentialsCreateRequest { + this := WebhooksOAuth2ClientCredentialsCreateRequest{} + return &this +} + +// GetData returns the Data field value. +func (o *WebhooksOAuth2ClientCredentialsCreateRequest) GetData() WebhooksOAuth2ClientCredentialsCreateData { + if o == nil { + var ret WebhooksOAuth2ClientCredentialsCreateData + return ret + } + return o.Data +} + +// GetDataOk returns a tuple with the Data field value +// and a boolean to check if the value has been set. +func (o *WebhooksOAuth2ClientCredentialsCreateRequest) GetDataOk() (*WebhooksOAuth2ClientCredentialsCreateData, bool) { + if o == nil { + return nil, false + } + return &o.Data, true +} + +// SetData sets field value. +func (o *WebhooksOAuth2ClientCredentialsCreateRequest) SetData(v WebhooksOAuth2ClientCredentialsCreateData) { + o.Data = v +} + +// MarshalJSON serializes the struct using spec logic. +func (o WebhooksOAuth2ClientCredentialsCreateRequest) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + toSerialize["data"] = o.Data + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *WebhooksOAuth2ClientCredentialsCreateRequest) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + Data *WebhooksOAuth2ClientCredentialsCreateData `json:"data"` + }{} + if err = datadog.Unmarshal(bytes, &all); err != nil { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + if all.Data == nil { + return fmt.Errorf("required field data missing") + } + additionalProperties := make(map[string]interface{}) + if err = datadog.UnmarshalUseNumber(bytes, &additionalProperties); err == nil { + datadog.DeleteKeys(additionalProperties, &[]string{"data"}) + } else { + return err + } + + hasInvalidField := false + if all.Data.UnparsedObject != nil && o.UnparsedObject == nil { + hasInvalidField = true + } + o.Data = *all.Data + + if len(additionalProperties) > 0 { + o.AdditionalProperties = additionalProperties + } + + if hasInvalidField { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + + return nil +} diff --git a/api/datadogV2/model_webhooks_o_auth2_client_credentials_relationship.go b/api/datadogV2/model_webhooks_o_auth2_client_credentials_relationship.go new file mode 100644 index 00000000000..2a9515088b8 --- /dev/null +++ b/api/datadogV2/model_webhooks_o_auth2_client_credentials_relationship.go @@ -0,0 +1,111 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. + +package datadogV2 + +import ( + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// WebhooksOAuth2ClientCredentialsRelationship Relationship pointing to the OAuth2 client credentials resource for this auth method. +type WebhooksOAuth2ClientCredentialsRelationship struct { + // Relationship data referencing an OAuth2 client credentials resource. + Data *WebhooksOAuth2ClientCredentialsRelationshipData `json:"data,omitempty"` + // UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct + UnparsedObject map[string]interface{} `json:"-"` + AdditionalProperties map[string]interface{} `json:"-"` +} + +// NewWebhooksOAuth2ClientCredentialsRelationship instantiates a new WebhooksOAuth2ClientCredentialsRelationship object. +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed. +func NewWebhooksOAuth2ClientCredentialsRelationship() *WebhooksOAuth2ClientCredentialsRelationship { + this := WebhooksOAuth2ClientCredentialsRelationship{} + return &this +} + +// NewWebhooksOAuth2ClientCredentialsRelationshipWithDefaults instantiates a new WebhooksOAuth2ClientCredentialsRelationship object. +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set. +func NewWebhooksOAuth2ClientCredentialsRelationshipWithDefaults() *WebhooksOAuth2ClientCredentialsRelationship { + this := WebhooksOAuth2ClientCredentialsRelationship{} + return &this +} + +// GetData returns the Data field value if set, zero value otherwise. +func (o *WebhooksOAuth2ClientCredentialsRelationship) GetData() WebhooksOAuth2ClientCredentialsRelationshipData { + if o == nil || o.Data == nil { + var ret WebhooksOAuth2ClientCredentialsRelationshipData + return ret + } + return *o.Data +} + +// GetDataOk returns a tuple with the Data field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *WebhooksOAuth2ClientCredentialsRelationship) GetDataOk() (*WebhooksOAuth2ClientCredentialsRelationshipData, bool) { + if o == nil || o.Data == nil { + return nil, false + } + return o.Data, true +} + +// HasData returns a boolean if a field has been set. +func (o *WebhooksOAuth2ClientCredentialsRelationship) HasData() bool { + return o != nil && o.Data != nil +} + +// SetData gets a reference to the given WebhooksOAuth2ClientCredentialsRelationshipData and assigns it to the Data field. +func (o *WebhooksOAuth2ClientCredentialsRelationship) SetData(v WebhooksOAuth2ClientCredentialsRelationshipData) { + o.Data = &v +} + +// MarshalJSON serializes the struct using spec logic. +func (o WebhooksOAuth2ClientCredentialsRelationship) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + if o.Data != nil { + toSerialize["data"] = o.Data + } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *WebhooksOAuth2ClientCredentialsRelationship) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + Data *WebhooksOAuth2ClientCredentialsRelationshipData `json:"data,omitempty"` + }{} + if err = datadog.Unmarshal(bytes, &all); err != nil { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + additionalProperties := make(map[string]interface{}) + if err = datadog.UnmarshalUseNumber(bytes, &additionalProperties); err == nil { + datadog.DeleteKeys(additionalProperties, &[]string{"data"}) + } else { + return err + } + + hasInvalidField := false + if all.Data != nil && all.Data.UnparsedObject != nil && o.UnparsedObject == nil { + hasInvalidField = true + } + o.Data = all.Data + + if len(additionalProperties) > 0 { + o.AdditionalProperties = additionalProperties + } + + if hasInvalidField { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + + return nil +} diff --git a/api/datadogV2/model_webhooks_o_auth2_client_credentials_relationship_data.go b/api/datadogV2/model_webhooks_o_auth2_client_credentials_relationship_data.go new file mode 100644 index 00000000000..b987426661f --- /dev/null +++ b/api/datadogV2/model_webhooks_o_auth2_client_credentials_relationship_data.go @@ -0,0 +1,151 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. + +package datadogV2 + +import ( + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// WebhooksOAuth2ClientCredentialsRelationshipData Relationship data referencing an OAuth2 client credentials resource. +type WebhooksOAuth2ClientCredentialsRelationshipData struct { + // The ID of the OAuth2 client credentials resource. + Id *string `json:"id,omitempty"` + // OAuth2 client credentials resource type. + Type *WebhooksOAuth2ClientCredentialsType `json:"type,omitempty"` + // UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct + UnparsedObject map[string]interface{} `json:"-"` + AdditionalProperties map[string]interface{} `json:"-"` +} + +// NewWebhooksOAuth2ClientCredentialsRelationshipData instantiates a new WebhooksOAuth2ClientCredentialsRelationshipData object. +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed. +func NewWebhooksOAuth2ClientCredentialsRelationshipData() *WebhooksOAuth2ClientCredentialsRelationshipData { + this := WebhooksOAuth2ClientCredentialsRelationshipData{} + var typeVar WebhooksOAuth2ClientCredentialsType = WEBHOOKSOAUTH2CLIENTCREDENTIALSTYPE_WEBHOOKS_AUTH_METHOD_OAUTH2_CLIENT_CREDENTIALS + this.Type = &typeVar + return &this +} + +// NewWebhooksOAuth2ClientCredentialsRelationshipDataWithDefaults instantiates a new WebhooksOAuth2ClientCredentialsRelationshipData object. +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set. +func NewWebhooksOAuth2ClientCredentialsRelationshipDataWithDefaults() *WebhooksOAuth2ClientCredentialsRelationshipData { + this := WebhooksOAuth2ClientCredentialsRelationshipData{} + var typeVar WebhooksOAuth2ClientCredentialsType = WEBHOOKSOAUTH2CLIENTCREDENTIALSTYPE_WEBHOOKS_AUTH_METHOD_OAUTH2_CLIENT_CREDENTIALS + this.Type = &typeVar + return &this +} + +// GetId returns the Id field value if set, zero value otherwise. +func (o *WebhooksOAuth2ClientCredentialsRelationshipData) GetId() string { + if o == nil || o.Id == nil { + var ret string + return ret + } + return *o.Id +} + +// GetIdOk returns a tuple with the Id field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *WebhooksOAuth2ClientCredentialsRelationshipData) GetIdOk() (*string, bool) { + if o == nil || o.Id == nil { + return nil, false + } + return o.Id, true +} + +// HasId returns a boolean if a field has been set. +func (o *WebhooksOAuth2ClientCredentialsRelationshipData) HasId() bool { + return o != nil && o.Id != nil +} + +// SetId gets a reference to the given string and assigns it to the Id field. +func (o *WebhooksOAuth2ClientCredentialsRelationshipData) SetId(v string) { + o.Id = &v +} + +// GetType returns the Type field value if set, zero value otherwise. +func (o *WebhooksOAuth2ClientCredentialsRelationshipData) GetType() WebhooksOAuth2ClientCredentialsType { + if o == nil || o.Type == nil { + var ret WebhooksOAuth2ClientCredentialsType + return ret + } + return *o.Type +} + +// GetTypeOk returns a tuple with the Type field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *WebhooksOAuth2ClientCredentialsRelationshipData) GetTypeOk() (*WebhooksOAuth2ClientCredentialsType, bool) { + if o == nil || o.Type == nil { + return nil, false + } + return o.Type, true +} + +// HasType returns a boolean if a field has been set. +func (o *WebhooksOAuth2ClientCredentialsRelationshipData) HasType() bool { + return o != nil && o.Type != nil +} + +// SetType gets a reference to the given WebhooksOAuth2ClientCredentialsType and assigns it to the Type field. +func (o *WebhooksOAuth2ClientCredentialsRelationshipData) SetType(v WebhooksOAuth2ClientCredentialsType) { + o.Type = &v +} + +// MarshalJSON serializes the struct using spec logic. +func (o WebhooksOAuth2ClientCredentialsRelationshipData) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + if o.Id != nil { + toSerialize["id"] = o.Id + } + if o.Type != nil { + toSerialize["type"] = o.Type + } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *WebhooksOAuth2ClientCredentialsRelationshipData) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + Id *string `json:"id,omitempty"` + Type *WebhooksOAuth2ClientCredentialsType `json:"type,omitempty"` + }{} + if err = datadog.Unmarshal(bytes, &all); err != nil { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + additionalProperties := make(map[string]interface{}) + if err = datadog.UnmarshalUseNumber(bytes, &additionalProperties); err == nil { + datadog.DeleteKeys(additionalProperties, &[]string{"id", "type"}) + } else { + return err + } + + hasInvalidField := false + o.Id = all.Id + if all.Type != nil && !all.Type.IsValid() { + hasInvalidField = true + } else { + o.Type = all.Type + } + + if len(additionalProperties) > 0 { + o.AdditionalProperties = additionalProperties + } + + if hasInvalidField { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + + return nil +} diff --git a/api/datadogV2/model_webhooks_o_auth2_client_credentials_response.go b/api/datadogV2/model_webhooks_o_auth2_client_credentials_response.go new file mode 100644 index 00000000000..8d66380b793 --- /dev/null +++ b/api/datadogV2/model_webhooks_o_auth2_client_credentials_response.go @@ -0,0 +1,110 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. + +package datadogV2 + +import ( + "fmt" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// WebhooksOAuth2ClientCredentialsResponse Response containing an OAuth2 client credentials auth method. +type WebhooksOAuth2ClientCredentialsResponse struct { + // OAuth2 client credentials data from a response. + Data WebhooksOAuth2ClientCredentialsResponseData `json:"data"` + // UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct + UnparsedObject map[string]interface{} `json:"-"` + AdditionalProperties map[string]interface{} `json:"-"` +} + +// NewWebhooksOAuth2ClientCredentialsResponse instantiates a new WebhooksOAuth2ClientCredentialsResponse object. +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed. +func NewWebhooksOAuth2ClientCredentialsResponse(data WebhooksOAuth2ClientCredentialsResponseData) *WebhooksOAuth2ClientCredentialsResponse { + this := WebhooksOAuth2ClientCredentialsResponse{} + this.Data = data + return &this +} + +// NewWebhooksOAuth2ClientCredentialsResponseWithDefaults instantiates a new WebhooksOAuth2ClientCredentialsResponse object. +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set. +func NewWebhooksOAuth2ClientCredentialsResponseWithDefaults() *WebhooksOAuth2ClientCredentialsResponse { + this := WebhooksOAuth2ClientCredentialsResponse{} + return &this +} + +// GetData returns the Data field value. +func (o *WebhooksOAuth2ClientCredentialsResponse) GetData() WebhooksOAuth2ClientCredentialsResponseData { + if o == nil { + var ret WebhooksOAuth2ClientCredentialsResponseData + return ret + } + return o.Data +} + +// GetDataOk returns a tuple with the Data field value +// and a boolean to check if the value has been set. +func (o *WebhooksOAuth2ClientCredentialsResponse) GetDataOk() (*WebhooksOAuth2ClientCredentialsResponseData, bool) { + if o == nil { + return nil, false + } + return &o.Data, true +} + +// SetData sets field value. +func (o *WebhooksOAuth2ClientCredentialsResponse) SetData(v WebhooksOAuth2ClientCredentialsResponseData) { + o.Data = v +} + +// MarshalJSON serializes the struct using spec logic. +func (o WebhooksOAuth2ClientCredentialsResponse) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + toSerialize["data"] = o.Data + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *WebhooksOAuth2ClientCredentialsResponse) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + Data *WebhooksOAuth2ClientCredentialsResponseData `json:"data"` + }{} + if err = datadog.Unmarshal(bytes, &all); err != nil { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + if all.Data == nil { + return fmt.Errorf("required field data missing") + } + additionalProperties := make(map[string]interface{}) + if err = datadog.UnmarshalUseNumber(bytes, &additionalProperties); err == nil { + datadog.DeleteKeys(additionalProperties, &[]string{"data"}) + } else { + return err + } + + hasInvalidField := false + if all.Data.UnparsedObject != nil && o.UnparsedObject == nil { + hasInvalidField = true + } + o.Data = *all.Data + + if len(additionalProperties) > 0 { + o.AdditionalProperties = additionalProperties + } + + if hasInvalidField { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + + return nil +} diff --git a/api/datadogV2/model_webhooks_o_auth2_client_credentials_response_attributes.go b/api/datadogV2/model_webhooks_o_auth2_client_credentials_response_attributes.go new file mode 100644 index 00000000000..7d77896a728 --- /dev/null +++ b/api/datadogV2/model_webhooks_o_auth2_client_credentials_response_attributes.go @@ -0,0 +1,309 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. + +package datadogV2 + +import ( + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// WebhooksOAuth2ClientCredentialsResponseAttributes OAuth2 client credentials attributes returned by the API. The `client_secret` is never echoed. +type WebhooksOAuth2ClientCredentialsResponseAttributes struct { + // URL of the OAuth2 access token endpoint. + AccessTokenUrl *string `json:"access_token_url,omitempty"` + // The intended audience for the OAuth2 access token. + Audience datadog.NullableString `json:"audience,omitempty"` + // The OAuth2 client ID issued by the authorization server. + ClientId *string `json:"client_id,omitempty"` + // Human-readable name for this auth method. + Name *string `json:"name,omitempty"` + // Authentication protocol used by the auth method. + Protocol *WebhooksAuthMethodProtocol `json:"protocol,omitempty"` + // Space-separated list of OAuth2 scopes to request. + Scope datadog.NullableString `json:"scope,omitempty"` + // UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct + UnparsedObject map[string]interface{} `json:"-"` + AdditionalProperties map[string]interface{} `json:"-"` +} + +// NewWebhooksOAuth2ClientCredentialsResponseAttributes instantiates a new WebhooksOAuth2ClientCredentialsResponseAttributes object. +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed. +func NewWebhooksOAuth2ClientCredentialsResponseAttributes() *WebhooksOAuth2ClientCredentialsResponseAttributes { + this := WebhooksOAuth2ClientCredentialsResponseAttributes{} + return &this +} + +// NewWebhooksOAuth2ClientCredentialsResponseAttributesWithDefaults instantiates a new WebhooksOAuth2ClientCredentialsResponseAttributes object. +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set. +func NewWebhooksOAuth2ClientCredentialsResponseAttributesWithDefaults() *WebhooksOAuth2ClientCredentialsResponseAttributes { + this := WebhooksOAuth2ClientCredentialsResponseAttributes{} + return &this +} + +// GetAccessTokenUrl returns the AccessTokenUrl field value if set, zero value otherwise. +func (o *WebhooksOAuth2ClientCredentialsResponseAttributes) GetAccessTokenUrl() string { + if o == nil || o.AccessTokenUrl == nil { + var ret string + return ret + } + return *o.AccessTokenUrl +} + +// GetAccessTokenUrlOk returns a tuple with the AccessTokenUrl field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *WebhooksOAuth2ClientCredentialsResponseAttributes) GetAccessTokenUrlOk() (*string, bool) { + if o == nil || o.AccessTokenUrl == nil { + return nil, false + } + return o.AccessTokenUrl, true +} + +// HasAccessTokenUrl returns a boolean if a field has been set. +func (o *WebhooksOAuth2ClientCredentialsResponseAttributes) HasAccessTokenUrl() bool { + return o != nil && o.AccessTokenUrl != nil +} + +// SetAccessTokenUrl gets a reference to the given string and assigns it to the AccessTokenUrl field. +func (o *WebhooksOAuth2ClientCredentialsResponseAttributes) SetAccessTokenUrl(v string) { + o.AccessTokenUrl = &v +} + +// GetAudience returns the Audience field value if set, zero value otherwise (both if not set or set to explicit null). +func (o *WebhooksOAuth2ClientCredentialsResponseAttributes) GetAudience() string { + if o == nil || o.Audience.Get() == nil { + var ret string + return ret + } + return *o.Audience.Get() +} + +// GetAudienceOk returns a tuple with the Audience field value if set, nil otherwise +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned. +func (o *WebhooksOAuth2ClientCredentialsResponseAttributes) GetAudienceOk() (*string, bool) { + if o == nil { + return nil, false + } + return o.Audience.Get(), o.Audience.IsSet() +} + +// HasAudience returns a boolean if a field has been set. +func (o *WebhooksOAuth2ClientCredentialsResponseAttributes) HasAudience() bool { + return o != nil && o.Audience.IsSet() +} + +// SetAudience gets a reference to the given datadog.NullableString and assigns it to the Audience field. +func (o *WebhooksOAuth2ClientCredentialsResponseAttributes) SetAudience(v string) { + o.Audience.Set(&v) +} + +// SetAudienceNil sets the value for Audience to be an explicit nil. +func (o *WebhooksOAuth2ClientCredentialsResponseAttributes) SetAudienceNil() { + o.Audience.Set(nil) +} + +// UnsetAudience ensures that no value is present for Audience, not even an explicit nil. +func (o *WebhooksOAuth2ClientCredentialsResponseAttributes) UnsetAudience() { + o.Audience.Unset() +} + +// GetClientId returns the ClientId field value if set, zero value otherwise. +func (o *WebhooksOAuth2ClientCredentialsResponseAttributes) GetClientId() string { + if o == nil || o.ClientId == nil { + var ret string + return ret + } + return *o.ClientId +} + +// GetClientIdOk returns a tuple with the ClientId field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *WebhooksOAuth2ClientCredentialsResponseAttributes) GetClientIdOk() (*string, bool) { + if o == nil || o.ClientId == nil { + return nil, false + } + return o.ClientId, true +} + +// HasClientId returns a boolean if a field has been set. +func (o *WebhooksOAuth2ClientCredentialsResponseAttributes) HasClientId() bool { + return o != nil && o.ClientId != nil +} + +// SetClientId gets a reference to the given string and assigns it to the ClientId field. +func (o *WebhooksOAuth2ClientCredentialsResponseAttributes) SetClientId(v string) { + o.ClientId = &v +} + +// GetName returns the Name field value if set, zero value otherwise. +func (o *WebhooksOAuth2ClientCredentialsResponseAttributes) GetName() string { + if o == nil || o.Name == nil { + var ret string + return ret + } + return *o.Name +} + +// GetNameOk returns a tuple with the Name field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *WebhooksOAuth2ClientCredentialsResponseAttributes) GetNameOk() (*string, bool) { + if o == nil || o.Name == nil { + return nil, false + } + return o.Name, true +} + +// HasName returns a boolean if a field has been set. +func (o *WebhooksOAuth2ClientCredentialsResponseAttributes) HasName() bool { + return o != nil && o.Name != nil +} + +// SetName gets a reference to the given string and assigns it to the Name field. +func (o *WebhooksOAuth2ClientCredentialsResponseAttributes) SetName(v string) { + o.Name = &v +} + +// GetProtocol returns the Protocol field value if set, zero value otherwise. +func (o *WebhooksOAuth2ClientCredentialsResponseAttributes) GetProtocol() WebhooksAuthMethodProtocol { + if o == nil || o.Protocol == nil { + var ret WebhooksAuthMethodProtocol + return ret + } + return *o.Protocol +} + +// GetProtocolOk returns a tuple with the Protocol field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *WebhooksOAuth2ClientCredentialsResponseAttributes) GetProtocolOk() (*WebhooksAuthMethodProtocol, bool) { + if o == nil || o.Protocol == nil { + return nil, false + } + return o.Protocol, true +} + +// HasProtocol returns a boolean if a field has been set. +func (o *WebhooksOAuth2ClientCredentialsResponseAttributes) HasProtocol() bool { + return o != nil && o.Protocol != nil +} + +// SetProtocol gets a reference to the given WebhooksAuthMethodProtocol and assigns it to the Protocol field. +func (o *WebhooksOAuth2ClientCredentialsResponseAttributes) SetProtocol(v WebhooksAuthMethodProtocol) { + o.Protocol = &v +} + +// GetScope returns the Scope field value if set, zero value otherwise (both if not set or set to explicit null). +func (o *WebhooksOAuth2ClientCredentialsResponseAttributes) GetScope() string { + if o == nil || o.Scope.Get() == nil { + var ret string + return ret + } + return *o.Scope.Get() +} + +// GetScopeOk returns a tuple with the Scope field value if set, nil otherwise +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned. +func (o *WebhooksOAuth2ClientCredentialsResponseAttributes) GetScopeOk() (*string, bool) { + if o == nil { + return nil, false + } + return o.Scope.Get(), o.Scope.IsSet() +} + +// HasScope returns a boolean if a field has been set. +func (o *WebhooksOAuth2ClientCredentialsResponseAttributes) HasScope() bool { + return o != nil && o.Scope.IsSet() +} + +// SetScope gets a reference to the given datadog.NullableString and assigns it to the Scope field. +func (o *WebhooksOAuth2ClientCredentialsResponseAttributes) SetScope(v string) { + o.Scope.Set(&v) +} + +// SetScopeNil sets the value for Scope to be an explicit nil. +func (o *WebhooksOAuth2ClientCredentialsResponseAttributes) SetScopeNil() { + o.Scope.Set(nil) +} + +// UnsetScope ensures that no value is present for Scope, not even an explicit nil. +func (o *WebhooksOAuth2ClientCredentialsResponseAttributes) UnsetScope() { + o.Scope.Unset() +} + +// MarshalJSON serializes the struct using spec logic. +func (o WebhooksOAuth2ClientCredentialsResponseAttributes) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + if o.AccessTokenUrl != nil { + toSerialize["access_token_url"] = o.AccessTokenUrl + } + if o.Audience.IsSet() { + toSerialize["audience"] = o.Audience.Get() + } + if o.ClientId != nil { + toSerialize["client_id"] = o.ClientId + } + if o.Name != nil { + toSerialize["name"] = o.Name + } + if o.Protocol != nil { + toSerialize["protocol"] = o.Protocol + } + if o.Scope.IsSet() { + toSerialize["scope"] = o.Scope.Get() + } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *WebhooksOAuth2ClientCredentialsResponseAttributes) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + AccessTokenUrl *string `json:"access_token_url,omitempty"` + Audience datadog.NullableString `json:"audience,omitempty"` + ClientId *string `json:"client_id,omitempty"` + Name *string `json:"name,omitempty"` + Protocol *WebhooksAuthMethodProtocol `json:"protocol,omitempty"` + Scope datadog.NullableString `json:"scope,omitempty"` + }{} + if err = datadog.Unmarshal(bytes, &all); err != nil { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + additionalProperties := make(map[string]interface{}) + if err = datadog.UnmarshalUseNumber(bytes, &additionalProperties); err == nil { + datadog.DeleteKeys(additionalProperties, &[]string{"access_token_url", "audience", "client_id", "name", "protocol", "scope"}) + } else { + return err + } + + hasInvalidField := false + o.AccessTokenUrl = all.AccessTokenUrl + o.Audience = all.Audience + o.ClientId = all.ClientId + o.Name = all.Name + if all.Protocol != nil && !all.Protocol.IsValid() { + hasInvalidField = true + } else { + o.Protocol = all.Protocol + } + o.Scope = all.Scope + + if len(additionalProperties) > 0 { + o.AdditionalProperties = additionalProperties + } + + if hasInvalidField { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + + return nil +} diff --git a/api/datadogV2/model_webhooks_o_auth2_client_credentials_response_data.go b/api/datadogV2/model_webhooks_o_auth2_client_credentials_response_data.go new file mode 100644 index 00000000000..9117ee2568b --- /dev/null +++ b/api/datadogV2/model_webhooks_o_auth2_client_credentials_response_data.go @@ -0,0 +1,180 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. + +package datadogV2 + +import ( + "fmt" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// WebhooksOAuth2ClientCredentialsResponseData OAuth2 client credentials data from a response. +type WebhooksOAuth2ClientCredentialsResponseData struct { + // OAuth2 client credentials attributes returned by the API. The `client_secret` is never echoed. + Attributes WebhooksOAuth2ClientCredentialsResponseAttributes `json:"attributes"` + // The ID of the OAuth2 client credentials auth method. + Id string `json:"id"` + // OAuth2 client credentials resource type. + Type WebhooksOAuth2ClientCredentialsType `json:"type"` + // UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct + UnparsedObject map[string]interface{} `json:"-"` + AdditionalProperties map[string]interface{} `json:"-"` +} + +// NewWebhooksOAuth2ClientCredentialsResponseData instantiates a new WebhooksOAuth2ClientCredentialsResponseData object. +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed. +func NewWebhooksOAuth2ClientCredentialsResponseData(attributes WebhooksOAuth2ClientCredentialsResponseAttributes, id string, typeVar WebhooksOAuth2ClientCredentialsType) *WebhooksOAuth2ClientCredentialsResponseData { + this := WebhooksOAuth2ClientCredentialsResponseData{} + this.Attributes = attributes + this.Id = id + this.Type = typeVar + return &this +} + +// NewWebhooksOAuth2ClientCredentialsResponseDataWithDefaults instantiates a new WebhooksOAuth2ClientCredentialsResponseData object. +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set. +func NewWebhooksOAuth2ClientCredentialsResponseDataWithDefaults() *WebhooksOAuth2ClientCredentialsResponseData { + this := WebhooksOAuth2ClientCredentialsResponseData{} + var typeVar WebhooksOAuth2ClientCredentialsType = WEBHOOKSOAUTH2CLIENTCREDENTIALSTYPE_WEBHOOKS_AUTH_METHOD_OAUTH2_CLIENT_CREDENTIALS + this.Type = typeVar + return &this +} + +// GetAttributes returns the Attributes field value. +func (o *WebhooksOAuth2ClientCredentialsResponseData) GetAttributes() WebhooksOAuth2ClientCredentialsResponseAttributes { + if o == nil { + var ret WebhooksOAuth2ClientCredentialsResponseAttributes + return ret + } + return o.Attributes +} + +// GetAttributesOk returns a tuple with the Attributes field value +// and a boolean to check if the value has been set. +func (o *WebhooksOAuth2ClientCredentialsResponseData) GetAttributesOk() (*WebhooksOAuth2ClientCredentialsResponseAttributes, bool) { + if o == nil { + return nil, false + } + return &o.Attributes, true +} + +// SetAttributes sets field value. +func (o *WebhooksOAuth2ClientCredentialsResponseData) SetAttributes(v WebhooksOAuth2ClientCredentialsResponseAttributes) { + o.Attributes = v +} + +// GetId returns the Id field value. +func (o *WebhooksOAuth2ClientCredentialsResponseData) GetId() string { + if o == nil { + var ret string + return ret + } + return o.Id +} + +// GetIdOk returns a tuple with the Id field value +// and a boolean to check if the value has been set. +func (o *WebhooksOAuth2ClientCredentialsResponseData) GetIdOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Id, true +} + +// SetId sets field value. +func (o *WebhooksOAuth2ClientCredentialsResponseData) SetId(v string) { + o.Id = v +} + +// GetType returns the Type field value. +func (o *WebhooksOAuth2ClientCredentialsResponseData) GetType() WebhooksOAuth2ClientCredentialsType { + if o == nil { + var ret WebhooksOAuth2ClientCredentialsType + return ret + } + return o.Type +} + +// GetTypeOk returns a tuple with the Type field value +// and a boolean to check if the value has been set. +func (o *WebhooksOAuth2ClientCredentialsResponseData) GetTypeOk() (*WebhooksOAuth2ClientCredentialsType, bool) { + if o == nil { + return nil, false + } + return &o.Type, true +} + +// SetType sets field value. +func (o *WebhooksOAuth2ClientCredentialsResponseData) SetType(v WebhooksOAuth2ClientCredentialsType) { + o.Type = v +} + +// MarshalJSON serializes the struct using spec logic. +func (o WebhooksOAuth2ClientCredentialsResponseData) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + toSerialize["attributes"] = o.Attributes + toSerialize["id"] = o.Id + toSerialize["type"] = o.Type + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *WebhooksOAuth2ClientCredentialsResponseData) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + Attributes *WebhooksOAuth2ClientCredentialsResponseAttributes `json:"attributes"` + Id *string `json:"id"` + Type *WebhooksOAuth2ClientCredentialsType `json:"type"` + }{} + if err = datadog.Unmarshal(bytes, &all); err != nil { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + if all.Attributes == nil { + return fmt.Errorf("required field attributes missing") + } + if all.Id == nil { + return fmt.Errorf("required field id missing") + } + if all.Type == nil { + return fmt.Errorf("required field type missing") + } + additionalProperties := make(map[string]interface{}) + if err = datadog.UnmarshalUseNumber(bytes, &additionalProperties); err == nil { + datadog.DeleteKeys(additionalProperties, &[]string{"attributes", "id", "type"}) + } else { + return err + } + + hasInvalidField := false + if all.Attributes.UnparsedObject != nil && o.UnparsedObject == nil { + hasInvalidField = true + } + o.Attributes = *all.Attributes + o.Id = *all.Id + if !all.Type.IsValid() { + hasInvalidField = true + } else { + o.Type = *all.Type + } + + if len(additionalProperties) > 0 { + o.AdditionalProperties = additionalProperties + } + + if hasInvalidField { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + + return nil +} diff --git a/api/datadogV2/model_webhooks_o_auth2_client_credentials_type.go b/api/datadogV2/model_webhooks_o_auth2_client_credentials_type.go new file mode 100644 index 00000000000..b48da62649f --- /dev/null +++ b/api/datadogV2/model_webhooks_o_auth2_client_credentials_type.go @@ -0,0 +1,64 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. + +package datadogV2 + +import ( + "fmt" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// WebhooksOAuth2ClientCredentialsType OAuth2 client credentials resource type. +type WebhooksOAuth2ClientCredentialsType string + +// List of WebhooksOAuth2ClientCredentialsType. +const ( + WEBHOOKSOAUTH2CLIENTCREDENTIALSTYPE_WEBHOOKS_AUTH_METHOD_OAUTH2_CLIENT_CREDENTIALS WebhooksOAuth2ClientCredentialsType = "webhooks-auth-method-oauth2-client-credentials" +) + +var allowedWebhooksOAuth2ClientCredentialsTypeEnumValues = []WebhooksOAuth2ClientCredentialsType{ + WEBHOOKSOAUTH2CLIENTCREDENTIALSTYPE_WEBHOOKS_AUTH_METHOD_OAUTH2_CLIENT_CREDENTIALS, +} + +// GetAllowedValues reeturns the list of possible values. +func (v *WebhooksOAuth2ClientCredentialsType) GetAllowedValues() []WebhooksOAuth2ClientCredentialsType { + return allowedWebhooksOAuth2ClientCredentialsTypeEnumValues +} + +// UnmarshalJSON deserializes the given payload. +func (v *WebhooksOAuth2ClientCredentialsType) UnmarshalJSON(src []byte) error { + var value string + err := datadog.Unmarshal(src, &value) + if err != nil { + return err + } + *v = WebhooksOAuth2ClientCredentialsType(value) + return nil +} + +// NewWebhooksOAuth2ClientCredentialsTypeFromValue returns a pointer to a valid WebhooksOAuth2ClientCredentialsType +// for the value passed as argument, or an error if the value passed is not allowed by the enum. +func NewWebhooksOAuth2ClientCredentialsTypeFromValue(v string) (*WebhooksOAuth2ClientCredentialsType, error) { + ev := WebhooksOAuth2ClientCredentialsType(v) + if ev.IsValid() { + return &ev, nil + } + return nil, fmt.Errorf("invalid value '%v' for WebhooksOAuth2ClientCredentialsType: valid values are %v", v, allowedWebhooksOAuth2ClientCredentialsTypeEnumValues) +} + +// IsValid return true if the value is valid for the enum, false otherwise. +func (v WebhooksOAuth2ClientCredentialsType) IsValid() bool { + for _, existing := range allowedWebhooksOAuth2ClientCredentialsTypeEnumValues { + if existing == v { + return true + } + } + return false +} + +// Ptr returns reference to WebhooksOAuth2ClientCredentialsType value. +func (v WebhooksOAuth2ClientCredentialsType) Ptr() *WebhooksOAuth2ClientCredentialsType { + return &v +} diff --git a/api/datadogV2/model_webhooks_o_auth2_client_credentials_update_attributes.go b/api/datadogV2/model_webhooks_o_auth2_client_credentials_update_attributes.go new file mode 100644 index 00000000000..41f59062fb7 --- /dev/null +++ b/api/datadogV2/model_webhooks_o_auth2_client_credentials_update_attributes.go @@ -0,0 +1,300 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. + +package datadogV2 + +import ( + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// WebhooksOAuth2ClientCredentialsUpdateAttributes OAuth2 client credentials attributes for an update request. +type WebhooksOAuth2ClientCredentialsUpdateAttributes struct { + // URL of the OAuth2 access token endpoint. + AccessTokenUrl *string `json:"access_token_url,omitempty"` + // The intended audience for the OAuth2 access token. + Audience datadog.NullableString `json:"audience,omitempty"` + // The OAuth2 client ID issued by the authorization server. + ClientId *string `json:"client_id,omitempty"` + // The OAuth2 client secret issued by the authorization server. + // Write-only; never returned by the API. + ClientSecret *string `json:"client_secret,omitempty"` + // Human-readable name for this auth method. + Name *string `json:"name,omitempty"` + // Space-separated list of OAuth2 scopes to request. + Scope datadog.NullableString `json:"scope,omitempty"` + // UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct + UnparsedObject map[string]interface{} `json:"-"` + AdditionalProperties map[string]interface{} `json:"-"` +} + +// NewWebhooksOAuth2ClientCredentialsUpdateAttributes instantiates a new WebhooksOAuth2ClientCredentialsUpdateAttributes object. +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed. +func NewWebhooksOAuth2ClientCredentialsUpdateAttributes() *WebhooksOAuth2ClientCredentialsUpdateAttributes { + this := WebhooksOAuth2ClientCredentialsUpdateAttributes{} + return &this +} + +// NewWebhooksOAuth2ClientCredentialsUpdateAttributesWithDefaults instantiates a new WebhooksOAuth2ClientCredentialsUpdateAttributes object. +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set. +func NewWebhooksOAuth2ClientCredentialsUpdateAttributesWithDefaults() *WebhooksOAuth2ClientCredentialsUpdateAttributes { + this := WebhooksOAuth2ClientCredentialsUpdateAttributes{} + return &this +} + +// GetAccessTokenUrl returns the AccessTokenUrl field value if set, zero value otherwise. +func (o *WebhooksOAuth2ClientCredentialsUpdateAttributes) GetAccessTokenUrl() string { + if o == nil || o.AccessTokenUrl == nil { + var ret string + return ret + } + return *o.AccessTokenUrl +} + +// GetAccessTokenUrlOk returns a tuple with the AccessTokenUrl field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *WebhooksOAuth2ClientCredentialsUpdateAttributes) GetAccessTokenUrlOk() (*string, bool) { + if o == nil || o.AccessTokenUrl == nil { + return nil, false + } + return o.AccessTokenUrl, true +} + +// HasAccessTokenUrl returns a boolean if a field has been set. +func (o *WebhooksOAuth2ClientCredentialsUpdateAttributes) HasAccessTokenUrl() bool { + return o != nil && o.AccessTokenUrl != nil +} + +// SetAccessTokenUrl gets a reference to the given string and assigns it to the AccessTokenUrl field. +func (o *WebhooksOAuth2ClientCredentialsUpdateAttributes) SetAccessTokenUrl(v string) { + o.AccessTokenUrl = &v +} + +// GetAudience returns the Audience field value if set, zero value otherwise (both if not set or set to explicit null). +func (o *WebhooksOAuth2ClientCredentialsUpdateAttributes) GetAudience() string { + if o == nil || o.Audience.Get() == nil { + var ret string + return ret + } + return *o.Audience.Get() +} + +// GetAudienceOk returns a tuple with the Audience field value if set, nil otherwise +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned. +func (o *WebhooksOAuth2ClientCredentialsUpdateAttributes) GetAudienceOk() (*string, bool) { + if o == nil { + return nil, false + } + return o.Audience.Get(), o.Audience.IsSet() +} + +// HasAudience returns a boolean if a field has been set. +func (o *WebhooksOAuth2ClientCredentialsUpdateAttributes) HasAudience() bool { + return o != nil && o.Audience.IsSet() +} + +// SetAudience gets a reference to the given datadog.NullableString and assigns it to the Audience field. +func (o *WebhooksOAuth2ClientCredentialsUpdateAttributes) SetAudience(v string) { + o.Audience.Set(&v) +} + +// SetAudienceNil sets the value for Audience to be an explicit nil. +func (o *WebhooksOAuth2ClientCredentialsUpdateAttributes) SetAudienceNil() { + o.Audience.Set(nil) +} + +// UnsetAudience ensures that no value is present for Audience, not even an explicit nil. +func (o *WebhooksOAuth2ClientCredentialsUpdateAttributes) UnsetAudience() { + o.Audience.Unset() +} + +// GetClientId returns the ClientId field value if set, zero value otherwise. +func (o *WebhooksOAuth2ClientCredentialsUpdateAttributes) GetClientId() string { + if o == nil || o.ClientId == nil { + var ret string + return ret + } + return *o.ClientId +} + +// GetClientIdOk returns a tuple with the ClientId field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *WebhooksOAuth2ClientCredentialsUpdateAttributes) GetClientIdOk() (*string, bool) { + if o == nil || o.ClientId == nil { + return nil, false + } + return o.ClientId, true +} + +// HasClientId returns a boolean if a field has been set. +func (o *WebhooksOAuth2ClientCredentialsUpdateAttributes) HasClientId() bool { + return o != nil && o.ClientId != nil +} + +// SetClientId gets a reference to the given string and assigns it to the ClientId field. +func (o *WebhooksOAuth2ClientCredentialsUpdateAttributes) SetClientId(v string) { + o.ClientId = &v +} + +// GetClientSecret returns the ClientSecret field value if set, zero value otherwise. +func (o *WebhooksOAuth2ClientCredentialsUpdateAttributes) GetClientSecret() string { + if o == nil || o.ClientSecret == nil { + var ret string + return ret + } + return *o.ClientSecret +} + +// GetClientSecretOk returns a tuple with the ClientSecret field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *WebhooksOAuth2ClientCredentialsUpdateAttributes) GetClientSecretOk() (*string, bool) { + if o == nil || o.ClientSecret == nil { + return nil, false + } + return o.ClientSecret, true +} + +// HasClientSecret returns a boolean if a field has been set. +func (o *WebhooksOAuth2ClientCredentialsUpdateAttributes) HasClientSecret() bool { + return o != nil && o.ClientSecret != nil +} + +// SetClientSecret gets a reference to the given string and assigns it to the ClientSecret field. +func (o *WebhooksOAuth2ClientCredentialsUpdateAttributes) SetClientSecret(v string) { + o.ClientSecret = &v +} + +// GetName returns the Name field value if set, zero value otherwise. +func (o *WebhooksOAuth2ClientCredentialsUpdateAttributes) GetName() string { + if o == nil || o.Name == nil { + var ret string + return ret + } + return *o.Name +} + +// GetNameOk returns a tuple with the Name field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *WebhooksOAuth2ClientCredentialsUpdateAttributes) GetNameOk() (*string, bool) { + if o == nil || o.Name == nil { + return nil, false + } + return o.Name, true +} + +// HasName returns a boolean if a field has been set. +func (o *WebhooksOAuth2ClientCredentialsUpdateAttributes) HasName() bool { + return o != nil && o.Name != nil +} + +// SetName gets a reference to the given string and assigns it to the Name field. +func (o *WebhooksOAuth2ClientCredentialsUpdateAttributes) SetName(v string) { + o.Name = &v +} + +// GetScope returns the Scope field value if set, zero value otherwise (both if not set or set to explicit null). +func (o *WebhooksOAuth2ClientCredentialsUpdateAttributes) GetScope() string { + if o == nil || o.Scope.Get() == nil { + var ret string + return ret + } + return *o.Scope.Get() +} + +// GetScopeOk returns a tuple with the Scope field value if set, nil otherwise +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned. +func (o *WebhooksOAuth2ClientCredentialsUpdateAttributes) GetScopeOk() (*string, bool) { + if o == nil { + return nil, false + } + return o.Scope.Get(), o.Scope.IsSet() +} + +// HasScope returns a boolean if a field has been set. +func (o *WebhooksOAuth2ClientCredentialsUpdateAttributes) HasScope() bool { + return o != nil && o.Scope.IsSet() +} + +// SetScope gets a reference to the given datadog.NullableString and assigns it to the Scope field. +func (o *WebhooksOAuth2ClientCredentialsUpdateAttributes) SetScope(v string) { + o.Scope.Set(&v) +} + +// SetScopeNil sets the value for Scope to be an explicit nil. +func (o *WebhooksOAuth2ClientCredentialsUpdateAttributes) SetScopeNil() { + o.Scope.Set(nil) +} + +// UnsetScope ensures that no value is present for Scope, not even an explicit nil. +func (o *WebhooksOAuth2ClientCredentialsUpdateAttributes) UnsetScope() { + o.Scope.Unset() +} + +// MarshalJSON serializes the struct using spec logic. +func (o WebhooksOAuth2ClientCredentialsUpdateAttributes) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + if o.AccessTokenUrl != nil { + toSerialize["access_token_url"] = o.AccessTokenUrl + } + if o.Audience.IsSet() { + toSerialize["audience"] = o.Audience.Get() + } + if o.ClientId != nil { + toSerialize["client_id"] = o.ClientId + } + if o.ClientSecret != nil { + toSerialize["client_secret"] = o.ClientSecret + } + if o.Name != nil { + toSerialize["name"] = o.Name + } + if o.Scope.IsSet() { + toSerialize["scope"] = o.Scope.Get() + } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *WebhooksOAuth2ClientCredentialsUpdateAttributes) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + AccessTokenUrl *string `json:"access_token_url,omitempty"` + Audience datadog.NullableString `json:"audience,omitempty"` + ClientId *string `json:"client_id,omitempty"` + ClientSecret *string `json:"client_secret,omitempty"` + Name *string `json:"name,omitempty"` + Scope datadog.NullableString `json:"scope,omitempty"` + }{} + if err = datadog.Unmarshal(bytes, &all); err != nil { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + additionalProperties := make(map[string]interface{}) + if err = datadog.UnmarshalUseNumber(bytes, &additionalProperties); err == nil { + datadog.DeleteKeys(additionalProperties, &[]string{"access_token_url", "audience", "client_id", "client_secret", "name", "scope"}) + } else { + return err + } + o.AccessTokenUrl = all.AccessTokenUrl + o.Audience = all.Audience + o.ClientId = all.ClientId + o.ClientSecret = all.ClientSecret + o.Name = all.Name + o.Scope = all.Scope + + if len(additionalProperties) > 0 { + o.AdditionalProperties = additionalProperties + } + + return nil +} diff --git a/api/datadogV2/model_webhooks_o_auth2_client_credentials_update_data.go b/api/datadogV2/model_webhooks_o_auth2_client_credentials_update_data.go new file mode 100644 index 00000000000..aa80771227f --- /dev/null +++ b/api/datadogV2/model_webhooks_o_auth2_client_credentials_update_data.go @@ -0,0 +1,148 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. + +package datadogV2 + +import ( + "fmt" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// WebhooksOAuth2ClientCredentialsUpdateData OAuth2 client credentials data for an update request. +type WebhooksOAuth2ClientCredentialsUpdateData struct { + // OAuth2 client credentials attributes for an update request. + Attributes WebhooksOAuth2ClientCredentialsUpdateAttributes `json:"attributes"` + // OAuth2 client credentials resource type. + Type WebhooksOAuth2ClientCredentialsType `json:"type"` + // UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct + UnparsedObject map[string]interface{} `json:"-"` + AdditionalProperties map[string]interface{} `json:"-"` +} + +// NewWebhooksOAuth2ClientCredentialsUpdateData instantiates a new WebhooksOAuth2ClientCredentialsUpdateData object. +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed. +func NewWebhooksOAuth2ClientCredentialsUpdateData(attributes WebhooksOAuth2ClientCredentialsUpdateAttributes, typeVar WebhooksOAuth2ClientCredentialsType) *WebhooksOAuth2ClientCredentialsUpdateData { + this := WebhooksOAuth2ClientCredentialsUpdateData{} + this.Attributes = attributes + this.Type = typeVar + return &this +} + +// NewWebhooksOAuth2ClientCredentialsUpdateDataWithDefaults instantiates a new WebhooksOAuth2ClientCredentialsUpdateData object. +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set. +func NewWebhooksOAuth2ClientCredentialsUpdateDataWithDefaults() *WebhooksOAuth2ClientCredentialsUpdateData { + this := WebhooksOAuth2ClientCredentialsUpdateData{} + var typeVar WebhooksOAuth2ClientCredentialsType = WEBHOOKSOAUTH2CLIENTCREDENTIALSTYPE_WEBHOOKS_AUTH_METHOD_OAUTH2_CLIENT_CREDENTIALS + this.Type = typeVar + return &this +} + +// GetAttributes returns the Attributes field value. +func (o *WebhooksOAuth2ClientCredentialsUpdateData) GetAttributes() WebhooksOAuth2ClientCredentialsUpdateAttributes { + if o == nil { + var ret WebhooksOAuth2ClientCredentialsUpdateAttributes + return ret + } + return o.Attributes +} + +// GetAttributesOk returns a tuple with the Attributes field value +// and a boolean to check if the value has been set. +func (o *WebhooksOAuth2ClientCredentialsUpdateData) GetAttributesOk() (*WebhooksOAuth2ClientCredentialsUpdateAttributes, bool) { + if o == nil { + return nil, false + } + return &o.Attributes, true +} + +// SetAttributes sets field value. +func (o *WebhooksOAuth2ClientCredentialsUpdateData) SetAttributes(v WebhooksOAuth2ClientCredentialsUpdateAttributes) { + o.Attributes = v +} + +// GetType returns the Type field value. +func (o *WebhooksOAuth2ClientCredentialsUpdateData) GetType() WebhooksOAuth2ClientCredentialsType { + if o == nil { + var ret WebhooksOAuth2ClientCredentialsType + return ret + } + return o.Type +} + +// GetTypeOk returns a tuple with the Type field value +// and a boolean to check if the value has been set. +func (o *WebhooksOAuth2ClientCredentialsUpdateData) GetTypeOk() (*WebhooksOAuth2ClientCredentialsType, bool) { + if o == nil { + return nil, false + } + return &o.Type, true +} + +// SetType sets field value. +func (o *WebhooksOAuth2ClientCredentialsUpdateData) SetType(v WebhooksOAuth2ClientCredentialsType) { + o.Type = v +} + +// MarshalJSON serializes the struct using spec logic. +func (o WebhooksOAuth2ClientCredentialsUpdateData) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + toSerialize["attributes"] = o.Attributes + toSerialize["type"] = o.Type + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *WebhooksOAuth2ClientCredentialsUpdateData) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + Attributes *WebhooksOAuth2ClientCredentialsUpdateAttributes `json:"attributes"` + Type *WebhooksOAuth2ClientCredentialsType `json:"type"` + }{} + if err = datadog.Unmarshal(bytes, &all); err != nil { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + if all.Attributes == nil { + return fmt.Errorf("required field attributes missing") + } + if all.Type == nil { + return fmt.Errorf("required field type missing") + } + additionalProperties := make(map[string]interface{}) + if err = datadog.UnmarshalUseNumber(bytes, &additionalProperties); err == nil { + datadog.DeleteKeys(additionalProperties, &[]string{"attributes", "type"}) + } else { + return err + } + + hasInvalidField := false + if all.Attributes.UnparsedObject != nil && o.UnparsedObject == nil { + hasInvalidField = true + } + o.Attributes = *all.Attributes + if !all.Type.IsValid() { + hasInvalidField = true + } else { + o.Type = *all.Type + } + + if len(additionalProperties) > 0 { + o.AdditionalProperties = additionalProperties + } + + if hasInvalidField { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + + return nil +} diff --git a/api/datadogV2/model_webhooks_o_auth2_client_credentials_update_request.go b/api/datadogV2/model_webhooks_o_auth2_client_credentials_update_request.go new file mode 100644 index 00000000000..0210326fc5a --- /dev/null +++ b/api/datadogV2/model_webhooks_o_auth2_client_credentials_update_request.go @@ -0,0 +1,110 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. + +package datadogV2 + +import ( + "fmt" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// WebhooksOAuth2ClientCredentialsUpdateRequest Update request for an OAuth2 client credentials auth method. +type WebhooksOAuth2ClientCredentialsUpdateRequest struct { + // OAuth2 client credentials data for an update request. + Data WebhooksOAuth2ClientCredentialsUpdateData `json:"data"` + // UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct + UnparsedObject map[string]interface{} `json:"-"` + AdditionalProperties map[string]interface{} `json:"-"` +} + +// NewWebhooksOAuth2ClientCredentialsUpdateRequest instantiates a new WebhooksOAuth2ClientCredentialsUpdateRequest object. +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed. +func NewWebhooksOAuth2ClientCredentialsUpdateRequest(data WebhooksOAuth2ClientCredentialsUpdateData) *WebhooksOAuth2ClientCredentialsUpdateRequest { + this := WebhooksOAuth2ClientCredentialsUpdateRequest{} + this.Data = data + return &this +} + +// NewWebhooksOAuth2ClientCredentialsUpdateRequestWithDefaults instantiates a new WebhooksOAuth2ClientCredentialsUpdateRequest object. +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set. +func NewWebhooksOAuth2ClientCredentialsUpdateRequestWithDefaults() *WebhooksOAuth2ClientCredentialsUpdateRequest { + this := WebhooksOAuth2ClientCredentialsUpdateRequest{} + return &this +} + +// GetData returns the Data field value. +func (o *WebhooksOAuth2ClientCredentialsUpdateRequest) GetData() WebhooksOAuth2ClientCredentialsUpdateData { + if o == nil { + var ret WebhooksOAuth2ClientCredentialsUpdateData + return ret + } + return o.Data +} + +// GetDataOk returns a tuple with the Data field value +// and a boolean to check if the value has been set. +func (o *WebhooksOAuth2ClientCredentialsUpdateRequest) GetDataOk() (*WebhooksOAuth2ClientCredentialsUpdateData, bool) { + if o == nil { + return nil, false + } + return &o.Data, true +} + +// SetData sets field value. +func (o *WebhooksOAuth2ClientCredentialsUpdateRequest) SetData(v WebhooksOAuth2ClientCredentialsUpdateData) { + o.Data = v +} + +// MarshalJSON serializes the struct using spec logic. +func (o WebhooksOAuth2ClientCredentialsUpdateRequest) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + toSerialize["data"] = o.Data + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *WebhooksOAuth2ClientCredentialsUpdateRequest) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + Data *WebhooksOAuth2ClientCredentialsUpdateData `json:"data"` + }{} + if err = datadog.Unmarshal(bytes, &all); err != nil { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + if all.Data == nil { + return fmt.Errorf("required field data missing") + } + additionalProperties := make(map[string]interface{}) + if err = datadog.UnmarshalUseNumber(bytes, &additionalProperties); err == nil { + datadog.DeleteKeys(additionalProperties, &[]string{"data"}) + } else { + return err + } + + hasInvalidField := false + if all.Data.UnparsedObject != nil && o.UnparsedObject == nil { + hasInvalidField = true + } + o.Data = *all.Data + + if len(additionalProperties) > 0 { + o.AdditionalProperties = additionalProperties + } + + if hasInvalidField { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + + return nil +} diff --git a/examples/v2/webhooks-integration/CreateOAuth2ClientCredentials.go b/examples/v2/webhooks-integration/CreateOAuth2ClientCredentials.go new file mode 100644 index 00000000000..36bce2f0f8e --- /dev/null +++ b/examples/v2/webhooks-integration/CreateOAuth2ClientCredentials.go @@ -0,0 +1,42 @@ +// Create an OAuth2 client credentials auth method returns "CREATED" response + +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" + "github.com/DataDog/datadog-api-client-go/v2/api/datadogV2" +) + +func main() { + body := datadogV2.WebhooksOAuth2ClientCredentialsCreateRequest{ + Data: datadogV2.WebhooksOAuth2ClientCredentialsCreateData{ + Attributes: datadogV2.WebhooksOAuth2ClientCredentialsCreateAttributes{ + AccessTokenUrl: "https://example.com/oauth/token", + Audience: *datadog.NewNullableString(datadog.PtrString("https://api.example.com")), + ClientId: "my-client-id", + ClientSecret: "my-client-secret", + Name: "my-oauth2-auth", + Scope: *datadog.NewNullableString(datadog.PtrString("read:webhooks write:webhooks")), + }, + Type: datadogV2.WEBHOOKSOAUTH2CLIENTCREDENTIALSTYPE_WEBHOOKS_AUTH_METHOD_OAUTH2_CLIENT_CREDENTIALS, + }, + } + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + api := datadogV2.NewWebhooksIntegrationApi(apiClient) + resp, r, err := api.CreateOAuth2ClientCredentials(ctx, body) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `WebhooksIntegrationApi.CreateOAuth2ClientCredentials`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `WebhooksIntegrationApi.CreateOAuth2ClientCredentials`:\n%s\n", responseContent) +} diff --git a/examples/v2/webhooks-integration/DeleteOAuth2ClientCredentials.go b/examples/v2/webhooks-integration/DeleteOAuth2ClientCredentials.go new file mode 100644 index 00000000000..9caeebf6a9a --- /dev/null +++ b/examples/v2/webhooks-integration/DeleteOAuth2ClientCredentials.go @@ -0,0 +1,25 @@ +// Delete an OAuth2 client credentials auth method returns "OK" response + +package main + +import ( + "context" + "fmt" + "os" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" + "github.com/DataDog/datadog-api-client-go/v2/api/datadogV2" +) + +func main() { + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + api := datadogV2.NewWebhooksIntegrationApi(apiClient) + r, err := api.DeleteOAuth2ClientCredentials(ctx, "auth_method_id") + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `WebhooksIntegrationApi.DeleteOAuth2ClientCredentials`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } +} diff --git a/examples/v2/webhooks-integration/GetAllAuthMethods.go b/examples/v2/webhooks-integration/GetAllAuthMethods.go new file mode 100644 index 00000000000..66ec81e49a1 --- /dev/null +++ b/examples/v2/webhooks-integration/GetAllAuthMethods.go @@ -0,0 +1,29 @@ +// Get all auth methods returns "OK" response + +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" + "github.com/DataDog/datadog-api-client-go/v2/api/datadogV2" +) + +func main() { + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + api := datadogV2.NewWebhooksIntegrationApi(apiClient) + resp, r, err := api.GetAllAuthMethods(ctx, *datadogV2.NewGetAllAuthMethodsOptionalParameters()) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `WebhooksIntegrationApi.GetAllAuthMethods`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `WebhooksIntegrationApi.GetAllAuthMethods`:\n%s\n", responseContent) +} diff --git a/examples/v2/webhooks-integration/GetOAuth2ClientCredentials.go b/examples/v2/webhooks-integration/GetOAuth2ClientCredentials.go new file mode 100644 index 00000000000..f66841fc41d --- /dev/null +++ b/examples/v2/webhooks-integration/GetOAuth2ClientCredentials.go @@ -0,0 +1,29 @@ +// Get an OAuth2 client credentials auth method returns "OK" response + +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" + "github.com/DataDog/datadog-api-client-go/v2/api/datadogV2" +) + +func main() { + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + api := datadogV2.NewWebhooksIntegrationApi(apiClient) + resp, r, err := api.GetOAuth2ClientCredentials(ctx, "auth_method_id") + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `WebhooksIntegrationApi.GetOAuth2ClientCredentials`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `WebhooksIntegrationApi.GetOAuth2ClientCredentials`:\n%s\n", responseContent) +} diff --git a/examples/v2/webhooks-integration/UpdateOAuth2ClientCredentials.go b/examples/v2/webhooks-integration/UpdateOAuth2ClientCredentials.go new file mode 100644 index 00000000000..c3053b0c926 --- /dev/null +++ b/examples/v2/webhooks-integration/UpdateOAuth2ClientCredentials.go @@ -0,0 +1,42 @@ +// Update an OAuth2 client credentials auth method returns "OK" response + +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" + "github.com/DataDog/datadog-api-client-go/v2/api/datadogV2" +) + +func main() { + body := datadogV2.WebhooksOAuth2ClientCredentialsUpdateRequest{ + Data: datadogV2.WebhooksOAuth2ClientCredentialsUpdateData{ + Attributes: datadogV2.WebhooksOAuth2ClientCredentialsUpdateAttributes{ + AccessTokenUrl: datadog.PtrString("https://example.com/oauth/token"), + Audience: *datadog.NewNullableString(datadog.PtrString("https://api.example.com")), + ClientId: datadog.PtrString("my-client-id"), + ClientSecret: datadog.PtrString("my-client-secret"), + Name: datadog.PtrString("my-oauth2-auth"), + Scope: *datadog.NewNullableString(datadog.PtrString("read:webhooks write:webhooks")), + }, + Type: datadogV2.WEBHOOKSOAUTH2CLIENTCREDENTIALSTYPE_WEBHOOKS_AUTH_METHOD_OAUTH2_CLIENT_CREDENTIALS, + }, + } + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + api := datadogV2.NewWebhooksIntegrationApi(apiClient) + resp, r, err := api.UpdateOAuth2ClientCredentials(ctx, "auth_method_id", body) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `WebhooksIntegrationApi.UpdateOAuth2ClientCredentials`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `WebhooksIntegrationApi.UpdateOAuth2ClientCredentials`:\n%s\n", responseContent) +} diff --git a/tests/scenarios/api_mappings.go b/tests/scenarios/api_mappings.go index b672b467579..f3912505450 100644 --- a/tests/scenarios/api_mappings.go +++ b/tests/scenarios/api_mappings.go @@ -104,6 +104,7 @@ var apiMappings = map[string]map[string]reflect.Value{ "OpsgenieIntegrationApi": reflect.ValueOf(datadogV2.NewOpsgenieIntegrationApi), "ServiceNowIntegrationApi": reflect.ValueOf(datadogV2.NewServiceNowIntegrationApi), "StatuspageIntegrationApi": reflect.ValueOf(datadogV2.NewStatuspageIntegrationApi), + "WebhooksIntegrationApi": reflect.ValueOf(datadogV2.NewWebhooksIntegrationApi), "IntegrationsApi": reflect.ValueOf(datadogV2.NewIntegrationsApi), "CloudflareIntegrationApi": reflect.ValueOf(datadogV2.NewCloudflareIntegrationApi), "ConfluentCloudApi": reflect.ValueOf(datadogV2.NewConfluentCloudApi), diff --git a/tests/scenarios/features/v2/given.json b/tests/scenarios/features/v2/given.json index 3f42086a160..63f710c0e91 100644 --- a/tests/scenarios/features/v2/given.json +++ b/tests/scenarios/features/v2/given.json @@ -722,6 +722,18 @@ "tag": "Statuspage Integration", "operationId": "CreateStatuspageUrlSetting" }, + { + "parameters": [ + { + "name": "body", + "value": "{\n \"data\": {\n \"attributes\": {\n \"name\": \"{{ unique }}\",\n \"access_token_url\": \"https://example.com/oauth/token\",\n \"client_id\": \"my-client-id\",\n \"client_secret\": \"my-client-secret\"\n },\n \"type\": \"webhooks-auth-method-oauth2-client-credentials\"\n }\n}" + } + ], + "step": "there is a valid \"webhooks_oauth2_client_credentials\" in the system", + "key": "webhooks_oauth2_client_credentials", + "tag": "Webhooks Integration", + "operationId": "CreateOAuth2ClientCredentials" + }, { "parameters": [ { diff --git a/tests/scenarios/features/v2/undo.json b/tests/scenarios/features/v2/undo.json index ba8ce78c4ea..3e68f592842 100644 --- a/tests/scenarios/features/v2/undo.json +++ b/tests/scenarios/features/v2/undo.json @@ -3641,6 +3641,43 @@ "type": "idempotent" } }, + "GetAllAuthMethods": { + "tag": "Webhooks Integration", + "undo": { + "type": "safe" + } + }, + "CreateOAuth2ClientCredentials": { + "tag": "Webhooks Integration", + "undo": { + "operationId": "DeleteOAuth2ClientCredentials", + "parameters": [ + { + "name": "auth_method_id", + "source": "data.id" + } + ], + "type": "unsafe" + } + }, + "DeleteOAuth2ClientCredentials": { + "tag": "Webhooks Integration", + "undo": { + "type": "idempotent" + } + }, + "GetOAuth2ClientCredentials": { + "tag": "Webhooks Integration", + "undo": { + "type": "safe" + } + }, + "UpdateOAuth2ClientCredentials": { + "tag": "Webhooks Integration", + "undo": { + "type": "idempotent" + } + }, "ListIntegrations": { "tag": "Integrations", "undo": { diff --git a/tests/scenarios/features/v2/webhooks_integration.feature b/tests/scenarios/features/v2/webhooks_integration.feature new file mode 100644 index 00000000000..c97a2d40375 --- /dev/null +++ b/tests/scenarios/features/v2/webhooks_integration.feature @@ -0,0 +1,97 @@ +@endpoint(webhooks-integration) @endpoint(webhooks-integration-v2) +Feature: Webhooks Integration + Configure your [Datadog Webhooks + integration](https://docs.datadoghq.com/integrations/webhooks/) directly + through the Datadog API. + + Background: + Given a valid "apiKeyAuth" key in the system + And a valid "appKeyAuth" key in the system + And an instance of "WebhooksIntegration" API + + @generated @skip @team:Datadog/collaboration-integrations + Scenario: Create an OAuth2 client credentials auth method returns "Bad Request" response + Given new "CreateOAuth2ClientCredentials" request + And body with value {"data": {"attributes": {"access_token_url": "https://example.com/oauth/token", "audience": "https://api.example.com", "client_id": "my-client-id", "client_secret": "my-client-secret", "name": "my-oauth2-auth", "scope": "read:webhooks write:webhooks"}, "type": "webhooks-auth-method-oauth2-client-credentials"}} + When the request is sent + Then the response status is 400 Bad Request + + @generated @skip @team:Datadog/collaboration-integrations + Scenario: Create an OAuth2 client credentials auth method returns "CREATED" response + Given new "CreateOAuth2ClientCredentials" request + And body with value {"data": {"attributes": {"access_token_url": "https://example.com/oauth/token", "audience": "https://api.example.com", "client_id": "my-client-id", "client_secret": "my-client-secret", "name": "my-oauth2-auth", "scope": "read:webhooks write:webhooks"}, "type": "webhooks-auth-method-oauth2-client-credentials"}} + When the request is sent + Then the response status is 201 CREATED + + @generated @skip @team:Datadog/collaboration-integrations + Scenario: Create an OAuth2 client credentials auth method returns "Conflict" response + Given new "CreateOAuth2ClientCredentials" request + And body with value {"data": {"attributes": {"access_token_url": "https://example.com/oauth/token", "audience": "https://api.example.com", "client_id": "my-client-id", "client_secret": "my-client-secret", "name": "my-oauth2-auth", "scope": "read:webhooks write:webhooks"}, "type": "webhooks-auth-method-oauth2-client-credentials"}} + When the request is sent + Then the response status is 409 Conflict + + @generated @skip @team:Datadog/collaboration-integrations + Scenario: Delete an OAuth2 client credentials auth method returns "Not Found" response + Given new "DeleteOAuth2ClientCredentials" request + And request contains "auth_method_id" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 404 Not Found + + @generated @skip @team:Datadog/collaboration-integrations + Scenario: Delete an OAuth2 client credentials auth method returns "OK" response + Given new "DeleteOAuth2ClientCredentials" request + And request contains "auth_method_id" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 204 OK + + @generated @skip @team:Datadog/collaboration-integrations + Scenario: Get all auth methods returns "OK" response + Given new "GetAllAuthMethods" request + When the request is sent + Then the response status is 200 OK + + @generated @skip @team:Datadog/collaboration-integrations + Scenario: Get an OAuth2 client credentials auth method returns "Not Found" response + Given new "GetOAuth2ClientCredentials" request + And request contains "auth_method_id" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 404 Not Found + + @generated @skip @team:Datadog/collaboration-integrations + Scenario: Get an OAuth2 client credentials auth method returns "OK" response + Given new "GetOAuth2ClientCredentials" request + And request contains "auth_method_id" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 200 OK + + @generated @skip @team:Datadog/collaboration-integrations + Scenario: Update an OAuth2 client credentials auth method returns "Bad Request" response + Given new "UpdateOAuth2ClientCredentials" request + And request contains "auth_method_id" parameter from "REPLACE.ME" + And body with value {"data": {"attributes": {"access_token_url": "https://example.com/oauth/token", "audience": "https://api.example.com", "client_id": "my-client-id", "client_secret": "my-client-secret", "name": "my-oauth2-auth", "scope": "read:webhooks write:webhooks"}, "type": "webhooks-auth-method-oauth2-client-credentials"}} + When the request is sent + Then the response status is 400 Bad Request + + @generated @skip @team:Datadog/collaboration-integrations + Scenario: Update an OAuth2 client credentials auth method returns "Conflict" response + Given new "UpdateOAuth2ClientCredentials" request + And request contains "auth_method_id" parameter from "REPLACE.ME" + And body with value {"data": {"attributes": {"access_token_url": "https://example.com/oauth/token", "audience": "https://api.example.com", "client_id": "my-client-id", "client_secret": "my-client-secret", "name": "my-oauth2-auth", "scope": "read:webhooks write:webhooks"}, "type": "webhooks-auth-method-oauth2-client-credentials"}} + When the request is sent + Then the response status is 409 Conflict + + @generated @skip @team:Datadog/collaboration-integrations + Scenario: Update an OAuth2 client credentials auth method returns "Not Found" response + Given new "UpdateOAuth2ClientCredentials" request + And request contains "auth_method_id" parameter from "REPLACE.ME" + And body with value {"data": {"attributes": {"access_token_url": "https://example.com/oauth/token", "audience": "https://api.example.com", "client_id": "my-client-id", "client_secret": "my-client-secret", "name": "my-oauth2-auth", "scope": "read:webhooks write:webhooks"}, "type": "webhooks-auth-method-oauth2-client-credentials"}} + When the request is sent + Then the response status is 404 Not Found + + @generated @skip @team:Datadog/collaboration-integrations + Scenario: Update an OAuth2 client credentials auth method returns "OK" response + Given new "UpdateOAuth2ClientCredentials" request + And request contains "auth_method_id" parameter from "REPLACE.ME" + And body with value {"data": {"attributes": {"access_token_url": "https://example.com/oauth/token", "audience": "https://api.example.com", "client_id": "my-client-id", "client_secret": "my-client-secret", "name": "my-oauth2-auth", "scope": "read:webhooks write:webhooks"}, "type": "webhooks-auth-method-oauth2-client-credentials"}} + When the request is sent + Then the response status is 200 OK