|
| 1 | +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. |
| 2 | +// This product includes software developed at Datadog (https://www.datadoghq.com/). |
| 3 | +// Copyright 2019-Present Datadog, Inc. |
| 4 | + |
| 5 | +package datadogV2 |
| 6 | + |
| 7 | +import ( |
| 8 | + "fmt" |
| 9 | + |
| 10 | + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" |
| 11 | +) |
| 12 | + |
| 13 | +// ObservabilityPipelineOcsfMappingCustom Custom OCSF mapping configuration for transforming logs. |
| 14 | +type ObservabilityPipelineOcsfMappingCustom struct { |
| 15 | + // A list of field mapping rules for transforming log fields to OCSF schema fields. |
| 16 | + Mapping []ObservabilityPipelineOcsfMappingCustomFieldMapping `json:"mapping"` |
| 17 | + // Metadata for the custom OCSF mapping. |
| 18 | + Metadata ObservabilityPipelineOcsfMappingCustomMetadata `json:"metadata"` |
| 19 | + // The version of the custom mapping configuration. |
| 20 | + Version int64 `json:"version"` |
| 21 | + // UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct |
| 22 | + UnparsedObject map[string]interface{} `json:"-"` |
| 23 | + AdditionalProperties map[string]interface{} `json:"-"` |
| 24 | +} |
| 25 | + |
| 26 | +// NewObservabilityPipelineOcsfMappingCustom instantiates a new ObservabilityPipelineOcsfMappingCustom object. |
| 27 | +// This constructor will assign default values to properties that have it defined, |
| 28 | +// and makes sure properties required by API are set, but the set of arguments |
| 29 | +// will change when the set of required properties is changed. |
| 30 | +func NewObservabilityPipelineOcsfMappingCustom(mapping []ObservabilityPipelineOcsfMappingCustomFieldMapping, metadata ObservabilityPipelineOcsfMappingCustomMetadata, version int64) *ObservabilityPipelineOcsfMappingCustom { |
| 31 | + this := ObservabilityPipelineOcsfMappingCustom{} |
| 32 | + this.Mapping = mapping |
| 33 | + this.Metadata = metadata |
| 34 | + this.Version = version |
| 35 | + return &this |
| 36 | +} |
| 37 | + |
| 38 | +// NewObservabilityPipelineOcsfMappingCustomWithDefaults instantiates a new ObservabilityPipelineOcsfMappingCustom object. |
| 39 | +// This constructor will only assign default values to properties that have it defined, |
| 40 | +// but it doesn't guarantee that properties required by API are set. |
| 41 | +func NewObservabilityPipelineOcsfMappingCustomWithDefaults() *ObservabilityPipelineOcsfMappingCustom { |
| 42 | + this := ObservabilityPipelineOcsfMappingCustom{} |
| 43 | + return &this |
| 44 | +} |
| 45 | + |
| 46 | +// GetMapping returns the Mapping field value. |
| 47 | +func (o *ObservabilityPipelineOcsfMappingCustom) GetMapping() []ObservabilityPipelineOcsfMappingCustomFieldMapping { |
| 48 | + if o == nil { |
| 49 | + var ret []ObservabilityPipelineOcsfMappingCustomFieldMapping |
| 50 | + return ret |
| 51 | + } |
| 52 | + return o.Mapping |
| 53 | +} |
| 54 | + |
| 55 | +// GetMappingOk returns a tuple with the Mapping field value |
| 56 | +// and a boolean to check if the value has been set. |
| 57 | +func (o *ObservabilityPipelineOcsfMappingCustom) GetMappingOk() (*[]ObservabilityPipelineOcsfMappingCustomFieldMapping, bool) { |
| 58 | + if o == nil { |
| 59 | + return nil, false |
| 60 | + } |
| 61 | + return &o.Mapping, true |
| 62 | +} |
| 63 | + |
| 64 | +// SetMapping sets field value. |
| 65 | +func (o *ObservabilityPipelineOcsfMappingCustom) SetMapping(v []ObservabilityPipelineOcsfMappingCustomFieldMapping) { |
| 66 | + o.Mapping = v |
| 67 | +} |
| 68 | + |
| 69 | +// GetMetadata returns the Metadata field value. |
| 70 | +func (o *ObservabilityPipelineOcsfMappingCustom) GetMetadata() ObservabilityPipelineOcsfMappingCustomMetadata { |
| 71 | + if o == nil { |
| 72 | + var ret ObservabilityPipelineOcsfMappingCustomMetadata |
| 73 | + return ret |
| 74 | + } |
| 75 | + return o.Metadata |
| 76 | +} |
| 77 | + |
| 78 | +// GetMetadataOk returns a tuple with the Metadata field value |
| 79 | +// and a boolean to check if the value has been set. |
| 80 | +func (o *ObservabilityPipelineOcsfMappingCustom) GetMetadataOk() (*ObservabilityPipelineOcsfMappingCustomMetadata, bool) { |
| 81 | + if o == nil { |
| 82 | + return nil, false |
| 83 | + } |
| 84 | + return &o.Metadata, true |
| 85 | +} |
| 86 | + |
| 87 | +// SetMetadata sets field value. |
| 88 | +func (o *ObservabilityPipelineOcsfMappingCustom) SetMetadata(v ObservabilityPipelineOcsfMappingCustomMetadata) { |
| 89 | + o.Metadata = v |
| 90 | +} |
| 91 | + |
| 92 | +// GetVersion returns the Version field value. |
| 93 | +func (o *ObservabilityPipelineOcsfMappingCustom) GetVersion() int64 { |
| 94 | + if o == nil { |
| 95 | + var ret int64 |
| 96 | + return ret |
| 97 | + } |
| 98 | + return o.Version |
| 99 | +} |
| 100 | + |
| 101 | +// GetVersionOk returns a tuple with the Version field value |
| 102 | +// and a boolean to check if the value has been set. |
| 103 | +func (o *ObservabilityPipelineOcsfMappingCustom) GetVersionOk() (*int64, bool) { |
| 104 | + if o == nil { |
| 105 | + return nil, false |
| 106 | + } |
| 107 | + return &o.Version, true |
| 108 | +} |
| 109 | + |
| 110 | +// SetVersion sets field value. |
| 111 | +func (o *ObservabilityPipelineOcsfMappingCustom) SetVersion(v int64) { |
| 112 | + o.Version = v |
| 113 | +} |
| 114 | + |
| 115 | +// MarshalJSON serializes the struct using spec logic. |
| 116 | +func (o ObservabilityPipelineOcsfMappingCustom) MarshalJSON() ([]byte, error) { |
| 117 | + toSerialize := map[string]interface{}{} |
| 118 | + if o.UnparsedObject != nil { |
| 119 | + return datadog.Marshal(o.UnparsedObject) |
| 120 | + } |
| 121 | + toSerialize["mapping"] = o.Mapping |
| 122 | + toSerialize["metadata"] = o.Metadata |
| 123 | + toSerialize["version"] = o.Version |
| 124 | + |
| 125 | + for key, value := range o.AdditionalProperties { |
| 126 | + toSerialize[key] = value |
| 127 | + } |
| 128 | + return datadog.Marshal(toSerialize) |
| 129 | +} |
| 130 | + |
| 131 | +// UnmarshalJSON deserializes the given payload. |
| 132 | +func (o *ObservabilityPipelineOcsfMappingCustom) UnmarshalJSON(bytes []byte) (err error) { |
| 133 | + all := struct { |
| 134 | + Mapping *[]ObservabilityPipelineOcsfMappingCustomFieldMapping `json:"mapping"` |
| 135 | + Metadata *ObservabilityPipelineOcsfMappingCustomMetadata `json:"metadata"` |
| 136 | + Version *int64 `json:"version"` |
| 137 | + }{} |
| 138 | + if err = datadog.Unmarshal(bytes, &all); err != nil { |
| 139 | + return datadog.Unmarshal(bytes, &o.UnparsedObject) |
| 140 | + } |
| 141 | + if all.Mapping == nil { |
| 142 | + return fmt.Errorf("required field mapping missing") |
| 143 | + } |
| 144 | + if all.Metadata == nil { |
| 145 | + return fmt.Errorf("required field metadata missing") |
| 146 | + } |
| 147 | + if all.Version == nil { |
| 148 | + return fmt.Errorf("required field version missing") |
| 149 | + } |
| 150 | + additionalProperties := make(map[string]interface{}) |
| 151 | + if err = datadog.Unmarshal(bytes, &additionalProperties); err == nil { |
| 152 | + datadog.DeleteKeys(additionalProperties, &[]string{"mapping", "metadata", "version"}) |
| 153 | + } else { |
| 154 | + return err |
| 155 | + } |
| 156 | + |
| 157 | + hasInvalidField := false |
| 158 | + o.Mapping = *all.Mapping |
| 159 | + if all.Metadata.UnparsedObject != nil && o.UnparsedObject == nil { |
| 160 | + hasInvalidField = true |
| 161 | + } |
| 162 | + o.Metadata = *all.Metadata |
| 163 | + o.Version = *all.Version |
| 164 | + |
| 165 | + if len(additionalProperties) > 0 { |
| 166 | + o.AdditionalProperties = additionalProperties |
| 167 | + } |
| 168 | + |
| 169 | + if hasInvalidField { |
| 170 | + return datadog.Unmarshal(bytes, &o.UnparsedObject) |
| 171 | + } |
| 172 | + |
| 173 | + return nil |
| 174 | +} |
0 commit comments