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 support for digest auth in synthetics tests #1622

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.2",
"regenerated": "2022-08-04 14:08:04.711882",
"spec_repo_commit": "43d0c8cf"
"regenerated": "2022-08-04 14:45:29.625822",
"spec_repo_commit": "27b7ba8d"
},
"v2": {
"apigentools_version": "1.6.2",
"regenerated": "2022-08-04 14:08:04.725381",
"spec_repo_commit": "43d0c8cf"
"regenerated": "2022-08-04 14:45:29.640704",
"spec_repo_commit": "27b7ba8d"
}
}
}
27 changes: 27 additions & 0 deletions .generator/schemas/v1/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10868,7 +10868,34 @@ components:
- $ref: '#/components/schemas/SyntheticsBasicAuthWeb'
- $ref: '#/components/schemas/SyntheticsBasicAuthSigv4'
- $ref: '#/components/schemas/SyntheticsBasicAuthNTLM'
- $ref: '#/components/schemas/SyntheticsBasicAuthDigest'
type: object
SyntheticsBasicAuthDigest:
description: Object to handle digest authentication when performing the test.
properties:
password:
description: Password to use for the digest authentication.
example: PaSSw0RD!
type: string
type:
$ref: '#/components/schemas/SyntheticsBasicAuthDigestType'
username:
description: Username to use for the digest authentication.
example: my_username
type: string
required:
- password
- username
type: object
SyntheticsBasicAuthDigestType:
default: digest
description: The type of basic authentication to use when performing the test.
enum:
- digest
example: digest
type: string
x-enum-varnames:
- DIGEST
SyntheticsBasicAuthNTLM:
description: Object to handle `NTLM` authentication when performing the test.
properties:
Expand Down
38 changes: 35 additions & 3 deletions api/v1/datadog/model_synthetics_basic_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import (

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

// UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct
UnparsedObject interface{}
Expand All @@ -33,6 +34,11 @@ func SyntheticsBasicAuthNTLMAsSyntheticsBasicAuth(v *SyntheticsBasicAuthNTLM) Sy
return SyntheticsBasicAuth{SyntheticsBasicAuthNTLM: v}
}

// SyntheticsBasicAuthDigestAsSyntheticsBasicAuth is a convenience function that returns SyntheticsBasicAuthDigest wrapped in SyntheticsBasicAuth.
func SyntheticsBasicAuthDigestAsSyntheticsBasicAuth(v *SyntheticsBasicAuthDigest) SyntheticsBasicAuth {
return SyntheticsBasicAuth{SyntheticsBasicAuthDigest: 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 @@ -88,11 +94,29 @@ func (obj *SyntheticsBasicAuth) UnmarshalJSON(data []byte) error {
obj.SyntheticsBasicAuthNTLM = nil
}

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

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

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

if obj.UnparsedObject != nil {
return json.Marshal(obj.UnparsedObject)
}
Expand All @@ -132,6 +160,10 @@ func (obj *SyntheticsBasicAuth) GetActualInstance() interface{} {
return obj.SyntheticsBasicAuthNTLM
}

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

// all schemas are nil
return nil
}
Expand Down
187 changes: 187 additions & 0 deletions api/v1/datadog/model_synthetics_basic_auth_digest.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
// 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 datadog

import (
"encoding/json"
"fmt"
)

// SyntheticsBasicAuthDigest Object to handle digest authentication when performing the test.
type SyntheticsBasicAuthDigest struct {
// Password to use for the digest authentication.
Password string `json:"password"`
// The type of basic authentication to use when performing the test.
Type *SyntheticsBasicAuthDigestType `json:"type,omitempty"`
// Username to use for the digest authentication.
Username string `json:"username"`
// 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{}
}

// NewSyntheticsBasicAuthDigest instantiates a new SyntheticsBasicAuthDigest 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 NewSyntheticsBasicAuthDigest(password string, username string) *SyntheticsBasicAuthDigest {
this := SyntheticsBasicAuthDigest{}
this.Password = password
var typeVar SyntheticsBasicAuthDigestType = SYNTHETICSBASICAUTHDIGESTTYPE_DIGEST
this.Type = &typeVar
this.Username = username
return &this
}

// NewSyntheticsBasicAuthDigestWithDefaults instantiates a new SyntheticsBasicAuthDigest 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 NewSyntheticsBasicAuthDigestWithDefaults() *SyntheticsBasicAuthDigest {
this := SyntheticsBasicAuthDigest{}
var typeVar SyntheticsBasicAuthDigestType = SYNTHETICSBASICAUTHDIGESTTYPE_DIGEST
this.Type = &typeVar
return &this
}

// GetPassword returns the Password field value.
func (o *SyntheticsBasicAuthDigest) GetPassword() string {
if o == nil {
var ret string
return ret
}
return o.Password
}

// GetPasswordOk returns a tuple with the Password field value
// and a boolean to check if the value has been set.
func (o *SyntheticsBasicAuthDigest) GetPasswordOk() (*string, bool) {
if o == nil {
return nil, false
}
return &o.Password, true
}

// SetPassword sets field value.
func (o *SyntheticsBasicAuthDigest) SetPassword(v string) {
o.Password = v
}

// GetType returns the Type field value if set, zero value otherwise.
func (o *SyntheticsBasicAuthDigest) GetType() SyntheticsBasicAuthDigestType {
if o == nil || o.Type == nil {
var ret SyntheticsBasicAuthDigestType
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 *SyntheticsBasicAuthDigest) GetTypeOk() (*SyntheticsBasicAuthDigestType, 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 *SyntheticsBasicAuthDigest) HasType() bool {
if o != nil && o.Type != nil {
return true
}

return false
}

// SetType gets a reference to the given SyntheticsBasicAuthDigestType and assigns it to the Type field.
func (o *SyntheticsBasicAuthDigest) SetType(v SyntheticsBasicAuthDigestType) {
o.Type = &v
}

// GetUsername returns the Username field value.
func (o *SyntheticsBasicAuthDigest) GetUsername() string {
if o == nil {
var ret string
return ret
}
return o.Username
}

// GetUsernameOk returns a tuple with the Username field value
// and a boolean to check if the value has been set.
func (o *SyntheticsBasicAuthDigest) GetUsernameOk() (*string, bool) {
if o == nil {
return nil, false
}
return &o.Username, true
}

// SetUsername sets field value.
func (o *SyntheticsBasicAuthDigest) SetUsername(v string) {
o.Username = v
}

// MarshalJSON serializes the struct using spec logic.
func (o SyntheticsBasicAuthDigest) MarshalJSON() ([]byte, error) {
toSerialize := map[string]interface{}{}
if o.UnparsedObject != nil {
return json.Marshal(o.UnparsedObject)
}
toSerialize["password"] = o.Password
if o.Type != nil {
toSerialize["type"] = o.Type
}
toSerialize["username"] = o.Username

for key, value := range o.AdditionalProperties {
toSerialize[key] = value
}
return json.Marshal(toSerialize)
}

// UnmarshalJSON deserializes the given payload.
func (o *SyntheticsBasicAuthDigest) UnmarshalJSON(bytes []byte) (err error) {
raw := map[string]interface{}{}
required := struct {
Password *string `json:"password"`
Username *string `json:"username"`
}{}
all := struct {
Password string `json:"password"`
Type *SyntheticsBasicAuthDigestType `json:"type,omitempty"`
Username string `json:"username"`
}{}
err = json.Unmarshal(bytes, &required)
if err != nil {
return err
}
if required.Password == nil {
return fmt.Errorf("Required field password missing")
}
if required.Username == nil {
return fmt.Errorf("Required field username missing")
}
err = json.Unmarshal(bytes, &all)
if err != nil {
err = json.Unmarshal(bytes, &raw)
if err != nil {
return err
}
o.UnparsedObject = raw
return nil
}
if v := all.Type; v != nil && !v.IsValid() {
err = json.Unmarshal(bytes, &raw)
if err != nil {
return err
}
o.UnparsedObject = raw
return nil
}
o.Password = all.Password
o.Type = all.Type
o.Username = all.Username
return nil
}
Loading