Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OAuth support for Synthetics tests #1764

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .apigentools-info
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"spec_versions": {
"v1": {
"apigentools_version": "1.6.4",
"regenerated": "2022-11-22 09:27:46.825033",
"spec_repo_commit": "b67ecba8"
"regenerated": "2022-11-22 13:49:25.462163",
"spec_repo_commit": "dad9f2c8"
},
"v2": {
"apigentools_version": "1.6.4",
"regenerated": "2022-11-22 09:27:46.840251",
"spec_repo_commit": "b67ecba8"
"regenerated": "2022-11-22 13:49:25.474063",
"spec_repo_commit": "dad9f2c8"
}
}
}
111 changes: 111 additions & 0 deletions .generator/schemas/v1/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11523,6 +11523,8 @@ components:
- $ref: '#/components/schemas/SyntheticsBasicAuthSigv4'
- $ref: '#/components/schemas/SyntheticsBasicAuthNTLM'
- $ref: '#/components/schemas/SyntheticsBasicAuthDigest'
- $ref: '#/components/schemas/SyntheticsBasicAuthOauthClient'
- $ref: '#/components/schemas/SyntheticsBasicAuthOauthROP'
type: object
SyntheticsBasicAuthDigest:
description: Object to handle digest authentication when performing the test.
Expand Down Expand Up @@ -11586,6 +11588,115 @@ components:
type: string
x-enum-varnames:
- NTLM
SyntheticsBasicAuthOauthClient:
description: Object to handle `oauth client` authentication when performing
the test.
properties:
accessTokenUrl:
description: Access token URL to use when performing the authentication.
example: https://example.com
type: string
audience:
description: Audience to use when performing the authentication.
example: audience
type: string
clientId:
description: Client ID to use when performing the authentication.
example: oauth-username
type: string
clientSecret:
description: Client secret to use when performing the authentication.
example: oauth-password
type: string
resource:
description: Resource to use when performing the authentication.
example: resource
type: string
scope:
description: Scope to use when performing the authentication.
example: scope
type: string
tokenApiAuthentication:
$ref: '#/components/schemas/SyntheticsBasicAuthOauthTokenApiAuthentication'
type:
$ref: '#/components/schemas/SyntheticsBasicAuthOauthClientType'
required:
- accessTokenUrl
- tokenApiAuthentication
- clientId
- clientSecret
type: object
SyntheticsBasicAuthOauthClientType:
default: oauth-client
description: The type of basic authentication to use when performing the test.
enum:
- oauth-client
example: oauth-client
type: string
x-enum-varnames:
- OAUTH_CLIENT
SyntheticsBasicAuthOauthROP:
description: Object to handle `oauth rop` authentication when performing the
test.
properties:
accessTokenUrl:
description: Access token URL to use when performing the authentication.
example: https://example.com
type: string
audience:
description: Audience to use when performing the authentication.
example: audience
type: string
clientId:
description: Client ID to use when performing the authentication.
example: client-id
type: string
clientSecret:
description: Client secret to use when performing the authentication.
example: client-secret
type: string
password:
description: Password to use when performing the authentication.
example: password
type: string
resource:
description: Resource to use when performing the authentication.
example: resource
type: string
scope:
description: Scope to use when performing the authentication.
example: scope
type: string
type:
$ref: '#/components/schemas/SyntheticsBasicAuthOauthROPType'
username:
description: Username to use when performing the authentication.
example: username
type: string
required:
- accessTokenUrl
- password
- username
type: object
SyntheticsBasicAuthOauthROPType:
default: oauth-rop
description: The type of basic authentication to use when performing the test.
enum:
- oauth-rop
example: oauth-rop
type: string
x-enum-varnames:
- OAUTH_ROP
SyntheticsBasicAuthOauthTokenApiAuthentication:
description: Type of token to use when performing the authentication.
enum:
- header
- body
example: header
type: string
x-enum-varnames:
- HEADER
- BODY
SyntheticsBasicAuthSigv4:
description: Object to handle `SIGV4` authentication when performing the test.
properties:
Expand Down
72 changes: 68 additions & 4 deletions api/datadogV1/model_synthetics_basic_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ import (

// SyntheticsBasicAuth - Object to handle basic authentication when performing the test.
type SyntheticsBasicAuth struct {
SyntheticsBasicAuthWeb *SyntheticsBasicAuthWeb
SyntheticsBasicAuthSigv4 *SyntheticsBasicAuthSigv4
SyntheticsBasicAuthNTLM *SyntheticsBasicAuthNTLM
SyntheticsBasicAuthDigest *SyntheticsBasicAuthDigest
SyntheticsBasicAuthWeb *SyntheticsBasicAuthWeb
SyntheticsBasicAuthSigv4 *SyntheticsBasicAuthSigv4
SyntheticsBasicAuthNTLM *SyntheticsBasicAuthNTLM
SyntheticsBasicAuthDigest *SyntheticsBasicAuthDigest
SyntheticsBasicAuthOauthClient *SyntheticsBasicAuthOauthClient
SyntheticsBasicAuthOauthROP *SyntheticsBasicAuthOauthROP

// UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct
UnparsedObject interface{}
Expand All @@ -39,6 +41,16 @@ func SyntheticsBasicAuthDigestAsSyntheticsBasicAuth(v *SyntheticsBasicAuthDigest
return SyntheticsBasicAuth{SyntheticsBasicAuthDigest: v}
}

// SyntheticsBasicAuthOauthClientAsSyntheticsBasicAuth is a convenience function that returns SyntheticsBasicAuthOauthClient wrapped in SyntheticsBasicAuth.
func SyntheticsBasicAuthOauthClientAsSyntheticsBasicAuth(v *SyntheticsBasicAuthOauthClient) SyntheticsBasicAuth {
return SyntheticsBasicAuth{SyntheticsBasicAuthOauthClient: v}
}

// SyntheticsBasicAuthOauthROPAsSyntheticsBasicAuth is a convenience function that returns SyntheticsBasicAuthOauthROP wrapped in SyntheticsBasicAuth.
func SyntheticsBasicAuthOauthROPAsSyntheticsBasicAuth(v *SyntheticsBasicAuthOauthROP) SyntheticsBasicAuth {
return SyntheticsBasicAuth{SyntheticsBasicAuthOauthROP: v}
}

// UnmarshalJSON turns data into one of the pointers in the struct.
func (obj *SyntheticsBasicAuth) UnmarshalJSON(data []byte) error {
var err error
Expand Down Expand Up @@ -111,12 +123,48 @@ func (obj *SyntheticsBasicAuth) UnmarshalJSON(data []byte) error {
obj.SyntheticsBasicAuthDigest = nil
}

// try to unmarshal data into SyntheticsBasicAuthOauthClient
err = json.Unmarshal(data, &obj.SyntheticsBasicAuthOauthClient)
if err == nil {
if obj.SyntheticsBasicAuthOauthClient != nil && obj.SyntheticsBasicAuthOauthClient.UnparsedObject == nil {
jsonSyntheticsBasicAuthOauthClient, _ := json.Marshal(obj.SyntheticsBasicAuthOauthClient)
if string(jsonSyntheticsBasicAuthOauthClient) == "{}" { // empty struct
obj.SyntheticsBasicAuthOauthClient = nil
} else {
match++
}
} else {
obj.SyntheticsBasicAuthOauthClient = nil
}
} else {
obj.SyntheticsBasicAuthOauthClient = nil
}

// try to unmarshal data into SyntheticsBasicAuthOauthROP
err = json.Unmarshal(data, &obj.SyntheticsBasicAuthOauthROP)
if err == nil {
if obj.SyntheticsBasicAuthOauthROP != nil && obj.SyntheticsBasicAuthOauthROP.UnparsedObject == nil {
jsonSyntheticsBasicAuthOauthROP, _ := json.Marshal(obj.SyntheticsBasicAuthOauthROP)
if string(jsonSyntheticsBasicAuthOauthROP) == "{}" { // empty struct
obj.SyntheticsBasicAuthOauthROP = nil
} else {
match++
}
} else {
obj.SyntheticsBasicAuthOauthROP = nil
}
} else {
obj.SyntheticsBasicAuthOauthROP = nil
}

if match != 1 { // more than 1 match
// reset to nil
obj.SyntheticsBasicAuthWeb = nil
obj.SyntheticsBasicAuthSigv4 = nil
obj.SyntheticsBasicAuthNTLM = nil
obj.SyntheticsBasicAuthDigest = nil
obj.SyntheticsBasicAuthOauthClient = nil
obj.SyntheticsBasicAuthOauthROP = nil
return json.Unmarshal(data, &obj.UnparsedObject)
}
return nil // exactly one match
Expand All @@ -140,6 +188,14 @@ func (obj SyntheticsBasicAuth) MarshalJSON() ([]byte, error) {
return json.Marshal(&obj.SyntheticsBasicAuthDigest)
}

if obj.SyntheticsBasicAuthOauthClient != nil {
return json.Marshal(&obj.SyntheticsBasicAuthOauthClient)
}

if obj.SyntheticsBasicAuthOauthROP != nil {
return json.Marshal(&obj.SyntheticsBasicAuthOauthROP)
}

if obj.UnparsedObject != nil {
return json.Marshal(obj.UnparsedObject)
}
Expand All @@ -164,6 +220,14 @@ func (obj *SyntheticsBasicAuth) GetActualInstance() interface{} {
return obj.SyntheticsBasicAuthDigest
}

if obj.SyntheticsBasicAuthOauthClient != nil {
return obj.SyntheticsBasicAuthOauthClient
}

if obj.SyntheticsBasicAuthOauthROP != nil {
return obj.SyntheticsBasicAuthOauthROP
}

// all schemas are nil
return nil
}
Expand Down
Loading