diff --git a/.generator/src/generator/formatter.py b/.generator/src/generator/formatter.py index 89afeabb47d..a9c4aeb21cf 100644 --- a/.generator/src/generator/formatter.py +++ b/.generator/src/generator/formatter.py @@ -153,7 +153,7 @@ def simple_type(schema, render_nullable=False, render_new=False): "date": "time.Time" if not nullable else f"{nullable_prefix}Time", "date-time": "time.Time" if not nullable else f"{nullable_prefix}Time", "email": "string" if not nullable else f"{nullable_prefix}String", - "binary": "*os.File", + "binary": "_io.Reader", "uuid": "uuid.UUID" if not nullable else f"{nullable_prefix}String", None: "string" if not nullable else f"{nullable_prefix}String", }[type_format] @@ -454,7 +454,7 @@ def format_uuid(x): return f'uuid.MustParse("{x}")' def open_file(x): - return f"func() *os.File {{ fp, _ := os.Open({format_string(x)}); return fp }}()" + return f"func() io.Reader {{ fp, _ := os.Open({format_string(x)}); return fp }}()" formatter = { "int32": str, diff --git a/.generator/src/generator/templates/api.j2 b/.generator/src/generator/templates/api.j2 index feb59877dbd..7241db90e12 100644 --- a/.generator/src/generator/templates/api.j2 +++ b/.generator/src/generator/templates/api.j2 @@ -221,8 +221,6 @@ localVarQueryParams.Add("{{ parameter.name }}", {{ common_package_name }}.Parame if localVarFile != nil { fbs, _ := _io.ReadAll(localVarFile) formFile.FileBytes = fbs - formFile.FileName = localVarFile.Name() - localVarFile.Close() } {%- endif %} diff --git a/api/datadogV1/api_organizations.go b/api/datadogV1/api_organizations.go index 1c893596dad..9fd4ca25d46 100644 --- a/api/datadogV1/api_organizations.go +++ b/api/datadogV1/api_organizations.go @@ -9,7 +9,6 @@ import ( _io "io" _nethttp "net/http" _neturl "net/url" - "os" "strings" "github.com/DataDog/datadog-api-client-go/v2/api/datadog" @@ -393,7 +392,7 @@ func (a *OrganizationsApi) UpdateOrg(ctx _context.Context, publicId string, body // * **Multipart Form-Data**: Post the IdP metadata file using a form post. // // * **XML Body:** Post the IdP metadata file as the body of the request. -func (a *OrganizationsApi) UploadIdPForOrg(ctx _context.Context, publicId string, idpFile *os.File) (IdpResponse, *_nethttp.Response, error) { +func (a *OrganizationsApi) UploadIdPForOrg(ctx _context.Context, publicId string, idpFile _io.Reader) (IdpResponse, *_nethttp.Response, error) { var ( localVarHTTPMethod = _nethttp.MethodPost localVarPostBody interface{} @@ -420,8 +419,6 @@ func (a *OrganizationsApi) UploadIdPForOrg(ctx _context.Context, publicId string if localVarFile != nil { fbs, _ := _io.ReadAll(localVarFile) formFile.FileBytes = fbs - formFile.FileName = localVarFile.Name() - localVarFile.Close() } datadog.SetAuthKeys( ctx, diff --git a/api/datadogV1/model_idp_form_data.go b/api/datadogV1/model_idp_form_data.go index 0127fce353f..3bac1d922f2 100644 --- a/api/datadogV1/model_idp_form_data.go +++ b/api/datadogV1/model_idp_form_data.go @@ -6,7 +6,7 @@ package datadogV1 import ( "fmt" - "os" + _io "io" "github.com/DataDog/datadog-api-client-go/v2/api/datadog" ) @@ -14,7 +14,7 @@ import ( // IdpFormData Object describing the IdP configuration. type IdpFormData struct { // The path to the XML metadata file you wish to upload. - IdpFile *os.File `json:"idp_file"` + IdpFile _io.Reader `json:"idp_file"` // 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{} @@ -24,7 +24,7 @@ type IdpFormData struct { // 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 NewIdpFormData(idpFile *os.File) *IdpFormData { +func NewIdpFormData(idpFile _io.Reader) *IdpFormData { this := IdpFormData{} this.IdpFile = idpFile return &this @@ -39,9 +39,9 @@ func NewIdpFormDataWithDefaults() *IdpFormData { } // GetIdpFile returns the IdpFile field value. -func (o *IdpFormData) GetIdpFile() *os.File { +func (o *IdpFormData) GetIdpFile() _io.Reader { if o == nil { - var ret *os.File + var ret _io.Reader return ret } return o.IdpFile @@ -49,7 +49,7 @@ func (o *IdpFormData) GetIdpFile() *os.File { // GetIdpFileOk returns a tuple with the IdpFile field value // and a boolean to check if the value has been set. -func (o *IdpFormData) GetIdpFileOk() (**os.File, bool) { +func (o *IdpFormData) GetIdpFileOk() (*_io.Reader, bool) { if o == nil { return nil, false } @@ -57,7 +57,7 @@ func (o *IdpFormData) GetIdpFileOk() (**os.File, bool) { } // SetIdpFile sets field value. -func (o *IdpFormData) SetIdpFile(v *os.File) { +func (o *IdpFormData) SetIdpFile(v _io.Reader) { o.IdpFile = v } @@ -78,7 +78,7 @@ func (o IdpFormData) MarshalJSON() ([]byte, error) { // UnmarshalJSON deserializes the given payload. func (o *IdpFormData) UnmarshalJSON(bytes []byte) (err error) { all := struct { - IdpFile **os.File `json:"idp_file"` + IdpFile *_io.Reader `json:"idp_file"` }{} if err = datadog.Unmarshal(bytes, &all); err != nil { return datadog.Unmarshal(bytes, &o.UnparsedObject) diff --git a/api/datadogV2/api_cloud_workload_security.go b/api/datadogV2/api_cloud_workload_security.go index c5273bd1463..366a40b153b 100644 --- a/api/datadogV2/api_cloud_workload_security.go +++ b/api/datadogV2/api_cloud_workload_security.go @@ -6,9 +6,9 @@ package datadogV2 import ( _context "context" + _io "io" _nethttp "net/http" _neturl "net/url" - "os" "strings" "github.com/DataDog/datadog-api-client-go/v2/api/datadog" @@ -155,11 +155,11 @@ func (a *CloudWorkloadSecurityApi) DeleteCloudWorkloadSecurityAgentRule(ctx _con // The download endpoint generates a Cloud Workload Security policy file from your currently active // Cloud Workload Security rules, and downloads them as a .policy file. This file can then be deployed to // your Agents to update the policy running in your environment. -func (a *CloudWorkloadSecurityApi) DownloadCloudWorkloadPolicyFile(ctx _context.Context) (*os.File, *_nethttp.Response, error) { +func (a *CloudWorkloadSecurityApi) DownloadCloudWorkloadPolicyFile(ctx _context.Context) (_io.Reader, *_nethttp.Response, error) { var ( localVarHTTPMethod = _nethttp.MethodGet localVarPostBody interface{} - localVarReturnValue *os.File + localVarReturnValue _io.Reader ) localBasePath, err := a.Client.Cfg.ServerURLWithContext(ctx, "v2.CloudWorkloadSecurityApi.DownloadCloudWorkloadPolicyFile") diff --git a/api/datadogV2/api_organizations.go b/api/datadogV2/api_organizations.go index b6fa405bdb4..8a2ff71376d 100644 --- a/api/datadogV2/api_organizations.go +++ b/api/datadogV2/api_organizations.go @@ -9,7 +9,6 @@ import ( _io "io" _nethttp "net/http" _neturl "net/url" - "os" "github.com/DataDog/datadog-api-client-go/v2/api/datadog" ) @@ -19,7 +18,7 @@ type OrganizationsApi datadog.Service // UploadIdPMetadataOptionalParameters holds optional parameters for UploadIdPMetadata. type UploadIdPMetadataOptionalParameters struct { - IdpFile **os.File + IdpFile *_io.Reader } // NewUploadIdPMetadataOptionalParameters creates an empty struct for parameters. @@ -29,7 +28,7 @@ func NewUploadIdPMetadataOptionalParameters() *UploadIdPMetadataOptionalParamete } // WithIdpFile sets the corresponding parameter name and returns the struct. -func (r *UploadIdPMetadataOptionalParameters) WithIdpFile(idpFile *os.File) *UploadIdPMetadataOptionalParameters { +func (r *UploadIdPMetadataOptionalParameters) WithIdpFile(idpFile _io.Reader) *UploadIdPMetadataOptionalParameters { r.IdpFile = &idpFile return r } @@ -67,15 +66,13 @@ func (a *OrganizationsApi) UploadIdPMetadata(ctx _context.Context, o ...UploadId formFile := datadog.FormFile{} formFile.FormFileName = "idp_file" - var localVarFile *os.File + var localVarFile _io.Reader if optionalParams.IdpFile != nil { localVarFile = *optionalParams.IdpFile } if localVarFile != nil { fbs, _ := _io.ReadAll(localVarFile) formFile.FileBytes = fbs - formFile.FileName = localVarFile.Name() - localVarFile.Close() } datadog.SetAuthKeys( ctx, diff --git a/api/datadogV2/model_id_p_metadata_form_data.go b/api/datadogV2/model_id_p_metadata_form_data.go index 187ae0403fc..a7ede889a10 100644 --- a/api/datadogV2/model_id_p_metadata_form_data.go +++ b/api/datadogV2/model_id_p_metadata_form_data.go @@ -5,7 +5,7 @@ package datadogV2 import ( - "os" + _io "io" "github.com/DataDog/datadog-api-client-go/v2/api/datadog" ) @@ -13,7 +13,7 @@ import ( // IdPMetadataFormData The form data submitted to upload IdP metadata type IdPMetadataFormData struct { // The IdP metadata XML file - IdpFile **os.File `json:"idp_file,omitempty"` + IdpFile *_io.Reader `json:"idp_file,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{} @@ -37,9 +37,9 @@ func NewIdPMetadataFormDataWithDefaults() *IdPMetadataFormData { } // GetIdpFile returns the IdpFile field value if set, zero value otherwise. -func (o *IdPMetadataFormData) GetIdpFile() *os.File { +func (o *IdPMetadataFormData) GetIdpFile() _io.Reader { if o == nil || o.IdpFile == nil { - var ret *os.File + var ret _io.Reader return ret } return *o.IdpFile @@ -47,7 +47,7 @@ func (o *IdPMetadataFormData) GetIdpFile() *os.File { // GetIdpFileOk returns a tuple with the IdpFile field value if set, nil otherwise // and a boolean to check if the value has been set. -func (o *IdPMetadataFormData) GetIdpFileOk() (**os.File, bool) { +func (o *IdPMetadataFormData) GetIdpFileOk() (*_io.Reader, bool) { if o == nil || o.IdpFile == nil { return nil, false } @@ -59,8 +59,8 @@ func (o *IdPMetadataFormData) HasIdpFile() bool { return o != nil && o.IdpFile != nil } -// SetIdpFile gets a reference to the given *os.File and assigns it to the IdpFile field. -func (o *IdPMetadataFormData) SetIdpFile(v *os.File) { +// SetIdpFile gets a reference to the given _io.Reader and assigns it to the IdpFile field. +func (o *IdPMetadataFormData) SetIdpFile(v _io.Reader) { o.IdpFile = &v } @@ -83,7 +83,7 @@ func (o IdPMetadataFormData) MarshalJSON() ([]byte, error) { // UnmarshalJSON deserializes the given payload. func (o *IdPMetadataFormData) UnmarshalJSON(bytes []byte) (err error) { all := struct { - IdpFile **os.File `json:"idp_file,omitempty"` + IdpFile *_io.Reader `json:"idp_file,omitempty"` }{} if err = datadog.Unmarshal(bytes, &all); err != nil { return datadog.Unmarshal(bytes, &o.UnparsedObject) diff --git a/examples/v1/organizations/UploadIdPForOrg.go b/examples/v1/organizations/UploadIdPForOrg.go index 34bbc4a4707..95f77332d98 100644 --- a/examples/v1/organizations/UploadIdPForOrg.go +++ b/examples/v1/organizations/UploadIdPForOrg.go @@ -6,6 +6,7 @@ import ( "context" "encoding/json" "fmt" + "io" "os" "github.com/DataDog/datadog-api-client-go/v2/api/datadog" @@ -17,7 +18,7 @@ func main() { configuration := datadog.NewConfiguration() apiClient := datadog.NewAPIClient(configuration) api := datadogV1.NewOrganizationsApi(apiClient) - resp, r, err := api.UploadIdPForOrg(ctx, "abc123", func() *os.File { fp, _ := os.Open("./idp_metadata.xml"); return fp }()) + resp, r, err := api.UploadIdPForOrg(ctx, "abc123", func() io.Reader { fp, _ := os.Open("./idp_metadata.xml"); return fp }()) if err != nil { fmt.Fprintf(os.Stderr, "Error when calling `OrganizationsApi.UploadIdPForOrg`: %v\n", err) diff --git a/examples/v2/organizations/UploadIdPMetadata.go b/examples/v2/organizations/UploadIdPMetadata.go index ccda90603e4..e13fab1bbfe 100644 --- a/examples/v2/organizations/UploadIdPMetadata.go +++ b/examples/v2/organizations/UploadIdPMetadata.go @@ -5,6 +5,7 @@ package main import ( "context" "fmt" + "io" "os" "github.com/DataDog/datadog-api-client-go/v2/api/datadog" @@ -16,7 +17,7 @@ func main() { configuration := datadog.NewConfiguration() apiClient := datadog.NewAPIClient(configuration) api := datadogV2.NewOrganizationsApi(apiClient) - r, err := api.UploadIdPMetadata(ctx, *datadogV2.NewUploadIdPMetadataOptionalParameters().WithIdpFile(func() *os.File { + r, err := api.UploadIdPMetadata(ctx, *datadogV2.NewUploadIdPMetadataOptionalParameters().WithIdpFile(func() io.Reader { fp, _ := os.Open("fixtures/organizations/saml_configurations/valid_idp_metadata.xml") return fp }())) diff --git a/tests/api/datadogV1/cassettes/TestOrgsUploadIdpErrors/400_Bad_Request.freeze b/tests/api/datadogV1/cassettes/TestOrgsUploadIdpErrors/400_Bad_Request.freeze index f9ed9a0f2da..508fa2ec171 100644 --- a/tests/api/datadogV1/cassettes/TestOrgsUploadIdpErrors/400_Bad_Request.freeze +++ b/tests/api/datadogV1/cassettes/TestOrgsUploadIdpErrors/400_Bad_Request.freeze @@ -1 +1 @@ -2021-04-12T11:53:46.715643+02:00 \ No newline at end of file +2023-12-22T14:30:08.685141784+01:00 \ No newline at end of file diff --git a/tests/api/datadogV1/cassettes/TestOrgsUploadIdpErrors/400_Bad_Request.yaml b/tests/api/datadogV1/cassettes/TestOrgsUploadIdpErrors/400_Bad_Request.yaml index 28f8d70f54b..f7f3c120734 100644 --- a/tests/api/datadogV1/cassettes/TestOrgsUploadIdpErrors/400_Bad_Request.yaml +++ b/tests/api/datadogV1/cassettes/TestOrgsUploadIdpErrors/400_Bad_Request.yaml @@ -2,48 +2,42 @@ version: 1 interactions: - request: - body: "--a1a19613f5d9afb0dc96c923c789d65708322400bd16f5341f51906e00e0\r\nContent-Disposition: - form-data; name=\"idp_file\"; filename=\"error_415.json\"\r\nContent-Type: application/octet-stream\r\n\r\n{\"errors\": - [\"Attempt to upload idp metadata with an unsupported Content-Type\"]}\n\r\n--a1a19613f5d9afb0dc96c923c789d65708322400bd16f5341f51906e00e0--\r\n" + body: "--8d7a497f381cc1f9f9c0ddb59aba34ec3a25f1875e7930165eadae6e6632\r\nContent-Disposition: + form-data; name=\"idp_file\"; filename=\".\"\r\nContent-Type: application/octet-stream\r\n\r\n{\"errors\": + [\"Attempt to upload idp metadata with an unsupported Content-Type\"]}\n\r\n--8d7a497f381cc1f9f9c0ddb59aba34ec3a25f1875e7930165eadae6e6632--\r\n" form: {} headers: Accept: - application/json Content-Length: - - "262" + - "317" Content-Type: - - multipart/form-data; boundary=a1a19613f5d9afb0dc96c923c789d65708322400bd16f5341f51906e00e0 + - multipart/form-data; boundary=8d7a497f381cc1f9f9c0ddb59aba34ec3a25f1875e7930165eadae6e6632 User-Agent: - - datadog-api-client-go/1.0.0-beta.19+dev (go go1.15.7; os darwin; arch amd64) + - datadog-api-client-go/2.20.1+dev (go go1.21.5; os linux; arch amd64) X-Datadog-Parent-Id: - - "2135779211706672752" + - "7670172946023811925" X-Datadog-Sampling-Priority: - - "1" + - "2" X-Datadog-Trace-Id: - - "1207290177630451530" - url: https://api.datadoghq.com/api/v1/org/Test-TestOrgsUploadIdpErrors_400_Bad_Request-1618221226/idp_metadata + - "1208129418755230576" + url: https://api.datadoghq.com/api/v1/org/Test-TestOrgsUploadIdpErrors_400_Bad_Request-1703251808/idp_metadata method: POST response: - body: '{"errors": ["Not allowed to access this organization"]}' + body: '{"errors":["Not allowed to access this organization"]}' headers: - Cache-Control: - - no-cache Connection: - keep-alive - Content-Length: - - "55" Content-Type: - application/json Date: - - Mon, 12 Apr 2021 09:53:46 GMT - Pragma: - - no-cache + - Fri, 22 Dec 2023 13:30:09 GMT Strict-Transport-Security: - - max-age=15724800; + - max-age=31536000; includeSubDomains; preload + Vary: + - Accept-Encoding X-Content-Type-Options: - nosniff - X-Dd-Version: - - "35.4287331" X-Frame-Options: - SAMEORIGIN status: 400 Bad Request diff --git a/tests/api/datadogV1/cassettes/TestOrgsUploadIdpErrors/403_Forbidden.freeze b/tests/api/datadogV1/cassettes/TestOrgsUploadIdpErrors/403_Forbidden.freeze index b1b8e86b0e2..b75034ae9af 100644 --- a/tests/api/datadogV1/cassettes/TestOrgsUploadIdpErrors/403_Forbidden.freeze +++ b/tests/api/datadogV1/cassettes/TestOrgsUploadIdpErrors/403_Forbidden.freeze @@ -1 +1 @@ -2021-04-12T11:53:46.63022+02:00 \ No newline at end of file +2023-12-22T14:31:05.452351676+01:00 \ No newline at end of file diff --git a/tests/api/datadogV1/cassettes/TestOrgsUploadIdpErrors/403_Forbidden.yaml b/tests/api/datadogV1/cassettes/TestOrgsUploadIdpErrors/403_Forbidden.yaml index 8682bed784c..4b51f099f96 100644 --- a/tests/api/datadogV1/cassettes/TestOrgsUploadIdpErrors/403_Forbidden.yaml +++ b/tests/api/datadogV1/cassettes/TestOrgsUploadIdpErrors/403_Forbidden.yaml @@ -2,43 +2,42 @@ version: 1 interactions: - request: - body: "--cc0c336e63eed4970804cceb92076fdc49166742a010de577818bf89c041\r\nContent-Disposition: - form-data; name=\"idp_file\"; filename=\"error_415.json\"\r\nContent-Type: application/octet-stream\r\n\r\n{\"errors\": - [\"Attempt to upload idp metadata with an unsupported Content-Type\"]}\n\r\n--cc0c336e63eed4970804cceb92076fdc49166742a010de577818bf89c041--\r\n" + body: "--c64b1780807c2726b3824a38988ac60e600953b47b65ca857e59bccb810f\r\nContent-Disposition: + form-data; name=\"idp_file\"; filename=\".\"\r\nContent-Type: application/octet-stream\r\n\r\n{\"errors\": + [\"Attempt to upload idp metadata with an unsupported Content-Type\"]}\n\r\n--c64b1780807c2726b3824a38988ac60e600953b47b65ca857e59bccb810f--\r\n" form: {} headers: Accept: - application/json Content-Length: - - "262" + - "317" Content-Type: - - multipart/form-data; boundary=cc0c336e63eed4970804cceb92076fdc49166742a010de577818bf89c041 + - multipart/form-data; boundary=c64b1780807c2726b3824a38988ac60e600953b47b65ca857e59bccb810f User-Agent: - - datadog-api-client-go/1.0.0-beta.19+dev (go go1.15.7; os darwin; arch amd64) + - datadog-api-client-go/2.20.1+dev (go go1.21.5; os linux; arch amd64) X-Datadog-Parent-Id: - - "7984283734026566391" + - "403394975109196788" X-Datadog-Sampling-Priority: - - "1" + - "2" X-Datadog-Trace-Id: - - "1207290177630451530" - url: https://api.datadoghq.com/api/v1/org/Test-TestOrgsUploadIdpErrors_403_Forbidden-1618221226/idp_metadata + - "959583525592524867" + url: https://api.datadoghq.com/api/v1/org/Test-TestOrgsUploadIdpErrors_403_Forbidden-1703251865/idp_metadata method: POST response: - body: | - {"status":"error","code":403,"errors":["Forbidden"],"statuspage":"http://status.datadoghq.com","twitter":"http://twitter.com/datadogops","email":"support@datadoghq.com"} + body: '{"errors":["Forbidden"]}' headers: - Cache-Control: - - no-cache Connection: - keep-alive Content-Length: - - "170" + - "24" Content-Type: - application/json Date: - - Mon, 12 Apr 2021 09:53:46 GMT - Via: - - haproxy + - Fri, 22 Dec 2023 13:31:05 GMT + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + X-Content-Type-Options: + - nosniff status: 403 Forbidden code: 403 duration: ""