diff --git a/.gitignore b/.gitignore index 3cfe1e1..25eabcc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ +**/.speakeasy/temp/ +**/.speakeasy/logs/ +.env +.env.local # .gitignore .terraform .terraform* @@ -30,8 +34,6 @@ override.tf.json .terraformrc terraform.rc .DS_Store - terraform-provider-epilot-file - original.yaml original_modified.yaml diff --git a/.speakeasy/gen.lock b/.speakeasy/gen.lock index 0767fa0..157640d 100755 --- a/.speakeasy/gen.lock +++ b/.speakeasy/gen.lock @@ -1,12 +1,12 @@ lockVersion: 2.0.0 id: 11c8545a-deb6-44f9-ba56-e71722af6a51 management: - docChecksum: 0383a3b8b71da53f168ab4cd3da53caa - docVersion: 0.2.0 - speakeasyVersion: 1.422.1 - generationVersion: 2.438.15 - releaseVersion: 0.5.0 - configChecksum: 166ca9b280afae98c5bf4536bf99033d + docChecksum: f1966eb41c96abbc86f9353f2da5272c + docVersion: 1.0.0 + speakeasyVersion: 1.640.0 + generationVersion: 2.730.5 + releaseVersion: 0.6.0 + configChecksum: 7fa9ea0411f3aaf05be19015b7eb0900 repoURL: https://github.com/epilot-dev/terraform-provider-epilot-file.git repoSubDirectory: . published: true @@ -14,28 +14,24 @@ features: terraform: additionalDependencies: 0.1.0 additionalProperties: 0.1.2 - constsAndDefaults: 0.1.4 - core: 3.25.0 - deprecations: 2.81.1 - envVarSecurityUsage: 0.1.0 - globalSecurity: 2.81.9 - globalServerURLs: 2.82.1 + constsAndDefaults: 0.3.0 + core: 3.46.3 + deprecations: 2.82.0 + globalSecurity: 2.82.1 + globalServerURLs: 2.83.0 inputOutputModels: 2.83.0 nullables: 0.0.0 - retries: 2.81.1 - unions: 2.81.16 + unions: 2.82.1 generatedFiles: - .gitattributes - USAGE.md - - examples/README.md - - examples/data-sources/epilot-file_file/data-source.tf - examples/provider/provider.tf - - examples/resources/epilot-file_file/import.sh - - examples/resources/epilot-file_file/resource.tf - go.mod - go.sum - internal/planmodifiers/boolplanmodifier/suppress_diff.go + - internal/planmodifiers/float32planmodifier/suppress_diff.go - internal/planmodifiers/float64planmodifier/suppress_diff.go + - internal/planmodifiers/int32planmodifier/suppress_diff.go - internal/planmodifiers/int64planmodifier/suppress_diff.go - internal/planmodifiers/listplanmodifier/suppress_diff.go - internal/planmodifiers/mapplanmodifier/suppress_diff.go @@ -44,10 +40,6 @@ generatedFiles: - internal/planmodifiers/setplanmodifier/suppress_diff.go - internal/planmodifiers/stringplanmodifier/suppress_diff.go - internal/planmodifiers/utils/state_check.go - - internal/provider/file_data_source.go - - internal/provider/file_data_source_sdk.go - - internal/provider/file_resource.go - - internal/provider/file_resource_sdk.go - internal/provider/provider.go - internal/provider/reflect/diags.go - internal/provider/reflect/doc.go @@ -63,18 +55,18 @@ generatedFiles: - internal/provider/reflect/primitive.go - internal/provider/reflect/slice.go - internal/provider/reflect/struct.go - - internal/provider/types/base_entity_acl.go - - internal/provider/types/base_entity_owner.go - - internal/provider/types/file_item.go - - internal/provider/types/s3_ref.go + - internal/provider/typeconvert/date.go + - internal/provider/typeconvert/datetime.go + - internal/provider/typeconvert/int.go - internal/provider/utils.go - internal/sdk/.gitattributes - - internal/sdk/.gitignore - - internal/sdk/CONTRIBUTING.md - internal/sdk/deprecated.go - internal/sdk/file.go + - internal/sdk/filefolders.go + - internal/sdk/internal/config/sdkconfiguration.go - internal/sdk/internal/hooks/hooks.go - internal/sdk/internal/utils/contenttype.go + - internal/sdk/internal/utils/env.go - internal/sdk/internal/utils/form.go - internal/sdk/internal/utils/headers.go - internal/sdk/internal/utils/json.go @@ -86,13 +78,17 @@ generatedFiles: - internal/sdk/internal/utils/utils.go - internal/sdk/models/errors/sdkerror.go - internal/sdk/models/operations/accesspubliclink.go + - internal/sdk/models/operations/createfilefolder.go - internal/sdk/models/operations/deletefile.go + - internal/sdk/models/operations/deletefilefolder.go - internal/sdk/models/operations/deletesession.go - internal/sdk/models/operations/downloadfile.go - internal/sdk/models/operations/downloadfiles.go - internal/sdk/models/operations/downloads3file.go - internal/sdk/models/operations/generatepubliclink.go - internal/sdk/models/operations/getfile.go + - internal/sdk/models/operations/getfilefolders.go + - internal/sdk/models/operations/getfilesinfolder.go - internal/sdk/models/operations/getsession.go - internal/sdk/models/operations/listpubliclinksforfile.go - internal/sdk/models/operations/options.go @@ -103,6 +99,7 @@ generatedFiles: - internal/sdk/models/operations/revokepubliclink.go - internal/sdk/models/operations/savefile.go - internal/sdk/models/operations/savefilev2.go + - internal/sdk/models/operations/updatefilefolder.go - internal/sdk/models/operations/uploadfile.go - internal/sdk/models/operations/uploadfilepublic.go - internal/sdk/models/operations/uploadfilev2.go @@ -111,6 +108,9 @@ generatedFiles: - internal/sdk/models/shared/baseentityowner.go - internal/sdk/models/shared/downloadfilespayload.go - internal/sdk/models/shared/fileentity.go + - internal/sdk/models/shared/filefolderattributes.go + - internal/sdk/models/shared/filefoldercreaterequest.go + - internal/sdk/models/shared/filefolderitem.go - internal/sdk/models/shared/fileitem.go - internal/sdk/models/shared/filerelationitem.go - internal/sdk/models/shared/filetype.go @@ -125,6 +125,8 @@ generatedFiles: - internal/sdk/models/shared/security.go - internal/sdk/models/shared/uploadfilepayload.go - internal/sdk/models/shared/verifycustomdownloadurlpayload.go + - internal/sdk/optionalnullable/optionalnullable.go + - internal/sdk/optionalnullable/optionalnullable_test.go - internal/sdk/preview.go - internal/sdk/publiclinks.go - internal/sdk/retry/config.go @@ -133,14 +135,15 @@ generatedFiles: - internal/sdk/types/bigint.go - internal/sdk/types/date.go - internal/sdk/types/datetime.go - - internal/sdk/types/decimal.go - internal/sdk/types/pointers.go - internal/validators/DateValidator.go - internal/validators/ExactlyOneChild.go - internal/validators/JSONParseValidator.go - internal/validators/RFC3339Validator.go - internal/validators/boolvalidators/not_null.go + - internal/validators/float32validators/not_null.go - internal/validators/float64validators/not_null.go + - internal/validators/int32validators/not_null.go - internal/validators/int64validators/not_null.go - internal/validators/listvalidators/not_null.go - internal/validators/mapvalidators/not_null.go @@ -152,16 +155,74 @@ generatedFiles: - terraform-registry-manifest.json - tools/tools.go examples: + createFileFolder: + speakeasy-default-create-file-folder: + parameters: + path: + id: "ef7d985c-2385-44f4-9c71-ae06a52264f8" + requestBody: + application/json: {"name": "", "starred": false} + responses: + "201": + application/json: {"created_at": "2024-01-01T12:00:00Z", "name": "Documents", "parents": ["_system_files_collection_entity-123"], "slug": "_system_files_collection_entity-123:documents", "starred": false, "updated_at": "2024-01-02T12:00:00Z"} + "404": + application/json: {"error": "Not Found", "status": 404} + deleteFileFolder: + speakeasy-default-delete-file-folder: + parameters: + path: + id: "ef7d985c-2385-44f4-9c71-ae06a52264f8" + folderSlug: "documents" + responses: + "404": + application/json: {"error": "Not Found", "status": 404} + getFileFolders: + speakeasy-default-get-file-folders: + parameters: + path: + id: "ef7d985c-2385-44f4-9c71-ae06a52264f8" + responses: + "200": + application/json: [{"created_at": "2024-01-01T12:00:00Z", "name": "Documents", "parents": ["_system_files_collection_entity-123"], "slug": "_system_files_collection_entity-123:documents", "starred": false, "updated_at": "2024-01-02T12:00:00Z"}] + "404": + application/json: {"error": "Not Found", "status": 404} + getFilesInFolder: + speakeasy-default-get-files-in-folder: + parameters: + path: + id: "ef7d985c-2385-44f4-9c71-ae06a52264f8" + folderSlug: "documents" + responses: + "200": + application/json: [{"_acl": {"delete": ["org:456"], "edit": ["org:456"], "view": ["org:456"]}, "_id": "ef7d985c-2385-44f4-9c71-ae06a52264f8", "_manifest": ["123e4567-e89b-12d3-a456-426614174000"], "_org": "123", "_owners": [{"org_id": "123", "user_id": "123"}], "_purpose": ["8d396871-95a0-4c9d-bb4d-9eda9c35776c", "da7cdf9a-01be-40c9-a29c-9a8f9f0de6f8"], "_schema": "file", "_tags": ["tag1", "tag2"], "_title": "document.pdf", "access_control": "private", "custom_download_url": "https://some-api-url.com/download?file_id=123", "filename": "document.pdf", "mime_type": "application/pdf", "public_url": "https://epilot-prod-user-content.s3.eu-central-1.amazonaws.com/123/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf", "readable_size": "1.2 MB", "s3ref": {"bucket": "epilot-prod-user-content", "key": "123/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf"}, "size_bytes": 1234, "source_url": "https://productengineer-content.s3.eu-west-1.amazonaws.com/product-engineer-checklist.pdf", "type": "unknown", "versions": [{"filename": "document.pdf", "mime_type": "image/jpeg", "readable_size": "1.2 MB", "s3ref": {"bucket": "epilot-prod-user-content", "key": "123/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf"}, "size_bytes": 1234}]}] + "403": + application/json: {"error": "User must have permission to view this entity to access its files"} + "404": + application/json: {"error": "Entity not found"} + updateFileFolder: + speakeasy-default-update-file-folder: + parameters: + path: + id: "ef7d985c-2385-44f4-9c71-ae06a52264f8" + folderSlug: "documents" + requestBody: + application/json: {"starred": false} + responses: + "200": + application/json: {"created_at": "2024-01-01T12:00:00Z", "name": "Documents", "parents": ["_system_files_collection_entity-123"], "slug": "_system_files_collection_entity-123:documents", "starred": false, "updated_at": "2024-01-02T12:00:00Z"} + "404": + application/json: {"error": "Not Found", "status": 404} saveFile: speakeasy-default-save-file: parameters: query: activity_id: "01F130Q52Q6MWSNS8N2AVXV4JN" + async: false requestBody: - application/json: {"_id": "ef7d985c-2385-44f4-9c71-ae06a52264f8", "_manifest": ["123e4567-e89b-12d3-a456-426614174000"], "_purpose": ["8d396871-95a0-4c9d-bb4d-9eda9c35776c", "da7cdf9a-01be-40c9-a29c-9a8f9f0de6f8"], "_tags": ["tag1", "tag2"], "custom_download_url": "https://some-api-url.com/download?file_id=123", "filename": "document.pdf", "mime_type": "application/pdf", "relations": [], "source_url": "https://some-api-url.com/download?file_id=123", "s3ref": {"bucket": "epilot-prod-user-content", "key": "123/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf"}} + application/json: {"_id": "ef7d985c-2385-44f4-9c71-ae06a52264f8", "_manifest": ["123e4567-e89b-12d3-a456-426614174000"], "_purpose": ["8d396871-95a0-4c9d-bb4d-9eda9c35776c", "da7cdf9a-01be-40c9-a29c-9a8f9f0de6f8"], "_tags": ["tag1", "tag2"], "access_control": "private", "custom_download_url": "https://some-api-url.com/download?file_id=123", "filename": "document.pdf", "mime_type": "application/pdf", "relations": [{"_schema": "contact", "entity_id": "ef7d985c-2385-44f4-9c71-ae06a52264f8"}]} responses: "201": - application/json: {"_acl": {"delete": ["org:456"], "edit": ["org:456"], "view": ["org:456"]}, "_id": "ef7d985c-2385-44f4-9c71-ae06a52264f8", "_manifest": ["123e4567-e89b-12d3-a456-426614174000"], "_org": "123", "_owners": [], "_purpose": ["8d396871-95a0-4c9d-bb4d-9eda9c35776c", "da7cdf9a-01be-40c9-a29c-9a8f9f0de6f8"], "_tags": ["tag1", "tag2"], "_title": "document.pdf", "custom_download_url": "https://some-api-url.com/download?file_id=123", "filename": "document.pdf", "mime_type": "application/pdf", "public_url": "https://epilot-prod-user-content.s3.eu-central-1.amazonaws.com/123/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf", "readable_size": "1.2 MB", "s3ref": {"bucket": "epilot-prod-user-content", "key": "123/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf"}, "size_bytes": 1234, "source_url": "https://productengineer-content.s3.eu-west-1.amazonaws.com/product-engineer-checklist.pdf", "versions": []} + application/json: {"_acl": {"delete": ["org:456"], "edit": ["org:456"], "view": ["org:456"]}, "_id": "ef7d985c-2385-44f4-9c71-ae06a52264f8", "_manifest": ["123e4567-e89b-12d3-a456-426614174000"], "_org": "123", "_owners": [{"org_id": "123", "user_id": "123"}], "_purpose": ["8d396871-95a0-4c9d-bb4d-9eda9c35776c", "da7cdf9a-01be-40c9-a29c-9a8f9f0de6f8"], "_schema": "file", "_tags": ["tag1", "tag2"], "_title": "document.pdf", "access_control": "private", "custom_download_url": "https://some-api-url.com/download?file_id=123", "filename": "document.pdf", "mime_type": "application/pdf", "public_url": "https://epilot-prod-user-content.s3.eu-central-1.amazonaws.com/123/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf", "readable_size": "1.2 MB", "s3ref": {"bucket": "epilot-prod-user-content", "key": "123/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf"}, "size_bytes": 1234, "source_url": "https://productengineer-content.s3.eu-west-1.amazonaws.com/product-engineer-checklist.pdf", "type": "application", "versions": []} uploadFile: speakeasy-default-upload-file: parameters: @@ -171,39 +232,44 @@ examples: application/json: {"filename": "document.pdf", "index_tag": "2f6a377c8e78", "metadata": {"color": "blue"}, "mime_type": "application/pdf"} responses: "201": - application/json: {"public_url": "https://epilot-prod-user-content.s3.eu-central-1.amazonaws.com/123/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf", "s3ref": {"bucket": "epilot-prod-user-content", "key": "123/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf"}, "upload_url": "https://epilot-prod-user-content.s3.eu-central-1.amazonaws.com/123/temp/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf?AWSParams=123"} + application/json: {"public_url": "https://epilot-prod-user-content.s3.eu-central-1.amazonaws.com/123/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf", "s3ref": {"bucket": "epilot-prod-user-content", "key": "123/temp/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf"}, "upload_url": "https://epilot-prod-user-content.s3.eu-central-1.amazonaws.com/123/temp/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf?AWSParams=123"} deleteFile: speakeasy-default-delete-file: parameters: path: id: "ef7d985c-2385-44f4-9c71-ae06a52264f8" query: + purge: false activity_id: "01F130Q52Q6MWSNS8N2AVXV4JN" + strict: false responses: "200": - application/json: {"_acl": {"delete": ["org:456"], "edit": ["org:456"], "view": ["org:456"]}, "_id": "ef7d985c-2385-44f4-9c71-ae06a52264f8", "_manifest": ["123e4567-e89b-12d3-a456-426614174000"], "_org": "123", "_owners": [], "_purpose": ["8d396871-95a0-4c9d-bb4d-9eda9c35776c", "da7cdf9a-01be-40c9-a29c-9a8f9f0de6f8"], "_tags": ["tag1", "tag2"], "_title": "document.pdf", "custom_download_url": "https://some-api-url.com/download?file_id=123", "filename": "document.pdf", "mime_type": "application/pdf", "public_url": "https://epilot-prod-user-content.s3.eu-central-1.amazonaws.com/123/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf", "readable_size": "1.2 MB", "s3ref": {"bucket": "epilot-prod-user-content", "key": "123/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf"}, "size_bytes": 1234, "source_url": "https://productengineer-content.s3.eu-west-1.amazonaws.com/product-engineer-checklist.pdf", "versions": []} + application/json: {"_acl": {"delete": ["org:456"], "edit": ["org:456"], "view": ["org:456"]}, "_id": "ef7d985c-2385-44f4-9c71-ae06a52264f8", "_manifest": ["123e4567-e89b-12d3-a456-426614174000"], "_org": "123", "_owners": [{"org_id": "123", "user_id": "123"}], "_purpose": ["8d396871-95a0-4c9d-bb4d-9eda9c35776c", "da7cdf9a-01be-40c9-a29c-9a8f9f0de6f8"], "_schema": "file", "_tags": ["tag1", "tag2"], "_title": "document.pdf", "access_control": "private", "custom_download_url": "https://some-api-url.com/download?file_id=123", "filename": "document.pdf", "mime_type": "application/pdf", "public_url": "https://epilot-prod-user-content.s3.eu-central-1.amazonaws.com/123/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf", "readable_size": "1.2 MB", "s3ref": {"bucket": "epilot-prod-user-content", "key": "123/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf"}, "size_bytes": 1234, "source_url": "https://productengineer-content.s3.eu-west-1.amazonaws.com/product-engineer-checklist.pdf", "type": "application", "versions": []} downloadFile: speakeasy-default-download-file: parameters: path: id: "ef7d985c-2385-44f4-9c71-ae06a52264f8" - query: {} + query: + version: 0 + attachment: true responses: "200": application/json: {"download_url": "https://epilot-prod-user-content.s3.eu-central-1.amazonaws.com/123/temp/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf?AWSParams=123"} downloadFiles: speakeasy-default-download-files: requestBody: - application/json: [] + application/json: [{"id": "ef7d985c-2385-44f4-9c71-ae06a52264f8", "version": 0}] responses: "200": - application/json: [] + application/json: [{"download_url": "https://epilot-prod-user-content.s3.eu-central-1.amazonaws.com/123/temp/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf?AWSParams=123"}] downloadS3File: speakeasy-default-download-s3-file: parameters: query: s3_key: "" s3_bucket: "" + attachment: true responses: "200": application/json: {"download_url": "https://epilot-prod-user-content.s3.eu-central-1.amazonaws.com/123/temp/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf?AWSParams=123"} @@ -212,67 +278,86 @@ examples: parameters: path: id: "ef7d985c-2385-44f4-9c71-ae06a52264f8" - query: {} + query: + source_url: false + strict: false + async: false responses: "200": - application/json: {"_acl": {"delete": ["org:456"], "edit": ["org:456"], "view": ["org:456"]}, "_id": "ef7d985c-2385-44f4-9c71-ae06a52264f8", "_manifest": ["123e4567-e89b-12d3-a456-426614174000"], "_org": "123", "_owners": [], "_purpose": ["8d396871-95a0-4c9d-bb4d-9eda9c35776c", "da7cdf9a-01be-40c9-a29c-9a8f9f0de6f8"], "_tags": ["tag1", "tag2"], "_title": "document.pdf", "custom_download_url": "https://some-api-url.com/download?file_id=123", "filename": "document.pdf", "mime_type": "application/pdf", "public_url": "https://epilot-prod-user-content.s3.eu-central-1.amazonaws.com/123/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf", "readable_size": "1.2 MB", "s3ref": {"bucket": "epilot-prod-user-content", "key": "123/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf"}, "size_bytes": 1234, "source_url": "https://productengineer-content.s3.eu-west-1.amazonaws.com/product-engineer-checklist.pdf", "versions": []} + application/json: {"_acl": {"delete": ["org:456"], "edit": ["org:456"], "view": ["org:456"]}, "_id": "ef7d985c-2385-44f4-9c71-ae06a52264f8", "_manifest": ["123e4567-e89b-12d3-a456-426614174000"], "_org": "123", "_owners": [{"org_id": "123", "user_id": "123"}], "_purpose": ["8d396871-95a0-4c9d-bb4d-9eda9c35776c", "da7cdf9a-01be-40c9-a29c-9a8f9f0de6f8"], "_schema": "file", "_tags": ["tag1", "tag2"], "_title": "document.pdf", "access_control": "private", "custom_download_url": "https://some-api-url.com/download?file_id=123", "filename": "document.pdf", "mime_type": "application/pdf", "public_url": "https://epilot-prod-user-content.s3.eu-central-1.amazonaws.com/123/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf", "readable_size": "1.2 MB", "s3ref": {"bucket": "epilot-prod-user-content", "key": "123/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf"}, "size_bytes": 1234, "source_url": "https://productengineer-content.s3.eu-west-1.amazonaws.com/product-engineer-checklist.pdf", "type": "application", "versions": [{"filename": "document.pdf", "mime_type": "image/jpeg", "readable_size": "1.2 MB", "s3ref": {"bucket": "epilot-prod-user-content", "key": "123/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf"}, "size_bytes": 1234}]} saveFileV2: New file from s3ref: parameters: query: activity_id: "01F130Q52Q6MWSNS8N2AVXV4JN" + fill_activity: false + strict: false + async: false + delete_temp_file: true requestBody: - application/json: {"_acl": {"delete": ["org:456"], "edit": ["org:456"], "view": ["org:456"]}, "_id": "ef7d985c-2385-44f4-9c71-ae06a52264f8", "_manifest": ["123e4567-e89b-12d3-a456-426614174000"], "_purpose": ["8d396871-95a0-4c9d-bb4d-9eda9c35776c", "da7cdf9a-01be-40c9-a29c-9a8f9f0de6f8"], "_tags": ["string"], "_title": "document.pdf", "access_control": "private", "custom_download_url": "https://some-api-url.com/download?file_id=123", "filename": "document.pdf", "mime_type": "application/pdf", "s3ref": {"bucket": "epilot-prod-user-content", "key": "123/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf"}, "source_url": "https://productengineer-content.s3.eu-west-1.amazonaws.com/product-engineer-checklist.pdf", "type": "document"} + application/json: {"_tags": ["string"], "access_control": "private", "filename": "document.pdf", "s3ref": {"bucket": "epilot-prod-user-content", "key": "123/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf"}, "type": "document"} responses: "200": - application/json: {"_acl": {"delete": ["org:456"], "edit": ["org:456"], "view": ["org:456"]}, "_id": "ef7d985c-2385-44f4-9c71-ae06a52264f8", "_manifest": ["123e4567-e89b-12d3-a456-426614174000"], "_org": "123", "_owners": [], "_purpose": ["8d396871-95a0-4c9d-bb4d-9eda9c35776c", "da7cdf9a-01be-40c9-a29c-9a8f9f0de6f8"], "_tags": ["tag1", "tag2"], "_title": "document.pdf", "custom_download_url": "https://some-api-url.com/download?file_id=123", "filename": "document.pdf", "mime_type": "application/pdf", "public_url": "https://epilot-prod-user-content.s3.eu-central-1.amazonaws.com/123/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf", "readable_size": "1.2 MB", "s3ref": {"bucket": "epilot-prod-user-content", "key": "123/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf"}, "size_bytes": 1234, "source_url": "https://productengineer-content.s3.eu-west-1.amazonaws.com/product-engineer-checklist.pdf", "versions": []} + application/json: {"_acl": {"delete": ["org:456"], "edit": ["org:456"], "view": ["org:456"]}, "_id": "ef7d985c-2385-44f4-9c71-ae06a52264f8", "_manifest": ["123e4567-e89b-12d3-a456-426614174000"], "_org": "123", "_owners": [{"org_id": "123", "user_id": "123"}], "_purpose": ["8d396871-95a0-4c9d-bb4d-9eda9c35776c", "da7cdf9a-01be-40c9-a29c-9a8f9f0de6f8"], "_schema": "file", "_tags": ["tag1", "tag2"], "_title": "document.pdf", "access_control": "private", "custom_download_url": "https://some-api-url.com/download?file_id=123", "filename": "document.pdf", "mime_type": "application/pdf", "public_url": "https://epilot-prod-user-content.s3.eu-central-1.amazonaws.com/123/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf", "readable_size": "1.2 MB", "s3ref": {"bucket": "epilot-prod-user-content", "key": "123/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf"}, "size_bytes": 1234, "source_url": "https://productengineer-content.s3.eu-west-1.amazonaws.com/product-engineer-checklist.pdf", "type": "document_template", "versions": [{"filename": "document.pdf", "mime_type": "image/jpeg", "readable_size": "1.2 MB", "s3ref": {"bucket": "epilot-prod-user-content", "key": "123/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf"}, "size_bytes": 1234}]} Update existing file with relations: parameters: query: activity_id: "01F130Q52Q6MWSNS8N2AVXV4JN" + fill_activity: false + strict: false + async: false + delete_temp_file: true requestBody: - application/json: {"_acl": {"delete": ["org:456"], "edit": ["org:456"], "view": ["org:456"]}, "_id": "ef7d985c-2385-44f4-9c71-ae06a52264f8", "_manifest": ["123e4567-e89b-12d3-a456-426614174000"], "_purpose": ["8d396871-95a0-4c9d-bb4d-9eda9c35776c", "da7cdf9a-01be-40c9-a29c-9a8f9f0de6f8"], "_tags": ["tag1", "tag2"], "_title": "document.pdf", "access_control": "private", "custom_download_url": "https://some-api-url.com/download?file_id=123", "filename": "document.pdf", "mime_type": "application/pdf", "s3ref": {"bucket": "epilot-prod-user-content", "key": "123/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf"}, "source_url": "https://productengineer-content.s3.eu-west-1.amazonaws.com/product-engineer-checklist.pdf"} + application/json: {"_id": "ef7d985c-2385-44f4-9c71-ae06a52264f8", "access_control": "private", "custom_download_url": "https://some-api-url.com/download?file_id=123", "filename": "document.pdf", "relations": [{"_schema": "contact", "entity_id": "77a1e0cc-7b92-4d41-8cce-eefd317ec004"}], "shared_with_end_customer": true} responses: "200": - application/json: {"_acl": {"delete": ["org:456"], "edit": ["org:456"], "view": ["org:456"]}, "_id": "ef7d985c-2385-44f4-9c71-ae06a52264f8", "_manifest": ["123e4567-e89b-12d3-a456-426614174000"], "_org": "123", "_owners": [], "_purpose": ["8d396871-95a0-4c9d-bb4d-9eda9c35776c", "da7cdf9a-01be-40c9-a29c-9a8f9f0de6f8"], "_tags": ["tag1", "tag2"], "_title": "document.pdf", "custom_download_url": "https://some-api-url.com/download?file_id=123", "filename": "document.pdf", "mime_type": "application/pdf", "public_url": "https://epilot-prod-user-content.s3.eu-central-1.amazonaws.com/123/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf", "readable_size": "1.2 MB", "s3ref": {"bucket": "epilot-prod-user-content", "key": "123/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf"}, "size_bytes": 1234, "source_url": "https://productengineer-content.s3.eu-west-1.amazonaws.com/product-engineer-checklist.pdf", "versions": []} + application/json: {"_acl": {"delete": ["org:456"], "edit": ["org:456"], "view": ["org:456"]}, "_id": "ef7d985c-2385-44f4-9c71-ae06a52264f8", "_manifest": ["123e4567-e89b-12d3-a456-426614174000"], "_org": "123", "_owners": [{"org_id": "123", "user_id": "123"}], "_purpose": ["8d396871-95a0-4c9d-bb4d-9eda9c35776c", "da7cdf9a-01be-40c9-a29c-9a8f9f0de6f8"], "_schema": "file", "_tags": ["tag1", "tag2"], "_title": "document.pdf", "access_control": "private", "custom_download_url": "https://some-api-url.com/download?file_id=123", "filename": "document.pdf", "mime_type": "application/pdf", "public_url": "https://epilot-prod-user-content.s3.eu-central-1.amazonaws.com/123/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf", "readable_size": "1.2 MB", "s3ref": {"bucket": "epilot-prod-user-content", "key": "123/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf"}, "size_bytes": 1234, "source_url": "https://productengineer-content.s3.eu-west-1.amazonaws.com/product-engineer-checklist.pdf", "type": "document_template", "versions": [{"filename": "document.pdf", "mime_type": "image/jpeg", "readable_size": "1.2 MB", "s3ref": {"bucket": "epilot-prod-user-content", "key": "123/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf"}, "size_bytes": 1234}]} New file from source_url: parameters: query: activity_id: "01F130Q52Q6MWSNS8N2AVXV4JN" + fill_activity: false + strict: false + async: false + delete_temp_file: true requestBody: - application/json: {"_acl": {"delete": ["org:456"], "edit": ["org:456"], "view": ["org:456"]}, "_id": "ef7d985c-2385-44f4-9c71-ae06a52264f8", "_manifest": ["123e4567-e89b-12d3-a456-426614174000"], "_purpose": ["8d396871-95a0-4c9d-bb4d-9eda9c35776c", "da7cdf9a-01be-40c9-a29c-9a8f9f0de6f8"], "_tags": ["string"], "_title": "document.pdf", "access_control": "private", "custom_download_url": "https://some-api-url.com/download?file_id=123", "filename": "document.pdf", "mime_type": "application/pdf", "s3ref": {"bucket": "epilot-prod-user-content", "key": "123/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf"}, "source_url": "https://docs.epilot.io/document.pdf", "type": "document"} + application/json: {"_tags": ["string"], "access_control": "private", "filename": "document.pdf", "source_url": "https://docs.epilot.io/document.pdf", "type": "document"} responses: "200": - application/json: {"_acl": {"delete": ["org:456"], "edit": ["org:456"], "view": ["org:456"]}, "_id": "ef7d985c-2385-44f4-9c71-ae06a52264f8", "_manifest": ["123e4567-e89b-12d3-a456-426614174000"], "_org": "123", "_owners": [], "_purpose": ["8d396871-95a0-4c9d-bb4d-9eda9c35776c", "da7cdf9a-01be-40c9-a29c-9a8f9f0de6f8"], "_tags": ["tag1", "tag2"], "_title": "document.pdf", "custom_download_url": "https://some-api-url.com/download?file_id=123", "filename": "document.pdf", "mime_type": "application/pdf", "public_url": "https://epilot-prod-user-content.s3.eu-central-1.amazonaws.com/123/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf", "readable_size": "1.2 MB", "s3ref": {"bucket": "epilot-prod-user-content", "key": "123/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf"}, "size_bytes": 1234, "source_url": "https://productengineer-content.s3.eu-west-1.amazonaws.com/product-engineer-checklist.pdf", "versions": []} + application/json: {"_acl": {"delete": ["org:456"], "edit": ["org:456"], "view": ["org:456"]}, "_id": "ef7d985c-2385-44f4-9c71-ae06a52264f8", "_manifest": ["123e4567-e89b-12d3-a456-426614174000"], "_org": "123", "_owners": [{"org_id": "123", "user_id": "123"}], "_purpose": ["8d396871-95a0-4c9d-bb4d-9eda9c35776c", "da7cdf9a-01be-40c9-a29c-9a8f9f0de6f8"], "_schema": "file", "_tags": ["tag1", "tag2"], "_title": "document.pdf", "access_control": "private", "custom_download_url": "https://some-api-url.com/download?file_id=123", "filename": "document.pdf", "mime_type": "application/pdf", "public_url": "https://epilot-prod-user-content.s3.eu-central-1.amazonaws.com/123/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf", "readable_size": "1.2 MB", "s3ref": {"bucket": "epilot-prod-user-content", "key": "123/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf"}, "size_bytes": 1234, "source_url": "https://productengineer-content.s3.eu-west-1.amazonaws.com/product-engineer-checklist.pdf", "type": "document_template", "versions": [{"filename": "document.pdf", "mime_type": "image/jpeg", "readable_size": "1.2 MB", "s3ref": {"bucket": "epilot-prod-user-content", "key": "123/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf"}, "size_bytes": 1234}]} File with custom download URL (external): parameters: query: activity_id: "01F130Q52Q6MWSNS8N2AVXV4JN" + fill_activity: false + strict: false + async: false + delete_temp_file: true requestBody: - application/json: {"_acl": {"delete": ["org:456"], "edit": ["org:456"], "view": ["org:456"]}, "_id": "ef7d985c-2385-44f4-9c71-ae06a52264f8", "_manifest": ["123e4567-e89b-12d3-a456-426614174000"], "_purpose": ["8d396871-95a0-4c9d-bb4d-9eda9c35776c", "da7cdf9a-01be-40c9-a29c-9a8f9f0de6f8"], "_tags": ["string"], "_title": "document.pdf", "access_control": "private", "custom_download_url": "https://some-api-url.com/download?file_id=123", "filename": "document.pdf", "mime_type": "application/pdf", "s3ref": {"bucket": "epilot-prod-user-content", "key": "123/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf"}, "source_url": "https://productengineer-content.s3.eu-west-1.amazonaws.com/product-engineer-checklist.pdf", "type": "document"} + application/json: {"_tags": ["string"], "access_control": "private", "custom_download_url": "https://some-api-url.com/download?file_id=123", "filename": "document.pdf", "type": "document", "shared_with_end_customer": true} responses: "200": - application/json: {"_acl": {"delete": ["org:456"], "edit": ["org:456"], "view": ["org:456"]}, "_id": "ef7d985c-2385-44f4-9c71-ae06a52264f8", "_manifest": ["123e4567-e89b-12d3-a456-426614174000"], "_org": "123", "_owners": [], "_purpose": ["8d396871-95a0-4c9d-bb4d-9eda9c35776c", "da7cdf9a-01be-40c9-a29c-9a8f9f0de6f8"], "_tags": ["tag1", "tag2"], "_title": "document.pdf", "custom_download_url": "https://some-api-url.com/download?file_id=123", "filename": "document.pdf", "mime_type": "application/pdf", "public_url": "https://epilot-prod-user-content.s3.eu-central-1.amazonaws.com/123/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf", "readable_size": "1.2 MB", "s3ref": {"bucket": "epilot-prod-user-content", "key": "123/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf"}, "size_bytes": 1234, "source_url": "https://productengineer-content.s3.eu-west-1.amazonaws.com/product-engineer-checklist.pdf", "versions": []} + application/json: {"_acl": {"delete": ["org:456"], "edit": ["org:456"], "view": ["org:456"]}, "_id": "ef7d985c-2385-44f4-9c71-ae06a52264f8", "_manifest": ["123e4567-e89b-12d3-a456-426614174000"], "_org": "123", "_owners": [{"org_id": "123", "user_id": "123"}], "_purpose": ["8d396871-95a0-4c9d-bb4d-9eda9c35776c", "da7cdf9a-01be-40c9-a29c-9a8f9f0de6f8"], "_schema": "file", "_tags": ["tag1", "tag2"], "_title": "document.pdf", "access_control": "private", "custom_download_url": "https://some-api-url.com/download?file_id=123", "filename": "document.pdf", "mime_type": "application/pdf", "public_url": "https://epilot-prod-user-content.s3.eu-central-1.amazonaws.com/123/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf", "readable_size": "1.2 MB", "s3ref": {"bucket": "epilot-prod-user-content", "key": "123/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf"}, "size_bytes": 1234, "source_url": "https://productengineer-content.s3.eu-west-1.amazonaws.com/product-engineer-checklist.pdf", "type": "document_template", "versions": [{"filename": "document.pdf", "mime_type": "image/jpeg", "readable_size": "1.2 MB", "s3ref": {"bucket": "epilot-prod-user-content", "key": "123/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf"}, "size_bytes": 1234}]} uploadFilePublic: Upload an image file: requestBody: - application/json: {"filename": "image.png", "index_tag": "2f6a377c8e78", "metadata": {"color": "blue"}, "mime_type": "image/png"} + application/json: {"filename": "image.png", "mime_type": "image/png"} responses: "201": - application/json: {"s3ref": {"bucket": "epilot-prod-user-content", "key": "123/temp/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf"}, "upload_url": "https://epilot-prod-user-content.s3.eu-central-1.amazonaws.com/123/temp/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf?AWSParams=123"} + application/json: {"error": "File entity not found", "s3ref": {"bucket": "epilot-prod-user-content", "key": "123/temp/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf"}, "upload_url": "https://epilot-prod-user-content.s3.eu-central-1.amazonaws.com/123/temp/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf?AWSParams=123"} Upload a document: requestBody: - application/json: {"filename": "document.pdf", "index_tag": "2f6a377c8e78", "metadata": {"color": "blue"}, "mime_type": "application/pdf"} + application/json: {"filename": "document.pdf", "mime_type": "application/pdf"} responses: "201": - application/json: {"s3ref": {"bucket": "epilot-prod-user-content", "key": "123/temp/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf"}, "upload_url": "https://epilot-prod-user-content.s3.eu-central-1.amazonaws.com/123/temp/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf?AWSParams=123"} + application/json: {"error": "File entity not found", "s3ref": {"bucket": "epilot-prod-user-content", "key": "123/temp/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf"}, "upload_url": "https://epilot-prod-user-content.s3.eu-central-1.amazonaws.com/123/temp/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf?AWSParams=123"} uploadFileV2: Upload an image file: parameters: query: file_entity_id: "ef7d985c-2385-44f4-9c71-ae06a52264f8" requestBody: - application/json: {"filename": "image.png", "index_tag": "2f6a377c8e78", "metadata": {"color": "blue"}, "mime_type": "image/png"} + application/json: {"filename": "image.png", "mime_type": "image/png"} responses: "201": application/json: {"public_url": "https://epilot-prod-user-content.s3.eu-central-1.amazonaws.com/123/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf", "s3ref": {"bucket": "epilot-prod-user-content", "key": "123/temp/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf"}, "upload_url": "https://epilot-prod-user-content.s3.eu-central-1.amazonaws.com/123/temp/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf?AWSParams=123"} @@ -281,7 +366,7 @@ examples: query: file_entity_id: "ef7d985c-2385-44f4-9c71-ae06a52264f8" requestBody: - application/json: {"filename": "document.pdf", "index_tag": "2f6a377c8e78", "metadata": {"color": "blue"}, "mime_type": "application/pdf"} + application/json: {"filename": "document.pdf", "mime_type": "application/pdf"} responses: "201": application/json: {"public_url": "https://epilot-prod-user-content.s3.eu-central-1.amazonaws.com/123/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf", "s3ref": {"bucket": "epilot-prod-user-content", "key": "123/temp/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf"}, "upload_url": "https://epilot-prod-user-content.s3.eu-central-1.amazonaws.com/123/temp/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf?AWSParams=123"} @@ -289,6 +374,9 @@ examples: speakeasy-default-verify-custom-download-url: requestBody: application/json: {"custom_download_url": "https://some-api-url.com?file_id=123&expires_at=1699273500029&signature=abcdefg"} + responses: + "200": + application/json: {} accessPublicLink: speakeasy-default-access-public-link: parameters: @@ -310,7 +398,7 @@ examples: id: "13d22918-36bd-4227-9ad4-2cb978788c8d" responses: "200": - application/json: {"results": []} + application/json: {"results": [{"id": "3ef5c6d9-818d-45e6-8efb-b1de59079a1c", "link": "https://file.sls.epilot.io/v1/files/public/links/3ef5c6d9-818d-45e6-8efb-b1de59079a1c"}]} revokePublicLink: speakeasy-default-revoke-public-link: parameters: @@ -324,13 +412,15 @@ examples: parameters: path: id: "ef7d985c-2385-44f4-9c71-ae06a52264f8" - query: {} + query: + version: 0 previewPublicFile: speakeasy-default-preview-public-file: parameters: path: id: "ef7d985c-2385-44f4-9c71-ae06a52264f8" - query: {} + query: + version: 0 previewS3File: speakeasy-default-preview-s3-file: requestBody: @@ -341,7 +431,6 @@ examples: query: key: "" bucket: "" - deleteSession: - speakeasy-default-delete-session: {} - getSession: - speakeasy-default-get-session: {} + deleteSession: {} + getSession: {} +examplesVersion: 1.0.2 diff --git a/.speakeasy/workflow.lock b/.speakeasy/workflow.lock new file mode 100644 index 0000000..67f289d --- /dev/null +++ b/.speakeasy/workflow.lock @@ -0,0 +1,29 @@ +speakeasyVersion: 1.640.0 +sources: + my-source: + sourceNamespace: my-source + sourceRevisionDigest: sha256:083886e23c0af69c08fe7fd90f62dcb4b35d0146e90cdd5b5ab80d367986f7c7 + sourceBlobDigest: sha256:a15225f21252c4d0cda133c8bce1992c0ec367b86e34c81f4e7526d07b5253bd + tags: + - latest + - speakeasy-sdk-regen-1758759850 + - 1.0.0 +targets: + terraform: + source: my-source + sourceNamespace: my-source + sourceRevisionDigest: sha256:083886e23c0af69c08fe7fd90f62dcb4b35d0146e90cdd5b5ab80d367986f7c7 + sourceBlobDigest: sha256:a15225f21252c4d0cda133c8bce1992c0ec367b86e34c81f4e7526d07b5253bd +workflow: + workflowVersion: 1.0.0 + speakeasyVersion: latest + sources: + my-source: + inputs: + - location: https://docs.api.epilot.io/file.yaml + registry: + location: registry.speakeasyapi.dev/epilot/epilot/my-source + targets: + terraform: + target: terraform + source: my-source diff --git a/.speakeasy/workflow.yaml b/.speakeasy/workflow.yaml index 6ebb44c..cb056d0 100644 --- a/.speakeasy/workflow.yaml +++ b/.speakeasy/workflow.yaml @@ -1,8 +1,11 @@ workflowVersion: 1.0.0 +speakeasyVersion: latest sources: my-source: inputs: - location: https://docs.api.epilot.io/file.yaml + registry: + location: registry.speakeasyapi.dev/epilot/epilot/my-source targets: terraform: target: terraform diff --git a/README.md b/README.md index d767863..8f0ce26 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ terraform { required_providers { epilot-file = { source = "epilot-dev/epilot-file" - version = "0.5.0" + version = "0.6.0" } } } @@ -112,29 +112,46 @@ provider_installation { ``` + +## Authentication + +This provider supports authentication configuration via provider configuration. + +Available configuration: + +| Provider Attribute | Description | +|---|---| +| `cookie_auth` | Cookie with epilot OAuth2 token. | +| `epilot_auth` | Authorization header with epilot OAuth2 bearer token. | + + ## Available Resources and Data Sources ### Resources -* [epilot-file_file](docs/resources/file.md) ### Data Sources - -* [epilot-file_file](docs/data-sources/file.md) ## Summary File API: Upload and manage epilot Files + +## Changelog +View API Changelog ## Table of Contents + +* [epilot-file](#epilot-file) + * [Installation](#installation) + * [Testing the provider locally](#testing-the-provider-locally) + * [Authentication](#authentication) + * [Available Resources and Data Sources](#available-resources-and-data-sources) + * [Changelog](#changelog) -* [Installation](#installation) -* [Available Resources and Data Sources](#available-resources-and-data-sources) -* [Testing the provider locally](#testing-the-provider-locally) diff --git a/RELEASES.md b/RELEASES.md index 0a3b4a6..5662771 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -14,4 +14,14 @@ Based on: - OpenAPI Doc 0.1.0 - Speakeasy CLI 1.148.0 (2.237.3) https://github.com/speakeasy-api/speakeasy ### Generated -- [terraform v0.1.0] . \ No newline at end of file +- [terraform v0.1.0] . + +## 2025-10-28 00:24:13 +### Changes +Based on: +- OpenAPI Doc +- Speakeasy CLI 1.640.0 (2.730.5) https://github.com/speakeasy-api/speakeasy +### Generated +- [terraform v0.6.0] . +### Releases +- [Terraform v0.6.0] https://registry.terraform.io/providers/epilot-dev/epilot-file/0.6.0 - . \ No newline at end of file diff --git a/docs/data-sources/file.md b/docs/data-sources/file.md deleted file mode 100644 index 3276844..0000000 --- a/docs/data-sources/file.md +++ /dev/null @@ -1,102 +0,0 @@ ---- -# generated by https://github.com/hashicorp/terraform-plugin-docs -page_title: "epilot-file_file Data Source - terraform-provider-epilot-file" -subcategory: "" -description: |- - File DataSource ---- - -# epilot-file_file (Data Source) - -File DataSource - -## Example Usage - -```terraform -data "epilot-file_file" "my_file" { - async = true - id = "ef7d985c-2385-44f4-9c71-ae06a52264f8" - strict = false -} -``` - - -## Schema - -### Optional - -- `async` (Boolean) Don't wait for updated entity to become available in Search API. Useful for large migrations -- `strict` (Boolean) When passed true, the response will contain only fields that match the schema, with non-matching fields included in `__additional` - -### Read-Only - -- `access_control` (String) -- `acl` (Attributes) Access control list (ACL) for an entity. Defines sharing access to external orgs or users. (see [below for nested schema](#nestedatt--acl)) -- `additional` (Map of String) Additional fields that are not part of the schema -- `created_at` (String) -- `custom_download_url` (String) Custom external download url used for the file -- `filename` (String) -- `id` (String) The ID of this resource. -- `manifest` (List of String) Manifest ID used to create/update the entity -- `mime_type` (String) MIME type of the file -- `org` (String) -- `owners` (Attributes List) (see [below for nested schema](#nestedatt--owners)) -- `public_url` (String) Direct URL for file (public only if file access control is public-read) -- `purpose` (List of String) -- `readable_size` (String) Human readable file size -- `s3ref` (Attributes) (see [below for nested schema](#nestedatt--s3ref)) -- `schema` (String) -- `size_bytes` (Number) File size in bytes -- `source_url` (String) Source URL for the file. Included if the entity was created from source_url, or when ?source_url=true -- `tags` (List of String) -- `title` (String) -- `type` (String) -- `updated_at` (String) -- `versions` (Attributes List) (see [below for nested schema](#nestedatt--versions)) - - -### Nested Schema for `acl` - -Read-Only: - -- `delete` (List of String) -- `edit` (List of String) -- `view` (List of String) - - - -### Nested Schema for `owners` - -Read-Only: - -- `org_id` (String) -- `user_id` (String) - - - -### Nested Schema for `s3ref` - -Read-Only: - -- `bucket` (String) -- `key` (String) - - - -### Nested Schema for `versions` - -Read-Only: - -- `filename` (String) -- `mime_type` (String) -- `readable_size` (String) -- `s3ref` (Attributes) (see [below for nested schema](#nestedatt--versions--s3ref)) -- `size_bytes` (Number) - - -### Nested Schema for `versions.s3ref` - -Read-Only: - -- `bucket` (String) -- `key` (String) diff --git a/docs/index.md b/docs/index.md index 3130b5a..6564280 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,15 +1,19 @@ --- # generated by https://github.com/hashicorp/terraform-plugin-docs page_title: "epilot-file Provider" -subcategory: "" description: |- File API: Upload and manage epilot Files + Changelog + View API Changelog --- # epilot-file Provider File API: Upload and manage epilot Files +## Changelog +View API Changelog + ## Example Usage ```terraform @@ -17,7 +21,7 @@ terraform { required_providers { epilot-file = { source = "epilot-dev/epilot-file" - version = "0.5.0" + version = "0.6.0" } } } @@ -32,6 +36,6 @@ provider "epilot-file" { ### Optional -- `cookie_auth` (String, Sensitive) -- `epilot_auth` (String, Sensitive) +- `cookie_auth` (String, Sensitive) Cookie with epilot OAuth2 token. +- `epilot_auth` (String, Sensitive) Authorization header with epilot OAuth2 bearer token. - `server_url` (String) Server URL (defaults to https://file.sls.epilot.io) diff --git a/docs/resources/file.md b/docs/resources/file.md deleted file mode 100644 index d7e0207..0000000 --- a/docs/resources/file.md +++ /dev/null @@ -1,150 +0,0 @@ ---- -# generated by https://github.com/hashicorp/terraform-plugin-docs -page_title: "epilot-file_file Resource - terraform-provider-epilot-file" -subcategory: "" -description: |- - File Resource ---- - -# epilot-file_file (Resource) - -File Resource - -## Example Usage - -```terraform -resource "epilot-file_file" "my_file" { - access_control = "public-read" - acl = { - delete = [ - "org:456" - ] - edit = [ - "org:456" - ] - view = [ - "org:456" - ] - } - activity_id = "01F130Q52Q6MWSNS8N2AVXV4JN" - additional = { - "see" : jsonencode("documentation"), - } - async = true - custom_download_url = "https://some-api-url.com/download?file_id=123" - filename = "document.pdf" - fill_activity = true - id = "ef7d985c-2385-44f4-9c71-ae06a52264f8" - manifest = [ - "123e4567-e89b-12d3-a456-426614174000" - ] - mime_type = "application/pdf" - purpose = [ - "..." - ] - s3ref = { - bucket = "epilot-prod-user-content" - key = "123/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf" - } - source_url = "https://productengineer-content.s3.eu-west-1.amazonaws.com/product-engineer-checklist.pdf" - strict = false - tags = [ - "..." - ] - title = "document.pdf" - type = "font" -} -``` - - -## Schema - -### Optional - -- `access_control` (String) Default: "private"; must be one of ["private", "public-read"] -- `acl` (Attributes) Access control list (ACL) for an entity. Defines sharing access to external orgs or users. (see [below for nested schema](#nestedatt--acl)) -- `activity_id` (String) Activity to include in event feed -- `additional` (Map of String) Additional fields that are not part of the schema -- `async` (Boolean) Don't wait for updated entity to become available in Search API. Useful for large migrations. Default: false -- `custom_download_url` (String) Custom external download url used for the file -- `filename` (String) -- `fill_activity` (Boolean) Update the diff and entity for the custom activity included in the query. -Pending state on activity is automatically ended when activity is filled. -Default: false -- `manifest` (List of String) Manifest ID used to create/update the entity -- `mime_type` (String) MIME type of the file -- `purpose` (List of String) -- `s3ref` (Attributes) (see [below for nested schema](#nestedatt--s3ref)) -- `source_url` (String) Source URL for the file. Included if the entity was created from source_url, or when ?source_url=true -- `strict` (Boolean) When passed true, the response will contain only fields that match the schema, with non-matching fields included in `__additional`. Default: false -- `tags` (List of String) -- `title` (String) -- `type` (String) must be one of ["document", "document_template", "text", "image", "video", "audio", "spreadsheet", "presentation", "font", "archive", "application", "unknown"] - -### Read-Only - -- `created_at` (String) -- `id` (String) The ID of this resource. -- `org` (String) -- `owners` (Attributes List) (see [below for nested schema](#nestedatt--owners)) -- `public_url` (String) Direct URL for file (public only if file access control is public-read) -- `readable_size` (String) Human readable file size -- `schema` (String) must be "file" -- `size_bytes` (Number) File size in bytes -- `updated_at` (String) -- `versions` (Attributes List) (see [below for nested schema](#nestedatt--versions)) - - -### Nested Schema for `acl` - -Optional: - -- `delete` (List of String) -- `edit` (List of String) -- `view` (List of String) - - - -### Nested Schema for `s3ref` - -Optional: - -- `bucket` (String) Not Null -- `key` (String) Not Null - - - -### Nested Schema for `owners` - -Read-Only: - -- `org_id` (String) -- `user_id` (String) - - - -### Nested Schema for `versions` - -Read-Only: - -- `filename` (String) -- `mime_type` (String) -- `readable_size` (String) -- `s3ref` (Attributes) (see [below for nested schema](#nestedatt--versions--s3ref)) -- `size_bytes` (Number) - - -### Nested Schema for `versions.s3ref` - -Read-Only: - -- `bucket` (String) -- `key` (String) - -## Import - -Import is supported using the following syntax: - -```shell -terraform import epilot-file_file.my_epilot-file_file "ef7d985c-2385-44f4-9c71-ae06a52264f8" -``` diff --git a/examples/README.md b/examples/README.md deleted file mode 100644 index f87f5c1..0000000 --- a/examples/README.md +++ /dev/null @@ -1 +0,0 @@ -# TODO \ No newline at end of file diff --git a/examples/data-sources/epilot-file_file/data-source.tf b/examples/data-sources/epilot-file_file/data-source.tf deleted file mode 100644 index 0090c78..0000000 --- a/examples/data-sources/epilot-file_file/data-source.tf +++ /dev/null @@ -1,5 +0,0 @@ -data "epilot-file_file" "my_file" { - async = true - id = "ef7d985c-2385-44f4-9c71-ae06a52264f8" - strict = false -} \ No newline at end of file diff --git a/examples/provider/provider.tf b/examples/provider/provider.tf index 6670b8a..c386459 100644 --- a/examples/provider/provider.tf +++ b/examples/provider/provider.tf @@ -2,7 +2,7 @@ terraform { required_providers { epilot-file = { source = "epilot-dev/epilot-file" - version = "0.5.0" + version = "0.6.0" } } } diff --git a/examples/resources/epilot-file_file/import.sh b/examples/resources/epilot-file_file/import.sh deleted file mode 100644 index 031c010..0000000 --- a/examples/resources/epilot-file_file/import.sh +++ /dev/null @@ -1 +0,0 @@ -terraform import epilot-file_file.my_epilot-file_file "ef7d985c-2385-44f4-9c71-ae06a52264f8" diff --git a/examples/resources/epilot-file_file/resource.tf b/examples/resources/epilot-file_file/resource.tf deleted file mode 100644 index c486b9f..0000000 --- a/examples/resources/epilot-file_file/resource.tf +++ /dev/null @@ -1,41 +0,0 @@ -resource "epilot-file_file" "my_file" { - access_control = "public-read" - acl = { - delete = [ - "org:456" - ] - edit = [ - "org:456" - ] - view = [ - "org:456" - ] - } - activity_id = "01F130Q52Q6MWSNS8N2AVXV4JN" - additional = { - "see" : jsonencode("documentation"), - } - async = true - custom_download_url = "https://some-api-url.com/download?file_id=123" - filename = "document.pdf" - fill_activity = true - id = "ef7d985c-2385-44f4-9c71-ae06a52264f8" - manifest = [ - "123e4567-e89b-12d3-a456-426614174000" - ] - mime_type = "application/pdf" - purpose = [ - "..." - ] - s3ref = { - bucket = "epilot-prod-user-content" - key = "123/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf" - } - source_url = "https://productengineer-content.s3.eu-west-1.amazonaws.com/product-engineer-checklist.pdf" - strict = false - tags = [ - "..." - ] - title = "document.pdf" - type = "font" -} \ No newline at end of file diff --git a/gen.yaml b/gen.yaml index de8daec..a806e06 100644 --- a/gen.yaml +++ b/gen.yaml @@ -3,12 +3,23 @@ generation: sdkClassName: SDK usageSnippets: optionalPropertyRendering: withExample + sdkInitStyle: constructor fixes: - nameResolutionDec2023: false + nameResolutionFeb2025: false parameterOrderingFeb2024: false requestResponseComponentNamesFeb2024: false + securityFeb2025: false + sharedErrorComponentsApr2025: false auth: oAuth2ClientCredentialsEnabled: false + oAuth2PasswordEnabled: false + hoistGlobalSecurity: true + schemas: + allOfMergeStrategy: shallowMerge + tests: + generateTests: true + generateNewTests: false + skipResponseBodyAssertions: false telemetryEnabled: false go: version: 0.0.1 @@ -27,12 +38,19 @@ go: outputModelSuffix: output packageName: openapi terraform: - version: 0.5.0 + version: 0.6.0 additionalDataSources: [] additionalDependencies: {} + additionalEphemeralResources: [] + additionalProviderAttributes: + httpHeaders: "" + tlsSkipVerify: "" additionalResources: [] allowUnknownFieldsInWeakUnions: false author: epilot-dev + baseErrorName: SDKBaseError + defaultErrorName: SDKError + enableTypeDeduplication: true environmentVariables: [] imports: option: openapi @@ -45,3 +63,4 @@ terraform: inputModelSuffix: input outputModelSuffix: output packageName: epilot-file + unionDeserializationStrategy: populated-fields diff --git a/go.mod b/go.mod index 07a48d6..ab84acc 100644 --- a/go.mod +++ b/go.mod @@ -1,14 +1,15 @@ module github.com/epilot-dev/terraform-provider-epilot-file -go 1.22.0 +go 1.23.7 require ( - github.com/cenkalti/backoff/v4 v4.2.0 - github.com/ericlagergren/decimal v0.0.0-20221120152707-495c53812d05 - github.com/hashicorp/terraform-plugin-docs v0.19.4 - github.com/hashicorp/terraform-plugin-framework v1.12.0 - github.com/hashicorp/terraform-plugin-framework-validators v0.13.0 - github.com/hashicorp/terraform-plugin-go v0.24.0 + github.com/hashicorp/go-uuid v1.0.3 + github.com/hashicorp/terraform-plugin-docs v0.22.0 + github.com/hashicorp/terraform-plugin-framework v1.15.1 + github.com/hashicorp/terraform-plugin-framework-validators v0.18.0 + github.com/hashicorp/terraform-plugin-go v0.28.0 + github.com/hashicorp/terraform-plugin-log v0.9.0 + github.com/stretchr/testify v1.8.3 ) require ( @@ -17,58 +18,59 @@ require ( github.com/Masterminds/goutils v1.1.1 // indirect github.com/Masterminds/semver/v3 v3.2.0 // indirect github.com/Masterminds/sprig/v3 v3.2.3 // indirect - github.com/ProtonMail/go-crypto v1.1.0-alpha.2 // indirect + github.com/ProtonMail/go-crypto v1.1.6 // indirect github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect github.com/armon/go-radix v1.0.0 // indirect github.com/bgentry/speakeasy v0.1.0 // indirect - github.com/bmatcuk/doublestar/v4 v4.6.1 // indirect - github.com/cloudflare/circl v1.3.7 // indirect + github.com/bmatcuk/doublestar/v4 v4.8.1 // indirect + github.com/cloudflare/circl v1.6.1 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect github.com/fatih/color v1.16.0 // indirect github.com/golang/protobuf v1.5.4 // indirect github.com/google/uuid v1.6.0 // indirect - github.com/hashicorp/cli v1.1.6 // indirect + github.com/hashicorp/cli v1.1.7 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/go-checkpoint v0.5.0 // indirect github.com/hashicorp/go-cleanhttp v0.5.2 // indirect - github.com/hashicorp/go-hclog v1.5.0 // indirect + github.com/hashicorp/go-hclog v1.6.3 // indirect github.com/hashicorp/go-multierror v1.1.1 // indirect - github.com/hashicorp/go-plugin v1.6.1 // indirect - github.com/hashicorp/go-uuid v1.0.3 // indirect + github.com/hashicorp/go-plugin v1.6.3 // indirect + github.com/hashicorp/go-retryablehttp v0.7.7 // indirect github.com/hashicorp/go-version v1.7.0 // indirect - github.com/hashicorp/hc-install v0.7.0 // indirect - github.com/hashicorp/terraform-exec v0.21.0 // indirect - github.com/hashicorp/terraform-json v0.22.1 // indirect - github.com/hashicorp/terraform-plugin-log v0.9.0 // indirect - github.com/hashicorp/terraform-registry-address v0.2.3 // indirect + github.com/hashicorp/hc-install v0.9.2 // indirect + github.com/hashicorp/terraform-exec v0.23.0 // indirect + github.com/hashicorp/terraform-json v0.25.0 // indirect + github.com/hashicorp/terraform-registry-address v0.2.5 // indirect github.com/hashicorp/terraform-svchost v0.1.1 // indirect github.com/hashicorp/yamux v0.1.1 // indirect github.com/huandu/xstrings v1.3.3 // indirect github.com/imdario/mergo v0.3.15 // indirect - github.com/mattn/go-colorable v0.1.13 // indirect + github.com/mattn/go-colorable v0.1.14 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-runewidth v0.0.9 // indirect github.com/mitchellh/copystructure v1.2.0 // indirect github.com/mitchellh/go-testing-interface v1.14.1 // indirect github.com/mitchellh/reflectwalk v1.0.2 // indirect github.com/oklog/run v1.0.0 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect github.com/posener/complete v1.2.3 // indirect github.com/shopspring/decimal v1.3.1 // indirect github.com/spf13/cast v1.5.0 // indirect github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect - github.com/yuin/goldmark v1.7.1 // indirect + github.com/yuin/goldmark v1.7.7 // indirect github.com/yuin/goldmark-meta v1.1.0 // indirect - github.com/zclconf/go-cty v1.14.4 // indirect + github.com/zclconf/go-cty v1.16.3 // indirect go.abhg.dev/goldmark/frontmatter v0.2.0 // indirect - golang.org/x/crypto v0.24.0 // indirect + golang.org/x/crypto v0.38.0 // indirect golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df // indirect - golang.org/x/mod v0.17.0 // indirect - golang.org/x/net v0.26.0 // indirect - golang.org/x/sys v0.21.0 // indirect - golang.org/x/text v0.16.0 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20240604185151-ef581f913117 // indirect - google.golang.org/grpc v1.66.2 // indirect - google.golang.org/protobuf v1.34.2 // indirect + golang.org/x/mod v0.25.0 // indirect + golang.org/x/net v0.39.0 // indirect + golang.org/x/sys v0.33.0 // indirect + golang.org/x/text v0.26.0 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20250218202821-56aae31c358a // indirect + google.golang.org/grpc v1.72.1 // indirect + google.golang.org/protobuf v1.36.6 // indirect gopkg.in/yaml.v2 v2.3.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index f9e8505..e91839d 100644 --- a/go.sum +++ b/go.sum @@ -10,33 +10,29 @@ github.com/Masterminds/semver/v3 v3.2.0 h1:3MEsd0SM6jqZojhjLWWeBY+Kcjy9i6MQAeY7Y github.com/Masterminds/semver/v3 v3.2.0/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ= github.com/Masterminds/sprig/v3 v3.2.3 h1:eL2fZNezLomi0uOLqjQoN6BfsDD+fyLtgbJMAj9n6YA= github.com/Masterminds/sprig/v3 v3.2.3/go.mod h1:rXcFaZ2zZbLRJv/xSysmlgIM1u11eBaRMhvYXJNkGuM= -github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow= -github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM= -github.com/ProtonMail/go-crypto v1.1.0-alpha.2 h1:bkyFVUP+ROOARdgCiJzNQo2V2kiB97LyUpzH9P6Hrlg= -github.com/ProtonMail/go-crypto v1.1.0-alpha.2/go.mod h1:rA3QumHc/FZ8pAHreoekgiAbzpNsfQAosU5td4SnOrE= +github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY= +github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU= +github.com/ProtonMail/go-crypto v1.1.6 h1:ZcV+Ropw6Qn0AX9brlQLAUXfqLBc7Bl+f/DmNxpLfdw= +github.com/ProtonMail/go-crypto v1.1.6/go.mod h1:rA3QumHc/FZ8pAHreoekgiAbzpNsfQAosU5td4SnOrE= github.com/apparentlymart/go-textseg/v15 v15.0.0 h1:uYvfpb3DyLSCGWnctWKGj857c6ew1u1fNQOlOtuGxQY= github.com/apparentlymart/go-textseg/v15 v15.0.0/go.mod h1:K8XmNZdhEBkdlyDdvbmmsvpAG721bKi0joRfFdHIWJ4= github.com/armon/go-radix v1.0.0 h1:F4z6KzEeeQIMeLFa97iZU6vupzoecKdU5TX24SNppXI= github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= github.com/bgentry/speakeasy v0.1.0 h1:ByYyxL9InA1OWqxJqqp2A5pYHUrCiAL6K3J+LKSsQkY= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= -github.com/bmatcuk/doublestar/v4 v4.6.1 h1:FH9SifrbvJhnlQpztAx++wlkk70QBf0iBWDwNy7PA4I= -github.com/bmatcuk/doublestar/v4 v4.6.1/go.mod h1:xBQ8jztBU6kakFMg+8WGxn0c6z1fTSPVIjEY1Wr7jzc= +github.com/bmatcuk/doublestar/v4 v4.8.1 h1:54Bopc5c2cAvhLRAzqOGCYHYyhcDHsFF4wWIR5wKP38= +github.com/bmatcuk/doublestar/v4 v4.8.1/go.mod h1:xBQ8jztBU6kakFMg+8WGxn0c6z1fTSPVIjEY1Wr7jzc= github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA= github.com/bufbuild/protocompile v0.4.0/go.mod h1:3v93+mbWn/v3xzN+31nwkJfrEpAUwp+BagBSZWx+TP8= -github.com/cenkalti/backoff/v4 v4.2.0 h1:HN5dHm3WBOgndBH6E8V0q2jIYIR3s9yglV8k/+MN3u4= -github.com/cenkalti/backoff/v4 v4.2.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= -github.com/cloudflare/circl v1.3.7 h1:qlCDlTPz2n9fu58M0Nh1J/JzcFpfgkFHHX3O35r5vcU= -github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBSc8r4zxgA= -github.com/cyphar/filepath-securejoin v0.2.4 h1:Ugdm7cg7i6ZK6x3xDF1oEu1nfkyfH53EtKeQYTC3kyg= -github.com/cyphar/filepath-securejoin v0.2.4/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4= +github.com/cloudflare/circl v1.6.1 h1:zqIqSPIndyBh1bjLVVDHMPpVKqp8Su/V+6MeDzzQBQ0= +github.com/cloudflare/circl v1.6.1/go.mod h1:uddAzsPgqdMAYatqJ0lsjX1oECcQLIlRpzZh3pJrofs= +github.com/cyphar/filepath-securejoin v0.4.1 h1:JyxxyPEaktOD+GAnqIqTf9A8tHyAG22rowi7HkoSU1s= +github.com/cyphar/filepath-securejoin v0.4.1/go.mod h1:Sdj7gXlvMcPZsbhwhQ33GguGLDGQL7h7bg04C/+u9jI= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc= github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ= -github.com/ericlagergren/decimal v0.0.0-20221120152707-495c53812d05 h1:S92OBrGuLLZsyM5ybUzgc/mPjIYk2AZqufieooe98uw= -github.com/ericlagergren/decimal v0.0.0-20221120152707-495c53812d05/go.mod h1:M9R1FoZ3y//hwwnJtO51ypFGwm8ZfpxPT/ZLtO1mcgQ= github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM= github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE= @@ -44,21 +40,25 @@ github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3 github.com/frankban/quicktest v1.14.3/go.mod h1:mgiwOwqx65TmIk1wJ6Q7wvnVMocbUorkibMOrVTHZps= github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI= github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376/go.mod h1:an3vInlBmSxCcxctByoQdvwPiA7DTK7jaaFDBTtu0ic= -github.com/go-git/go-billy/v5 v5.5.0 h1:yEY4yhzCDuMGSv83oGxiBotRzhwhNr8VZyphhiu+mTU= -github.com/go-git/go-billy/v5 v5.5.0/go.mod h1:hmexnoNsr2SJU1Ju67OaNz5ASJY3+sHgFRpCtpDCKow= -github.com/go-git/go-git/v5 v5.12.0 h1:7Md+ndsjrzZxbddRDZjF14qK+NN56sy6wkqaVrjZtys= -github.com/go-git/go-git/v5 v5.12.0/go.mod h1:FTM9VKtnI2m65hNI/TenDDDnUf2Q9FHnXYjuz9i5OEY= -github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= -github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/go-git/go-billy/v5 v5.6.2 h1:6Q86EsPXMa7c3YZ3aLAQsMA0VlWmy43r6FHqa/UNbRM= +github.com/go-git/go-billy/v5 v5.6.2/go.mod h1:rcFC2rAsp/erv7CMz9GczHcuD0D32fWzH+MJAU+jaUU= +github.com/go-git/go-git/v5 v5.14.0 h1:/MD3lCrGjCen5WfEAzKg00MJJffKhC8gzS80ycmCi60= +github.com/go-git/go-git/v5 v5.14.0/go.mod h1:Z5Xhoia5PcWA3NF8vRLURn9E5FRhSl7dGj9ItW3Wk5k= +github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= +github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= +github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 h1:f+oWsMOmNPc8JmEHVZIycC7hBoQxHH9pNKQORJNozsQ= +github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8/go.mod h1:wcDNUvekVysuuOpQKo3191zZyTpiI6se1N1ULghS0sw= github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= -github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= -github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= +github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/hashicorp/cli v1.1.6 h1:CMOV+/LJfL1tXCOKrgAX0uRKnzjj/mpmqNXloRSy2K8= -github.com/hashicorp/cli v1.1.6/go.mod h1:MPon5QYlgjjo0BSoAiN0ESeT5fRzDjVRp+uioJ0piz4= +github.com/hashicorp/cli v1.1.7 h1:/fZJ+hNdwfTSfsxMBa9WWMlfjUZbX8/LnUxgAd7lCVU= +github.com/hashicorp/cli v1.1.7/go.mod h1:e6Mfpga9OCT1vqzFuoGZiiF/KaG9CbUfO5s3ghU3YgU= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= @@ -67,36 +67,38 @@ github.com/hashicorp/go-checkpoint v0.5.0/go.mod h1:7nfLNL10NsxqO4iWuW6tWW0HjZuD github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ= github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48= -github.com/hashicorp/go-hclog v1.5.0 h1:bI2ocEMgcVlz55Oj1xZNBsVi900c7II+fWDyV9o+13c= -github.com/hashicorp/go-hclog v1.5.0/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M= +github.com/hashicorp/go-hclog v1.6.3 h1:Qr2kF+eVWjTiYmU7Y31tYlP1h0q/X3Nl3tPGdaB11/k= +github.com/hashicorp/go-hclog v1.6.3/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M= github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= -github.com/hashicorp/go-plugin v1.6.1 h1:P7MR2UP6gNKGPp+y7EZw2kOiq4IR9WiqLvp0XOsVdwI= -github.com/hashicorp/go-plugin v1.6.1/go.mod h1:XPHFku2tFo3o3QKFgSYo+cghcUhw1NA1hZyMK0PWAw0= +github.com/hashicorp/go-plugin v1.6.3 h1:xgHB+ZUSYeuJi96WtxEjzi23uh7YQpznjGh0U0UUrwg= +github.com/hashicorp/go-plugin v1.6.3/go.mod h1:MRobyh+Wc/nYy1V4KAXUiYfzxoYhs7V1mlH1Z7iY2h0= +github.com/hashicorp/go-retryablehttp v0.7.7 h1:C8hUCYzor8PIfXHa4UrZkU4VvK8o9ISHxT2Q8+VepXU= +github.com/hashicorp/go-retryablehttp v0.7.7/go.mod h1:pkQpWZeYWskR+D1tR2O5OcBFOxfA7DoAO6xtkuQnHTk= github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8= github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/go-version v1.7.0 h1:5tqGy27NaOTB8yJKUZELlFAS/LTKJkrmONwQKeRZfjY= github.com/hashicorp/go-version v1.7.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= -github.com/hashicorp/hc-install v0.7.0 h1:Uu9edVqjKQxxuD28mR5TikkKDd/p55S8vzPC1659aBk= -github.com/hashicorp/hc-install v0.7.0/go.mod h1:ELmmzZlGnEcqoUMKUuykHaPCIR1sYLYX+KSggWSKZuA= -github.com/hashicorp/terraform-exec v0.21.0 h1:uNkLAe95ey5Uux6KJdua6+cv8asgILFVWkd/RG0D2XQ= -github.com/hashicorp/terraform-exec v0.21.0/go.mod h1:1PPeMYou+KDUSSeRE9szMZ/oHf4fYUmB923Wzbq1ICg= -github.com/hashicorp/terraform-json v0.22.1 h1:xft84GZR0QzjPVWs4lRUwvTcPnegqlyS7orfb5Ltvec= -github.com/hashicorp/terraform-json v0.22.1/go.mod h1:JbWSQCLFSXFFhg42T7l9iJwdGXBYV8fmmD6o/ML4p3A= -github.com/hashicorp/terraform-plugin-docs v0.19.4 h1:G3Bgo7J22OMtegIgn8Cd/CaSeyEljqjH3G39w28JK4c= -github.com/hashicorp/terraform-plugin-docs v0.19.4/go.mod h1:4pLASsatTmRynVzsjEhbXZ6s7xBlUw/2Kt0zfrq8HxA= -github.com/hashicorp/terraform-plugin-framework v1.12.0 h1:7HKaueHPaikX5/7cbC1r9d1m12iYHY+FlNZEGxQ42CQ= -github.com/hashicorp/terraform-plugin-framework v1.12.0/go.mod h1:N/IOQ2uYjW60Jp39Cp3mw7I/OpC/GfZ0385R0YibmkE= -github.com/hashicorp/terraform-plugin-framework-validators v0.13.0 h1:bxZfGo9DIUoLLtHMElsu+zwqI4IsMZQBRRy4iLzZJ8E= -github.com/hashicorp/terraform-plugin-framework-validators v0.13.0/go.mod h1:wGeI02gEhj9nPANU62F2jCaHjXulejm/X+af4PdZaNo= -github.com/hashicorp/terraform-plugin-go v0.24.0 h1:2WpHhginCdVhFIrWHxDEg6RBn3YaWzR2o6qUeIEat2U= -github.com/hashicorp/terraform-plugin-go v0.24.0/go.mod h1:tUQ53lAsOyYSckFGEefGC5C8BAaO0ENqzFd3bQeuYQg= +github.com/hashicorp/hc-install v0.9.2 h1:v80EtNX4fCVHqzL9Lg/2xkp62bbvQMnvPQ0G+OmtO24= +github.com/hashicorp/hc-install v0.9.2/go.mod h1:XUqBQNnuT4RsxoxiM9ZaUk0NX8hi2h+Lb6/c0OZnC/I= +github.com/hashicorp/terraform-exec v0.23.0 h1:MUiBM1s0CNlRFsCLJuM5wXZrzA3MnPYEsiXmzATMW/I= +github.com/hashicorp/terraform-exec v0.23.0/go.mod h1:mA+qnx1R8eePycfwKkCRk3Wy65mwInvlpAeOwmA7vlY= +github.com/hashicorp/terraform-json v0.25.0 h1:rmNqc/CIfcWawGiwXmRuiXJKEiJu1ntGoxseG1hLhoQ= +github.com/hashicorp/terraform-json v0.25.0/go.mod h1:sMKS8fiRDX4rVlR6EJUMudg1WcanxCMoWwTLkgZP/vc= +github.com/hashicorp/terraform-plugin-docs v0.22.0 h1:fwIDStbFel1PPNkM+mDPnpB4efHZBdGoMz/zt5FbTDw= +github.com/hashicorp/terraform-plugin-docs v0.22.0/go.mod h1:55DJVyZ7BNK4t/lANcQ1YpemRuS6KsvIO1BbGA+xzGE= +github.com/hashicorp/terraform-plugin-framework v1.15.1 h1:2mKDkwb8rlx/tvJTlIcpw0ykcmvdWv+4gY3SIgk8Pq8= +github.com/hashicorp/terraform-plugin-framework v1.15.1/go.mod h1:hxrNI/GY32KPISpWqlCoTLM9JZsGH3CyYlir09bD/fI= +github.com/hashicorp/terraform-plugin-framework-validators v0.18.0 h1:OQnlOt98ua//rCw+QhBbSqfW3QbwtVrcdWeQN5gI3Hw= +github.com/hashicorp/terraform-plugin-framework-validators v0.18.0/go.mod h1:lZvZvagw5hsJwuY7mAY6KUz45/U6fiDR0CzQAwWD0CA= +github.com/hashicorp/terraform-plugin-go v0.28.0 h1:zJmu2UDwhVN0J+J20RE5huiF3XXlTYVIleaevHZgKPA= +github.com/hashicorp/terraform-plugin-go v0.28.0/go.mod h1:FDa2Bb3uumkTGSkTFpWSOwWJDwA7bf3vdP3ltLDTH6o= github.com/hashicorp/terraform-plugin-log v0.9.0 h1:i7hOA+vdAItN1/7UrfBqBwvYPQ9TFvymaRGZED3FCV0= github.com/hashicorp/terraform-plugin-log v0.9.0/go.mod h1:rKL8egZQ/eXSyDqzLUuwUYLVdlYeamldAHSxjUFADow= -github.com/hashicorp/terraform-registry-address v0.2.3 h1:2TAiKJ1A3MAkZlH1YI/aTVcLZRu7JseiXNRHbOAyoTI= -github.com/hashicorp/terraform-registry-address v0.2.3/go.mod h1:lFHA76T8jfQteVfT7caREqguFrW3c4MFSPhZB7HHgUM= +github.com/hashicorp/terraform-registry-address v0.2.5 h1:2GTftHqmUhVOeuu9CW3kwDkRe4pcBDq0uuK5VJngU1M= +github.com/hashicorp/terraform-registry-address v0.2.5/go.mod h1:PpzXWINwB5kuVS5CA7m1+eO2f1jKb5ZDIxrOPfpnGkg= github.com/hashicorp/terraform-svchost v0.1.1 h1:EZZimZ1GxdqFRinZ1tpJwVxxt49xc/S52uzrw4x0jKQ= github.com/hashicorp/terraform-svchost v0.1.1/go.mod h1:mNsjQfZyf/Jhz35v6/0LWcv26+X7JPS+buii2c9/ctc= github.com/hashicorp/yamux v0.1.1 h1:yrQxtgseBDrq9Y652vSRDvsKCJKOUD+GzTS4Y0Y8pvE= @@ -118,11 +120,10 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= -github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= -github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= +github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE= +github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= -github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0= @@ -137,21 +138,21 @@ github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zx github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw= github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA= -github.com/pjbgf/sha1cd v0.3.0 h1:4D5XXmUUBUl/xQ6IjCkEAbqXskkq/4O7LmGn0AqMDs4= -github.com/pjbgf/sha1cd v0.3.0/go.mod h1:nZ1rrWOcGJ5uZgEEVL1VUM9iRQiZvWdbZjkKyFzPPsI= +github.com/pjbgf/sha1cd v0.3.2 h1:a9wb0bp1oC2TGwStyn0Umc/IGKQnEgF0vVaZ8QF8eo4= +github.com/pjbgf/sha1cd v0.3.2/go.mod h1:zQWigSxVmsHEZow5qaLtPYxpcKMMQpa09ixqBxuCS6A= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/posener/complete v1.2.3 h1:NP0eAhjcjImqslEwo/1hq7gpajME0fTLTezBKDqfXqo= github.com/posener/complete v1.2.3/go.mod h1:WZIdtGGp+qx0sLrYKtIRAruyNpv6hFCicSgv7Sy7s/s= -github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= -github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= +github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ= +github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc= github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8= github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4= github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8= github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= -github.com/skeema/knownhosts v1.2.2 h1:Iug2P4fLmDw9f41PB6thxUkNUkJzB5i+1/exaj40L3A= -github.com/skeema/knownhosts v1.2.2/go.mod h1:xYbVRSPxqBZFrdmDyMmsOs+uX1UZC3nTN3ThzgDxUwo= +github.com/skeema/knownhosts v1.3.1 h1:X2osQ+RAjK76shCbvhHHHVl3ZlgDm8apHEHFqRjnBY8= +github.com/skeema/knownhosts v1.3.1/go.mod h1:r7KTdC8l4uxWRyK2TpQZ/1o5HaSzh06ePQNxPwTcfiY= github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= github.com/spf13/cast v1.5.0 h1:rj3WzYc11XZaIZMPKmwP96zkFEnnAmV8s6XbB2aY32w= github.com/spf13/cast v1.5.0/go.mod h1:SpXXQ5YoyJw6s3/6cMTQuxvgRl3PCJiyaX9p6b155UU= @@ -160,8 +161,8 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= -github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= -github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY= +github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/vmihailenco/msgpack/v5 v5.4.1 h1:cQriyiUvjTwOHg8QZaPihLWeRAAVoCpE00IUPn0Bjt8= github.com/vmihailenco/msgpack/v5 v5.4.1/go.mod h1:GaZTsDaehaPpQVyxrf5mtQlH+pc21PIudVV/E3rRQok= github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g= @@ -169,34 +170,44 @@ github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM= github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= -github.com/yuin/goldmark v1.7.1 h1:3bajkSilaCbjdKVsKdZjZCLBNPL9pYzrCakKaf4U49U= -github.com/yuin/goldmark v1.7.1/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E= +github.com/yuin/goldmark v1.7.7 h1:5m9rrB1sW3JUMToKFQfb+FGt1U7r57IHu5GrYrG2nqU= +github.com/yuin/goldmark v1.7.7/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E= github.com/yuin/goldmark-meta v1.1.0 h1:pWw+JLHGZe8Rk0EGsMVssiNb/AaPMHfSRszZeUeiOUc= github.com/yuin/goldmark-meta v1.1.0/go.mod h1:U4spWENafuA7Zyg+Lj5RqK/MF+ovMYtBvXi1lBb2VP0= -github.com/zclconf/go-cty v1.14.4 h1:uXXczd9QDGsgu0i/QFR/hzI5NYCHLf6NQw/atrbnhq8= -github.com/zclconf/go-cty v1.14.4/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE= +github.com/zclconf/go-cty v1.16.3 h1:osr++gw2T61A8KVYHoQiFbFd1Lh3JOCXc/jFLJXKTxk= +github.com/zclconf/go-cty v1.16.3/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE= go.abhg.dev/goldmark/frontmatter v0.2.0 h1:P8kPG0YkL12+aYk2yU3xHv4tcXzeVnN+gU0tJ5JnxRw= go.abhg.dev/goldmark/frontmatter v0.2.0/go.mod h1:XqrEkZuM57djk7zrlRUB02x8I5J0px76YjkOzhB4YlU= +go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA= +go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A= +go.opentelemetry.io/otel v1.34.0 h1:zRLXxLCgL1WyKsPVrgbSdMN4c0FMkDAskSTQP+0hdUY= +go.opentelemetry.io/otel v1.34.0/go.mod h1:OWFPOQ+h4G8xpyjgqo4SxJYdDQ/qmRH+wivy7zzx9oI= +go.opentelemetry.io/otel/metric v1.34.0 h1:+eTR3U0MyfWjRDhmFMxe2SsW64QrZ84AOhvqS7Y+PoQ= +go.opentelemetry.io/otel/metric v1.34.0/go.mod h1:CEDrp0fy2D0MvkXE+dPV7cMi8tWZwX3dmaIhwPOaqHE= +go.opentelemetry.io/otel/sdk v1.34.0 h1:95zS4k/2GOy069d321O8jWgYsW3MzVV+KuSPKp7Wr1A= +go.opentelemetry.io/otel/sdk v1.34.0/go.mod h1:0e/pNiaMAqaykJGKbi+tSjWfNNHMTxoC9qANsCzbyxU= +go.opentelemetry.io/otel/sdk/metric v1.34.0 h1:5CeK9ujjbFVL5c1PhLuStg1wxA7vQv7ce1EK0Gyvahk= +go.opentelemetry.io/otel/sdk/metric v1.34.0/go.mod h1:jQ/r8Ze28zRKoNRdkjCZxfs6YvBTG1+YIqyFVFYec5w= +go.opentelemetry.io/otel/trace v1.34.0 h1:+ouXS2V8Rd4hp4580a8q23bg0azF2nI8cqLYnC8mh/k= +go.opentelemetry.io/otel/trace v1.34.0/go.mod h1:Svm7lSjQD7kG7KJ/MUHPVXSDGz2OX4h0M2jHBhmSfRE= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= -golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI= -golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM= +golang.org/x/crypto v0.38.0 h1:jt+WWG8IZlBnVbomuhg2Mdq0+BBQaHbtqHEFEigjUV8= +golang.org/x/crypto v0.38.0/go.mod h1:MvrbAqul58NNYPKnOra203SB9vpuZW0e+RRZV+Ggqjw= golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df h1:UA2aFVmmsIlefxMk29Dp2juaUSth8Pyn3Tq5Y5mJGME= golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= -golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= -golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/mod v0.25.0 h1:n7a+ZbQKQA/Ysbyb0/6IbB1H/X41mKgbhfv7AfG/44w= +golang.org/x/mod v0.25.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY= -golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ= -golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE= +golang.org/x/net v0.39.0 h1:ZCu7HMWDxpXpaiKdhzIfaltL9Lp31x/3fCP11bc6/fY= +golang.org/x/net v0.39.0/go.mod h1:X7NRbYVEA+ewNkCNyJ513WmMdQ3BineSwVtN2zD/d+E= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= -golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -207,11 +218,10 @@ golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= -golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw= +golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= @@ -219,20 +229,20 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= -golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= +golang.org/x/text v0.26.0 h1:P42AVeLghgTYr4+xUnTRKDMqpar+PtX7KWuNQL21L8M= +golang.org/x/text v0.26.0/go.mod h1:QK15LZJUUQVJxhz7wXgxSy/CJaTFjd0G+YLonydOVQA= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= -golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg= -golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= +golang.org/x/tools v0.33.0 h1:4qz2S3zmRxbGIhDIAgjxvFutSvH5EfnsYrRBj0UI0bc= +golang.org/x/tools v0.33.0/go.mod h1:CIJMaWEY88juyUfo7UbgPqbC8rU2OqfAV1h2Qp0oMYI= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240604185151-ef581f913117 h1:1GBuWVLM/KMVUv1t1En5Gs+gFZCNd360GGb4sSxtrhU= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240604185151-ef581f913117/go.mod h1:EfXuqaE1J41VCDicxHzUDm+8rk+7ZdXzHV0IhO/I6s0= -google.golang.org/grpc v1.66.2 h1:3QdXkuq3Bkh7w+ywLdLvM56cmGvQHUMZpiCzt6Rqaoo= -google.golang.org/grpc v1.66.2/go.mod h1:s3/l6xSSCURdVfAnL+TqCNMyTDAGN6+lZeVxnZR128Y= -google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= -google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= +google.golang.org/genproto/googleapis/rpc v0.0.0-20250218202821-56aae31c358a h1:51aaUVRocpvUOSQKM6Q7VuoaktNIaMCLuhZB6DKksq4= +google.golang.org/genproto/googleapis/rpc v0.0.0-20250218202821-56aae31c358a/go.mod h1:uRxBH1mhmO8PGhU89cMcHaXKZqO+OfakD8QQO0oYwlQ= +google.golang.org/grpc v1.72.1 h1:HR03wO6eyZ7lknl75XlxABNVLLFc2PAb6mHlYh756mA= +google.golang.org/grpc v1.72.1/go.mod h1:wH5Aktxcg25y1I3w7H69nHfXdOG3UiadoBtjh3izSDM= +google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY= +google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME= diff --git a/internal/planmodifiers/float32planmodifier/suppress_diff.go b/internal/planmodifiers/float32planmodifier/suppress_diff.go new file mode 100644 index 0000000..e4ca952 --- /dev/null +++ b/internal/planmodifiers/float32planmodifier/suppress_diff.go @@ -0,0 +1,56 @@ +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + +package float32planmodifier + +import ( + "context" + "github.com/epilot-dev/terraform-provider-epilot-file/internal/planmodifiers/utils" + + "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" +) + +const ( + // ExplicitSuppress strategy suppresses "(known after changes)" messages unless we're in the initial creation + ExplicitSuppress = iota +) + +// SuppressDiff returns a plan modifier that propagates a state value into the planned value, when it is Known, and the Plan Value is Unknown +func SuppressDiff(strategy int) planmodifier.Float32 { + return suppressDiff{ + strategy: strategy, + } +} + +// suppressDiff implements the plan modifier. +type suppressDiff struct { + strategy int +} + +// Description returns a human-readable description of the plan modifier. +func (m suppressDiff) Description(_ context.Context) string { + return "Once set, the value of this attribute in state will not change." +} + +// MarkdownDescription returns a markdown description of the plan modifier. +func (m suppressDiff) MarkdownDescription(_ context.Context) string { + return "Once set, the value of this attribute in state will not change." +} + +// PlanModifyFloat32 implements the plan modification logic. +func (m suppressDiff) PlanModifyFloat32(ctx context.Context, req planmodifier.Float32Request, resp *planmodifier.Float32Response) { + // Do nothing if there is a known planned value. + if !req.PlanValue.IsUnknown() { + return + } + + // Do nothing if there is an unknown configuration value + if req.ConfigValue.IsUnknown() { + return + } + + if utils.IsAllStateUnknown(ctx, req.State) { + return + } + + resp.PlanValue = req.StateValue +} diff --git a/internal/planmodifiers/int32planmodifier/suppress_diff.go b/internal/planmodifiers/int32planmodifier/suppress_diff.go new file mode 100644 index 0000000..7625ded --- /dev/null +++ b/internal/planmodifiers/int32planmodifier/suppress_diff.go @@ -0,0 +1,56 @@ +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + +package int32planmodifier + +import ( + "context" + "github.com/epilot-dev/terraform-provider-epilot-file/internal/planmodifiers/utils" + + "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" +) + +const ( + // ExplicitSuppress strategy suppresses "(known after changes)" messages unless we're in the initial creation + ExplicitSuppress = iota +) + +// SuppressDiff returns a plan modifier that propagates a state value into the planned value, when it is Known, and the Plan Value is Unknown +func SuppressDiff(strategy int) planmodifier.Int32 { + return suppressDiff{ + strategy: strategy, + } +} + +// suppressDiff implements the plan modifier. +type suppressDiff struct { + strategy int +} + +// Description returns a human-readable description of the plan modifier. +func (m suppressDiff) Description(_ context.Context) string { + return "Once set, the value of this attribute in state will not change." +} + +// MarkdownDescription returns a markdown description of the plan modifier. +func (m suppressDiff) MarkdownDescription(_ context.Context) string { + return "Once set, the value of this attribute in state will not change." +} + +// PlanModifyInt32 implements the plan modification logic. +func (m suppressDiff) PlanModifyInt32(ctx context.Context, req planmodifier.Int32Request, resp *planmodifier.Int32Response) { + // Do nothing if there is a known planned value. + if !req.PlanValue.IsUnknown() { + return + } + + // Do nothing if there is an unknown configuration value + if req.ConfigValue.IsUnknown() { + return + } + + if utils.IsAllStateUnknown(ctx, req.State) { + return + } + + resp.PlanValue = req.StateValue +} diff --git a/internal/planmodifiers/utils/state_check.go b/internal/planmodifiers/utils/state_check.go index 51d5362..0ea64fb 100644 --- a/internal/planmodifiers/utils/state_check.go +++ b/internal/planmodifiers/utils/state_check.go @@ -4,6 +4,7 @@ package utils import ( "context" + "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/tfsdk" @@ -12,7 +13,7 @@ import ( func IsAllStateUnknown(ctx context.Context, state tfsdk.State) bool { attrs := state.Schema.GetAttributes() anyFound := false - for k, _ := range attrs { + for k := range attrs { attrValue := new(attr.Value) state.GetAttribute(ctx, path.Root(k), attrValue) if attrValue != nil && !(*attrValue).IsUnknown() && !(*attrValue).IsNull() { diff --git a/internal/provider/file_data_source.go b/internal/provider/file_data_source.go deleted file mode 100644 index 91c4bfc..0000000 --- a/internal/provider/file_data_source.go +++ /dev/null @@ -1,311 +0,0 @@ -// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. - -package provider - -import ( - "context" - "fmt" - tfTypes "github.com/epilot-dev/terraform-provider-epilot-file/internal/provider/types" - "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk" - "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/models/operations" - "github.com/hashicorp/terraform-plugin-framework/datasource" - "github.com/hashicorp/terraform-plugin-framework/datasource/schema" - "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/hashicorp/terraform-plugin-framework/types/basetypes" -) - -// Ensure provider defined types fully satisfy framework interfaces. -var _ datasource.DataSource = &FileDataSource{} -var _ datasource.DataSourceWithConfigure = &FileDataSource{} - -func NewFileDataSource() datasource.DataSource { - return &FileDataSource{} -} - -// FileDataSource is the data source implementation. -type FileDataSource struct { - client *sdk.SDK -} - -// FileDataSourceModel describes the data model. -type FileDataSourceModel struct { - AccessControl types.String `tfsdk:"access_control"` - ACL *tfTypes.BaseEntityACL `tfsdk:"acl"` - Additional map[string]types.String `tfsdk:"additional"` - Async types.Bool `tfsdk:"async"` - CreatedAt types.String `tfsdk:"created_at"` - CustomDownloadURL types.String `tfsdk:"custom_download_url"` - Filename types.String `tfsdk:"filename"` - ID types.String `tfsdk:"id"` - Manifest []types.String `tfsdk:"manifest"` - MimeType types.String `tfsdk:"mime_type"` - Org types.String `tfsdk:"org"` - Owners []tfTypes.BaseEntityOwner `tfsdk:"owners"` - PublicURL types.String `tfsdk:"public_url"` - Purpose []types.String `tfsdk:"purpose"` - ReadableSize types.String `tfsdk:"readable_size"` - S3ref *tfTypes.S3Ref `tfsdk:"s3ref"` - Schema types.String `tfsdk:"schema"` - SizeBytes types.Int64 `tfsdk:"size_bytes"` - SourceURL types.String `tfsdk:"source_url"` - Strict types.Bool `tfsdk:"strict"` - Tags []types.String `tfsdk:"tags"` - Title types.String `tfsdk:"title"` - Type types.String `tfsdk:"type"` - UpdatedAt types.String `tfsdk:"updated_at"` - Versions []tfTypes.FileItem `tfsdk:"versions"` -} - -// Metadata returns the data source type name. -func (r *FileDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { - resp.TypeName = req.ProviderTypeName + "_file" -} - -// Schema defines the schema for the data source. -func (r *FileDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { - resp.Schema = schema.Schema{ - MarkdownDescription: "File DataSource", - - Attributes: map[string]schema.Attribute{ - "access_control": schema.StringAttribute{ - Computed: true, - }, - "acl": schema.SingleNestedAttribute{ - Computed: true, - Attributes: map[string]schema.Attribute{ - "delete": schema.ListAttribute{ - Computed: true, - ElementType: types.StringType, - }, - "edit": schema.ListAttribute{ - Computed: true, - ElementType: types.StringType, - }, - "view": schema.ListAttribute{ - Computed: true, - ElementType: types.StringType, - }, - }, - Description: `Access control list (ACL) for an entity. Defines sharing access to external orgs or users.`, - }, - "additional": schema.MapAttribute{ - Computed: true, - ElementType: types.StringType, - Description: `Additional fields that are not part of the schema`, - }, - "async": schema.BoolAttribute{ - Computed: true, - Optional: true, - Description: `Don't wait for updated entity to become available in Search API. Useful for large migrations`, - }, - "created_at": schema.StringAttribute{ - Computed: true, - }, - "custom_download_url": schema.StringAttribute{ - Computed: true, - Description: `Custom external download url used for the file`, - }, - "filename": schema.StringAttribute{ - Computed: true, - }, - "id": schema.StringAttribute{ - Required: true, - }, - "manifest": schema.ListAttribute{ - Computed: true, - ElementType: types.StringType, - Description: `Manifest ID used to create/update the entity`, - }, - "mime_type": schema.StringAttribute{ - Computed: true, - Description: `MIME type of the file`, - }, - "org": schema.StringAttribute{ - Computed: true, - }, - "owners": schema.ListNestedAttribute{ - Computed: true, - NestedObject: schema.NestedAttributeObject{ - Attributes: map[string]schema.Attribute{ - "org_id": schema.StringAttribute{ - Computed: true, - }, - "user_id": schema.StringAttribute{ - Computed: true, - }, - }, - }, - }, - "public_url": schema.StringAttribute{ - Computed: true, - Description: `Direct URL for file (public only if file access control is public-read)`, - }, - "purpose": schema.ListAttribute{ - Computed: true, - ElementType: types.StringType, - }, - "readable_size": schema.StringAttribute{ - Computed: true, - Description: `Human readable file size`, - }, - "s3ref": schema.SingleNestedAttribute{ - Computed: true, - Attributes: map[string]schema.Attribute{ - "bucket": schema.StringAttribute{ - Computed: true, - }, - "key": schema.StringAttribute{ - Computed: true, - }, - }, - }, - "schema": schema.StringAttribute{ - Computed: true, - }, - "size_bytes": schema.Int64Attribute{ - Computed: true, - Description: `File size in bytes`, - }, - "source_url": schema.StringAttribute{ - Computed: true, - Description: `Source URL for the file. Included if the entity was created from source_url, or when ?source_url=true`, - }, - "strict": schema.BoolAttribute{ - Computed: true, - Optional: true, - Description: `When passed true, the response will contain only fields that match the schema, with non-matching fields included in ` + "`" + `__additional` + "`" + ``, - }, - "tags": schema.ListAttribute{ - Computed: true, - ElementType: types.StringType, - }, - "title": schema.StringAttribute{ - Computed: true, - }, - "type": schema.StringAttribute{ - Computed: true, - }, - "updated_at": schema.StringAttribute{ - Computed: true, - }, - "versions": schema.ListNestedAttribute{ - Computed: true, - NestedObject: schema.NestedAttributeObject{ - Attributes: map[string]schema.Attribute{ - "filename": schema.StringAttribute{ - Computed: true, - }, - "mime_type": schema.StringAttribute{ - Computed: true, - }, - "readable_size": schema.StringAttribute{ - Computed: true, - }, - "s3ref": schema.SingleNestedAttribute{ - Computed: true, - Attributes: map[string]schema.Attribute{ - "bucket": schema.StringAttribute{ - Computed: true, - }, - "key": schema.StringAttribute{ - Computed: true, - }, - }, - }, - "size_bytes": schema.Int64Attribute{ - Computed: true, - }, - }, - }, - }, - }, - } -} - -func (r *FileDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { - // Prevent panic if the provider has not been configured. - if req.ProviderData == nil { - return - } - - client, ok := req.ProviderData.(*sdk.SDK) - - if !ok { - resp.Diagnostics.AddError( - "Unexpected DataSource Configure Type", - fmt.Sprintf("Expected *sdk.SDK, got: %T. Please report this issue to the provider developers.", req.ProviderData), - ) - - return - } - - r.client = client -} - -func (r *FileDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { - var data *FileDataSourceModel - var item types.Object - - resp.Diagnostics.Append(req.Config.Get(ctx, &item)...) - if resp.Diagnostics.HasError() { - return - } - - resp.Diagnostics.Append(item.As(ctx, &data, basetypes.ObjectAsOptions{ - UnhandledNullAsEmpty: true, - UnhandledUnknownAsEmpty: true, - })...) - - if resp.Diagnostics.HasError() { - return - } - - async := new(bool) - if !data.Async.IsUnknown() && !data.Async.IsNull() { - *async = data.Async.ValueBool() - } else { - async = nil - } - var id string - id = data.ID.ValueString() - - strict := new(bool) - if !data.Strict.IsUnknown() && !data.Strict.IsNull() { - *strict = data.Strict.ValueBool() - } else { - strict = nil - } - request := operations.GetFileRequest{ - Async: async, - ID: id, - Strict: strict, - } - res, err := r.client.File.GetFile(ctx, request) - if err != nil { - resp.Diagnostics.AddError("failure to invoke API", err.Error()) - if res != nil && res.RawResponse != nil { - resp.Diagnostics.AddError("unexpected http request/response", debugResponse(res.RawResponse)) - } - return - } - if res == nil { - resp.Diagnostics.AddError("unexpected response from API", fmt.Sprintf("%v", res)) - return - } - if res.StatusCode == 404 { - resp.State.RemoveResource(ctx) - return - } - if res.StatusCode != 200 { - resp.Diagnostics.AddError(fmt.Sprintf("unexpected response from API. Got an unexpected response code %v", res.StatusCode), debugResponse(res.RawResponse)) - return - } - if !(res.FileEntity != nil) { - resp.Diagnostics.AddError("unexpected response from API. Got an unexpected response body", debugResponse(res.RawResponse)) - return - } - data.RefreshFromSharedFileEntity(res.FileEntity) - - // Save updated data into Terraform state - resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) -} diff --git a/internal/provider/file_data_source_sdk.go b/internal/provider/file_data_source_sdk.go deleted file mode 100644 index 4d3623b..0000000 --- a/internal/provider/file_data_source_sdk.go +++ /dev/null @@ -1,136 +0,0 @@ -// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. - -package provider - -import ( - "encoding/json" - tfTypes "github.com/epilot-dev/terraform-provider-epilot-file/internal/provider/types" - "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/models/shared" - "github.com/hashicorp/terraform-plugin-framework/types" - "time" -) - -func (r *FileDataSourceModel) RefreshFromSharedFileEntity(resp *shared.FileEntity) { - if resp != nil { - if len(resp.Additional) > 0 { - r.Additional = make(map[string]types.String) - for key, value := range resp.Additional { - result, _ := json.Marshal(value) - r.Additional[key] = types.StringValue(string(result)) - } - } - if resp.ACL == nil { - r.ACL = nil - } else { - r.ACL = &tfTypes.BaseEntityACL{} - r.ACL.Delete = []types.String{} - for _, v := range resp.ACL.Delete { - r.ACL.Delete = append(r.ACL.Delete, types.StringValue(v)) - } - r.ACL.Edit = []types.String{} - for _, v := range resp.ACL.Edit { - r.ACL.Edit = append(r.ACL.Edit, types.StringValue(v)) - } - r.ACL.View = []types.String{} - for _, v := range resp.ACL.View { - r.ACL.View = append(r.ACL.View, types.StringValue(v)) - } - } - if resp.CreatedAt != nil { - r.CreatedAt = types.StringValue(resp.CreatedAt.Format(time.RFC3339Nano)) - } else { - r.CreatedAt = types.StringNull() - } - r.Manifest = []types.String{} - for _, v := range resp.Manifest { - r.Manifest = append(r.Manifest, types.StringValue(v)) - } - r.Org = types.StringPointerValue(resp.Org) - r.Owners = []tfTypes.BaseEntityOwner{} - if len(r.Owners) > len(resp.Owners) { - r.Owners = r.Owners[:len(resp.Owners)] - } - for ownersCount, ownersItem := range resp.Owners { - var owners1 tfTypes.BaseEntityOwner - owners1.OrgID = types.StringValue(ownersItem.OrgID) - owners1.UserID = types.StringPointerValue(ownersItem.UserID) - if ownersCount+1 > len(r.Owners) { - r.Owners = append(r.Owners, owners1) - } else { - r.Owners[ownersCount].OrgID = owners1.OrgID - r.Owners[ownersCount].UserID = owners1.UserID - } - } - r.Purpose = []types.String{} - for _, v := range resp.Purpose { - r.Purpose = append(r.Purpose, types.StringValue(v)) - } - if resp.Schema != nil { - r.Schema = types.StringValue(string(*resp.Schema)) - } else { - r.Schema = types.StringNull() - } - r.Tags = []types.String{} - for _, v := range resp.Tags { - r.Tags = append(r.Tags, types.StringValue(v)) - } - r.Title = types.StringPointerValue(resp.Title) - if resp.UpdatedAt != nil { - r.UpdatedAt = types.StringValue(resp.UpdatedAt.Format(time.RFC3339Nano)) - } else { - r.UpdatedAt = types.StringNull() - } - if resp.AccessControl != nil { - r.AccessControl = types.StringValue(string(*resp.AccessControl)) - } else { - r.AccessControl = types.StringNull() - } - r.CustomDownloadURL = types.StringPointerValue(resp.CustomDownloadURL) - r.Filename = types.StringPointerValue(resp.Filename) - r.ID = types.StringPointerValue(resp.ID) - r.MimeType = types.StringPointerValue(resp.MimeType) - r.PublicURL = types.StringPointerValue(resp.PublicURL) - r.ReadableSize = types.StringPointerValue(resp.ReadableSize) - if resp.S3ref == nil { - r.S3ref = nil - } else { - r.S3ref = &tfTypes.S3Ref{} - r.S3ref.Bucket = types.StringValue(resp.S3ref.Bucket) - r.S3ref.Key = types.StringValue(resp.S3ref.Key) - } - r.SizeBytes = types.Int64PointerValue(resp.SizeBytes) - r.SourceURL = types.StringPointerValue(resp.SourceURL) - if resp.Type != nil { - r.Type = types.StringValue(string(*resp.Type)) - } else { - r.Type = types.StringNull() - } - r.Versions = []tfTypes.FileItem{} - if len(r.Versions) > len(resp.Versions) { - r.Versions = r.Versions[:len(resp.Versions)] - } - for versionsCount, versionsItem := range resp.Versions { - var versions1 tfTypes.FileItem - versions1.Filename = types.StringPointerValue(versionsItem.Filename) - versions1.MimeType = types.StringPointerValue(versionsItem.MimeType) - versions1.ReadableSize = types.StringPointerValue(versionsItem.ReadableSize) - if versionsItem.S3ref == nil { - versions1.S3ref = nil - } else { - versions1.S3ref = &tfTypes.S3Ref{} - versions1.S3ref.Bucket = types.StringValue(versionsItem.S3ref.Bucket) - versions1.S3ref.Key = types.StringValue(versionsItem.S3ref.Key) - } - versions1.SizeBytes = types.Int64PointerValue(versionsItem.SizeBytes) - if versionsCount+1 > len(r.Versions) { - r.Versions = append(r.Versions, versions1) - } else { - r.Versions[versionsCount].Filename = versions1.Filename - r.Versions[versionsCount].MimeType = versions1.MimeType - r.Versions[versionsCount].ReadableSize = versions1.ReadableSize - r.Versions[versionsCount].S3ref = versions1.S3ref - r.Versions[versionsCount].SizeBytes = versions1.SizeBytes - } - } - } -} diff --git a/internal/provider/file_resource.go b/internal/provider/file_resource.go deleted file mode 100644 index 8f0a083..0000000 --- a/internal/provider/file_resource.go +++ /dev/null @@ -1,815 +0,0 @@ -// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. - -package provider - -import ( - "context" - "fmt" - speakeasy_int64planmodifier "github.com/epilot-dev/terraform-provider-epilot-file/internal/planmodifiers/int64planmodifier" - speakeasy_listplanmodifier "github.com/epilot-dev/terraform-provider-epilot-file/internal/planmodifiers/listplanmodifier" - speakeasy_mapplanmodifier "github.com/epilot-dev/terraform-provider-epilot-file/internal/planmodifiers/mapplanmodifier" - speakeasy_objectplanmodifier "github.com/epilot-dev/terraform-provider-epilot-file/internal/planmodifiers/objectplanmodifier" - speakeasy_stringplanmodifier "github.com/epilot-dev/terraform-provider-epilot-file/internal/planmodifiers/stringplanmodifier" - tfTypes "github.com/epilot-dev/terraform-provider-epilot-file/internal/provider/types" - "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk" - "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/models/operations" - "github.com/epilot-dev/terraform-provider-epilot-file/internal/validators" - speakeasy_stringvalidators "github.com/epilot-dev/terraform-provider-epilot-file/internal/validators/stringvalidators" - "github.com/hashicorp/terraform-plugin-framework-validators/mapvalidator" - "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" - "github.com/hashicorp/terraform-plugin-framework/path" - "github.com/hashicorp/terraform-plugin-framework/resource" - "github.com/hashicorp/terraform-plugin-framework/resource/schema" - "github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault" - "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" - "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault" - "github.com/hashicorp/terraform-plugin-framework/schema/validator" - "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/hashicorp/terraform-plugin-framework/types/basetypes" -) - -// Ensure provider defined types fully satisfy framework interfaces. -var _ resource.Resource = &FileResource{} -var _ resource.ResourceWithImportState = &FileResource{} - -func NewFileResource() resource.Resource { - return &FileResource{} -} - -// FileResource defines the resource implementation. -type FileResource struct { - client *sdk.SDK -} - -// FileResourceModel describes the resource data model. -type FileResourceModel struct { - AccessControl types.String `tfsdk:"access_control"` - ACL *tfTypes.BaseEntityACL `tfsdk:"acl"` - ActivityID types.String `tfsdk:"activity_id"` - Additional map[string]types.String `tfsdk:"additional"` - Async types.Bool `tfsdk:"async"` - CreatedAt types.String `tfsdk:"created_at"` - CustomDownloadURL types.String `tfsdk:"custom_download_url"` - Filename types.String `tfsdk:"filename"` - FillActivity types.Bool `tfsdk:"fill_activity"` - ID types.String `tfsdk:"id"` - Manifest []types.String `tfsdk:"manifest"` - MimeType types.String `tfsdk:"mime_type"` - Org types.String `tfsdk:"org"` - Owners []tfTypes.BaseEntityOwner `tfsdk:"owners"` - PublicURL types.String `tfsdk:"public_url"` - Purpose []types.String `tfsdk:"purpose"` - ReadableSize types.String `tfsdk:"readable_size"` - S3ref *tfTypes.S3Ref `tfsdk:"s3ref"` - Schema types.String `tfsdk:"schema"` - SizeBytes types.Int64 `tfsdk:"size_bytes"` - SourceURL types.String `tfsdk:"source_url"` - Strict types.Bool `tfsdk:"strict"` - Tags []types.String `tfsdk:"tags"` - Title types.String `tfsdk:"title"` - Type types.String `tfsdk:"type"` - UpdatedAt types.String `tfsdk:"updated_at"` - Versions []tfTypes.FileItem `tfsdk:"versions"` -} - -func (r *FileResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { - resp.TypeName = req.ProviderTypeName + "_file" -} - -func (r *FileResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { - resp.Schema = schema.Schema{ - MarkdownDescription: "File Resource", - Attributes: map[string]schema.Attribute{ - "access_control": schema.StringAttribute{ - Computed: true, - Optional: true, - Default: stringdefault.StaticString("private"), - PlanModifiers: []planmodifier.String{ - speakeasy_stringplanmodifier.SuppressDiff(speakeasy_stringplanmodifier.ExplicitSuppress), - }, - Description: `Default: "private"; must be one of ["private", "public-read"]`, - Validators: []validator.String{ - stringvalidator.OneOf( - "private", - "public-read", - ), - }, - }, - "acl": schema.SingleNestedAttribute{ - Computed: true, - Optional: true, - PlanModifiers: []planmodifier.Object{ - speakeasy_objectplanmodifier.SuppressDiff(speakeasy_objectplanmodifier.ExplicitSuppress), - }, - Attributes: map[string]schema.Attribute{ - "delete": schema.ListAttribute{ - Computed: true, - Optional: true, - PlanModifiers: []planmodifier.List{ - speakeasy_listplanmodifier.SuppressDiff(speakeasy_listplanmodifier.ExplicitSuppress), - }, - ElementType: types.StringType, - }, - "edit": schema.ListAttribute{ - Computed: true, - Optional: true, - PlanModifiers: []planmodifier.List{ - speakeasy_listplanmodifier.SuppressDiff(speakeasy_listplanmodifier.ExplicitSuppress), - }, - ElementType: types.StringType, - }, - "view": schema.ListAttribute{ - Computed: true, - Optional: true, - PlanModifiers: []planmodifier.List{ - speakeasy_listplanmodifier.SuppressDiff(speakeasy_listplanmodifier.ExplicitSuppress), - }, - ElementType: types.StringType, - }, - }, - Description: `Access control list (ACL) for an entity. Defines sharing access to external orgs or users.`, - }, - "activity_id": schema.StringAttribute{ - Optional: true, - Description: `Activity to include in event feed`, - }, - "additional": schema.MapAttribute{ - Computed: true, - Optional: true, - PlanModifiers: []planmodifier.Map{ - speakeasy_mapplanmodifier.SuppressDiff(speakeasy_mapplanmodifier.ExplicitSuppress), - }, - ElementType: types.StringType, - Description: `Additional fields that are not part of the schema`, - Validators: []validator.Map{ - mapvalidator.ValueStringsAre(validators.IsValidJSON()), - }, - }, - "async": schema.BoolAttribute{ - Computed: true, - Optional: true, - Default: booldefault.StaticBool(false), - Description: `Don't wait for updated entity to become available in Search API. Useful for large migrations. Default: false`, - }, - "created_at": schema.StringAttribute{ - Computed: true, - PlanModifiers: []planmodifier.String{ - speakeasy_stringplanmodifier.SuppressDiff(speakeasy_stringplanmodifier.ExplicitSuppress), - }, - Validators: []validator.String{ - validators.IsRFC3339(), - }, - }, - "custom_download_url": schema.StringAttribute{ - Computed: true, - Optional: true, - PlanModifiers: []planmodifier.String{ - speakeasy_stringplanmodifier.SuppressDiff(speakeasy_stringplanmodifier.ExplicitSuppress), - }, - Description: `Custom external download url used for the file`, - }, - "filename": schema.StringAttribute{ - Computed: true, - Optional: true, - PlanModifiers: []planmodifier.String{ - speakeasy_stringplanmodifier.SuppressDiff(speakeasy_stringplanmodifier.ExplicitSuppress), - }, - }, - "fill_activity": schema.BoolAttribute{ - Computed: true, - Optional: true, - Default: booldefault.StaticBool(false), - MarkdownDescription: `Update the diff and entity for the custom activity included in the query.` + "\n" + - `Pending state on activity is automatically ended when activity is filled.` + "\n" + - `Default: false`, - }, - "id": schema.StringAttribute{ - Computed: true, - Optional: true, - PlanModifiers: []planmodifier.String{ - speakeasy_stringplanmodifier.SuppressDiff(speakeasy_stringplanmodifier.ExplicitSuppress), - }, - }, - "manifest": schema.ListAttribute{ - Computed: true, - Optional: true, - PlanModifiers: []planmodifier.List{ - speakeasy_listplanmodifier.SuppressDiff(speakeasy_listplanmodifier.ExplicitSuppress), - }, - ElementType: types.StringType, - Description: `Manifest ID used to create/update the entity`, - }, - "mime_type": schema.StringAttribute{ - Computed: true, - Optional: true, - PlanModifiers: []planmodifier.String{ - speakeasy_stringplanmodifier.SuppressDiff(speakeasy_stringplanmodifier.ExplicitSuppress), - }, - Description: `MIME type of the file`, - }, - "org": schema.StringAttribute{ - Computed: true, - PlanModifiers: []planmodifier.String{ - speakeasy_stringplanmodifier.SuppressDiff(speakeasy_stringplanmodifier.ExplicitSuppress), - }, - }, - "owners": schema.ListNestedAttribute{ - Computed: true, - PlanModifiers: []planmodifier.List{ - speakeasy_listplanmodifier.SuppressDiff(speakeasy_listplanmodifier.ExplicitSuppress), - }, - NestedObject: schema.NestedAttributeObject{ - PlanModifiers: []planmodifier.Object{ - speakeasy_objectplanmodifier.SuppressDiff(speakeasy_objectplanmodifier.ExplicitSuppress), - }, - Attributes: map[string]schema.Attribute{ - "org_id": schema.StringAttribute{ - Computed: true, - PlanModifiers: []planmodifier.String{ - speakeasy_stringplanmodifier.SuppressDiff(speakeasy_stringplanmodifier.ExplicitSuppress), - }, - }, - "user_id": schema.StringAttribute{ - Computed: true, - PlanModifiers: []planmodifier.String{ - speakeasy_stringplanmodifier.SuppressDiff(speakeasy_stringplanmodifier.ExplicitSuppress), - }, - }, - }, - }, - }, - "public_url": schema.StringAttribute{ - Computed: true, - PlanModifiers: []planmodifier.String{ - speakeasy_stringplanmodifier.SuppressDiff(speakeasy_stringplanmodifier.ExplicitSuppress), - }, - Description: `Direct URL for file (public only if file access control is public-read)`, - }, - "purpose": schema.ListAttribute{ - Computed: true, - Optional: true, - PlanModifiers: []planmodifier.List{ - speakeasy_listplanmodifier.SuppressDiff(speakeasy_listplanmodifier.ExplicitSuppress), - }, - ElementType: types.StringType, - }, - "readable_size": schema.StringAttribute{ - Computed: true, - PlanModifiers: []planmodifier.String{ - speakeasy_stringplanmodifier.SuppressDiff(speakeasy_stringplanmodifier.ExplicitSuppress), - }, - Description: `Human readable file size`, - }, - "s3ref": schema.SingleNestedAttribute{ - Computed: true, - Optional: true, - PlanModifiers: []planmodifier.Object{ - speakeasy_objectplanmodifier.SuppressDiff(speakeasy_objectplanmodifier.ExplicitSuppress), - }, - Attributes: map[string]schema.Attribute{ - "bucket": schema.StringAttribute{ - Computed: true, - Optional: true, - PlanModifiers: []planmodifier.String{ - speakeasy_stringplanmodifier.SuppressDiff(speakeasy_stringplanmodifier.ExplicitSuppress), - }, - Description: `Not Null`, - Validators: []validator.String{ - speakeasy_stringvalidators.NotNull(), - }, - }, - "key": schema.StringAttribute{ - Computed: true, - Optional: true, - PlanModifiers: []planmodifier.String{ - speakeasy_stringplanmodifier.SuppressDiff(speakeasy_stringplanmodifier.ExplicitSuppress), - }, - Description: `Not Null`, - Validators: []validator.String{ - speakeasy_stringvalidators.NotNull(), - }, - }, - }, - }, - "schema": schema.StringAttribute{ - Computed: true, - PlanModifiers: []planmodifier.String{ - speakeasy_stringplanmodifier.SuppressDiff(speakeasy_stringplanmodifier.ExplicitSuppress), - }, - Description: `must be "file"`, - Validators: []validator.String{ - stringvalidator.OneOf("file"), - }, - }, - "size_bytes": schema.Int64Attribute{ - Computed: true, - PlanModifiers: []planmodifier.Int64{ - speakeasy_int64planmodifier.SuppressDiff(speakeasy_int64planmodifier.ExplicitSuppress), - }, - Description: `File size in bytes`, - }, - "source_url": schema.StringAttribute{ - Computed: true, - Optional: true, - PlanModifiers: []planmodifier.String{ - speakeasy_stringplanmodifier.SuppressDiff(speakeasy_stringplanmodifier.ExplicitSuppress), - }, - Description: `Source URL for the file. Included if the entity was created from source_url, or when ?source_url=true`, - }, - "strict": schema.BoolAttribute{ - Computed: true, - Optional: true, - Default: booldefault.StaticBool(false), - Description: `When passed true, the response will contain only fields that match the schema, with non-matching fields included in ` + "`" + `__additional` + "`" + `. Default: false`, - }, - "tags": schema.ListAttribute{ - Computed: true, - Optional: true, - PlanModifiers: []planmodifier.List{ - speakeasy_listplanmodifier.SuppressDiff(speakeasy_listplanmodifier.ExplicitSuppress), - }, - ElementType: types.StringType, - }, - "title": schema.StringAttribute{ - Computed: true, - Optional: true, - PlanModifiers: []planmodifier.String{ - speakeasy_stringplanmodifier.SuppressDiff(speakeasy_stringplanmodifier.ExplicitSuppress), - }, - }, - "type": schema.StringAttribute{ - Computed: true, - Optional: true, - PlanModifiers: []planmodifier.String{ - speakeasy_stringplanmodifier.SuppressDiff(speakeasy_stringplanmodifier.ExplicitSuppress), - }, - Description: `must be one of ["document", "document_template", "text", "image", "video", "audio", "spreadsheet", "presentation", "font", "archive", "application", "unknown"]`, - Validators: []validator.String{ - stringvalidator.OneOf( - "document", - "document_template", - "text", - "image", - "video", - "audio", - "spreadsheet", - "presentation", - "font", - "archive", - "application", - "unknown", - ), - }, - }, - "updated_at": schema.StringAttribute{ - Computed: true, - PlanModifiers: []planmodifier.String{ - speakeasy_stringplanmodifier.SuppressDiff(speakeasy_stringplanmodifier.ExplicitSuppress), - }, - Validators: []validator.String{ - validators.IsRFC3339(), - }, - }, - "versions": schema.ListNestedAttribute{ - Computed: true, - PlanModifiers: []planmodifier.List{ - speakeasy_listplanmodifier.SuppressDiff(speakeasy_listplanmodifier.ExplicitSuppress), - }, - NestedObject: schema.NestedAttributeObject{ - PlanModifiers: []planmodifier.Object{ - speakeasy_objectplanmodifier.SuppressDiff(speakeasy_objectplanmodifier.ExplicitSuppress), - }, - Attributes: map[string]schema.Attribute{ - "filename": schema.StringAttribute{ - Computed: true, - PlanModifiers: []planmodifier.String{ - speakeasy_stringplanmodifier.SuppressDiff(speakeasy_stringplanmodifier.ExplicitSuppress), - }, - }, - "mime_type": schema.StringAttribute{ - Computed: true, - PlanModifiers: []planmodifier.String{ - speakeasy_stringplanmodifier.SuppressDiff(speakeasy_stringplanmodifier.ExplicitSuppress), - }, - }, - "readable_size": schema.StringAttribute{ - Computed: true, - PlanModifiers: []planmodifier.String{ - speakeasy_stringplanmodifier.SuppressDiff(speakeasy_stringplanmodifier.ExplicitSuppress), - }, - }, - "s3ref": schema.SingleNestedAttribute{ - Computed: true, - PlanModifiers: []planmodifier.Object{ - speakeasy_objectplanmodifier.SuppressDiff(speakeasy_objectplanmodifier.ExplicitSuppress), - }, - Attributes: map[string]schema.Attribute{ - "bucket": schema.StringAttribute{ - Computed: true, - PlanModifiers: []planmodifier.String{ - speakeasy_stringplanmodifier.SuppressDiff(speakeasy_stringplanmodifier.ExplicitSuppress), - }, - }, - "key": schema.StringAttribute{ - Computed: true, - PlanModifiers: []planmodifier.String{ - speakeasy_stringplanmodifier.SuppressDiff(speakeasy_stringplanmodifier.ExplicitSuppress), - }, - }, - }, - }, - "size_bytes": schema.Int64Attribute{ - Computed: true, - PlanModifiers: []planmodifier.Int64{ - speakeasy_int64planmodifier.SuppressDiff(speakeasy_int64planmodifier.ExplicitSuppress), - }, - }, - }, - }, - }, - }, - } -} - -func (r *FileResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { - // Prevent panic if the provider has not been configured. - if req.ProviderData == nil { - return - } - - client, ok := req.ProviderData.(*sdk.SDK) - - if !ok { - resp.Diagnostics.AddError( - "Unexpected Resource Configure Type", - fmt.Sprintf("Expected *sdk.SDK, got: %T. Please report this issue to the provider developers.", req.ProviderData), - ) - - return - } - - r.client = client -} - -func (r *FileResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { - var data *FileResourceModel - var plan types.Object - - resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...) - if resp.Diagnostics.HasError() { - return - } - - resp.Diagnostics.Append(plan.As(ctx, &data, basetypes.ObjectAsOptions{ - UnhandledNullAsEmpty: true, - UnhandledUnknownAsEmpty: true, - })...) - - if resp.Diagnostics.HasError() { - return - } - - saveFilePayloadV2 := data.ToSharedSaveFilePayloadV2() - activityID := new(string) - if !data.ActivityID.IsUnknown() && !data.ActivityID.IsNull() { - *activityID = data.ActivityID.ValueString() - } else { - activityID = nil - } - async := new(bool) - if !data.Async.IsUnknown() && !data.Async.IsNull() { - *async = data.Async.ValueBool() - } else { - async = nil - } - fillActivity := new(bool) - if !data.FillActivity.IsUnknown() && !data.FillActivity.IsNull() { - *fillActivity = data.FillActivity.ValueBool() - } else { - fillActivity = nil - } - strict := new(bool) - if !data.Strict.IsUnknown() && !data.Strict.IsNull() { - *strict = data.Strict.ValueBool() - } else { - strict = nil - } - request := operations.SaveFileV2Request{ - SaveFilePayloadV2: saveFilePayloadV2, - ActivityID: activityID, - Async: async, - FillActivity: fillActivity, - Strict: strict, - } - res, err := r.client.File.SaveFileV2(ctx, request) - if err != nil { - resp.Diagnostics.AddError("failure to invoke API", err.Error()) - if res != nil && res.RawResponse != nil { - resp.Diagnostics.AddError("unexpected http request/response", debugResponse(res.RawResponse)) - } - return - } - if res == nil { - resp.Diagnostics.AddError("unexpected response from API", fmt.Sprintf("%v", res)) - return - } - if res.StatusCode != 200 { - resp.Diagnostics.AddError(fmt.Sprintf("unexpected response from API. Got an unexpected response code %v", res.StatusCode), debugResponse(res.RawResponse)) - return - } - if !(res.FileEntity != nil) { - resp.Diagnostics.AddError("unexpected response from API. Got an unexpected response body", debugResponse(res.RawResponse)) - return - } - data.RefreshFromSharedFileEntity(res.FileEntity) - refreshPlan(ctx, plan, &data, resp.Diagnostics) - async1 := new(bool) - if !data.Async.IsUnknown() && !data.Async.IsNull() { - *async1 = data.Async.ValueBool() - } else { - async1 = nil - } - var id string - id = data.ID.ValueString() - - strict1 := new(bool) - if !data.Strict.IsUnknown() && !data.Strict.IsNull() { - *strict1 = data.Strict.ValueBool() - } else { - strict1 = nil - } - request1 := operations.GetFileRequest{ - Async: async1, - ID: id, - Strict: strict1, - } - res1, err := r.client.File.GetFile(ctx, request1) - if err != nil { - resp.Diagnostics.AddError("failure to invoke API", err.Error()) - if res1 != nil && res1.RawResponse != nil { - resp.Diagnostics.AddError("unexpected http request/response", debugResponse(res1.RawResponse)) - } - return - } - if res1 == nil { - resp.Diagnostics.AddError("unexpected response from API", fmt.Sprintf("%v", res1)) - return - } - if res1.StatusCode != 200 { - resp.Diagnostics.AddError(fmt.Sprintf("unexpected response from API. Got an unexpected response code %v", res1.StatusCode), debugResponse(res1.RawResponse)) - return - } - if !(res1.FileEntity != nil) { - resp.Diagnostics.AddError("unexpected response from API. Got an unexpected response body", debugResponse(res1.RawResponse)) - return - } - data.RefreshFromSharedFileEntity(res1.FileEntity) - refreshPlan(ctx, plan, &data, resp.Diagnostics) - - // Save updated data into Terraform state - resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) -} - -func (r *FileResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { - var data *FileResourceModel - var item types.Object - - resp.Diagnostics.Append(req.State.Get(ctx, &item)...) - if resp.Diagnostics.HasError() { - return - } - - resp.Diagnostics.Append(item.As(ctx, &data, basetypes.ObjectAsOptions{ - UnhandledNullAsEmpty: true, - UnhandledUnknownAsEmpty: true, - })...) - - if resp.Diagnostics.HasError() { - return - } - - async := new(bool) - if !data.Async.IsUnknown() && !data.Async.IsNull() { - *async = data.Async.ValueBool() - } else { - async = nil - } - var id string - id = data.ID.ValueString() - - strict := new(bool) - if !data.Strict.IsUnknown() && !data.Strict.IsNull() { - *strict = data.Strict.ValueBool() - } else { - strict = nil - } - request := operations.GetFileRequest{ - Async: async, - ID: id, - Strict: strict, - } - res, err := r.client.File.GetFile(ctx, request) - if err != nil { - resp.Diagnostics.AddError("failure to invoke API", err.Error()) - if res != nil && res.RawResponse != nil { - resp.Diagnostics.AddError("unexpected http request/response", debugResponse(res.RawResponse)) - } - return - } - if res == nil { - resp.Diagnostics.AddError("unexpected response from API", fmt.Sprintf("%v", res)) - return - } - if res.StatusCode == 404 { - resp.State.RemoveResource(ctx) - return - } - if res.StatusCode != 200 { - resp.Diagnostics.AddError(fmt.Sprintf("unexpected response from API. Got an unexpected response code %v", res.StatusCode), debugResponse(res.RawResponse)) - return - } - if !(res.FileEntity != nil) { - resp.Diagnostics.AddError("unexpected response from API. Got an unexpected response body", debugResponse(res.RawResponse)) - return - } - data.RefreshFromSharedFileEntity(res.FileEntity) - - // Save updated data into Terraform state - resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) -} - -func (r *FileResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { - var data *FileResourceModel - var plan types.Object - - resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...) - if resp.Diagnostics.HasError() { - return - } - - merge(ctx, req, resp, &data) - if resp.Diagnostics.HasError() { - return - } - - saveFilePayloadV2 := data.ToSharedSaveFilePayloadV2() - activityID := new(string) - if !data.ActivityID.IsUnknown() && !data.ActivityID.IsNull() { - *activityID = data.ActivityID.ValueString() - } else { - activityID = nil - } - async := new(bool) - if !data.Async.IsUnknown() && !data.Async.IsNull() { - *async = data.Async.ValueBool() - } else { - async = nil - } - fillActivity := new(bool) - if !data.FillActivity.IsUnknown() && !data.FillActivity.IsNull() { - *fillActivity = data.FillActivity.ValueBool() - } else { - fillActivity = nil - } - strict := new(bool) - if !data.Strict.IsUnknown() && !data.Strict.IsNull() { - *strict = data.Strict.ValueBool() - } else { - strict = nil - } - request := operations.SaveFileV2Request{ - SaveFilePayloadV2: saveFilePayloadV2, - ActivityID: activityID, - Async: async, - FillActivity: fillActivity, - Strict: strict, - } - res, err := r.client.File.SaveFileV2(ctx, request) - if err != nil { - resp.Diagnostics.AddError("failure to invoke API", err.Error()) - if res != nil && res.RawResponse != nil { - resp.Diagnostics.AddError("unexpected http request/response", debugResponse(res.RawResponse)) - } - return - } - if res == nil { - resp.Diagnostics.AddError("unexpected response from API", fmt.Sprintf("%v", res)) - return - } - if res.StatusCode != 200 { - resp.Diagnostics.AddError(fmt.Sprintf("unexpected response from API. Got an unexpected response code %v", res.StatusCode), debugResponse(res.RawResponse)) - return - } - if !(res.FileEntity != nil) { - resp.Diagnostics.AddError("unexpected response from API. Got an unexpected response body", debugResponse(res.RawResponse)) - return - } - data.RefreshFromSharedFileEntity(res.FileEntity) - refreshPlan(ctx, plan, &data, resp.Diagnostics) - async1 := new(bool) - if !data.Async.IsUnknown() && !data.Async.IsNull() { - *async1 = data.Async.ValueBool() - } else { - async1 = nil - } - var id string - id = data.ID.ValueString() - - strict1 := new(bool) - if !data.Strict.IsUnknown() && !data.Strict.IsNull() { - *strict1 = data.Strict.ValueBool() - } else { - strict1 = nil - } - request1 := operations.GetFileRequest{ - Async: async1, - ID: id, - Strict: strict1, - } - res1, err := r.client.File.GetFile(ctx, request1) - if err != nil { - resp.Diagnostics.AddError("failure to invoke API", err.Error()) - if res1 != nil && res1.RawResponse != nil { - resp.Diagnostics.AddError("unexpected http request/response", debugResponse(res1.RawResponse)) - } - return - } - if res1 == nil { - resp.Diagnostics.AddError("unexpected response from API", fmt.Sprintf("%v", res1)) - return - } - if res1.StatusCode != 200 { - resp.Diagnostics.AddError(fmt.Sprintf("unexpected response from API. Got an unexpected response code %v", res1.StatusCode), debugResponse(res1.RawResponse)) - return - } - if !(res1.FileEntity != nil) { - resp.Diagnostics.AddError("unexpected response from API. Got an unexpected response body", debugResponse(res1.RawResponse)) - return - } - data.RefreshFromSharedFileEntity(res1.FileEntity) - refreshPlan(ctx, plan, &data, resp.Diagnostics) - - // Save updated data into Terraform state - resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) -} - -func (r *FileResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { - var data *FileResourceModel - var item types.Object - - resp.Diagnostics.Append(req.State.Get(ctx, &item)...) - if resp.Diagnostics.HasError() { - return - } - - resp.Diagnostics.Append(item.As(ctx, &data, basetypes.ObjectAsOptions{ - UnhandledNullAsEmpty: true, - UnhandledUnknownAsEmpty: true, - })...) - - if resp.Diagnostics.HasError() { - return - } - - activityID := new(string) - if !data.ActivityID.IsUnknown() && !data.ActivityID.IsNull() { - *activityID = data.ActivityID.ValueString() - } else { - activityID = nil - } - var id string - id = data.ID.ValueString() - - strict := new(bool) - if !data.Strict.IsUnknown() && !data.Strict.IsNull() { - *strict = data.Strict.ValueBool() - } else { - strict = nil - } - request := operations.DeleteFileRequest{ - ActivityID: activityID, - ID: id, - Strict: strict, - } - res, err := r.client.File.DeleteFile(ctx, request) - if err != nil { - resp.Diagnostics.AddError("failure to invoke API", err.Error()) - if res != nil && res.RawResponse != nil { - resp.Diagnostics.AddError("unexpected http request/response", debugResponse(res.RawResponse)) - } - return - } - if res == nil { - resp.Diagnostics.AddError("unexpected response from API", fmt.Sprintf("%v", res)) - return - } - if res.StatusCode != 200 { - resp.Diagnostics.AddError(fmt.Sprintf("unexpected response from API. Got an unexpected response code %v", res.StatusCode), debugResponse(res.RawResponse)) - return - } - -} - -func (r *FileResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { - resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), req.ID)...) -} diff --git a/internal/provider/file_resource_sdk.go b/internal/provider/file_resource_sdk.go deleted file mode 100644 index 06866a3..0000000 --- a/internal/provider/file_resource_sdk.go +++ /dev/null @@ -1,255 +0,0 @@ -// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. - -package provider - -import ( - "encoding/json" - tfTypes "github.com/epilot-dev/terraform-provider-epilot-file/internal/provider/types" - "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/models/shared" - "github.com/hashicorp/terraform-plugin-framework/types" - "time" -) - -func (r *FileResourceModel) ToSharedSaveFilePayloadV2() *shared.SaveFilePayloadV2 { - additional := make(map[string]interface{}) - for additionalKey, additionalValue := range r.Additional { - var additionalInst interface{} - _ = json.Unmarshal([]byte(additionalValue.ValueString()), &additionalInst) - additional[additionalKey] = additionalInst - } - var acl *shared.BaseEntityACL - if r.ACL != nil { - var delete []string = []string{} - for _, deleteItem := range r.ACL.Delete { - delete = append(delete, deleteItem.ValueString()) - } - var edit []string = []string{} - for _, editItem := range r.ACL.Edit { - edit = append(edit, editItem.ValueString()) - } - var view []string = []string{} - for _, viewItem := range r.ACL.View { - view = append(view, viewItem.ValueString()) - } - acl = &shared.BaseEntityACL{ - Delete: delete, - Edit: edit, - View: view, - } - } - id := new(string) - if !r.ID.IsUnknown() && !r.ID.IsNull() { - *id = r.ID.ValueString() - } else { - id = nil - } - var manifest []string = []string{} - for _, manifestItem := range r.Manifest { - manifest = append(manifest, manifestItem.ValueString()) - } - var purpose []string = []string{} - for _, purposeItem := range r.Purpose { - purpose = append(purpose, purposeItem.ValueString()) - } - var tags []string = []string{} - for _, tagsItem := range r.Tags { - tags = append(tags, tagsItem.ValueString()) - } - title := new(string) - if !r.Title.IsUnknown() && !r.Title.IsNull() { - *title = r.Title.ValueString() - } else { - title = nil - } - accessControl := new(shared.SaveFilePayloadV2AccessControl) - if !r.AccessControl.IsUnknown() && !r.AccessControl.IsNull() { - *accessControl = shared.SaveFilePayloadV2AccessControl(r.AccessControl.ValueString()) - } else { - accessControl = nil - } - customDownloadURL := new(string) - if !r.CustomDownloadURL.IsUnknown() && !r.CustomDownloadURL.IsNull() { - *customDownloadURL = r.CustomDownloadURL.ValueString() - } else { - customDownloadURL = nil - } - filename := new(string) - if !r.Filename.IsUnknown() && !r.Filename.IsNull() { - *filename = r.Filename.ValueString() - } else { - filename = nil - } - mimeType := new(string) - if !r.MimeType.IsUnknown() && !r.MimeType.IsNull() { - *mimeType = r.MimeType.ValueString() - } else { - mimeType = nil - } - var s3ref *shared.S3Ref - if r.S3ref != nil { - var bucket string - bucket = r.S3ref.Bucket.ValueString() - - var key string - key = r.S3ref.Key.ValueString() - - s3ref = &shared.S3Ref{ - Bucket: bucket, - Key: key, - } - } - sourceURL := new(string) - if !r.SourceURL.IsUnknown() && !r.SourceURL.IsNull() { - *sourceURL = r.SourceURL.ValueString() - } else { - sourceURL = nil - } - typeVar := new(shared.FileType) - if !r.Type.IsUnknown() && !r.Type.IsNull() { - *typeVar = shared.FileType(r.Type.ValueString()) - } else { - typeVar = nil - } - out := shared.SaveFilePayloadV2{ - Additional: additional, - ACL: acl, - ID: id, - Manifest: manifest, - Purpose: purpose, - Tags: tags, - Title: title, - AccessControl: accessControl, - CustomDownloadURL: customDownloadURL, - Filename: filename, - MimeType: mimeType, - S3ref: s3ref, - SourceURL: sourceURL, - Type: typeVar, - } - return &out -} - -func (r *FileResourceModel) RefreshFromSharedFileEntity(resp *shared.FileEntity) { - if resp != nil { - if len(resp.Additional) > 0 { - r.Additional = make(map[string]types.String) - for key, value := range resp.Additional { - result, _ := json.Marshal(value) - r.Additional[key] = types.StringValue(string(result)) - } - } - if resp.ACL == nil { - r.ACL = nil - } else { - r.ACL = &tfTypes.BaseEntityACL{} - r.ACL.Delete = []types.String{} - for _, v := range resp.ACL.Delete { - r.ACL.Delete = append(r.ACL.Delete, types.StringValue(v)) - } - r.ACL.Edit = []types.String{} - for _, v := range resp.ACL.Edit { - r.ACL.Edit = append(r.ACL.Edit, types.StringValue(v)) - } - r.ACL.View = []types.String{} - for _, v := range resp.ACL.View { - r.ACL.View = append(r.ACL.View, types.StringValue(v)) - } - } - if resp.CreatedAt != nil { - r.CreatedAt = types.StringValue(resp.CreatedAt.Format(time.RFC3339Nano)) - } else { - r.CreatedAt = types.StringNull() - } - r.ID = types.StringPointerValue(resp.ID) - r.Manifest = []types.String{} - for _, v := range resp.Manifest { - r.Manifest = append(r.Manifest, types.StringValue(v)) - } - r.Org = types.StringPointerValue(resp.Org) - r.Owners = []tfTypes.BaseEntityOwner{} - if len(r.Owners) > len(resp.Owners) { - r.Owners = r.Owners[:len(resp.Owners)] - } - for ownersCount, ownersItem := range resp.Owners { - var owners1 tfTypes.BaseEntityOwner - owners1.OrgID = types.StringValue(ownersItem.OrgID) - owners1.UserID = types.StringPointerValue(ownersItem.UserID) - if ownersCount+1 > len(r.Owners) { - r.Owners = append(r.Owners, owners1) - } else { - r.Owners[ownersCount].OrgID = owners1.OrgID - r.Owners[ownersCount].UserID = owners1.UserID - } - } - r.Purpose = []types.String{} - for _, v := range resp.Purpose { - r.Purpose = append(r.Purpose, types.StringValue(v)) - } - if resp.Schema != nil { - r.Schema = types.StringValue(string(*resp.Schema)) - } else { - r.Schema = types.StringNull() - } - r.Tags = []types.String{} - for _, v := range resp.Tags { - r.Tags = append(r.Tags, types.StringValue(v)) - } - r.Title = types.StringPointerValue(resp.Title) - if resp.UpdatedAt != nil { - r.UpdatedAt = types.StringValue(resp.UpdatedAt.Format(time.RFC3339Nano)) - } else { - r.UpdatedAt = types.StringNull() - } - if resp.AccessControl != nil { - r.AccessControl = types.StringValue(string(*resp.AccessControl)) - } else { - r.AccessControl = types.StringNull() - } - r.CustomDownloadURL = types.StringPointerValue(resp.CustomDownloadURL) - r.Filename = types.StringPointerValue(resp.Filename) - r.MimeType = types.StringPointerValue(resp.MimeType) - r.PublicURL = types.StringPointerValue(resp.PublicURL) - r.ReadableSize = types.StringPointerValue(resp.ReadableSize) - if resp.S3ref == nil { - r.S3ref = nil - } else { - r.S3ref = &tfTypes.S3Ref{} - r.S3ref.Bucket = types.StringValue(resp.S3ref.Bucket) - r.S3ref.Key = types.StringValue(resp.S3ref.Key) - } - r.SizeBytes = types.Int64PointerValue(resp.SizeBytes) - r.SourceURL = types.StringPointerValue(resp.SourceURL) - if resp.Type != nil { - r.Type = types.StringValue(string(*resp.Type)) - } else { - r.Type = types.StringNull() - } - r.Versions = []tfTypes.FileItem{} - if len(r.Versions) > len(resp.Versions) { - r.Versions = r.Versions[:len(resp.Versions)] - } - for versionsCount, versionsItem := range resp.Versions { - var versions1 tfTypes.FileItem - versions1.Filename = types.StringPointerValue(versionsItem.Filename) - versions1.MimeType = types.StringPointerValue(versionsItem.MimeType) - versions1.ReadableSize = types.StringPointerValue(versionsItem.ReadableSize) - if versionsItem.S3ref == nil { - versions1.S3ref = nil - } else { - versions1.S3ref = &tfTypes.S3Ref{} - versions1.S3ref.Bucket = types.StringValue(versionsItem.S3ref.Bucket) - versions1.S3ref.Key = types.StringValue(versionsItem.S3ref.Key) - } - versions1.SizeBytes = types.Int64PointerValue(versionsItem.SizeBytes) - if versionsCount+1 > len(r.Versions) { - r.Versions = append(r.Versions, versions1) - } else { - r.Versions[versionsCount].Filename = versions1.Filename - r.Versions[versionsCount].MimeType = versions1.MimeType - r.Versions[versionsCount].ReadableSize = versions1.ReadableSize - r.Versions[versionsCount].S3ref = versions1.S3ref - r.Versions[versionsCount].SizeBytes = versions1.SizeBytes - } - } - } -} diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 958bb36..1d65268 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -7,6 +7,7 @@ import ( "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk" "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/models/shared" "github.com/hashicorp/terraform-plugin-framework/datasource" + "github.com/hashicorp/terraform-plugin-framework/ephemeral" "github.com/hashicorp/terraform-plugin-framework/provider" "github.com/hashicorp/terraform-plugin-framework/provider/schema" "github.com/hashicorp/terraform-plugin-framework/resource" @@ -14,7 +15,8 @@ import ( "net/http" ) -var _ provider.Provider = &EpilotFileProvider{} +var _ provider.Provider = (*EpilotFileProvider)(nil) +var _ provider.ProviderWithEphemeralResources = (*EpilotFileProvider)(nil) type EpilotFileProvider struct { // version is set to the provider version on release, "dev" when the @@ -25,9 +27,9 @@ type EpilotFileProvider struct { // EpilotFileProviderModel describes the provider data model. type EpilotFileProviderModel struct { - ServerURL types.String `tfsdk:"server_url"` CookieAuth types.String `tfsdk:"cookie_auth"` EpilotAuth types.String `tfsdk:"epilot_auth"` + ServerURL types.String `tfsdk:"server_url"` } func (p *EpilotFileProvider) Metadata(ctx context.Context, req provider.MetadataRequest, resp *provider.MetadataResponse) { @@ -37,22 +39,26 @@ func (p *EpilotFileProvider) Metadata(ctx context.Context, req provider.Metadata func (p *EpilotFileProvider) Schema(ctx context.Context, req provider.SchemaRequest, resp *provider.SchemaResponse) { resp.Schema = schema.Schema{ - Description: `File API: Upload and manage epilot Files`, Attributes: map[string]schema.Attribute{ - "server_url": schema.StringAttribute{ - MarkdownDescription: "Server URL (defaults to https://file.sls.epilot.io)", - Optional: true, - Required: false, - }, "cookie_auth": schema.StringAttribute{ - Sensitive: true, - Optional: true, + MarkdownDescription: `Cookie with epilot OAuth2 token.`, + Optional: true, + Sensitive: true, }, "epilot_auth": schema.StringAttribute{ - Sensitive: true, - Optional: true, + MarkdownDescription: `Authorization header with epilot OAuth2 bearer token.`, + Optional: true, + Sensitive: true, + }, + "server_url": schema.StringAttribute{ + Description: `Server URL (defaults to https://file.sls.epilot.io)`, + Optional: true, }, }, + MarkdownDescription: `File API: Upload and manage epilot Files` + "\n" + + `` + "\n" + + `## Changelog` + "\n" + + `View API Changelog`, } } @@ -65,50 +71,52 @@ func (p *EpilotFileProvider) Configure(ctx context.Context, req provider.Configu return } - ServerURL := data.ServerURL.ValueString() + serverUrl := data.ServerURL.ValueString() - if ServerURL == "" { - ServerURL = "https://file.sls.epilot.io" + if serverUrl == "" { + serverUrl = "https://file.sls.epilot.io" } - cookieAuth := new(string) - if !data.CookieAuth.IsUnknown() && !data.CookieAuth.IsNull() { - *cookieAuth = data.CookieAuth.ValueString() - } else { - cookieAuth = nil + security := shared.Security{} + + if !data.CookieAuth.IsUnknown() { + security.CookieAuth = data.CookieAuth.ValueStringPointer() } - epilotAuth := new(string) - if !data.EpilotAuth.IsUnknown() && !data.EpilotAuth.IsNull() { - *epilotAuth = data.EpilotAuth.ValueString() - } else { - epilotAuth = nil + + if !data.EpilotAuth.IsUnknown() { + security.EpilotAuth = data.EpilotAuth.ValueStringPointer() } - security := shared.Security{ - CookieAuth: cookieAuth, - EpilotAuth: epilotAuth, + + providerHTTPTransportOpts := ProviderHTTPTransportOpts{ + SetHeaders: make(map[string]string), + Transport: http.DefaultTransport, } + httpClient := http.DefaultClient + httpClient.Transport = NewProviderHTTPTransport(providerHTTPTransportOpts) + opts := []sdk.SDKOption{ - sdk.WithServerURL(ServerURL), + sdk.WithServerURL(serverUrl), sdk.WithSecurity(security), - sdk.WithClient(http.DefaultClient), + sdk.WithClient(httpClient), } - client := sdk.New(opts...) + client := sdk.New(opts...) resp.DataSourceData = client + resp.EphemeralResourceData = client resp.ResourceData = client } func (p *EpilotFileProvider) Resources(ctx context.Context) []func() resource.Resource { - return []func() resource.Resource{ - NewFileResource, - } + return []func() resource.Resource{} } func (p *EpilotFileProvider) DataSources(ctx context.Context) []func() datasource.DataSource { - return []func() datasource.DataSource{ - NewFileDataSource, - } + return []func() datasource.DataSource{} +} + +func (p *EpilotFileProvider) EphemeralResources(ctx context.Context) []func() ephemeral.EphemeralResource { + return []func() ephemeral.EphemeralResource{} } func New(version string) func() provider.Provider { diff --git a/internal/provider/reflect/helpers.go b/internal/provider/reflect/helpers.go index b17719d..8085789 100644 --- a/internal/provider/reflect/helpers.go +++ b/internal/provider/reflect/helpers.go @@ -46,7 +46,7 @@ func commaSeparatedString(in []string) string { // getStructTags returns a map of Terraform field names to their position in // the tags of the struct `in`. `in` must be a struct. -func getStructTags(_ context.Context, in reflect.Value, path path.Path, opts Options) (map[string]int, error) { +func getStructTags(_ context.Context, in reflect.Value, path path.Path, _ Options) (map[string]int, error) { tags := map[string]int{} typ := trueReflectValue(in).Type() if typ.Kind() != reflect.Struct { diff --git a/internal/provider/typeconvert/date.go b/internal/provider/typeconvert/date.go new file mode 100644 index 0000000..146c6f2 --- /dev/null +++ b/internal/provider/typeconvert/date.go @@ -0,0 +1,23 @@ +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + +package typeconvert + +import ( + sdkTypes "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/types" +) + +// Converts a date types.Date to string. +func DateToString(value sdkTypes.Date) string { + return value.String() +} + +// Converts a date *types.Date to *string. +func DatePointerToStringPointer(value *sdkTypes.Date) *string { + if value == nil { + return nil + } + + stringValue := DateToString(*value) + + return &stringValue +} diff --git a/internal/provider/typeconvert/datetime.go b/internal/provider/typeconvert/datetime.go new file mode 100644 index 0000000..7bfdc55 --- /dev/null +++ b/internal/provider/typeconvert/datetime.go @@ -0,0 +1,23 @@ +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + +package typeconvert + +import ( + "time" +) + +// Converts a date-time time.Time to string. +func TimeToString(value time.Time) string { + return value.Format(time.RFC3339Nano) +} + +// Converts a date-time *time.Time to *string. +func TimePointerToStringPointer(value *time.Time) *string { + if value == nil { + return nil + } + + stringValue := TimeToString(*value) + + return &stringValue +} diff --git a/internal/provider/typeconvert/int.go b/internal/provider/typeconvert/int.go new file mode 100644 index 0000000..54763e7 --- /dev/null +++ b/internal/provider/typeconvert/int.go @@ -0,0 +1,50 @@ +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + +package typeconvert + +// Converts an *int to *int32. +func IntPointerToInt32Pointer(value *int) *int32 { + if value == nil { + return nil + } + + int32Value := int32(*value) + + return &int32Value +} + +// Converts an *int to *int64. +func IntPointerToInt64Pointer(value *int) *int64 { + if value == nil { + return nil + } + + int64Value := int64(*value) + + return &int64Value +} + +// Converts an *int32 to *int. +func Int32PointerToIntPointer(value *int32) *int { + if value == nil { + return nil + } + + intValue := int(*value) + + return &intValue +} + +// Converts an *int64 to *int32. +func Int64PointerToInt32Pointer(value *int64) *int32 { + if value == nil { + return nil + } + + // This may panic and if it does, represents a schema mismatch between + // response and response types. Request and response types should always + // be consistent with the highest integer size necessary. + int32Value := int32(*value) + + return &int32Value +} diff --git a/internal/provider/types/base_entity_acl.go b/internal/provider/types/base_entity_acl.go deleted file mode 100644 index ea0f5f9..0000000 --- a/internal/provider/types/base_entity_acl.go +++ /dev/null @@ -1,11 +0,0 @@ -// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. - -package types - -import "github.com/hashicorp/terraform-plugin-framework/types" - -type BaseEntityACL struct { - Delete []types.String `tfsdk:"delete"` - Edit []types.String `tfsdk:"edit"` - View []types.String `tfsdk:"view"` -} diff --git a/internal/provider/types/base_entity_owner.go b/internal/provider/types/base_entity_owner.go deleted file mode 100644 index 10d217d..0000000 --- a/internal/provider/types/base_entity_owner.go +++ /dev/null @@ -1,10 +0,0 @@ -// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. - -package types - -import "github.com/hashicorp/terraform-plugin-framework/types" - -type BaseEntityOwner struct { - OrgID types.String `tfsdk:"org_id"` - UserID types.String `tfsdk:"user_id"` -} diff --git a/internal/provider/types/file_item.go b/internal/provider/types/file_item.go deleted file mode 100644 index 510bf6d..0000000 --- a/internal/provider/types/file_item.go +++ /dev/null @@ -1,13 +0,0 @@ -// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. - -package types - -import "github.com/hashicorp/terraform-plugin-framework/types" - -type FileItem struct { - Filename types.String `tfsdk:"filename"` - MimeType types.String `tfsdk:"mime_type"` - ReadableSize types.String `tfsdk:"readable_size"` - S3ref *S3Ref `tfsdk:"s3ref"` - SizeBytes types.Int64 `tfsdk:"size_bytes"` -} diff --git a/internal/provider/types/s3_ref.go b/internal/provider/types/s3_ref.go deleted file mode 100644 index e270ebd..0000000 --- a/internal/provider/types/s3_ref.go +++ /dev/null @@ -1,10 +0,0 @@ -// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. - -package types - -import "github.com/hashicorp/terraform-plugin-framework/types" - -type S3Ref struct { - Bucket types.String `tfsdk:"bucket"` - Key types.String `tfsdk:"key"` -} diff --git a/internal/provider/utils.go b/internal/provider/utils.go index 7086c77..349d389 100644 --- a/internal/provider/utils.go +++ b/internal/provider/utils.go @@ -3,17 +3,25 @@ package provider import ( + "bufio" + "bytes" "context" - "encoding/json" + "errors" "fmt" - tfReflect "github.com/epilot-dev/terraform-provider-epilot-file/internal/provider/reflect" + "io" + "net/http" + "net/http/httputil" + "net/textproto" + "strings" + + "github.com/hashicorp/go-uuid" "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/types" - "net/http" - "net/http/httputil" - "reflect" + "github.com/hashicorp/terraform-plugin-log/tflog" + + tfReflect "github.com/epilot-dev/terraform-provider-epilot-file/internal/provider/reflect" ) func debugResponse(response *http.Response) string { @@ -40,19 +48,6 @@ func debugResponse(response *http.Response) string { return fmt.Sprintf("**Request**:\n%s\n**Response**:\n%s", string(dumpReq), string(dumpRes)) } -func reflectJSONKey(data any, key string) reflect.Value { - jsonIfied, err := json.Marshal(data) - if err != nil { - panic(fmt.Errorf("failed to marshal data: %w", err)) - } - var jsonMap map[string]interface{} - err = json.Unmarshal(jsonIfied, &jsonMap) - if err != nil { - panic(fmt.Errorf("failed to unmarshal data: %w", err)) - } - return reflect.ValueOf(jsonMap[key]) -} - func merge(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse, target interface{}) { var plan types.Object var state types.Object @@ -78,19 +73,228 @@ func merge(ctx context.Context, req resource.UpdateRequest, resp *resource.Updat return } - refreshPlan(ctx, plan, target, resp.Diagnostics) + resp.Diagnostics.Append(refreshPlan(ctx, plan, target)...) } -func refreshPlan(ctx context.Context, plan types.Object, target interface{}, diagnostics diag.Diagnostics) { +func refreshPlan(ctx context.Context, plan types.Object, target any) diag.Diagnostics { + var diags diag.Diagnostics + obj := types.ObjectType{AttrTypes: plan.AttributeTypes(ctx)} val, err := plan.ToTerraformValue(ctx) if err != nil { - diagnostics.Append(diag.NewErrorDiagnostic("Object Conversion Error", "An unexpected error was encountered trying to convert object. This is always an error in the provider. Please report the following to the provider developer:\n\n"+err.Error())) - return + diags.AddError( + "Object Conversion Error", + "An unexpected error was encountered trying to convert object. This is always an error in the provider. Please report the following to the provider developer:\n\n"+err.Error(), + ) + return diags } - diagnostics.Append(tfReflect.Into(ctx, obj, val, target, tfReflect.Options{ + + diags.Append(tfReflect.Into(ctx, obj, val, target, tfReflect.Options{ UnhandledNullAsEmpty: true, UnhandledUnknownAsEmpty: true, SourceType: tfReflect.SourceTypePlan, }, path.Empty())...) + + return diags +} + +// Configurable options for the provider HTTP transport. +type ProviderHTTPTransportOpts struct { + // HTTP headers to set on all requests. + SetHeaders map[string]string + + // Underlying HTTP transport. + Transport http.RoundTripper +} + +// Note: this is taken as a more minimal/specific version of https://github.com/hashicorp/terraform-plugin-sdk/blob/main/helper/logging/logging_http_transport.go +func NewProviderHTTPTransport(opts ProviderHTTPTransportOpts) *providerHttpTransport { + return &providerHttpTransport{ + setHeaders: opts.SetHeaders, + transport: opts.Transport, + } +} + +const ( + FieldHttpOperationType = "tf_http_op_type" + OperationHttpRequest = "request" + OperationHttpResponse = "response" + FieldHttpRequestMethod = "tf_http_req_method" + FieldHttpRequestUri = "tf_http_req_uri" + FieldHttpRequestProtoVersion = "tf_http_req_version" + FieldHttpRequestBody = "tf_http_req_body" + FieldHttpResponseProtoVersion = "tf_http_res_version" + FieldHttpResponseStatusCode = "tf_http_res_status_code" + FieldHttpResponseStatusReason = "tf_http_res_status_reason" + FieldHttpResponseBody = "tf_http_res_body" + FieldHttpTransactionId = "tf_http_trans_id" +) + +type providerHttpTransport struct { + setHeaders map[string]string + transport http.RoundTripper +} + +func (t *providerHttpTransport) RoundTrip(req *http.Request) (*http.Response, error) { + ctx := req.Context() + ctx = t.addTransactionIdField(ctx) + + // Set globally defined HTTP headers in the request + t.setRequestHeaders(req) + + // Decompose the request bytes in a message (HTTP body) and fields (HTTP headers), then log it + fields, err := decomposeRequestForLogging(req) + if err != nil { + tflog.Error(ctx, "Failed to parse request bytes for logging", []map[string]interface{}{map[string]interface{}{ + "error": err, + }}...) + } else { + tflog.Debug(ctx, "Sending HTTP Request", []map[string]interface{}{fields}...) + } + + // Invoke the wrapped RoundTrip now + res, err := t.transport.RoundTrip(req) + if err != nil { + return res, err + } + + // Decompose the response bytes in a message (HTTP body) and fields (HTTP headers), then log it + fields, err = decomposeResponseForLogging(res) + if err != nil { + tflog.Error(ctx, "Failed to parse response bytes for logging", []map[string]interface{}{map[string]interface{}{ + "error": err, + }}...) + } else { + tflog.Debug(ctx, "Received HTTP Response", []map[string]interface{}{fields}...) + } + + return res, nil +} + +// Generates UUID and sets it into the tf_http_trans_id logging field. +func (t *providerHttpTransport) addTransactionIdField(ctx context.Context) context.Context { + tId, err := uuid.GenerateUUID() + + if err != nil { + tId = "Unable to assign Transaction ID: " + err.Error() + } + + return tflog.SetField(ctx, FieldHttpTransactionId, tId) +} + +// Sets globally defined HTTP headers in the request. +func (t *providerHttpTransport) setRequestHeaders(req *http.Request) { + for name, value := range t.setHeaders { + req.Header.Set(name, value) + } +} + +func decomposeRequestForLogging(req *http.Request) (map[string]interface{}, error) { + fields := make(map[string]interface{}, len(req.Header)+4) + fields[FieldHttpOperationType] = OperationHttpRequest + + fields[FieldHttpRequestMethod] = req.Method + fields[FieldHttpRequestUri] = req.URL.RequestURI() + fields[FieldHttpRequestProtoVersion] = req.Proto + + // Get the full body of the request, including headers appended by http.Transport: + // this is necessary because the http.Request at this stage doesn't contain + // all the headers that will be eventually sent. + // We rely on `httputil.DumpRequestOut` to obtain the actual bytes that will be sent out. + reqBytes, err := httputil.DumpRequestOut(req, true) + if err != nil { + return nil, err + } + + // Create a reader around the request full body + reqReader := textproto.NewReader(bufio.NewReader(bytes.NewReader(reqBytes))) + + err = fieldHeadersFromRequestReader(reqReader, fields) + if err != nil { + return nil, err + } + + // Read the rest of the body content + fields[FieldHttpRequestBody] = bodyFromRestOfRequestReader(reqReader) + return fields, nil +} + +func fieldHeadersFromRequestReader(reader *textproto.Reader, fields map[string]interface{}) error { + // Ignore the first line: it contains non-header content + // that we have already captured. + // Skipping this step, would cause the following call to `ReadMIMEHeader()` + // to fail as it cannot parse the first line. + _, err := reader.ReadLine() + if err != nil { + return err + } + + // Read the MIME-style headers + mimeHeader, err := reader.ReadMIMEHeader() + if err != nil { + return err + } + + // Set the headers as fields to log + for k, v := range mimeHeader { + if len(v) == 1 { + fields[k] = v[0] + } else { + fields[k] = v + } + } + if _, ok := fields["Authorization"]; ok { + fields["Authorization"] = "(sensitive)" + } + if _, ok := fields["token"]; ok { + fields["token"] = "(sensitive)" + } + + return nil +} + +func bodyFromRestOfRequestReader(reader *textproto.Reader) string { + var builder strings.Builder + for { + line, err := reader.ReadContinuedLine() + if errors.Is(err, io.EOF) { + break + } + builder.WriteString(line) + } + + return builder.String() +} + +func decomposeResponseForLogging(res *http.Response) (map[string]interface{}, error) { + fields := make(map[string]interface{}, len(res.Header)+4) + fields[FieldHttpOperationType] = OperationHttpResponse + + fields[FieldHttpResponseProtoVersion] = res.Proto + fields[FieldHttpResponseStatusCode] = res.StatusCode + fields[FieldHttpResponseStatusReason] = res.Status + + // Set the headers as fields to log + for k, v := range res.Header { + if len(v) == 1 { + fields[k] = v[0] + } else { + fields[k] = v + } + } + + // Read the whole response body + resBody, err := io.ReadAll(res.Body) + if err != nil { + return nil, err + } + + // Wrap the bytes from the response body, back into an io.ReadCloser, + // to respect the interface of http.Response, as expected by users of the + // http.Client + res.Body = io.NopCloser(bytes.NewBuffer(resBody)) + + fields[FieldHttpResponseBody] = string(resBody) + + return fields, nil } diff --git a/internal/sdk/.gitignore b/internal/sdk/.gitignore index d3c2f59..4f42473 100644 --- a/internal/sdk/.gitignore +++ b/internal/sdk/.gitignore @@ -1 +1,7 @@ +.DS_Store +**/.speakeasy/temp/ +**/.speakeasy/logs/ +.speakeasy/reports +.env +.env.local # .gitignore diff --git a/internal/sdk/deprecated.go b/internal/sdk/deprecated.go index 78cad8d..25ec561 100644 --- a/internal/sdk/deprecated.go +++ b/internal/sdk/deprecated.go @@ -6,25 +6,28 @@ import ( "bytes" "context" "fmt" - "github.com/cenkalti/backoff/v4" + "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/internal/config" "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/internal/hooks" "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/internal/utils" "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/models/errors" "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/models/operations" "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/models/shared" - "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/retry" "net/http" "net/url" ) // Deprecated APIs type Deprecated struct { - sdkConfiguration sdkConfiguration + rootSDK *SDK + sdkConfiguration config.SDKConfiguration + hooks *hooks.Hooks } -func newDeprecated(sdkConfig sdkConfiguration) *Deprecated { +func newDeprecated(rootSDK *SDK, sdkConfig config.SDKConfiguration, hooks *hooks.Hooks) *Deprecated { return &Deprecated{ + rootSDK: rootSDK, sdkConfiguration: sdkConfig, + hooks: hooks, } } @@ -35,18 +38,10 @@ func newDeprecated(sdkConfig sdkConfiguration) *Deprecated { // // # Saves metadata to file entity // -// Deprecated method: This will be removed in a future release, please migrate away from it as soon as possible. +// Deprecated: This will be removed in a future release, please migrate away from it as soon as possible. func (s *Deprecated) SaveFile(ctx context.Context, request operations.SaveFileRequest, opts ...operations.Option) (*operations.SaveFileResponse, error) { - hookCtx := hooks.HookContext{ - Context: ctx, - OperationID: "saveFile", - OAuth2Scopes: []string{}, - SecuritySource: s.sdkConfiguration.Security, - } - o := operations.Options{} supportedOptions := []string{ - operations.SupportedOptionRetries, operations.SupportedOptionTimeout, } @@ -56,12 +51,26 @@ func (s *Deprecated) SaveFile(ctx context.Context, request operations.SaveFileRe } } - baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + var baseURL string + if o.ServerURL == nil { + baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + } else { + baseURL = *o.ServerURL + } opURL, err := url.JoinPath(baseURL, "/v1/files") if err != nil { return nil, fmt.Errorf("error generating URL: %w", err) } + hookCtx := hooks.HookContext{ + SDK: s.rootSDK, + SDKConfiguration: s.sdkConfiguration, + BaseURL: baseURL, + Context: ctx, + OperationID: "saveFile", + OAuth2Scopes: nil, + SecuritySource: s.sdkConfiguration.Security, + } bodyReader, reqContentType, err := utils.SerializeRequestBody(ctx, request, false, true, "SaveFilePayload", "json", `request:"mediaType=application/json"`) if err != nil { return nil, err @@ -84,7 +93,9 @@ func (s *Deprecated) SaveFile(ctx context.Context, request operations.SaveFileRe } req.Header.Set("Accept", "application/json") req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent) - req.Header.Set("Content-Type", reqContentType) + if reqContentType != "" { + req.Header.Set("Content-Type", reqContentType) + } if err := utils.PopulateQueryParams(ctx, req, request, nil); err != nil { return nil, fmt.Errorf("error populating query params: %w", err) @@ -94,94 +105,36 @@ func (s *Deprecated) SaveFile(ctx context.Context, request operations.SaveFileRe return nil, err } - globalRetryConfig := s.sdkConfiguration.RetryConfig - retryConfig := o.Retries - if retryConfig == nil { - if globalRetryConfig != nil { - retryConfig = globalRetryConfig - } else { - retryConfig = &retry.Config{ - Strategy: "backoff", Backoff: &retry.BackoffStrategy{ - InitialInterval: 5000, - MaxInterval: 60000, - Exponent: 1.5, - MaxElapsedTime: 3600000, - }, - RetryConnectionErrors: true, - } - } + for k, v := range o.SetHeaders { + req.Header.Set(k, v) } - var httpRes *http.Response - if retryConfig != nil { - httpRes, err = utils.Retry(ctx, utils.Retries{ - Config: retryConfig, - StatusCodes: []string{ - "5XX", - }, - }, func() (*http.Response, error) { - if req.Body != nil { - copyBody, err := req.GetBody() - if err != nil { - return nil, err - } - req.Body = copyBody - } - - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) - if err != nil { - return nil, backoff.Permanent(err) - } - - httpRes, err := s.sdkConfiguration.Client.Do(req) - if err != nil || httpRes == nil { - if err != nil { - err = fmt.Errorf("error sending request: %w", err) - } else { - err = fmt.Errorf("error sending request: no response") - } - - _, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) - } - return httpRes, err - }) + req, err = s.hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + if err != nil { + return nil, err + } + httpRes, err := s.sdkConfiguration.Client.Do(req) + if err != nil || httpRes == nil { if err != nil { - return nil, err + err = fmt.Errorf("error sending request: %w", err) } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } + err = fmt.Errorf("error sending request: no response") } - } else { - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + + _, err = s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + return nil, err + } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { + _httpRes, err := s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) if err != nil { return nil, err + } else if _httpRes != nil { + httpRes = _httpRes } - - httpRes, err = s.sdkConfiguration.Client.Do(req) - if err != nil || httpRes == nil { - if err != nil { - err = fmt.Errorf("error sending request: %w", err) - } else { - err = fmt.Errorf("error sending request: no response") - } - - _, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + } else { + httpRes, err = s.hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) + if err != nil { return nil, err - } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { - _httpRes, err := s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) - if err != nil { - return nil, err - } else if _httpRes != nil { - httpRes = _httpRes - } - } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } } } @@ -230,18 +183,10 @@ func (s *Deprecated) SaveFile(ctx context.Context, request operations.SaveFileRe // // Use the saveFile operation to store file file permanently. // -// Deprecated method: This will be removed in a future release, please migrate away from it as soon as possible. +// Deprecated: This will be removed in a future release, please migrate away from it as soon as possible. func (s *Deprecated) UploadFile(ctx context.Context, request operations.UploadFileRequest, opts ...operations.Option) (*operations.UploadFileResponse, error) { - hookCtx := hooks.HookContext{ - Context: ctx, - OperationID: "uploadFile", - OAuth2Scopes: []string{}, - SecuritySource: s.sdkConfiguration.Security, - } - o := operations.Options{} supportedOptions := []string{ - operations.SupportedOptionRetries, operations.SupportedOptionTimeout, } @@ -251,12 +196,26 @@ func (s *Deprecated) UploadFile(ctx context.Context, request operations.UploadFi } } - baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + var baseURL string + if o.ServerURL == nil { + baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + } else { + baseURL = *o.ServerURL + } opURL, err := url.JoinPath(baseURL, "/v1/files/upload") if err != nil { return nil, fmt.Errorf("error generating URL: %w", err) } + hookCtx := hooks.HookContext{ + SDK: s.rootSDK, + SDKConfiguration: s.sdkConfiguration, + BaseURL: baseURL, + Context: ctx, + OperationID: "uploadFile", + OAuth2Scopes: nil, + SecuritySource: s.sdkConfiguration.Security, + } bodyReader, reqContentType, err := utils.SerializeRequestBody(ctx, request, false, true, "UploadFilePayload", "json", `request:"mediaType=application/json"`) if err != nil { return nil, err @@ -279,7 +238,9 @@ func (s *Deprecated) UploadFile(ctx context.Context, request operations.UploadFi } req.Header.Set("Accept", "application/json") req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent) - req.Header.Set("Content-Type", reqContentType) + if reqContentType != "" { + req.Header.Set("Content-Type", reqContentType) + } if err := utils.PopulateQueryParams(ctx, req, request, nil); err != nil { return nil, fmt.Errorf("error populating query params: %w", err) @@ -289,94 +250,36 @@ func (s *Deprecated) UploadFile(ctx context.Context, request operations.UploadFi return nil, err } - globalRetryConfig := s.sdkConfiguration.RetryConfig - retryConfig := o.Retries - if retryConfig == nil { - if globalRetryConfig != nil { - retryConfig = globalRetryConfig - } else { - retryConfig = &retry.Config{ - Strategy: "backoff", Backoff: &retry.BackoffStrategy{ - InitialInterval: 5000, - MaxInterval: 60000, - Exponent: 1.5, - MaxElapsedTime: 3600000, - }, - RetryConnectionErrors: true, - } - } + for k, v := range o.SetHeaders { + req.Header.Set(k, v) } - var httpRes *http.Response - if retryConfig != nil { - httpRes, err = utils.Retry(ctx, utils.Retries{ - Config: retryConfig, - StatusCodes: []string{ - "5XX", - }, - }, func() (*http.Response, error) { - if req.Body != nil { - copyBody, err := req.GetBody() - if err != nil { - return nil, err - } - req.Body = copyBody - } - - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) - if err != nil { - return nil, backoff.Permanent(err) - } - - httpRes, err := s.sdkConfiguration.Client.Do(req) - if err != nil || httpRes == nil { - if err != nil { - err = fmt.Errorf("error sending request: %w", err) - } else { - err = fmt.Errorf("error sending request: no response") - } - - _, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) - } - return httpRes, err - }) + req, err = s.hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + if err != nil { + return nil, err + } + httpRes, err := s.sdkConfiguration.Client.Do(req) + if err != nil || httpRes == nil { if err != nil { - return nil, err + err = fmt.Errorf("error sending request: %w", err) } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } + err = fmt.Errorf("error sending request: no response") } - } else { - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + + _, err = s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + return nil, err + } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { + _httpRes, err := s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) if err != nil { return nil, err + } else if _httpRes != nil { + httpRes = _httpRes } - - httpRes, err = s.sdkConfiguration.Client.Do(req) - if err != nil || httpRes == nil { - if err != nil { - err = fmt.Errorf("error sending request: %w", err) - } else { - err = fmt.Errorf("error sending request: no response") - } - - _, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + } else { + httpRes, err = s.hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) + if err != nil { return nil, err - } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { - _httpRes, err := s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) - if err != nil { - return nil, err - } else if _httpRes != nil { - httpRes = _httpRes - } - } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } } } diff --git a/internal/sdk/file.go b/internal/sdk/file.go index 1ddc161..60ecd82 100644 --- a/internal/sdk/file.go +++ b/internal/sdk/file.go @@ -6,41 +6,36 @@ import ( "bytes" "context" "fmt" - "github.com/cenkalti/backoff/v4" + "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/internal/config" "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/internal/hooks" "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/internal/utils" "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/models/errors" "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/models/operations" "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/models/shared" - "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/retry" "net/http" "net/url" ) // File - Upload and Manage File Entities type File struct { - sdkConfiguration sdkConfiguration + rootSDK *SDK + sdkConfiguration config.SDKConfiguration + hooks *hooks.Hooks } -func newFile(sdkConfig sdkConfiguration) *File { +func newFile(rootSDK *SDK, sdkConfig config.SDKConfiguration, hooks *hooks.Hooks) *File { return &File{ + rootSDK: rootSDK, sdkConfiguration: sdkConfig, + hooks: hooks, } } // DeleteFile - deleteFile // Delete a file entity by id func (s *File) DeleteFile(ctx context.Context, request operations.DeleteFileRequest, opts ...operations.Option) (*operations.DeleteFileResponse, error) { - hookCtx := hooks.HookContext{ - Context: ctx, - OperationID: "deleteFile", - OAuth2Scopes: []string{}, - SecuritySource: s.sdkConfiguration.Security, - } - o := operations.Options{} supportedOptions := []string{ - operations.SupportedOptionRetries, operations.SupportedOptionTimeout, } @@ -50,12 +45,27 @@ func (s *File) DeleteFile(ctx context.Context, request operations.DeleteFileRequ } } - baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + var baseURL string + if o.ServerURL == nil { + baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + } else { + baseURL = *o.ServerURL + } opURL, err := utils.GenerateURL(ctx, baseURL, "/v2/files/{id}", request, nil) if err != nil { return nil, fmt.Errorf("error generating URL: %w", err) } + hookCtx := hooks.HookContext{ + SDK: s.rootSDK, + SDKConfiguration: s.sdkConfiguration, + BaseURL: baseURL, + Context: ctx, + OperationID: "deleteFile", + OAuth2Scopes: nil, + SecuritySource: s.sdkConfiguration.Security, + } + timeout := o.Timeout if timeout == nil { timeout = s.sdkConfiguration.Timeout @@ -82,94 +92,36 @@ func (s *File) DeleteFile(ctx context.Context, request operations.DeleteFileRequ return nil, err } - globalRetryConfig := s.sdkConfiguration.RetryConfig - retryConfig := o.Retries - if retryConfig == nil { - if globalRetryConfig != nil { - retryConfig = globalRetryConfig - } else { - retryConfig = &retry.Config{ - Strategy: "backoff", Backoff: &retry.BackoffStrategy{ - InitialInterval: 5000, - MaxInterval: 60000, - Exponent: 1.5, - MaxElapsedTime: 3600000, - }, - RetryConnectionErrors: true, - } - } + for k, v := range o.SetHeaders { + req.Header.Set(k, v) } - var httpRes *http.Response - if retryConfig != nil { - httpRes, err = utils.Retry(ctx, utils.Retries{ - Config: retryConfig, - StatusCodes: []string{ - "5XX", - }, - }, func() (*http.Response, error) { - if req.Body != nil { - copyBody, err := req.GetBody() - if err != nil { - return nil, err - } - req.Body = copyBody - } - - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) - if err != nil { - return nil, backoff.Permanent(err) - } - - httpRes, err := s.sdkConfiguration.Client.Do(req) - if err != nil || httpRes == nil { - if err != nil { - err = fmt.Errorf("error sending request: %w", err) - } else { - err = fmt.Errorf("error sending request: no response") - } - - _, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) - } - return httpRes, err - }) + req, err = s.hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + if err != nil { + return nil, err + } + httpRes, err := s.sdkConfiguration.Client.Do(req) + if err != nil || httpRes == nil { if err != nil { - return nil, err + err = fmt.Errorf("error sending request: %w", err) } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } + err = fmt.Errorf("error sending request: no response") } - } else { - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + + _, err = s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + return nil, err + } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { + _httpRes, err := s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) if err != nil { return nil, err + } else if _httpRes != nil { + httpRes = _httpRes } - - httpRes, err = s.sdkConfiguration.Client.Do(req) - if err != nil || httpRes == nil { - if err != nil { - err = fmt.Errorf("error sending request: %w", err) - } else { - err = fmt.Errorf("error sending request: no response") - } - - _, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + } else { + httpRes, err = s.hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) + if err != nil { return nil, err - } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { - _httpRes, err := s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) - if err != nil { - return nil, err - } else if _httpRes != nil { - httpRes = _httpRes - } - } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } } } @@ -216,16 +168,8 @@ func (s *File) DeleteFile(ctx context.Context, request operations.DeleteFileRequ // DownloadFile - downloadFile // Generate pre-signed download S3 url for a file func (s *File) DownloadFile(ctx context.Context, request operations.DownloadFileRequest, opts ...operations.Option) (*operations.DownloadFileResponse, error) { - hookCtx := hooks.HookContext{ - Context: ctx, - OperationID: "downloadFile", - OAuth2Scopes: []string{}, - SecuritySource: s.sdkConfiguration.Security, - } - o := operations.Options{} supportedOptions := []string{ - operations.SupportedOptionRetries, operations.SupportedOptionTimeout, } @@ -235,12 +179,27 @@ func (s *File) DownloadFile(ctx context.Context, request operations.DownloadFile } } - baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + var baseURL string + if o.ServerURL == nil { + baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + } else { + baseURL = *o.ServerURL + } opURL, err := utils.GenerateURL(ctx, baseURL, "/v1/files/{id}/download", request, nil) if err != nil { return nil, fmt.Errorf("error generating URL: %w", err) } + hookCtx := hooks.HookContext{ + SDK: s.rootSDK, + SDKConfiguration: s.sdkConfiguration, + BaseURL: baseURL, + Context: ctx, + OperationID: "downloadFile", + OAuth2Scopes: nil, + SecuritySource: s.sdkConfiguration.Security, + } + timeout := o.Timeout if timeout == nil { timeout = s.sdkConfiguration.Timeout @@ -267,94 +226,36 @@ func (s *File) DownloadFile(ctx context.Context, request operations.DownloadFile return nil, err } - globalRetryConfig := s.sdkConfiguration.RetryConfig - retryConfig := o.Retries - if retryConfig == nil { - if globalRetryConfig != nil { - retryConfig = globalRetryConfig - } else { - retryConfig = &retry.Config{ - Strategy: "backoff", Backoff: &retry.BackoffStrategy{ - InitialInterval: 5000, - MaxInterval: 60000, - Exponent: 1.5, - MaxElapsedTime: 3600000, - }, - RetryConnectionErrors: true, - } - } + for k, v := range o.SetHeaders { + req.Header.Set(k, v) } - var httpRes *http.Response - if retryConfig != nil { - httpRes, err = utils.Retry(ctx, utils.Retries{ - Config: retryConfig, - StatusCodes: []string{ - "5XX", - }, - }, func() (*http.Response, error) { - if req.Body != nil { - copyBody, err := req.GetBody() - if err != nil { - return nil, err - } - req.Body = copyBody - } - - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) - if err != nil { - return nil, backoff.Permanent(err) - } - - httpRes, err := s.sdkConfiguration.Client.Do(req) - if err != nil || httpRes == nil { - if err != nil { - err = fmt.Errorf("error sending request: %w", err) - } else { - err = fmt.Errorf("error sending request: no response") - } - - _, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) - } - return httpRes, err - }) + req, err = s.hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + if err != nil { + return nil, err + } + httpRes, err := s.sdkConfiguration.Client.Do(req) + if err != nil || httpRes == nil { if err != nil { - return nil, err + err = fmt.Errorf("error sending request: %w", err) } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } + err = fmt.Errorf("error sending request: no response") } - } else { - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + + _, err = s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + return nil, err + } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { + _httpRes, err := s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) if err != nil { return nil, err + } else if _httpRes != nil { + httpRes = _httpRes } - - httpRes, err = s.sdkConfiguration.Client.Do(req) - if err != nil || httpRes == nil { - if err != nil { - err = fmt.Errorf("error sending request: %w", err) - } else { - err = fmt.Errorf("error sending request: no response") - } - - _, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + } else { + httpRes, err = s.hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) + if err != nil { return nil, err - } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { - _httpRes, err := s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) - if err != nil { - return nil, err - } else if _httpRes != nil { - httpRes = _httpRes - } - } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } } } @@ -401,16 +302,8 @@ func (s *File) DownloadFile(ctx context.Context, request operations.DownloadFile // DownloadFiles - downloadFiles // Bulk generate pre-signed download S3 urls for multiple files func (s *File) DownloadFiles(ctx context.Context, request []shared.DownloadFilesPayload, opts ...operations.Option) (*operations.DownloadFilesResponse, error) { - hookCtx := hooks.HookContext{ - Context: ctx, - OperationID: "downloadFiles", - OAuth2Scopes: []string{}, - SecuritySource: s.sdkConfiguration.Security, - } - o := operations.Options{} supportedOptions := []string{ - operations.SupportedOptionRetries, operations.SupportedOptionTimeout, } @@ -420,12 +313,26 @@ func (s *File) DownloadFiles(ctx context.Context, request []shared.DownloadFiles } } - baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + var baseURL string + if o.ServerURL == nil { + baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + } else { + baseURL = *o.ServerURL + } opURL, err := url.JoinPath(baseURL, "/v1/files:downloadFiles") if err != nil { return nil, fmt.Errorf("error generating URL: %w", err) } + hookCtx := hooks.HookContext{ + SDK: s.rootSDK, + SDKConfiguration: s.sdkConfiguration, + BaseURL: baseURL, + Context: ctx, + OperationID: "downloadFiles", + OAuth2Scopes: nil, + SecuritySource: s.sdkConfiguration.Security, + } bodyReader, reqContentType, err := utils.SerializeRequestBody(ctx, request, false, true, "Request", "json", `request:"mediaType=application/json"`) if err != nil { return nil, err @@ -448,100 +355,44 @@ func (s *File) DownloadFiles(ctx context.Context, request []shared.DownloadFiles } req.Header.Set("Accept", "application/json") req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent) - req.Header.Set("Content-Type", reqContentType) + if reqContentType != "" { + req.Header.Set("Content-Type", reqContentType) + } if err := utils.PopulateSecurity(ctx, req, s.sdkConfiguration.Security); err != nil { return nil, err } - globalRetryConfig := s.sdkConfiguration.RetryConfig - retryConfig := o.Retries - if retryConfig == nil { - if globalRetryConfig != nil { - retryConfig = globalRetryConfig - } else { - retryConfig = &retry.Config{ - Strategy: "backoff", Backoff: &retry.BackoffStrategy{ - InitialInterval: 5000, - MaxInterval: 60000, - Exponent: 1.5, - MaxElapsedTime: 3600000, - }, - RetryConnectionErrors: true, - } - } + for k, v := range o.SetHeaders { + req.Header.Set(k, v) } - var httpRes *http.Response - if retryConfig != nil { - httpRes, err = utils.Retry(ctx, utils.Retries{ - Config: retryConfig, - StatusCodes: []string{ - "5XX", - }, - }, func() (*http.Response, error) { - if req.Body != nil { - copyBody, err := req.GetBody() - if err != nil { - return nil, err - } - req.Body = copyBody - } - - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) - if err != nil { - return nil, backoff.Permanent(err) - } - - httpRes, err := s.sdkConfiguration.Client.Do(req) - if err != nil || httpRes == nil { - if err != nil { - err = fmt.Errorf("error sending request: %w", err) - } else { - err = fmt.Errorf("error sending request: no response") - } - - _, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) - } - return httpRes, err - }) + req, err = s.hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + if err != nil { + return nil, err + } + httpRes, err := s.sdkConfiguration.Client.Do(req) + if err != nil || httpRes == nil { if err != nil { - return nil, err + err = fmt.Errorf("error sending request: %w", err) } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } + err = fmt.Errorf("error sending request: no response") } - } else { - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + + _, err = s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + return nil, err + } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { + _httpRes, err := s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) if err != nil { return nil, err + } else if _httpRes != nil { + httpRes = _httpRes } - - httpRes, err = s.sdkConfiguration.Client.Do(req) - if err != nil || httpRes == nil { - if err != nil { - err = fmt.Errorf("error sending request: %w", err) - } else { - err = fmt.Errorf("error sending request: no response") - } - - _, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + } else { + httpRes, err = s.hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) + if err != nil { return nil, err - } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { - _httpRes, err := s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) - if err != nil { - return nil, err - } else if _httpRes != nil { - httpRes = _httpRes - } - } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } } } @@ -588,16 +439,8 @@ func (s *File) DownloadFiles(ctx context.Context, request []shared.DownloadFiles // DownloadS3File - downloadS3File // Generate pre-signed download S3 url for a file func (s *File) DownloadS3File(ctx context.Context, request operations.DownloadS3FileRequest, opts ...operations.Option) (*operations.DownloadS3FileResponse, error) { - hookCtx := hooks.HookContext{ - Context: ctx, - OperationID: "downloadS3File", - OAuth2Scopes: []string{}, - SecuritySource: s.sdkConfiguration.Security, - } - o := operations.Options{} supportedOptions := []string{ - operations.SupportedOptionRetries, operations.SupportedOptionTimeout, } @@ -607,12 +450,27 @@ func (s *File) DownloadS3File(ctx context.Context, request operations.DownloadS3 } } - baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + var baseURL string + if o.ServerURL == nil { + baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + } else { + baseURL = *o.ServerURL + } opURL, err := url.JoinPath(baseURL, "/v1/files:downloadS3") if err != nil { return nil, fmt.Errorf("error generating URL: %w", err) } + hookCtx := hooks.HookContext{ + SDK: s.rootSDK, + SDKConfiguration: s.sdkConfiguration, + BaseURL: baseURL, + Context: ctx, + OperationID: "downloadS3File", + OAuth2Scopes: nil, + SecuritySource: s.sdkConfiguration.Security, + } + timeout := o.Timeout if timeout == nil { timeout = s.sdkConfiguration.Timeout @@ -639,94 +497,36 @@ func (s *File) DownloadS3File(ctx context.Context, request operations.DownloadS3 return nil, err } - globalRetryConfig := s.sdkConfiguration.RetryConfig - retryConfig := o.Retries - if retryConfig == nil { - if globalRetryConfig != nil { - retryConfig = globalRetryConfig - } else { - retryConfig = &retry.Config{ - Strategy: "backoff", Backoff: &retry.BackoffStrategy{ - InitialInterval: 5000, - MaxInterval: 60000, - Exponent: 1.5, - MaxElapsedTime: 3600000, - }, - RetryConnectionErrors: true, - } - } + for k, v := range o.SetHeaders { + req.Header.Set(k, v) } - var httpRes *http.Response - if retryConfig != nil { - httpRes, err = utils.Retry(ctx, utils.Retries{ - Config: retryConfig, - StatusCodes: []string{ - "5XX", - }, - }, func() (*http.Response, error) { - if req.Body != nil { - copyBody, err := req.GetBody() - if err != nil { - return nil, err - } - req.Body = copyBody - } - - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) - if err != nil { - return nil, backoff.Permanent(err) - } - - httpRes, err := s.sdkConfiguration.Client.Do(req) - if err != nil || httpRes == nil { - if err != nil { - err = fmt.Errorf("error sending request: %w", err) - } else { - err = fmt.Errorf("error sending request: no response") - } - - _, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) - } - return httpRes, err - }) + req, err = s.hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + if err != nil { + return nil, err + } + httpRes, err := s.sdkConfiguration.Client.Do(req) + if err != nil || httpRes == nil { if err != nil { - return nil, err + err = fmt.Errorf("error sending request: %w", err) } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } + err = fmt.Errorf("error sending request: no response") } - } else { - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + + _, err = s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + return nil, err + } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { + _httpRes, err := s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) if err != nil { return nil, err + } else if _httpRes != nil { + httpRes = _httpRes } - - httpRes, err = s.sdkConfiguration.Client.Do(req) - if err != nil || httpRes == nil { - if err != nil { - err = fmt.Errorf("error sending request: %w", err) - } else { - err = fmt.Errorf("error sending request: no response") - } - - _, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + } else { + httpRes, err = s.hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) + if err != nil { return nil, err - } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { - _httpRes, err := s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) - if err != nil { - return nil, err - } else if _httpRes != nil { - httpRes = _httpRes - } - } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } } } @@ -773,16 +573,8 @@ func (s *File) DownloadS3File(ctx context.Context, request operations.DownloadS3 // GetFile - getFile // Get a file entity by id func (s *File) GetFile(ctx context.Context, request operations.GetFileRequest, opts ...operations.Option) (*operations.GetFileResponse, error) { - hookCtx := hooks.HookContext{ - Context: ctx, - OperationID: "getFile", - OAuth2Scopes: []string{}, - SecuritySource: s.sdkConfiguration.Security, - } - o := operations.Options{} supportedOptions := []string{ - operations.SupportedOptionRetries, operations.SupportedOptionTimeout, } @@ -792,12 +584,27 @@ func (s *File) GetFile(ctx context.Context, request operations.GetFileRequest, o } } - baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + var baseURL string + if o.ServerURL == nil { + baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + } else { + baseURL = *o.ServerURL + } opURL, err := utils.GenerateURL(ctx, baseURL, "/v2/files/{id}", request, nil) if err != nil { return nil, fmt.Errorf("error generating URL: %w", err) } + hookCtx := hooks.HookContext{ + SDK: s.rootSDK, + SDKConfiguration: s.sdkConfiguration, + BaseURL: baseURL, + Context: ctx, + OperationID: "getFile", + OAuth2Scopes: nil, + SecuritySource: s.sdkConfiguration.Security, + } + timeout := o.Timeout if timeout == nil { timeout = s.sdkConfiguration.Timeout @@ -824,94 +631,36 @@ func (s *File) GetFile(ctx context.Context, request operations.GetFileRequest, o return nil, err } - globalRetryConfig := s.sdkConfiguration.RetryConfig - retryConfig := o.Retries - if retryConfig == nil { - if globalRetryConfig != nil { - retryConfig = globalRetryConfig - } else { - retryConfig = &retry.Config{ - Strategy: "backoff", Backoff: &retry.BackoffStrategy{ - InitialInterval: 5000, - MaxInterval: 60000, - Exponent: 1.5, - MaxElapsedTime: 3600000, - }, - RetryConnectionErrors: true, - } - } + for k, v := range o.SetHeaders { + req.Header.Set(k, v) } - var httpRes *http.Response - if retryConfig != nil { - httpRes, err = utils.Retry(ctx, utils.Retries{ - Config: retryConfig, - StatusCodes: []string{ - "5XX", - }, - }, func() (*http.Response, error) { - if req.Body != nil { - copyBody, err := req.GetBody() - if err != nil { - return nil, err - } - req.Body = copyBody - } - - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) - if err != nil { - return nil, backoff.Permanent(err) - } - - httpRes, err := s.sdkConfiguration.Client.Do(req) - if err != nil || httpRes == nil { - if err != nil { - err = fmt.Errorf("error sending request: %w", err) - } else { - err = fmt.Errorf("error sending request: no response") - } - - _, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) - } - return httpRes, err - }) + req, err = s.hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + if err != nil { + return nil, err + } + httpRes, err := s.sdkConfiguration.Client.Do(req) + if err != nil || httpRes == nil { if err != nil { - return nil, err + err = fmt.Errorf("error sending request: %w", err) } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } + err = fmt.Errorf("error sending request: no response") } - } else { - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + + _, err = s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + return nil, err + } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { + _httpRes, err := s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) if err != nil { return nil, err + } else if _httpRes != nil { + httpRes = _httpRes } - - httpRes, err = s.sdkConfiguration.Client.Do(req) - if err != nil || httpRes == nil { - if err != nil { - err = fmt.Errorf("error sending request: %w", err) - } else { - err = fmt.Errorf("error sending request: no response") - } - - _, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + } else { + httpRes, err = s.hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) + if err != nil { return nil, err - } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { - _httpRes, err := s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) - if err != nil { - return nil, err - } else if _httpRes != nil { - httpRes = _httpRes - } - } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } } } @@ -960,16 +709,8 @@ func (s *File) GetFile(ctx context.Context, request operations.GetFileRequest, o // // Saves metadata to file entity and stores a version when `s3ref` or `source_url` is passed. func (s *File) SaveFileV2(ctx context.Context, request operations.SaveFileV2Request, opts ...operations.Option) (*operations.SaveFileV2Response, error) { - hookCtx := hooks.HookContext{ - Context: ctx, - OperationID: "saveFileV2", - OAuth2Scopes: []string{}, - SecuritySource: s.sdkConfiguration.Security, - } - o := operations.Options{} supportedOptions := []string{ - operations.SupportedOptionRetries, operations.SupportedOptionTimeout, } @@ -979,12 +720,26 @@ func (s *File) SaveFileV2(ctx context.Context, request operations.SaveFileV2Requ } } - baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + var baseURL string + if o.ServerURL == nil { + baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + } else { + baseURL = *o.ServerURL + } opURL, err := url.JoinPath(baseURL, "/v2/files") if err != nil { return nil, fmt.Errorf("error generating URL: %w", err) } + hookCtx := hooks.HookContext{ + SDK: s.rootSDK, + SDKConfiguration: s.sdkConfiguration, + BaseURL: baseURL, + Context: ctx, + OperationID: "saveFileV2", + OAuth2Scopes: nil, + SecuritySource: s.sdkConfiguration.Security, + } bodyReader, reqContentType, err := utils.SerializeRequestBody(ctx, request, false, true, "SaveFilePayloadV2", "json", `request:"mediaType=application/json"`) if err != nil { return nil, err @@ -1007,7 +762,9 @@ func (s *File) SaveFileV2(ctx context.Context, request operations.SaveFileV2Requ } req.Header.Set("Accept", "application/json") req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent) - req.Header.Set("Content-Type", reqContentType) + if reqContentType != "" { + req.Header.Set("Content-Type", reqContentType) + } if err := utils.PopulateQueryParams(ctx, req, request, nil); err != nil { return nil, fmt.Errorf("error populating query params: %w", err) @@ -1017,94 +774,36 @@ func (s *File) SaveFileV2(ctx context.Context, request operations.SaveFileV2Requ return nil, err } - globalRetryConfig := s.sdkConfiguration.RetryConfig - retryConfig := o.Retries - if retryConfig == nil { - if globalRetryConfig != nil { - retryConfig = globalRetryConfig - } else { - retryConfig = &retry.Config{ - Strategy: "backoff", Backoff: &retry.BackoffStrategy{ - InitialInterval: 5000, - MaxInterval: 60000, - Exponent: 1.5, - MaxElapsedTime: 3600000, - }, - RetryConnectionErrors: true, - } - } + for k, v := range o.SetHeaders { + req.Header.Set(k, v) } - var httpRes *http.Response - if retryConfig != nil { - httpRes, err = utils.Retry(ctx, utils.Retries{ - Config: retryConfig, - StatusCodes: []string{ - "5XX", - }, - }, func() (*http.Response, error) { - if req.Body != nil { - copyBody, err := req.GetBody() - if err != nil { - return nil, err - } - req.Body = copyBody - } - - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) - if err != nil { - return nil, backoff.Permanent(err) - } - - httpRes, err := s.sdkConfiguration.Client.Do(req) - if err != nil || httpRes == nil { - if err != nil { - err = fmt.Errorf("error sending request: %w", err) - } else { - err = fmt.Errorf("error sending request: no response") - } - - _, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) - } - return httpRes, err - }) + req, err = s.hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + if err != nil { + return nil, err + } + httpRes, err := s.sdkConfiguration.Client.Do(req) + if err != nil || httpRes == nil { if err != nil { - return nil, err + err = fmt.Errorf("error sending request: %w", err) } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } + err = fmt.Errorf("error sending request: no response") } - } else { - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + + _, err = s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + return nil, err + } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { + _httpRes, err := s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) if err != nil { return nil, err + } else if _httpRes != nil { + httpRes = _httpRes } - - httpRes, err = s.sdkConfiguration.Client.Do(req) - if err != nil || httpRes == nil { - if err != nil { - err = fmt.Errorf("error sending request: %w", err) - } else { - err = fmt.Errorf("error sending request: no response") - } - - _, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + } else { + httpRes, err = s.hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) + if err != nil { return nil, err - } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { - _httpRes, err := s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) - if err != nil { - return nil, err - } else if _httpRes != nil { - httpRes = _httpRes - } - } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } } } @@ -1153,16 +852,8 @@ func (s *File) SaveFileV2(ctx context.Context, request operations.SaveFileV2Requ // // Use the saveFileV2 operation to store file file permanently. func (s *File) UploadFilePublic(ctx context.Context, request *shared.UploadFilePayload, opts ...operations.Option) (*operations.UploadFilePublicResponse, error) { - hookCtx := hooks.HookContext{ - Context: ctx, - OperationID: "uploadFilePublic", - OAuth2Scopes: []string{}, - SecuritySource: nil, - } - o := operations.Options{} supportedOptions := []string{ - operations.SupportedOptionRetries, operations.SupportedOptionTimeout, } @@ -1172,12 +863,26 @@ func (s *File) UploadFilePublic(ctx context.Context, request *shared.UploadFileP } } - baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + var baseURL string + if o.ServerURL == nil { + baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + } else { + baseURL = *o.ServerURL + } opURL, err := url.JoinPath(baseURL, "/v1/files/public/upload") if err != nil { return nil, fmt.Errorf("error generating URL: %w", err) } + hookCtx := hooks.HookContext{ + SDK: s.rootSDK, + SDKConfiguration: s.sdkConfiguration, + BaseURL: baseURL, + Context: ctx, + OperationID: "uploadFilePublic", + OAuth2Scopes: nil, + SecuritySource: nil, + } bodyReader, reqContentType, err := utils.SerializeRequestBody(ctx, request, false, true, "Request", "json", `request:"mediaType=application/json"`) if err != nil { return nil, err @@ -1200,96 +905,40 @@ func (s *File) UploadFilePublic(ctx context.Context, request *shared.UploadFileP } req.Header.Set("Accept", "application/json") req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent) - req.Header.Set("Content-Type", reqContentType) - - globalRetryConfig := s.sdkConfiguration.RetryConfig - retryConfig := o.Retries - if retryConfig == nil { - if globalRetryConfig != nil { - retryConfig = globalRetryConfig - } else { - retryConfig = &retry.Config{ - Strategy: "backoff", Backoff: &retry.BackoffStrategy{ - InitialInterval: 5000, - MaxInterval: 60000, - Exponent: 1.5, - MaxElapsedTime: 3600000, - }, - RetryConnectionErrors: true, - } - } + if reqContentType != "" { + req.Header.Set("Content-Type", reqContentType) } - var httpRes *http.Response - if retryConfig != nil { - httpRes, err = utils.Retry(ctx, utils.Retries{ - Config: retryConfig, - StatusCodes: []string{ - "5XX", - }, - }, func() (*http.Response, error) { - if req.Body != nil { - copyBody, err := req.GetBody() - if err != nil { - return nil, err - } - req.Body = copyBody - } - - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) - if err != nil { - return nil, backoff.Permanent(err) - } - - httpRes, err := s.sdkConfiguration.Client.Do(req) - if err != nil || httpRes == nil { - if err != nil { - err = fmt.Errorf("error sending request: %w", err) - } else { - err = fmt.Errorf("error sending request: no response") - } + for k, v := range o.SetHeaders { + req.Header.Set(k, v) + } - _, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) - } - return httpRes, err - }) + req, err = s.hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + if err != nil { + return nil, err + } + httpRes, err := s.sdkConfiguration.Client.Do(req) + if err != nil || httpRes == nil { if err != nil { - return nil, err + err = fmt.Errorf("error sending request: %w", err) } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } + err = fmt.Errorf("error sending request: no response") } - } else { - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + + _, err = s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + return nil, err + } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { + _httpRes, err := s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) if err != nil { return nil, err + } else if _httpRes != nil { + httpRes = _httpRes } - - httpRes, err = s.sdkConfiguration.Client.Do(req) - if err != nil || httpRes == nil { - if err != nil { - err = fmt.Errorf("error sending request: %w", err) - } else { - err = fmt.Errorf("error sending request: no response") - } - - _, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + } else { + httpRes, err = s.hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) + if err != nil { return nil, err - } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { - _httpRes, err := s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) - if err != nil { - return nil, err - } else if _httpRes != nil { - httpRes = _httpRes - } - } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } } } @@ -1338,16 +987,8 @@ func (s *File) UploadFilePublic(ctx context.Context, request *shared.UploadFileP // // Use the saveFileV2 operation to store file file permanently. func (s *File) UploadFileV2(ctx context.Context, request operations.UploadFileV2Request, opts ...operations.Option) (*operations.UploadFileV2Response, error) { - hookCtx := hooks.HookContext{ - Context: ctx, - OperationID: "uploadFileV2", - OAuth2Scopes: []string{}, - SecuritySource: s.sdkConfiguration.Security, - } - o := operations.Options{} supportedOptions := []string{ - operations.SupportedOptionRetries, operations.SupportedOptionTimeout, } @@ -1357,12 +998,26 @@ func (s *File) UploadFileV2(ctx context.Context, request operations.UploadFileV2 } } - baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + var baseURL string + if o.ServerURL == nil { + baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + } else { + baseURL = *o.ServerURL + } opURL, err := url.JoinPath(baseURL, "/v2/files/upload") if err != nil { return nil, fmt.Errorf("error generating URL: %w", err) } + hookCtx := hooks.HookContext{ + SDK: s.rootSDK, + SDKConfiguration: s.sdkConfiguration, + BaseURL: baseURL, + Context: ctx, + OperationID: "uploadFileV2", + OAuth2Scopes: nil, + SecuritySource: s.sdkConfiguration.Security, + } bodyReader, reqContentType, err := utils.SerializeRequestBody(ctx, request, false, true, "UploadFilePayload", "json", `request:"mediaType=application/json"`) if err != nil { return nil, err @@ -1385,7 +1040,9 @@ func (s *File) UploadFileV2(ctx context.Context, request operations.UploadFileV2 } req.Header.Set("Accept", "application/json") req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent) - req.Header.Set("Content-Type", reqContentType) + if reqContentType != "" { + req.Header.Set("Content-Type", reqContentType) + } if err := utils.PopulateQueryParams(ctx, req, request, nil); err != nil { return nil, fmt.Errorf("error populating query params: %w", err) @@ -1395,94 +1052,36 @@ func (s *File) UploadFileV2(ctx context.Context, request operations.UploadFileV2 return nil, err } - globalRetryConfig := s.sdkConfiguration.RetryConfig - retryConfig := o.Retries - if retryConfig == nil { - if globalRetryConfig != nil { - retryConfig = globalRetryConfig - } else { - retryConfig = &retry.Config{ - Strategy: "backoff", Backoff: &retry.BackoffStrategy{ - InitialInterval: 5000, - MaxInterval: 60000, - Exponent: 1.5, - MaxElapsedTime: 3600000, - }, - RetryConnectionErrors: true, - } - } + for k, v := range o.SetHeaders { + req.Header.Set(k, v) } - var httpRes *http.Response - if retryConfig != nil { - httpRes, err = utils.Retry(ctx, utils.Retries{ - Config: retryConfig, - StatusCodes: []string{ - "5XX", - }, - }, func() (*http.Response, error) { - if req.Body != nil { - copyBody, err := req.GetBody() - if err != nil { - return nil, err - } - req.Body = copyBody - } - - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) - if err != nil { - return nil, backoff.Permanent(err) - } - - httpRes, err := s.sdkConfiguration.Client.Do(req) - if err != nil || httpRes == nil { - if err != nil { - err = fmt.Errorf("error sending request: %w", err) - } else { - err = fmt.Errorf("error sending request: no response") - } - - _, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) - } - return httpRes, err - }) + req, err = s.hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + if err != nil { + return nil, err + } + httpRes, err := s.sdkConfiguration.Client.Do(req) + if err != nil || httpRes == nil { if err != nil { - return nil, err + err = fmt.Errorf("error sending request: %w", err) } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } + err = fmt.Errorf("error sending request: no response") } - } else { - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + + _, err = s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + return nil, err + } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { + _httpRes, err := s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) if err != nil { return nil, err + } else if _httpRes != nil { + httpRes = _httpRes } - - httpRes, err = s.sdkConfiguration.Client.Do(req) - if err != nil || httpRes == nil { - if err != nil { - err = fmt.Errorf("error sending request: %w", err) - } else { - err = fmt.Errorf("error sending request: no response") - } - - _, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + } else { + httpRes, err = s.hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) + if err != nil { return nil, err - } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { - _httpRes, err := s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) - if err != nil { - return nil, err - } else if _httpRes != nil { - httpRes = _httpRes - } - } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } } } @@ -1529,16 +1128,8 @@ func (s *File) UploadFileV2(ctx context.Context, request operations.UploadFileV2 // VerifyCustomDownloadURL - verifyCustomDownloadUrl // Verify a pre-signed custom download url for a file func (s *File) VerifyCustomDownloadURL(ctx context.Context, request *shared.VerifyCustomDownloadURLPayload, opts ...operations.Option) (*operations.VerifyCustomDownloadURLResponse, error) { - hookCtx := hooks.HookContext{ - Context: ctx, - OperationID: "verifyCustomDownloadUrl", - OAuth2Scopes: []string{}, - SecuritySource: s.sdkConfiguration.Security, - } - o := operations.Options{} supportedOptions := []string{ - operations.SupportedOptionRetries, operations.SupportedOptionTimeout, } @@ -1548,12 +1139,26 @@ func (s *File) VerifyCustomDownloadURL(ctx context.Context, request *shared.Veri } } - baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + var baseURL string + if o.ServerURL == nil { + baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + } else { + baseURL = *o.ServerURL + } opURL, err := url.JoinPath(baseURL, "/v1/files/download:verify") if err != nil { return nil, fmt.Errorf("error generating URL: %w", err) } + hookCtx := hooks.HookContext{ + SDK: s.rootSDK, + SDKConfiguration: s.sdkConfiguration, + BaseURL: baseURL, + Context: ctx, + OperationID: "verifyCustomDownloadUrl", + OAuth2Scopes: nil, + SecuritySource: s.sdkConfiguration.Security, + } bodyReader, reqContentType, err := utils.SerializeRequestBody(ctx, request, false, true, "Request", "json", `request:"mediaType=application/json"`) if err != nil { return nil, err @@ -1576,100 +1181,44 @@ func (s *File) VerifyCustomDownloadURL(ctx context.Context, request *shared.Veri } req.Header.Set("Accept", "application/json") req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent) - req.Header.Set("Content-Type", reqContentType) + if reqContentType != "" { + req.Header.Set("Content-Type", reqContentType) + } if err := utils.PopulateSecurity(ctx, req, s.sdkConfiguration.Security); err != nil { return nil, err } - globalRetryConfig := s.sdkConfiguration.RetryConfig - retryConfig := o.Retries - if retryConfig == nil { - if globalRetryConfig != nil { - retryConfig = globalRetryConfig - } else { - retryConfig = &retry.Config{ - Strategy: "backoff", Backoff: &retry.BackoffStrategy{ - InitialInterval: 5000, - MaxInterval: 60000, - Exponent: 1.5, - MaxElapsedTime: 3600000, - }, - RetryConnectionErrors: true, - } - } + for k, v := range o.SetHeaders { + req.Header.Set(k, v) } - var httpRes *http.Response - if retryConfig != nil { - httpRes, err = utils.Retry(ctx, utils.Retries{ - Config: retryConfig, - StatusCodes: []string{ - "5XX", - }, - }, func() (*http.Response, error) { - if req.Body != nil { - copyBody, err := req.GetBody() - if err != nil { - return nil, err - } - req.Body = copyBody - } - - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) - if err != nil { - return nil, backoff.Permanent(err) - } - - httpRes, err := s.sdkConfiguration.Client.Do(req) - if err != nil || httpRes == nil { - if err != nil { - err = fmt.Errorf("error sending request: %w", err) - } else { - err = fmt.Errorf("error sending request: no response") - } - - _, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) - } - return httpRes, err - }) + req, err = s.hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + if err != nil { + return nil, err + } + httpRes, err := s.sdkConfiguration.Client.Do(req) + if err != nil || httpRes == nil { if err != nil { - return nil, err + err = fmt.Errorf("error sending request: %w", err) } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } + err = fmt.Errorf("error sending request: no response") } - } else { - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + + _, err = s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + return nil, err + } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { + _httpRes, err := s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) if err != nil { return nil, err + } else if _httpRes != nil { + httpRes = _httpRes } - - httpRes, err = s.sdkConfiguration.Client.Do(req) - if err != nil || httpRes == nil { - if err != nil { - err = fmt.Errorf("error sending request: %w", err) - } else { - err = fmt.Errorf("error sending request: no response") - } - - _, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + } else { + httpRes, err = s.hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) + if err != nil { return nil, err - } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { - _httpRes, err := s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) - if err != nil { - return nil, err - } else if _httpRes != nil { - httpRes = _httpRes - } - } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } } } diff --git a/internal/sdk/filefolders.go b/internal/sdk/filefolders.go new file mode 100644 index 0000000..3a58e2f --- /dev/null +++ b/internal/sdk/filefolders.go @@ -0,0 +1,805 @@ +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + +package sdk + +import ( + "bytes" + "context" + "fmt" + "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/internal/config" + "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/internal/hooks" + "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/internal/utils" + "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/models/errors" + "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/models/operations" + "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/models/shared" + "net/http" +) + +// FileFolders - Folder management for organizing files within entities +type FileFolders struct { + rootSDK *SDK + sdkConfiguration config.SDKConfiguration + hooks *hooks.Hooks +} + +func newFileFolders(rootSDK *SDK, sdkConfig config.SDKConfiguration, hooks *hooks.Hooks) *FileFolders { + return &FileFolders{ + rootSDK: rootSDK, + sdkConfiguration: sdkConfig, + hooks: hooks, + } +} + +// CreateFileFolder - createFileFolder +// Creates a new file folder for the specified entity +func (s *FileFolders) CreateFileFolder(ctx context.Context, request operations.CreateFileFolderRequest, opts ...operations.Option) (*operations.CreateFileFolderResponse, error) { + o := operations.Options{} + supportedOptions := []string{ + operations.SupportedOptionTimeout, + } + + for _, opt := range opts { + if err := opt(&o, supportedOptions...); err != nil { + return nil, fmt.Errorf("error applying option: %w", err) + } + } + + var baseURL string + if o.ServerURL == nil { + baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + } else { + baseURL = *o.ServerURL + } + opURL, err := utils.GenerateURL(ctx, baseURL, "/v1/entity/{id}/folders", request, nil) + if err != nil { + return nil, fmt.Errorf("error generating URL: %w", err) + } + + hookCtx := hooks.HookContext{ + SDK: s.rootSDK, + SDKConfiguration: s.sdkConfiguration, + BaseURL: baseURL, + Context: ctx, + OperationID: "createFileFolder", + OAuth2Scopes: nil, + SecuritySource: s.sdkConfiguration.Security, + } + bodyReader, reqContentType, err := utils.SerializeRequestBody(ctx, request, false, false, "FileFolderCreateRequest", "json", `request:"mediaType=application/json"`) + if err != nil { + return nil, err + } + + timeout := o.Timeout + if timeout == nil { + timeout = s.sdkConfiguration.Timeout + } + + if timeout != nil { + var cancel context.CancelFunc + ctx, cancel = context.WithTimeout(ctx, *timeout) + defer cancel() + } + + req, err := http.NewRequestWithContext(ctx, "POST", opURL, bodyReader) + if err != nil { + return nil, fmt.Errorf("error creating request: %w", err) + } + req.Header.Set("Accept", "application/json") + req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent) + if reqContentType != "" { + req.Header.Set("Content-Type", reqContentType) + } + + if err := utils.PopulateSecurity(ctx, req, s.sdkConfiguration.Security); err != nil { + return nil, err + } + + for k, v := range o.SetHeaders { + req.Header.Set(k, v) + } + + req, err = s.hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + if err != nil { + return nil, err + } + + httpRes, err := s.sdkConfiguration.Client.Do(req) + if err != nil || httpRes == nil { + if err != nil { + err = fmt.Errorf("error sending request: %w", err) + } else { + err = fmt.Errorf("error sending request: no response") + } + + _, err = s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + return nil, err + } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { + _httpRes, err := s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) + if err != nil { + return nil, err + } else if _httpRes != nil { + httpRes = _httpRes + } + } else { + httpRes, err = s.hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) + if err != nil { + return nil, err + } + } + + res := &operations.CreateFileFolderResponse{ + StatusCode: httpRes.StatusCode, + ContentType: httpRes.Header.Get("Content-Type"), + RawResponse: httpRes, + } + + switch { + case httpRes.StatusCode == 201: + switch { + case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } + + var out shared.FileFolderItem + if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil { + return nil, err + } + + res.FileFolderItem = &out + default: + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } + return nil, errors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) + } + case httpRes.StatusCode == 404: + switch { + case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } + + var out operations.CreateFileFolderResponseBody + if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil { + return nil, err + } + + res.Object = &out + default: + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } + return nil, errors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) + } + default: + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } + return nil, errors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) + } + + return res, nil + +} + +// DeleteFileFolder - deleteFileFolder +// Deletes a specific file folder by slug +func (s *FileFolders) DeleteFileFolder(ctx context.Context, request operations.DeleteFileFolderRequest, opts ...operations.Option) (*operations.DeleteFileFolderResponse, error) { + o := operations.Options{} + supportedOptions := []string{ + operations.SupportedOptionTimeout, + } + + for _, opt := range opts { + if err := opt(&o, supportedOptions...); err != nil { + return nil, fmt.Errorf("error applying option: %w", err) + } + } + + var baseURL string + if o.ServerURL == nil { + baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + } else { + baseURL = *o.ServerURL + } + opURL, err := utils.GenerateURL(ctx, baseURL, "/v1/entity/{id}/folders/{folderSlug}", request, nil) + if err != nil { + return nil, fmt.Errorf("error generating URL: %w", err) + } + + hookCtx := hooks.HookContext{ + SDK: s.rootSDK, + SDKConfiguration: s.sdkConfiguration, + BaseURL: baseURL, + Context: ctx, + OperationID: "deleteFileFolder", + OAuth2Scopes: nil, + SecuritySource: s.sdkConfiguration.Security, + } + + timeout := o.Timeout + if timeout == nil { + timeout = s.sdkConfiguration.Timeout + } + + if timeout != nil { + var cancel context.CancelFunc + ctx, cancel = context.WithTimeout(ctx, *timeout) + defer cancel() + } + + req, err := http.NewRequestWithContext(ctx, "DELETE", opURL, nil) + if err != nil { + return nil, fmt.Errorf("error creating request: %w", err) + } + req.Header.Set("Accept", "application/json") + req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent) + + if err := utils.PopulateSecurity(ctx, req, s.sdkConfiguration.Security); err != nil { + return nil, err + } + + for k, v := range o.SetHeaders { + req.Header.Set(k, v) + } + + req, err = s.hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + if err != nil { + return nil, err + } + + httpRes, err := s.sdkConfiguration.Client.Do(req) + if err != nil || httpRes == nil { + if err != nil { + err = fmt.Errorf("error sending request: %w", err) + } else { + err = fmt.Errorf("error sending request: no response") + } + + _, err = s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + return nil, err + } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { + _httpRes, err := s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) + if err != nil { + return nil, err + } else if _httpRes != nil { + httpRes = _httpRes + } + } else { + httpRes, err = s.hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) + if err != nil { + return nil, err + } + } + + res := &operations.DeleteFileFolderResponse{ + StatusCode: httpRes.StatusCode, + ContentType: httpRes.Header.Get("Content-Type"), + RawResponse: httpRes, + } + + switch { + case httpRes.StatusCode == 200: + case httpRes.StatusCode == 404: + switch { + case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } + + var out operations.DeleteFileFolderResponseBody + if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil { + return nil, err + } + + res.Object = &out + default: + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } + return nil, errors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) + } + default: + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } + return nil, errors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) + } + + return res, nil + +} + +// GetFileFolders - getFileFolders +// Gets a list of folders that exist for an entity +func (s *FileFolders) GetFileFolders(ctx context.Context, request operations.GetFileFoldersRequest, opts ...operations.Option) (*operations.GetFileFoldersResponse, error) { + o := operations.Options{} + supportedOptions := []string{ + operations.SupportedOptionTimeout, + } + + for _, opt := range opts { + if err := opt(&o, supportedOptions...); err != nil { + return nil, fmt.Errorf("error applying option: %w", err) + } + } + + var baseURL string + if o.ServerURL == nil { + baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + } else { + baseURL = *o.ServerURL + } + opURL, err := utils.GenerateURL(ctx, baseURL, "/v1/entity/{id}/folders", request, nil) + if err != nil { + return nil, fmt.Errorf("error generating URL: %w", err) + } + + hookCtx := hooks.HookContext{ + SDK: s.rootSDK, + SDKConfiguration: s.sdkConfiguration, + BaseURL: baseURL, + Context: ctx, + OperationID: "getFileFolders", + OAuth2Scopes: nil, + SecuritySource: s.sdkConfiguration.Security, + } + + timeout := o.Timeout + if timeout == nil { + timeout = s.sdkConfiguration.Timeout + } + + if timeout != nil { + var cancel context.CancelFunc + ctx, cancel = context.WithTimeout(ctx, *timeout) + defer cancel() + } + + req, err := http.NewRequestWithContext(ctx, "GET", opURL, nil) + if err != nil { + return nil, fmt.Errorf("error creating request: %w", err) + } + req.Header.Set("Accept", "application/json") + req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent) + + if err := utils.PopulateQueryParams(ctx, req, request, nil); err != nil { + return nil, fmt.Errorf("error populating query params: %w", err) + } + + if err := utils.PopulateSecurity(ctx, req, s.sdkConfiguration.Security); err != nil { + return nil, err + } + + for k, v := range o.SetHeaders { + req.Header.Set(k, v) + } + + req, err = s.hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + if err != nil { + return nil, err + } + + httpRes, err := s.sdkConfiguration.Client.Do(req) + if err != nil || httpRes == nil { + if err != nil { + err = fmt.Errorf("error sending request: %w", err) + } else { + err = fmt.Errorf("error sending request: no response") + } + + _, err = s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + return nil, err + } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { + _httpRes, err := s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) + if err != nil { + return nil, err + } else if _httpRes != nil { + httpRes = _httpRes + } + } else { + httpRes, err = s.hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) + if err != nil { + return nil, err + } + } + + res := &operations.GetFileFoldersResponse{ + StatusCode: httpRes.StatusCode, + ContentType: httpRes.Header.Get("Content-Type"), + RawResponse: httpRes, + } + + switch { + case httpRes.StatusCode == 200: + switch { + case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } + + var out []shared.FileFolderItem + if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil { + return nil, err + } + + res.Classes = out + default: + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } + return nil, errors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) + } + case httpRes.StatusCode == 404: + switch { + case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } + + var out operations.GetFileFoldersResponseBody + if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil { + return nil, err + } + + res.Object = &out + default: + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } + return nil, errors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) + } + default: + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } + return nil, errors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) + } + + return res, nil + +} + +// GetFilesInFolder - getFilesInFolder +// Gets all files within a specific folder for an entity +func (s *FileFolders) GetFilesInFolder(ctx context.Context, request operations.GetFilesInFolderRequest, opts ...operations.Option) (*operations.GetFilesInFolderResponse, error) { + o := operations.Options{} + supportedOptions := []string{ + operations.SupportedOptionTimeout, + } + + for _, opt := range opts { + if err := opt(&o, supportedOptions...); err != nil { + return nil, fmt.Errorf("error applying option: %w", err) + } + } + + var baseURL string + if o.ServerURL == nil { + baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + } else { + baseURL = *o.ServerURL + } + opURL, err := utils.GenerateURL(ctx, baseURL, "/v1/entity/{id}/folders/{folderSlug}/files", request, nil) + if err != nil { + return nil, fmt.Errorf("error generating URL: %w", err) + } + + hookCtx := hooks.HookContext{ + SDK: s.rootSDK, + SDKConfiguration: s.sdkConfiguration, + BaseURL: baseURL, + Context: ctx, + OperationID: "getFilesInFolder", + OAuth2Scopes: nil, + SecuritySource: s.sdkConfiguration.Security, + } + + timeout := o.Timeout + if timeout == nil { + timeout = s.sdkConfiguration.Timeout + } + + if timeout != nil { + var cancel context.CancelFunc + ctx, cancel = context.WithTimeout(ctx, *timeout) + defer cancel() + } + + req, err := http.NewRequestWithContext(ctx, "GET", opURL, nil) + if err != nil { + return nil, fmt.Errorf("error creating request: %w", err) + } + req.Header.Set("Accept", "application/json") + req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent) + + if err := utils.PopulateSecurity(ctx, req, s.sdkConfiguration.Security); err != nil { + return nil, err + } + + for k, v := range o.SetHeaders { + req.Header.Set(k, v) + } + + req, err = s.hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + if err != nil { + return nil, err + } + + httpRes, err := s.sdkConfiguration.Client.Do(req) + if err != nil || httpRes == nil { + if err != nil { + err = fmt.Errorf("error sending request: %w", err) + } else { + err = fmt.Errorf("error sending request: no response") + } + + _, err = s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + return nil, err + } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { + _httpRes, err := s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) + if err != nil { + return nil, err + } else if _httpRes != nil { + httpRes = _httpRes + } + } else { + httpRes, err = s.hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) + if err != nil { + return nil, err + } + } + + res := &operations.GetFilesInFolderResponse{ + StatusCode: httpRes.StatusCode, + ContentType: httpRes.Header.Get("Content-Type"), + RawResponse: httpRes, + } + + switch { + case httpRes.StatusCode == 200: + switch { + case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } + + var out []shared.FileEntity + if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil { + return nil, err + } + + res.TwoHundredApplicationJSONClasses = out + default: + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } + return nil, errors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) + } + case httpRes.StatusCode == 403: + switch { + case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } + + var out operations.GetFilesInFolderResponseBody + if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil { + return nil, err + } + + res.FourHundredAndThreeApplicationJSONObject = &out + default: + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } + return nil, errors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) + } + case httpRes.StatusCode == 404: + switch { + case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } + + var out operations.GetFilesInFolderFileFoldersResponseBody + if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil { + return nil, err + } + + res.FourHundredAndFourApplicationJSONObject = &out + default: + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } + return nil, errors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) + } + default: + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } + return nil, errors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) + } + + return res, nil + +} + +// UpdateFileFolder - updateFileFolder +// Updates a specific file folder by slug +func (s *FileFolders) UpdateFileFolder(ctx context.Context, request operations.UpdateFileFolderRequest, opts ...operations.Option) (*operations.UpdateFileFolderResponse, error) { + o := operations.Options{} + supportedOptions := []string{ + operations.SupportedOptionTimeout, + } + + for _, opt := range opts { + if err := opt(&o, supportedOptions...); err != nil { + return nil, fmt.Errorf("error applying option: %w", err) + } + } + + var baseURL string + if o.ServerURL == nil { + baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + } else { + baseURL = *o.ServerURL + } + opURL, err := utils.GenerateURL(ctx, baseURL, "/v1/entity/{id}/folders/{folderSlug}", request, nil) + if err != nil { + return nil, fmt.Errorf("error generating URL: %w", err) + } + + hookCtx := hooks.HookContext{ + SDK: s.rootSDK, + SDKConfiguration: s.sdkConfiguration, + BaseURL: baseURL, + Context: ctx, + OperationID: "updateFileFolder", + OAuth2Scopes: nil, + SecuritySource: s.sdkConfiguration.Security, + } + bodyReader, reqContentType, err := utils.SerializeRequestBody(ctx, request, false, false, "FileFolderAttributes", "json", `request:"mediaType=application/json"`) + if err != nil { + return nil, err + } + + timeout := o.Timeout + if timeout == nil { + timeout = s.sdkConfiguration.Timeout + } + + if timeout != nil { + var cancel context.CancelFunc + ctx, cancel = context.WithTimeout(ctx, *timeout) + defer cancel() + } + + req, err := http.NewRequestWithContext(ctx, "PUT", opURL, bodyReader) + if err != nil { + return nil, fmt.Errorf("error creating request: %w", err) + } + req.Header.Set("Accept", "application/json") + req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent) + if reqContentType != "" { + req.Header.Set("Content-Type", reqContentType) + } + + if err := utils.PopulateSecurity(ctx, req, s.sdkConfiguration.Security); err != nil { + return nil, err + } + + for k, v := range o.SetHeaders { + req.Header.Set(k, v) + } + + req, err = s.hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + if err != nil { + return nil, err + } + + httpRes, err := s.sdkConfiguration.Client.Do(req) + if err != nil || httpRes == nil { + if err != nil { + err = fmt.Errorf("error sending request: %w", err) + } else { + err = fmt.Errorf("error sending request: no response") + } + + _, err = s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + return nil, err + } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { + _httpRes, err := s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) + if err != nil { + return nil, err + } else if _httpRes != nil { + httpRes = _httpRes + } + } else { + httpRes, err = s.hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) + if err != nil { + return nil, err + } + } + + res := &operations.UpdateFileFolderResponse{ + StatusCode: httpRes.StatusCode, + ContentType: httpRes.Header.Get("Content-Type"), + RawResponse: httpRes, + } + + switch { + case httpRes.StatusCode == 200: + switch { + case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } + + var out shared.FileFolderItem + if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil { + return nil, err + } + + res.FileFolderItem = &out + default: + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } + return nil, errors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) + } + case httpRes.StatusCode == 404: + switch { + case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`): + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } + + var out operations.UpdateFileFolderResponseBody + if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil { + return nil, err + } + + res.Object = &out + default: + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } + return nil, errors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes) + } + default: + rawBody, err := utils.ConsumeRawBody(httpRes) + if err != nil { + return nil, err + } + return nil, errors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes) + } + + return res, nil + +} diff --git a/internal/sdk/internal/config/sdkconfiguration.go b/internal/sdk/internal/config/sdkconfiguration.go new file mode 100644 index 0000000..db252fa --- /dev/null +++ b/internal/sdk/internal/config/sdkconfiguration.go @@ -0,0 +1,33 @@ +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + +package config + +import ( + "context" + "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/retry" + "net/http" + "time" +) + +type HTTPClient interface { + Do(req *http.Request) (*http.Response, error) +} + +type SDKConfiguration struct { + Client HTTPClient + Security func(context.Context) (interface{}, error) + ServerURL string + ServerIndex int + ServerList []string + UserAgent string + RetryConfig *retry.Config + Timeout *time.Duration +} + +func (c *SDKConfiguration) GetServerDetails() (string, map[string]string) { + if c.ServerURL != "" { + return c.ServerURL, nil + } + + return c.ServerList[c.ServerIndex], nil +} diff --git a/internal/sdk/internal/hooks/hooks.go b/internal/sdk/internal/hooks/hooks.go index 8ea491a..259ff1f 100644 --- a/internal/sdk/internal/hooks/hooks.go +++ b/internal/sdk/internal/hooks/hooks.go @@ -5,6 +5,7 @@ package hooks import ( "context" "errors" + "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/internal/config" "net/http" ) @@ -24,10 +25,13 @@ type HTTPClient interface { } type HookContext struct { - Context context.Context - OperationID string - OAuth2Scopes []string - SecuritySource func(context.Context) (interface{}, error) + SDK any + SDKConfiguration config.SDKConfiguration + BaseURL string + Context context.Context + OperationID string + OAuth2Scopes []string + SecuritySource func(context.Context) (interface{}, error) } type BeforeRequestContext struct { @@ -70,6 +74,11 @@ type Hooks struct { afterErrorHook []afterErrorHook } +var _ sdkInitHook = (*Hooks)(nil) +var _ beforeRequestHook = (*Hooks)(nil) +var _ afterSuccessHook = (*Hooks)(nil) +var _ afterErrorHook = (*Hooks)(nil) + func New() *Hooks { h := &Hooks{ sdkInitHooks: []sdkInitHook{}, diff --git a/internal/sdk/internal/utils/env.go b/internal/sdk/internal/utils/env.go new file mode 100644 index 0000000..110d464 --- /dev/null +++ b/internal/sdk/internal/utils/env.go @@ -0,0 +1,16 @@ +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + +package utils + +import ( + "os" +) + +// GetEnv returns the value of the environment variable named by the key or the defaultValue if the environment variable is not set. +func GetEnv(name, defaultValue string) string { + value := os.Getenv(name) + if value == "" { + return defaultValue + } + return value +} diff --git a/internal/sdk/internal/utils/form.go b/internal/sdk/internal/utils/form.go index 387a62a..5a08e78 100644 --- a/internal/sdk/internal/utils/form.go +++ b/internal/sdk/internal/utils/form.go @@ -10,16 +10,19 @@ import ( "strings" "time" - "github.com/ericlagergren/decimal" - + "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/optionalnullable" "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/types" ) -func populateForm(paramName string, explode bool, objType reflect.Type, objValue reflect.Value, delimiter string, getFieldName func(reflect.StructField) string) url.Values { +func populateForm(paramName string, explode bool, objType reflect.Type, objValue reflect.Value, delimiter string, defaultValue *string, getFieldName func(reflect.StructField) string) url.Values { formValues := url.Values{} if isNil(objType, objValue) { + if defaultValue != nil { + formValues.Add(paramName, *defaultValue) + } + return formValues } @@ -37,8 +40,6 @@ func populateForm(paramName string, explode bool, objType reflect.Type, objValue formValues.Add(paramName, valToString(objValue.Interface())) case big.Int: formValues.Add(paramName, valToString(objValue.Interface())) - case decimal.Big: - formValues.Add(paramName, valToString(objValue.Interface())) default: var items []string @@ -60,7 +61,13 @@ func populateForm(paramName string, explode bool, objType reflect.Type, objValue } if explode { - formValues.Add(fieldName, valToString(valType.Interface())) + if valType.Kind() == reflect.Slice || valType.Kind() == reflect.Array { + for i := 0; i < valType.Len(); i++ { + formValues.Add(fieldName, valToString(valType.Index(i).Interface())) + } + } else { + formValues.Add(fieldName, valToString(valType.Interface())) + } } else { items = append(items, fmt.Sprintf("%s%s%s", fieldName, delimiter, valToString(valType.Interface()))) } @@ -71,6 +78,16 @@ func populateForm(paramName string, explode bool, objType reflect.Type, objValue } } case reflect.Map: + // check if optionalnullable.OptionalNullable[T] + if nullableValue, ok := optionalnullable.AsOptionalNullable(objValue); ok { + // Handle optionalnullable.OptionalNullable[T] using GetUntyped method + if value, isSet := nullableValue.GetUntyped(); isSet && value != nil { + formValues.Add(paramName, valToString(value)) + } + // If not set or explicitly null, skip adding to form + return formValues + } + items := []string{} iter := objValue.MapRange() diff --git a/internal/sdk/internal/utils/headers.go b/internal/sdk/internal/utils/headers.go index a07608b..f881531 100644 --- a/internal/sdk/internal/utils/headers.go +++ b/internal/sdk/internal/utils/headers.go @@ -8,6 +8,8 @@ import ( "net/http" "reflect" "strings" + + "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/optionalnullable" ) func PopulateHeaders(_ context.Context, req *http.Request, headers interface{}, globals interface{}) { @@ -98,6 +100,16 @@ func serializeHeader(objType reflect.Type, objValue reflect.Value, explode bool) return strings.Join(items, ",") case reflect.Map: + // check if optionalnullable.OptionalNullable[T] + if nullableValue, ok := optionalnullable.AsOptionalNullable(objValue); ok { + // Handle optionalnullable.OptionalNullable[T] using GetUntyped method + if value, isSet := nullableValue.GetUntyped(); isSet && value != nil { + return valToString(value) + } + // If not set or explicitly null, return empty string + return "" + } + items := []string{} iter := objValue.MapRange() diff --git a/internal/sdk/internal/utils/json.go b/internal/sdk/internal/utils/json.go index c67ba9b..aa9d0f8 100644 --- a/internal/sdk/internal/utils/json.go +++ b/internal/sdk/internal/utils/json.go @@ -5,6 +5,7 @@ package utils import ( "bytes" "encoding/json" + "errors" "fmt" "math/big" "reflect" @@ -14,8 +15,6 @@ import ( "unsafe" "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/types" - - "github.com/ericlagergren/decimal" ) func MarshalJSON(v interface{}, tag reflect.StructTag, topLevel bool) ([]byte, error) { @@ -114,9 +113,9 @@ func MarshalJSON(v interface{}, tag reflect.StructTag, topLevel bool) ([]byte, e } } -func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool, disallowUnknownFields bool) error { +func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool, requiredFields []string) error { if reflect.TypeOf(v).Kind() != reflect.Ptr { - return fmt.Errorf("v must be a pointer") + return errors.New("v must be a pointer") } typ, val := dereferencePointers(reflect.TypeOf(v), reflect.ValueOf(v)) @@ -124,19 +123,25 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool switch { case isModelType(typ): if topLevel || bytes.Equal(b, []byte("null")) { - d := json.NewDecoder(bytes.NewReader(b)) - if disallowUnknownFields { - d.DisallowUnknownFields() - } - return d.Decode(v) + return json.Unmarshal(b, v) } - var unmarhsaled map[string]json.RawMessage + var unmarshaled map[string]json.RawMessage - if err := json.Unmarshal(b, &unmarhsaled); err != nil { + if err := json.Unmarshal(b, &unmarshaled); err != nil { return err } + missingFields := []string{} + for _, requiredField := range requiredFields { + if _, ok := unmarshaled[requiredField]; !ok { + missingFields = append(missingFields, requiredField) + } + } + if len(missingFields) > 0 { + return fmt.Errorf("missing required fields: %s", strings.Join(missingFields, ", ")) + } + var additionalPropertiesField *reflect.StructField var additionalPropertiesValue *reflect.Value @@ -163,7 +168,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool // If we receive a value for a const field ignore it but mark it as unmarshaled if field.Tag.Get("const") != "" { - if r, ok := unmarhsaled[fieldName]; ok { + if r, ok := unmarshaled[fieldName]; ok { val := string(r) if strings.HasPrefix(val, `"`) && strings.HasSuffix(val, `"`) { @@ -178,40 +183,36 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool return fmt.Errorf("const field `%s` does not match expected value `%s` got `%s`", fieldName, constValue, val) } - delete(unmarhsaled, fieldName) + delete(unmarshaled, fieldName) } } else if !field.IsExported() { continue } - value, ok := unmarhsaled[fieldName] + value, ok := unmarshaled[fieldName] if !ok { - defaultTag := field.Tag.Get("default") - if defaultTag != "" { + defaultTag, defaultOk := field.Tag.Lookup("default") + if defaultOk { value = handleDefaultConstValue(defaultTag, fieldVal.Interface(), field.Tag) ok = true } } else { - delete(unmarhsaled, fieldName) + delete(unmarshaled, fieldName) } if ok { - if err := unmarshalValue(value, fieldVal, field.Tag, disallowUnknownFields); err != nil { + if err := unmarshalValue(value, fieldVal, field.Tag); err != nil { return err } } } - keys := make([]string, 0, len(unmarhsaled)) - for k := range unmarhsaled { + keys := make([]string, 0, len(unmarshaled)) + for k := range unmarshaled { keys = append(keys, k) } if len(keys) > 0 { - if disallowUnknownFields && (additionalPropertiesField == nil || additionalPropertiesValue == nil) { - return fmt.Errorf("unknown fields: %v", keys) - } - if additionalPropertiesField != nil && additionalPropertiesValue != nil { typeOfMap := additionalPropertiesField.Type if additionalPropertiesValue.Type().Kind() == reflect.Interface { @@ -222,10 +223,10 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool mapValue := reflect.MakeMap(typeOfMap) - for key, value := range unmarhsaled { + for key, value := range unmarshaled { val := reflect.New(typeOfMap.Elem()) - if err := unmarshalValue(value, val, additionalPropertiesField.Tag, disallowUnknownFields); err != nil { + if err := unmarshalValue(value, val, additionalPropertiesField.Tag); err != nil { return err } @@ -244,7 +245,7 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool } } default: - return unmarshalValue(b, reflect.ValueOf(v), tag, disallowUnknownFields) + return unmarshalValue(b, reflect.ValueOf(v), tag) } return nil @@ -257,8 +258,8 @@ func marshalValue(v interface{}, tag reflect.StructTag) (json.RawMessage, error) } if isNil(reflect.TypeOf(v), reflect.ValueOf(v)) { - defaultTag := tag.Get("default") - if defaultTag != "" { + defaultTag, ok := tag.Lookup("default") + if ok { return handleDefaultConstValue(defaultTag, v, tag), nil } @@ -284,6 +285,11 @@ func marshalValue(v interface{}, tag reflect.StructTag) (json.RawMessage, error) return []byte("null"), nil } + // Check if the map implements json.Marshaler (like optionalnullable.OptionalNullable[T]) + if marshaler, ok := val.Interface().(json.Marshaler); ok { + return marshaler.MarshalJSON() + } + out := map[string]json.RawMessage{} for _, key := range val.MapKeys() { @@ -337,17 +343,6 @@ func marshalValue(v interface{}, tag reflect.StructTag) (json.RawMessage, error) b := val.Interface().(big.Int) return []byte(fmt.Sprintf(`"%s"`, (&b).String())), nil } - case reflect.TypeOf(decimal.Big{}): - format := tag.Get("decimal") - if format == "number" { - b := val.Interface().(decimal.Big) - f, ok := (&b).Float64() - if ok { - return []byte(b.String()), nil - } - - return []byte(fmt.Sprintf(`%f`, f)), nil - } } } @@ -378,11 +373,6 @@ func handleDefaultConstValue(tagValue string, val interface{}, tag reflect.Struc if format == "string" { return []byte(fmt.Sprintf(`"%s"`, tagValue)) } - case reflect.TypeOf(decimal.Big{}): - decimalTag := tag.Get("decimal") - if decimalTag != "number" { - return []byte(fmt.Sprintf(`"%s"`, tagValue)) - } case reflect.TypeOf(types.Date{}): return []byte(fmt.Sprintf(`"%s"`, tagValue)) default: @@ -394,7 +384,7 @@ func handleDefaultConstValue(tagValue string, val interface{}, tag reflect.Struc return []byte(tagValue) } -func unmarshalValue(value json.RawMessage, v reflect.Value, tag reflect.StructTag, disallowUnknownFields bool) error { +func unmarshalValue(value json.RawMessage, v reflect.Value, tag reflect.StructTag) error { if bytes.Equal(value, []byte("null")) { if v.CanAddr() { return json.Unmarshal(value, v.Addr().Interface()) @@ -466,18 +456,18 @@ func unmarshalValue(value json.RawMessage, v reflect.Value, tag reflect.StructTa } } - var unmarhsaled map[string]json.RawMessage + var unmarshaled map[string]json.RawMessage - if err := json.Unmarshal(value, &unmarhsaled); err != nil { + if err := json.Unmarshal(value, &unmarshaled); err != nil { return err } m := reflect.MakeMap(typ) - for k, value := range unmarhsaled { + for k, value := range unmarshaled { itemVal := reflect.New(typ.Elem()) - if err := unmarshalValue(value, itemVal, tag, disallowUnknownFields); err != nil { + if err := unmarshalValue(value, itemVal, tag); err != nil { return err } @@ -498,7 +488,7 @@ func unmarshalValue(value json.RawMessage, v reflect.Value, tag reflect.StructTa for index, value := range unmarshaled { itemVal := reflect.New(typ.Elem()) - if err := unmarshalValue(value, itemVal, tag, disallowUnknownFields); err != nil { + if err := unmarshalValue(value, itemVal, tag); err != nil { return err } @@ -563,27 +553,6 @@ func unmarshalValue(value json.RawMessage, v reflect.Value, tag reflect.StructTa v.Set(reflect.ValueOf(b)) return nil - case reflect.TypeOf(decimal.Big{}): - var d *decimal.Big - format := tag.Get("decimal") - if format == "number" { - var ok bool - d, ok = new(decimal.Big).SetString(string(value)) - if !ok { - return fmt.Errorf("failed to parse number as decimal.Big") - } - } else { - if err := json.Unmarshal(value, &d); err != nil { - return err - } - } - - if v.Kind() == reflect.Ptr && v.Elem().Kind() == reflect.Ptr { - v = v.Elem() - } - - v.Set(reflect.ValueOf(d)) - return nil case reflect.TypeOf(types.Date{}): var s string @@ -616,11 +585,7 @@ func unmarshalValue(value json.RawMessage, v reflect.Value, tag reflect.StructTa val = v.Interface() } - d := json.NewDecoder(bytes.NewReader(value)) - if disallowUnknownFields { - d.DisallowUnknownFields() - } - return d.Decode(val) + return json.Unmarshal(value, val) } func dereferencePointers(typ reflect.Type, val reflect.Value) (reflect.Type, reflect.Value) { @@ -652,8 +617,6 @@ func isComplexValueType(typ reflect.Type) bool { fallthrough case reflect.TypeOf(big.Int{}): fallthrough - case reflect.TypeOf(decimal.Big{}): - fallthrough case reflect.TypeOf(types.Date{}): return true } @@ -673,3 +636,215 @@ func isModelType(typ reflect.Type) bool { return false } + +// CalculateJSONSize returns the byte size of the JSON representation of a value. +// This is used to determine which union type variant has the most data. +func CalculateJSONSize(v interface{}) int { + data, err := json.Marshal(v) + if err != nil { + return 0 + } + return len(data) +} + +// UnionCandidate represents a candidate type during union deserialization +type UnionCandidate struct { + FieldCount int + Size int + Type any // The union type enum value + Value any // The unmarshaled value +} + +// CountFields recursively counts the number of valid (non-nil, non-zero) fields set in a value. +// This is used as the primary discriminator for union types, with JSON size as a tiebreaker. +func CountFields(v interface{}) int { + if v == nil { + return 0 + } + + typ := reflect.TypeOf(v) + val := reflect.ValueOf(v) + + // Dereference pointers + for typ.Kind() == reflect.Ptr { + if val.IsNil() { + return 0 + } + typ = typ.Elem() + val = val.Elem() + } + + return countFieldsRecursive(typ, val) +} + +// PickBestCandidate selects the best union type candidate using a multi-stage filtering approach: +// 1. If multiple candidates, filter by field count (keep only those with max field count) +// 2. If still multiple, filter by JSON size (keep only those with max size) +// 3. Return the first remaining candidate +func PickBestCandidate(candidates []UnionCandidate) *UnionCandidate { + if len(candidates) == 0 { + return nil + } + + if len(candidates) == 1 { + return &candidates[0] + } + + // Filter by field count if we have multiple candidates + if len(candidates) > 1 { + maxFieldCount := -1 + for i := range candidates { + candidates[i].FieldCount = CountFields(candidates[i].Value) + if candidates[i].FieldCount > maxFieldCount { + maxFieldCount = candidates[i].FieldCount + } + } + + // Keep only candidates with maximum field count + filtered := make([]UnionCandidate, 0, len(candidates)) + for _, c := range candidates { + if c.FieldCount == maxFieldCount { + filtered = append(filtered, c) + } + } + candidates = filtered + } + + if len(candidates) == 1 { + return &candidates[0] + } + + // Filter by JSON size if we still have multiple candidates + if len(candidates) > 1 { + maxSize := -1 + for i := range candidates { + candidates[i].Size = CalculateJSONSize(candidates[i].Value) + if candidates[i].Size > maxSize { + maxSize = candidates[i].Size + } + } + + // Keep only candidates with maximum size + filtered := make([]UnionCandidate, 0, len(candidates)) + for _, c := range candidates { + if c.Size == maxSize { + filtered = append(filtered, c) + } + } + candidates = filtered + } + + // Pick the first remaining candidate + return &candidates[0] +} + +func countFieldsRecursive(typ reflect.Type, val reflect.Value) int { + count := 0 + + switch typ.Kind() { + case reflect.Struct: + // Handle special types + switch typ { + case reflect.TypeOf(time.Time{}): + if !val.Interface().(time.Time).IsZero() { + return 1 + } + return 0 + case reflect.TypeOf(big.Int{}): + b := val.Interface().(big.Int) + if b.Sign() != 0 { + return 1 + } + return 0 + case reflect.TypeOf(types.Date{}): + // Date is always counted if it exists + return 1 + } + + // For regular structs, count non-zero fields + for i := 0; i < typ.NumField(); i++ { + field := typ.Field(i) + fieldVal := val.Field(i) + + // Skip unexported fields and const fields + if !field.IsExported() || field.Tag.Get("const") != "" { + continue + } + + // Skip fields tagged with json:"-" + jsonTag := field.Tag.Get("json") + if jsonTag == "-" { + continue + } + + fieldTyp := field.Type + // Dereference pointer types for the field + for fieldTyp.Kind() == reflect.Ptr { + if fieldVal.IsNil() { + break + } + fieldTyp = fieldTyp.Elem() + fieldVal = fieldVal.Elem() + } + + if !isNil(field.Type, val.Field(i)) { + count += countFieldsRecursive(fieldTyp, fieldVal) + } + } + + case reflect.Slice, reflect.Array: + if val.IsNil() || val.Len() == 0 { + return 0 + } + // Count each array/slice element + for i := 0; i < val.Len(); i++ { + itemVal := val.Index(i) + itemTyp := itemVal.Type() + + // Dereference pointer types + for itemTyp.Kind() == reflect.Ptr { + if itemVal.IsNil() { + break + } + itemTyp = itemTyp.Elem() + itemVal = itemVal.Elem() + } + + if !isNil(itemTyp, itemVal) { + count += countFieldsRecursive(itemTyp, itemVal) + } + } + + case reflect.String: + if val.String() != "" { + count = 1 + } + + case reflect.Bool: + // Bools always count as a field (even if false) + count = 1 + + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: + if val.Int() != 0 { + count = 1 + } + + case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: + if val.Uint() != 0 { + count = 1 + } + + case reflect.Float32, reflect.Float64: + if val.Float() != 0 { + count = 1 + } + + default: + // For any other type, if it's not zero, count it as 1 + if !val.IsZero() { + count = 1 + } + } + + return count +} diff --git a/internal/sdk/internal/utils/pathparams.go b/internal/sdk/internal/utils/pathparams.go index 3e86d47..194a969 100644 --- a/internal/sdk/internal/utils/pathparams.go +++ b/internal/sdk/internal/utils/pathparams.go @@ -11,8 +11,7 @@ import ( "strings" "time" - "github.com/ericlagergren/decimal" - + "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/optionalnullable" "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/types" ) @@ -114,6 +113,16 @@ func getSimplePathParams(parentName string, objType reflect.Type, objValue refle } pathParams[parentName] = strings.Join(ppVals, ",") case reflect.Map: + // check if optionalnullable.OptionalNullable[T] + if nullableValue, ok := optionalnullable.AsOptionalNullable(objValue); ok { + // Handle optionalnullable.OptionalNullable[T] using GetUntyped method + if value, isSet := nullableValue.GetUntyped(); isSet && value != nil { + pathParams[parentName] = valToString(value) + } + // If not set or explicitly null, return nil (skip parameter) + return pathParams + } + if objValue.Len() == 0 { return nil } @@ -135,8 +144,6 @@ func getSimplePathParams(parentName string, objType reflect.Type, objValue refle pathParams[parentName] = valToString(objValue.Interface()) case big.Int: pathParams[parentName] = valToString(objValue.Interface()) - case decimal.Big: - pathParams[parentName] = valToString(objValue.Interface()) default: var ppVals []string for i := 0; i < objType.NumField(); i++ { diff --git a/internal/sdk/internal/utils/queryparams.go b/internal/sdk/internal/utils/queryparams.go index 8b33231..cc89474 100644 --- a/internal/sdk/internal/utils/queryparams.go +++ b/internal/sdk/internal/utils/queryparams.go @@ -12,8 +12,7 @@ import ( "reflect" "time" - "github.com/ericlagergren/decimal" - + "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/optionalnullable" "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/types" ) @@ -65,6 +64,14 @@ func populateQueryParams(queryParams interface{}, globals interface{}, values ur continue } + constValue := parseConstTag(fieldType) + if constValue != nil { + values.Add(qpTag.ParamName, *constValue) + continue + } + + defaultValue := parseDefaultTag(fieldType) + if globals != nil { var globalFound bool fieldType, valType, globalFound = populateFromGlobals(fieldType, valType, queryParamTagKey, globals) @@ -91,14 +98,14 @@ func populateQueryParams(queryParams interface{}, globals interface{}, values ur } } case "form": - vals := populateFormParams(qpTag, fieldType.Type, valType, ",") + vals := populateFormParams(qpTag, fieldType.Type, valType, ",", defaultValue) for k, v := range vals { for _, vv := range v { values.Add(k, vv) } } case "pipeDelimited": - vals := populateFormParams(qpTag, fieldType.Type, valType, "|") + vals := populateFormParams(qpTag, fieldType.Type, valType, "|", defaultValue) for k, v := range vals { for _, vv := range v { values.Add(k, vv) @@ -149,6 +156,16 @@ func populateDeepObjectParams(tag *paramTag, objType reflect.Type, objValue refl switch objValue.Kind() { case reflect.Map: + // check if optionalnullable.OptionalNullable[T] + if nullableValue, ok := optionalnullable.AsOptionalNullable(objValue); ok { + // Handle optionalnullable.OptionalNullable[T] using GetUntyped method + if value, isSet := nullableValue.GetUntyped(); isSet && value != nil { + values.Add(tag.ParamName, valToString(value)) + } + // If not set or explicitly null, skip adding to values + return values + } + populateDeepObjectParamsMap(values, tag.ParamName, objValue) case reflect.Struct: populateDeepObjectParamsStruct(values, tag.ParamName, objValue) @@ -214,7 +231,11 @@ func populateDeepObjectParamsStruct(qsValues url.Values, priorScope string, stru continue } - scope := priorScope + "[" + qpTag.ParamName + "]" + scope := priorScope + + if !qpTag.Inline { + scope = priorScope + "[" + qpTag.ParamName + "]" + } switch fieldValue.Kind() { case reflect.Array, reflect.Slice: @@ -223,7 +244,7 @@ func populateDeepObjectParamsStruct(qsValues url.Values, priorScope string, stru populateDeepObjectParamsMap(qsValues, scope, fieldValue) case reflect.Struct: switch fieldValue.Type() { - case reflect.TypeOf(big.Int{}), reflect.TypeOf(decimal.Big{}), reflect.TypeOf(time.Time{}), reflect.TypeOf(types.Date{}): + case reflect.TypeOf(big.Int{}), reflect.TypeOf(time.Time{}), reflect.TypeOf(types.Date{}): qsValues.Add(scope, valToString(fieldValue.Interface())) continue @@ -236,8 +257,8 @@ func populateDeepObjectParamsStruct(qsValues url.Values, priorScope string, stru } } -func populateFormParams(tag *paramTag, objType reflect.Type, objValue reflect.Value, delimiter string) url.Values { - return populateForm(tag.ParamName, tag.Explode, objType, objValue, delimiter, func(fieldType reflect.StructField) string { +func populateFormParams(tag *paramTag, objType reflect.Type, objValue reflect.Value, delimiter string, defaultValue *string) url.Values { + return populateForm(tag.ParamName, tag.Explode, objType, objValue, delimiter, defaultValue, func(fieldType reflect.StructField) string { qpTag := parseQueryParamTag(fieldType) if qpTag == nil { return "" @@ -252,6 +273,13 @@ type paramTag struct { Explode bool ParamName string Serialization string + + // Inline is a special case for union/oneOf. When a wrapper struct type is + // used, each union/oneOf value field should be inlined (e.g. not appended + // in deepObject style with the name) as if the value was directly on the + // parent struct field. Without this annotation, the value would not be + // encoded by downstream logic that requires the struct field tag. + Inline bool } func parseQueryParamTag(field reflect.StructField) *paramTag { diff --git a/internal/sdk/internal/utils/requestbody.go b/internal/sdk/internal/utils/requestbody.go index 000226e..ab8ce92 100644 --- a/internal/sdk/internal/utils/requestbody.go +++ b/internal/sdk/internal/utils/requestbody.go @@ -7,10 +7,15 @@ import ( "context" "fmt" "io" + "mime" "mime/multipart" + "net/textproto" "net/url" + "path/filepath" "reflect" "regexp" + + "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/optionalnullable" ) const ( @@ -166,9 +171,21 @@ func encodeMultipartFormData(w io.Writer, data interface{}) (string, error) { tag := parseMultipartFormTag(field) if tag.File { - if err := encodeMultipartFormDataFile(writer, fieldType, valType); err != nil { - writer.Close() - return "", err + switch fieldType.Kind() { + case reflect.Slice, reflect.Array: + for i := 0; i < valType.Len(); i++ { + arrayVal := valType.Index(i) + + if err := encodeMultipartFormDataFile(writer, tag.Name+"[]", arrayVal.Type(), arrayVal); err != nil { + writer.Close() + return "", err + } + } + default: + if err := encodeMultipartFormDataFile(writer, tag.Name, fieldType, valType); err != nil { + writer.Close() + return "", err + } } } else if tag.JSON { jw, err := writer.CreateFormField(tag.Name) @@ -211,12 +228,11 @@ func encodeMultipartFormData(w io.Writer, data interface{}) (string, error) { return writer.FormDataContentType(), nil } -func encodeMultipartFormDataFile(w *multipart.Writer, fieldType reflect.Type, valType reflect.Value) error { +func encodeMultipartFormDataFile(w *multipart.Writer, fieldName string, fieldType reflect.Type, valType reflect.Value) error { if fieldType.Kind() != reflect.Struct { return fmt.Errorf("invalid type %s for multipart/form-data file", valType.Type()) } - var fieldName string var fileName string var reader io.Reader @@ -236,16 +252,26 @@ func encodeMultipartFormDataFile(w *multipart.Writer, fieldType reflect.Type, va reader = val.Interface().(io.Reader) } } else { - fieldName = tag.Name fileName = val.String() } } - if fieldName == "" || fileName == "" || reader == nil { + if fileName == "" || reader == nil { return fmt.Errorf("invalid multipart/form-data file") } - fw, err := w.CreateFormFile(fieldName, fileName) + // Detect content type based on file extension + contentType := mime.TypeByExtension(filepath.Ext(fileName)) + if contentType == "" { + contentType = "application/octet-stream" + } + + // Create multipart header with proper content type + h := make(textproto.MIMEHeader) + h.Set("Content-Disposition", fmt.Sprintf(`form-data; name="%s"; filename="%s"`, fieldName, fileName)) + h.Set("Content-Type", contentType) + + fw, err := w.CreatePart(h) if err != nil { return err } @@ -253,6 +279,11 @@ func encodeMultipartFormDataFile(w *multipart.Writer, fieldType reflect.Type, va return err } + // Reset seek position to 0 if the reader supports seeking + if seeker, ok := reader.(io.Seeker); ok { + _, _ = seeker.Seek(0, io.SeekStart) + } + return nil } @@ -294,7 +325,7 @@ func encodeFormData(fieldName string, w io.Writer, data interface{}) error { switch tag.Style { // TODO: support other styles case "form": - values := populateForm(tag.Name, tag.Explode, fieldType, valType, ",", func(sf reflect.StructField) string { + values := populateForm(tag.Name, tag.Explode, fieldType, valType, ",", nil, func(sf reflect.StructField) string { tag := parseFormTag(field) if tag == nil { return "" @@ -311,6 +342,17 @@ func encodeFormData(fieldName string, w io.Writer, data interface{}) error { } } case reflect.Map: + // check if optionalnullable.OptionalNullable[T] + if nullableValue, ok := optionalnullable.AsOptionalNullable(requestValType); ok { + // Handle optionalnullable.OptionalNullable[T] using GetUntyped method + if value, isSet := nullableValue.GetUntyped(); isSet && value != nil { + dataValues.Set(fieldName, valToString(value)) + } + // If not set or explicitly null, skip adding to form + break + } + + // Handle regular map for _, k := range requestValType.MapKeys() { v := requestValType.MapIndex(k) dataValues.Set(fmt.Sprintf("%v", k.Interface()), valToString(v.Interface())) diff --git a/internal/sdk/internal/utils/retries.go b/internal/sdk/internal/utils/retries.go index 72d43ba..903d284 100644 --- a/internal/sdk/internal/utils/retries.go +++ b/internal/sdk/internal/utils/retries.go @@ -6,17 +6,18 @@ import ( "context" "errors" "fmt" - "github.com/cenkalti/backoff/v4" "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/retry" + "io" + "math" + "math/rand" "net/http" "net/url" + "slices" "strconv" "strings" "time" ) -var errRequestFailed = errors.New("request failed") - // Deprecated: Use retry.BackoffStrategy instead. type BackoffStrategy = retry.BackoffStrategy @@ -28,43 +29,84 @@ type Retries struct { StatusCodes []string } -func Retry(ctx context.Context, r Retries, action func() (*http.Response, error)) (*http.Response, error) { +var ( + // IETF RFC 7231 4.2 safe and idempotent HTTP methods for connection retries + idempotentHTTPMethods = []string{ + http.MethodDelete, + http.MethodGet, + http.MethodHead, + http.MethodOptions, + http.MethodPut, + } +) + +func Retry(ctx context.Context, r Retries, operation func() (*http.Response, error)) (*http.Response, error) { switch r.Config.Strategy { case "backoff": if r.Config.Backoff == nil { - return action() + return operation() } - config := backoff.NewExponentialBackOff() - config.InitialInterval = time.Duration(r.Config.Backoff.InitialInterval) * time.Millisecond - config.MaxInterval = time.Duration(r.Config.Backoff.MaxInterval) * time.Millisecond - config.Multiplier = r.Config.Backoff.Exponent - config.MaxElapsedTime = time.Duration(r.Config.Backoff.MaxElapsedTime) * time.Millisecond - config.Reset() - var resp *http.Response - err := backoff.Retry(func() error { + err := retryWithBackoff(ctx, r.Config.Backoff, func() error { if resp != nil { resp.Body.Close() } select { case <-ctx.Done(): - return backoff.Permanent(ctx.Err()) + return retry.Permanent(ctx.Err()) default: } - res, err := action() + res, err := operation() if err != nil { + if !r.Config.RetryConnectionErrors { + return retry.Permanent(err) + } + + var httpMethod string + + // Use http.Request method if available + if res != nil && res.Request != nil { + httpMethod = res.Request.Method + } + + isIdempotentHTTPMethod := slices.Contains(idempotentHTTPMethods, httpMethod) urlError := new(url.Error) + if errors.As(err, &urlError) { - if (urlError.Temporary() || urlError.Timeout()) && r.Config.RetryConnectionErrors { + if urlError.Temporary() || urlError.Timeout() { + return err + } + + // In certain error cases, the http.Request may not have + // been populated, so use url.Error.Op which only has its + // first character capitalized from the original request + // HTTP method. + if httpMethod == "" { + httpMethod = strings.ToUpper(urlError.Op) + } + + isIdempotentHTTPMethod = slices.Contains(idempotentHTTPMethods, httpMethod) + + // Connection closed + if errors.Is(urlError.Err, io.EOF) && isIdempotentHTTPMethod { return err } } - return backoff.Permanent(err) + // syscall detection is not available on every platform, so + // fallback to best effort string detection. + isBrokenPipeError := strings.Contains(err.Error(), "broken pipe") + isConnectionResetError := strings.Contains(err.Error(), "connection reset") + + if (isBrokenPipeError || isConnectionResetError) && isIdempotentHTTPMethod { + return err + } + + return retry.Permanent(err) } resp = res if res == nil { @@ -81,7 +123,7 @@ func Retry(ctx context.Context, r Retries, action func() (*http.Response, error) s := res.StatusCode / 100 if s >= codeRange && s < codeRange+1 { - return errRequestFailed + return retry.TemporaryFromResponse("request failed", res) } } else { parsedCode, err := strconv.Atoi(code) @@ -90,7 +132,7 @@ func Retry(ctx context.Context, r Retries, action func() (*http.Response, error) } if res.StatusCode == parsedCode { - return errRequestFailed + return retry.TemporaryFromResponse("request failed", res) } } } @@ -98,13 +140,131 @@ func Retry(ctx context.Context, r Retries, action func() (*http.Response, error) resp = res return nil - }, config) - if err != nil && !errors.Is(err, errRequestFailed) { + }) + + var tempErr *retry.TemporaryError + if err != nil && !errors.As(err, &tempErr) { return nil, err } return resp, nil default: - return action() + return operation() } } + +func retryWithBackoff(ctx context.Context, s *retry.BackoffStrategy, operation func() error) error { + var ( + err error + next time.Duration + attempt int + start = time.Now() + maxElapsedTime = time.Duration(s.MaxElapsedTime) * time.Millisecond + ) + + timer := &defaultTimer{} + defer func() { + timer.Stop() + }() + + for { + err = operation() + if err == nil { + return nil + } + + var permanent *retry.PermanentError + if errors.As(err, &permanent) { + return permanent.Unwrap() + } + + if time.Since(start) >= maxElapsedTime { + return err + } + + var temporary *retry.TemporaryError + if errors.As(err, &temporary) { + next = temporary.RetryAfter() + } + + if next <= 0 { + next = nextInterval(s, attempt) + } + + timer.Start(next) + + select { + case <-ctx.Done(): + return ctx.Err() + case <-timer.C(): + } + + attempt += 1 + } +} + +type Timer interface { + Start(duration time.Duration) + Stop() + C() <-chan time.Time +} + +// defaultTimer implements Timer interface using time.Timer +type defaultTimer struct { + timer *time.Timer +} + +// C returns the timers channel which receives the current time when the timer fires. +func (t *defaultTimer) C() <-chan time.Time { + return t.timer.C +} + +// Start starts the timer to fire after the given duration +func (t *defaultTimer) Start(duration time.Duration) { + if t.timer == nil { + t.timer = time.NewTimer(duration) + return + } + + if !t.timer.Stop() { + select { + case <-t.timer.C: + default: + } + } + + t.timer.Reset(duration) +} + +// Stop is called when the timer is not used anymore and resources may be freed. +func (t *defaultTimer) Stop() { + if t.timer != nil { + t.timer.Stop() + } +} + +func nextInterval(s *retry.BackoffStrategy, attempt int) time.Duration { + initialInterval := float64(time.Duration(s.InitialInterval) * time.Millisecond) + maxInterval := float64(time.Duration(s.MaxInterval) * time.Millisecond) + exponent := s.Exponent + jitterFactor := float64(0.25) + + interval := initialInterval * math.Pow(float64(attempt+1), exponent) + + jitter := rand.Float64() * jitterFactor * interval + if rand.Float64() < 0.5 { + jitter = -1 * jitter + } + + interval = interval + jitter + + if interval <= 0 { + interval = initialInterval + } + + if interval > maxInterval { + interval = maxInterval + } + + return time.Duration(interval) +} diff --git a/internal/sdk/internal/utils/utils.go b/internal/sdk/internal/utils/utils.go index f1ff9e0..76cbe94 100644 --- a/internal/sdk/internal/utils/utils.go +++ b/internal/sdk/internal/utils/utils.go @@ -14,8 +14,6 @@ import ( "strconv" "strings" "time" - - "github.com/ericlagergren/decimal" ) const ( @@ -40,8 +38,8 @@ func UnmarshalJsonFromResponseBody(body io.Reader, out interface{}, tag string) if err != nil { return fmt.Errorf("error reading response body: %w", err) } - if err := UnmarshalJSON(data, out, reflect.StructTag(tag), true, false); err != nil { - return fmt.Errorf("error unmarshalling json response body: %w", err) + if err := UnmarshalJSON(data, out, reflect.StructTag(tag), true, nil); err != nil { + return fmt.Errorf("error unmarshaling json response body: %w", err) } return nil @@ -96,6 +94,26 @@ func AsSecuritySource(security interface{}) func(context.Context) (interface{}, } } +func parseConstTag(field reflect.StructField) *string { + value := field.Tag.Get("const") + + if value == "" { + return nil + } + + return &value +} + +func parseDefaultTag(field reflect.StructField) *string { + value := field.Tag.Get("default") + + if value == "" { + return nil + } + + return &value +} + func parseStructTag(tagKey string, field reflect.StructField) map[string]string { tag := field.Tag.Get(tagKey) if tag == "" { @@ -127,6 +145,7 @@ func parseStructTag(tagKey string, field reflect.StructField) map[string]string func parseParamTag(tagKey string, field reflect.StructField, defaultStyle string, defaultExplode bool) *paramTag { // example `{tagKey}:"style=simple,explode=false,name=apiID"` + // example `{tagKey}:"inline"` values := parseStructTag(tagKey, field) if values == nil { return nil @@ -140,6 +159,8 @@ func parseParamTag(tagKey string, field reflect.StructField, defaultStyle string for k, v := range values { switch k { + case "inline": + tag.Inline = v == "true" case "style": tag.Style = v case "explode": @@ -160,8 +181,6 @@ func valToString(val interface{}) string { return v.Format(time.RFC3339Nano) case big.Int: return v.String() - case decimal.Big: - return v.String() default: return fmt.Sprintf("%v", v) } diff --git a/internal/sdk/models/operations/accesspubliclink.go b/internal/sdk/models/operations/accesspubliclink.go index 6bd8927..3fec492 100644 --- a/internal/sdk/models/operations/accesspubliclink.go +++ b/internal/sdk/models/operations/accesspubliclink.go @@ -7,22 +7,30 @@ import ( ) type AccessPublicLinkRequest struct { - Filename string `pathParam:"style=simple,explode=false,name=filename"` - ID string `pathParam:"style=simple,explode=false,name=id"` + Filename string `pathParam:"style=simple,explode=false,name=filename"` + Hash *string `queryParam:"style=form,explode=true,name=hash"` + ID string `pathParam:"style=simple,explode=false,name=id"` } -func (o *AccessPublicLinkRequest) GetFilename() string { - if o == nil { +func (a *AccessPublicLinkRequest) GetFilename() string { + if a == nil { return "" } - return o.Filename + return a.Filename } -func (o *AccessPublicLinkRequest) GetID() string { - if o == nil { +func (a *AccessPublicLinkRequest) GetHash() *string { + if a == nil { + return nil + } + return a.Hash +} + +func (a *AccessPublicLinkRequest) GetID() string { + if a == nil { return "" } - return o.ID + return a.ID } type AccessPublicLinkResponse struct { @@ -34,23 +42,23 @@ type AccessPublicLinkResponse struct { RawResponse *http.Response } -func (o *AccessPublicLinkResponse) GetContentType() string { - if o == nil { +func (a *AccessPublicLinkResponse) GetContentType() string { + if a == nil { return "" } - return o.ContentType + return a.ContentType } -func (o *AccessPublicLinkResponse) GetStatusCode() int { - if o == nil { +func (a *AccessPublicLinkResponse) GetStatusCode() int { + if a == nil { return 0 } - return o.StatusCode + return a.StatusCode } -func (o *AccessPublicLinkResponse) GetRawResponse() *http.Response { - if o == nil { +func (a *AccessPublicLinkResponse) GetRawResponse() *http.Response { + if a == nil { return nil } - return o.RawResponse + return a.RawResponse } diff --git a/internal/sdk/models/operations/createfilefolder.go b/internal/sdk/models/operations/createfilefolder.go new file mode 100644 index 0000000..dc08849 --- /dev/null +++ b/internal/sdk/models/operations/createfilefolder.go @@ -0,0 +1,98 @@ +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + +package operations + +import ( + "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/models/shared" + "net/http" +) + +type CreateFileFolderRequest struct { + FileFolderCreateRequest shared.FileFolderCreateRequest `request:"mediaType=application/json"` + // Entity id + ID string `pathParam:"style=simple,explode=false,name=id"` +} + +func (c *CreateFileFolderRequest) GetFileFolderCreateRequest() shared.FileFolderCreateRequest { + if c == nil { + return shared.FileFolderCreateRequest{} + } + return c.FileFolderCreateRequest +} + +func (c *CreateFileFolderRequest) GetID() string { + if c == nil { + return "" + } + return c.ID +} + +// CreateFileFolderResponseBody - A generic error returned by the API +type CreateFileFolderResponseBody struct { + // The error message + Error *string `json:"error,omitempty"` + // The HTTP status code of the error + Status *int64 `json:"status,omitempty"` +} + +func (c *CreateFileFolderResponseBody) GetError() *string { + if c == nil { + return nil + } + return c.Error +} + +func (c *CreateFileFolderResponseBody) GetStatus() *int64 { + if c == nil { + return nil + } + return c.Status +} + +type CreateFileFolderResponse struct { + // HTTP response content type for this operation + ContentType string + // File folder created successfully + FileFolderItem *shared.FileFolderItem + // HTTP response status code for this operation + StatusCode int + // Raw HTTP response; suitable for custom response parsing + RawResponse *http.Response + // The requested resource was not found + Object *CreateFileFolderResponseBody +} + +func (c *CreateFileFolderResponse) GetContentType() string { + if c == nil { + return "" + } + return c.ContentType +} + +func (c *CreateFileFolderResponse) GetFileFolderItem() *shared.FileFolderItem { + if c == nil { + return nil + } + return c.FileFolderItem +} + +func (c *CreateFileFolderResponse) GetStatusCode() int { + if c == nil { + return 0 + } + return c.StatusCode +} + +func (c *CreateFileFolderResponse) GetRawResponse() *http.Response { + if c == nil { + return nil + } + return c.RawResponse +} + +func (c *CreateFileFolderResponse) GetObject() *CreateFileFolderResponseBody { + if c == nil { + return nil + } + return c.Object +} diff --git a/internal/sdk/models/operations/deletefile.go b/internal/sdk/models/operations/deletefile.go index ec6e51b..3afe8a1 100644 --- a/internal/sdk/models/operations/deletefile.go +++ b/internal/sdk/models/operations/deletefile.go @@ -12,6 +12,7 @@ type DeleteFileRequest struct { // Activity to include in event feed ActivityID *string `queryParam:"style=form,explode=true,name=activity_id"` ID string `pathParam:"style=simple,explode=false,name=id"` + Purge *bool `default:"false" queryParam:"style=form,explode=true,name=purge"` // When passed true, the response will contain only fields that match the schema, with non-matching fields included in `__additional` Strict *bool `default:"false" queryParam:"style=form,explode=true,name=strict"` } @@ -21,31 +22,38 @@ func (d DeleteFileRequest) MarshalJSON() ([]byte, error) { } func (d *DeleteFileRequest) UnmarshalJSON(data []byte) error { - if err := utils.UnmarshalJSON(data, &d, "", false, false); err != nil { + if err := utils.UnmarshalJSON(data, &d, "", false, []string{"id"}); err != nil { return err } return nil } -func (o *DeleteFileRequest) GetActivityID() *string { - if o == nil { +func (d *DeleteFileRequest) GetActivityID() *string { + if d == nil { return nil } - return o.ActivityID + return d.ActivityID } -func (o *DeleteFileRequest) GetID() string { - if o == nil { +func (d *DeleteFileRequest) GetID() string { + if d == nil { return "" } - return o.ID + return d.ID } -func (o *DeleteFileRequest) GetStrict() *bool { - if o == nil { +func (d *DeleteFileRequest) GetPurge() *bool { + if d == nil { return nil } - return o.Strict + return d.Purge +} + +func (d *DeleteFileRequest) GetStrict() *bool { + if d == nil { + return nil + } + return d.Strict } type DeleteFileResponse struct { @@ -59,30 +67,30 @@ type DeleteFileResponse struct { RawResponse *http.Response } -func (o *DeleteFileResponse) GetContentType() string { - if o == nil { +func (d *DeleteFileResponse) GetContentType() string { + if d == nil { return "" } - return o.ContentType + return d.ContentType } -func (o *DeleteFileResponse) GetFileEntity() *shared.FileEntity { - if o == nil { +func (d *DeleteFileResponse) GetFileEntity() *shared.FileEntity { + if d == nil { return nil } - return o.FileEntity + return d.FileEntity } -func (o *DeleteFileResponse) GetStatusCode() int { - if o == nil { +func (d *DeleteFileResponse) GetStatusCode() int { + if d == nil { return 0 } - return o.StatusCode + return d.StatusCode } -func (o *DeleteFileResponse) GetRawResponse() *http.Response { - if o == nil { +func (d *DeleteFileResponse) GetRawResponse() *http.Response { + if d == nil { return nil } - return o.RawResponse + return d.RawResponse } diff --git a/internal/sdk/models/operations/deletefilefolder.go b/internal/sdk/models/operations/deletefilefolder.go new file mode 100644 index 0000000..771d6a4 --- /dev/null +++ b/internal/sdk/models/operations/deletefilefolder.go @@ -0,0 +1,89 @@ +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + +package operations + +import ( + "net/http" +) + +type DeleteFileFolderRequest struct { + // The slug identifier for the folder + FolderSlug string `pathParam:"style=simple,explode=false,name=folderSlug"` + // Entity id + ID string `pathParam:"style=simple,explode=false,name=id"` +} + +func (d *DeleteFileFolderRequest) GetFolderSlug() string { + if d == nil { + return "" + } + return d.FolderSlug +} + +func (d *DeleteFileFolderRequest) GetID() string { + if d == nil { + return "" + } + return d.ID +} + +// DeleteFileFolderResponseBody - A generic error returned by the API +type DeleteFileFolderResponseBody struct { + // The error message + Error *string `json:"error,omitempty"` + // The HTTP status code of the error + Status *int64 `json:"status,omitempty"` +} + +func (d *DeleteFileFolderResponseBody) GetError() *string { + if d == nil { + return nil + } + return d.Error +} + +func (d *DeleteFileFolderResponseBody) GetStatus() *int64 { + if d == nil { + return nil + } + return d.Status +} + +type DeleteFileFolderResponse struct { + // HTTP response content type for this operation + ContentType string + // HTTP response status code for this operation + StatusCode int + // Raw HTTP response; suitable for custom response parsing + RawResponse *http.Response + // The requested resource was not found + Object *DeleteFileFolderResponseBody +} + +func (d *DeleteFileFolderResponse) GetContentType() string { + if d == nil { + return "" + } + return d.ContentType +} + +func (d *DeleteFileFolderResponse) GetStatusCode() int { + if d == nil { + return 0 + } + return d.StatusCode +} + +func (d *DeleteFileFolderResponse) GetRawResponse() *http.Response { + if d == nil { + return nil + } + return d.RawResponse +} + +func (d *DeleteFileFolderResponse) GetObject() *DeleteFileFolderResponseBody { + if d == nil { + return nil + } + return d.Object +} diff --git a/internal/sdk/models/operations/deletesession.go b/internal/sdk/models/operations/deletesession.go index 796bf0d..813d31d 100644 --- a/internal/sdk/models/operations/deletesession.go +++ b/internal/sdk/models/operations/deletesession.go @@ -15,23 +15,23 @@ type DeleteSessionResponse struct { RawResponse *http.Response } -func (o *DeleteSessionResponse) GetContentType() string { - if o == nil { +func (d *DeleteSessionResponse) GetContentType() string { + if d == nil { return "" } - return o.ContentType + return d.ContentType } -func (o *DeleteSessionResponse) GetStatusCode() int { - if o == nil { +func (d *DeleteSessionResponse) GetStatusCode() int { + if d == nil { return 0 } - return o.StatusCode + return d.StatusCode } -func (o *DeleteSessionResponse) GetRawResponse() *http.Response { - if o == nil { +func (d *DeleteSessionResponse) GetRawResponse() *http.Response { + if d == nil { return nil } - return o.RawResponse + return d.RawResponse } diff --git a/internal/sdk/models/operations/downloadfile.go b/internal/sdk/models/operations/downloadfile.go index ae1a3d0..11f4f1f 100644 --- a/internal/sdk/models/operations/downloadfile.go +++ b/internal/sdk/models/operations/downloadfile.go @@ -20,31 +20,31 @@ func (d DownloadFileRequest) MarshalJSON() ([]byte, error) { } func (d *DownloadFileRequest) UnmarshalJSON(data []byte) error { - if err := utils.UnmarshalJSON(data, &d, "", false, false); err != nil { + if err := utils.UnmarshalJSON(data, &d, "", false, []string{"id"}); err != nil { return err } return nil } -func (o *DownloadFileRequest) GetAttachment() *bool { - if o == nil { +func (d *DownloadFileRequest) GetAttachment() *bool { + if d == nil { return nil } - return o.Attachment + return d.Attachment } -func (o *DownloadFileRequest) GetID() string { - if o == nil { +func (d *DownloadFileRequest) GetID() string { + if d == nil { return "" } - return o.ID + return d.ID } -func (o *DownloadFileRequest) GetVersion() *int64 { - if o == nil { +func (d *DownloadFileRequest) GetVersion() *int64 { + if d == nil { return nil } - return o.Version + return d.Version } // DownloadFileResponseBody - Generated thumbnail image @@ -52,11 +52,11 @@ type DownloadFileResponseBody struct { DownloadURL *string `json:"download_url,omitempty"` } -func (o *DownloadFileResponseBody) GetDownloadURL() *string { - if o == nil { +func (d *DownloadFileResponseBody) GetDownloadURL() *string { + if d == nil { return nil } - return o.DownloadURL + return d.DownloadURL } type DownloadFileResponse struct { @@ -70,30 +70,30 @@ type DownloadFileResponse struct { Object *DownloadFileResponseBody } -func (o *DownloadFileResponse) GetContentType() string { - if o == nil { +func (d *DownloadFileResponse) GetContentType() string { + if d == nil { return "" } - return o.ContentType + return d.ContentType } -func (o *DownloadFileResponse) GetStatusCode() int { - if o == nil { +func (d *DownloadFileResponse) GetStatusCode() int { + if d == nil { return 0 } - return o.StatusCode + return d.StatusCode } -func (o *DownloadFileResponse) GetRawResponse() *http.Response { - if o == nil { +func (d *DownloadFileResponse) GetRawResponse() *http.Response { + if d == nil { return nil } - return o.RawResponse + return d.RawResponse } -func (o *DownloadFileResponse) GetObject() *DownloadFileResponseBody { - if o == nil { +func (d *DownloadFileResponse) GetObject() *DownloadFileResponseBody { + if d == nil { return nil } - return o.Object + return d.Object } diff --git a/internal/sdk/models/operations/downloadfiles.go b/internal/sdk/models/operations/downloadfiles.go index bfd4cee..c43b216 100644 --- a/internal/sdk/models/operations/downloadfiles.go +++ b/internal/sdk/models/operations/downloadfiles.go @@ -11,18 +11,18 @@ type ResponseBody struct { FileEntityID *string `json:"file_entity_id,omitempty"` } -func (o *ResponseBody) GetDownloadURL() *string { - if o == nil { +func (r *ResponseBody) GetDownloadURL() *string { + if r == nil { return nil } - return o.DownloadURL + return r.DownloadURL } -func (o *ResponseBody) GetFileEntityID() *string { - if o == nil { +func (r *ResponseBody) GetFileEntityID() *string { + if r == nil { return nil } - return o.FileEntityID + return r.FileEntityID } type DownloadFilesResponse struct { @@ -36,30 +36,30 @@ type DownloadFilesResponse struct { Classes []ResponseBody } -func (o *DownloadFilesResponse) GetContentType() string { - if o == nil { +func (d *DownloadFilesResponse) GetContentType() string { + if d == nil { return "" } - return o.ContentType + return d.ContentType } -func (o *DownloadFilesResponse) GetStatusCode() int { - if o == nil { +func (d *DownloadFilesResponse) GetStatusCode() int { + if d == nil { return 0 } - return o.StatusCode + return d.StatusCode } -func (o *DownloadFilesResponse) GetRawResponse() *http.Response { - if o == nil { +func (d *DownloadFilesResponse) GetRawResponse() *http.Response { + if d == nil { return nil } - return o.RawResponse + return d.RawResponse } -func (o *DownloadFilesResponse) GetClasses() []ResponseBody { - if o == nil { +func (d *DownloadFilesResponse) GetClasses() []ResponseBody { + if d == nil { return nil } - return o.Classes + return d.Classes } diff --git a/internal/sdk/models/operations/downloads3file.go b/internal/sdk/models/operations/downloads3file.go index f518341..e754d8e 100644 --- a/internal/sdk/models/operations/downloads3file.go +++ b/internal/sdk/models/operations/downloads3file.go @@ -19,31 +19,31 @@ func (d DownloadS3FileRequest) MarshalJSON() ([]byte, error) { } func (d *DownloadS3FileRequest) UnmarshalJSON(data []byte) error { - if err := utils.UnmarshalJSON(data, &d, "", false, false); err != nil { + if err := utils.UnmarshalJSON(data, &d, "", false, []string{"s3_bucket", "s3_key"}); err != nil { return err } return nil } -func (o *DownloadS3FileRequest) GetAttachment() *bool { - if o == nil { +func (d *DownloadS3FileRequest) GetAttachment() *bool { + if d == nil { return nil } - return o.Attachment + return d.Attachment } -func (o *DownloadS3FileRequest) GetS3Bucket() string { - if o == nil { +func (d *DownloadS3FileRequest) GetS3Bucket() string { + if d == nil { return "" } - return o.S3Bucket + return d.S3Bucket } -func (o *DownloadS3FileRequest) GetS3Key() string { - if o == nil { +func (d *DownloadS3FileRequest) GetS3Key() string { + if d == nil { return "" } - return o.S3Key + return d.S3Key } // DownloadS3FileResponseBody - Generated thumbnail image @@ -51,11 +51,11 @@ type DownloadS3FileResponseBody struct { DownloadURL *string `json:"download_url,omitempty"` } -func (o *DownloadS3FileResponseBody) GetDownloadURL() *string { - if o == nil { +func (d *DownloadS3FileResponseBody) GetDownloadURL() *string { + if d == nil { return nil } - return o.DownloadURL + return d.DownloadURL } type DownloadS3FileResponse struct { @@ -69,30 +69,30 @@ type DownloadS3FileResponse struct { Object *DownloadS3FileResponseBody } -func (o *DownloadS3FileResponse) GetContentType() string { - if o == nil { +func (d *DownloadS3FileResponse) GetContentType() string { + if d == nil { return "" } - return o.ContentType + return d.ContentType } -func (o *DownloadS3FileResponse) GetStatusCode() int { - if o == nil { +func (d *DownloadS3FileResponse) GetStatusCode() int { + if d == nil { return 0 } - return o.StatusCode + return d.StatusCode } -func (o *DownloadS3FileResponse) GetRawResponse() *http.Response { - if o == nil { +func (d *DownloadS3FileResponse) GetRawResponse() *http.Response { + if d == nil { return nil } - return o.RawResponse + return d.RawResponse } -func (o *DownloadS3FileResponse) GetObject() *DownloadS3FileResponseBody { - if o == nil { +func (d *DownloadS3FileResponse) GetObject() *DownloadS3FileResponseBody { + if d == nil { return nil } - return o.Object + return d.Object } diff --git a/internal/sdk/models/operations/generatepubliclink.go b/internal/sdk/models/operations/generatepubliclink.go index 9148ce3..95f5b3e 100644 --- a/internal/sdk/models/operations/generatepubliclink.go +++ b/internal/sdk/models/operations/generatepubliclink.go @@ -10,11 +10,11 @@ type GeneratePublicLinkRequest struct { ID string `pathParam:"style=simple,explode=false,name=id"` } -func (o *GeneratePublicLinkRequest) GetID() string { - if o == nil { +func (g *GeneratePublicLinkRequest) GetID() string { + if g == nil { return "" } - return o.ID + return g.ID } type GeneratePublicLinkResponse struct { @@ -28,30 +28,30 @@ type GeneratePublicLinkResponse struct { String *string } -func (o *GeneratePublicLinkResponse) GetContentType() string { - if o == nil { +func (g *GeneratePublicLinkResponse) GetContentType() string { + if g == nil { return "" } - return o.ContentType + return g.ContentType } -func (o *GeneratePublicLinkResponse) GetStatusCode() int { - if o == nil { +func (g *GeneratePublicLinkResponse) GetStatusCode() int { + if g == nil { return 0 } - return o.StatusCode + return g.StatusCode } -func (o *GeneratePublicLinkResponse) GetRawResponse() *http.Response { - if o == nil { +func (g *GeneratePublicLinkResponse) GetRawResponse() *http.Response { + if g == nil { return nil } - return o.RawResponse + return g.RawResponse } -func (o *GeneratePublicLinkResponse) GetString() *string { - if o == nil { +func (g *GeneratePublicLinkResponse) GetString() *string { + if g == nil { return nil } - return o.String + return g.String } diff --git a/internal/sdk/models/operations/getfile.go b/internal/sdk/models/operations/getfile.go index 6e74cfc..b2cec8d 100644 --- a/internal/sdk/models/operations/getfile.go +++ b/internal/sdk/models/operations/getfile.go @@ -10,8 +10,9 @@ import ( type GetFileRequest struct { // Don't wait for updated entity to become available in Search API. Useful for large migrations - Async *bool `default:"false" queryParam:"style=form,explode=true,name=async"` - ID string `pathParam:"style=simple,explode=false,name=id"` + Async *bool `default:"false" queryParam:"style=form,explode=true,name=async"` + ID string `pathParam:"style=simple,explode=false,name=id"` + SourceURL *bool `default:"false" queryParam:"style=form,explode=true,name=source_url"` // When passed true, the response will contain only fields that match the schema, with non-matching fields included in `__additional` Strict *bool `default:"false" queryParam:"style=form,explode=true,name=strict"` } @@ -21,31 +22,38 @@ func (g GetFileRequest) MarshalJSON() ([]byte, error) { } func (g *GetFileRequest) UnmarshalJSON(data []byte) error { - if err := utils.UnmarshalJSON(data, &g, "", false, false); err != nil { + if err := utils.UnmarshalJSON(data, &g, "", false, []string{"id"}); err != nil { return err } return nil } -func (o *GetFileRequest) GetAsync() *bool { - if o == nil { +func (g *GetFileRequest) GetAsync() *bool { + if g == nil { return nil } - return o.Async + return g.Async } -func (o *GetFileRequest) GetID() string { - if o == nil { +func (g *GetFileRequest) GetID() string { + if g == nil { return "" } - return o.ID + return g.ID } -func (o *GetFileRequest) GetStrict() *bool { - if o == nil { +func (g *GetFileRequest) GetSourceURL() *bool { + if g == nil { return nil } - return o.Strict + return g.SourceURL +} + +func (g *GetFileRequest) GetStrict() *bool { + if g == nil { + return nil + } + return g.Strict } type GetFileResponse struct { @@ -59,30 +67,30 @@ type GetFileResponse struct { RawResponse *http.Response } -func (o *GetFileResponse) GetContentType() string { - if o == nil { +func (g *GetFileResponse) GetContentType() string { + if g == nil { return "" } - return o.ContentType + return g.ContentType } -func (o *GetFileResponse) GetFileEntity() *shared.FileEntity { - if o == nil { +func (g *GetFileResponse) GetFileEntity() *shared.FileEntity { + if g == nil { return nil } - return o.FileEntity + return g.FileEntity } -func (o *GetFileResponse) GetStatusCode() int { - if o == nil { +func (g *GetFileResponse) GetStatusCode() int { + if g == nil { return 0 } - return o.StatusCode + return g.StatusCode } -func (o *GetFileResponse) GetRawResponse() *http.Response { - if o == nil { +func (g *GetFileResponse) GetRawResponse() *http.Response { + if g == nil { return nil } - return o.RawResponse + return g.RawResponse } diff --git a/internal/sdk/models/operations/getfilefolders.go b/internal/sdk/models/operations/getfilefolders.go new file mode 100644 index 0000000..5cb8589 --- /dev/null +++ b/internal/sdk/models/operations/getfilefolders.go @@ -0,0 +1,99 @@ +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + +package operations + +import ( + "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/models/shared" + "net/http" +) + +type GetFileFoldersRequest struct { + // Entity id + ID string `pathParam:"style=simple,explode=false,name=id"` + // Optional array of parent folder slugs to filter by + Parents []string `queryParam:"style=form,explode=true,name=parents"` +} + +func (g *GetFileFoldersRequest) GetID() string { + if g == nil { + return "" + } + return g.ID +} + +func (g *GetFileFoldersRequest) GetParents() []string { + if g == nil { + return nil + } + return g.Parents +} + +// GetFileFoldersResponseBody - A generic error returned by the API +type GetFileFoldersResponseBody struct { + // The error message + Error *string `json:"error,omitempty"` + // The HTTP status code of the error + Status *int64 `json:"status,omitempty"` +} + +func (g *GetFileFoldersResponseBody) GetError() *string { + if g == nil { + return nil + } + return g.Error +} + +func (g *GetFileFoldersResponseBody) GetStatus() *int64 { + if g == nil { + return nil + } + return g.Status +} + +type GetFileFoldersResponse struct { + // HTTP response content type for this operation + ContentType string + // HTTP response status code for this operation + StatusCode int + // Raw HTTP response; suitable for custom response parsing + RawResponse *http.Response + // List of folders for the entity + Classes []shared.FileFolderItem + // The requested resource was not found + Object *GetFileFoldersResponseBody +} + +func (g *GetFileFoldersResponse) GetContentType() string { + if g == nil { + return "" + } + return g.ContentType +} + +func (g *GetFileFoldersResponse) GetStatusCode() int { + if g == nil { + return 0 + } + return g.StatusCode +} + +func (g *GetFileFoldersResponse) GetRawResponse() *http.Response { + if g == nil { + return nil + } + return g.RawResponse +} + +func (g *GetFileFoldersResponse) GetClasses() []shared.FileFolderItem { + if g == nil { + return nil + } + return g.Classes +} + +func (g *GetFileFoldersResponse) GetObject() *GetFileFoldersResponseBody { + if g == nil { + return nil + } + return g.Object +} diff --git a/internal/sdk/models/operations/getfilesinfolder.go b/internal/sdk/models/operations/getfilesinfolder.go new file mode 100644 index 0000000..18a3d6d --- /dev/null +++ b/internal/sdk/models/operations/getfilesinfolder.go @@ -0,0 +1,110 @@ +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + +package operations + +import ( + "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/models/shared" + "net/http" +) + +type GetFilesInFolderRequest struct { + // The slug identifier for the folder + FolderSlug string `pathParam:"style=simple,explode=false,name=folderSlug"` + // Entity id + ID string `pathParam:"style=simple,explode=false,name=id"` +} + +func (g *GetFilesInFolderRequest) GetFolderSlug() string { + if g == nil { + return "" + } + return g.FolderSlug +} + +func (g *GetFilesInFolderRequest) GetID() string { + if g == nil { + return "" + } + return g.ID +} + +// GetFilesInFolderFileFoldersResponseBody - Entity or folder not found +type GetFilesInFolderFileFoldersResponseBody struct { + Error *string `json:"error,omitempty"` +} + +func (g *GetFilesInFolderFileFoldersResponseBody) GetError() *string { + if g == nil { + return nil + } + return g.Error +} + +// GetFilesInFolderResponseBody - User must have permission to view this entity to access its files +type GetFilesInFolderResponseBody struct { + Error *string `json:"error,omitempty"` +} + +func (g *GetFilesInFolderResponseBody) GetError() *string { + if g == nil { + return nil + } + return g.Error +} + +type GetFilesInFolderResponse struct { + // List of files in the folder + TwoHundredApplicationJSONClasses []shared.FileEntity + // User must have permission to view this entity to access its files + FourHundredAndThreeApplicationJSONObject *GetFilesInFolderResponseBody + // Entity or folder not found + FourHundredAndFourApplicationJSONObject *GetFilesInFolderFileFoldersResponseBody + // HTTP response content type for this operation + ContentType string + // HTTP response status code for this operation + StatusCode int + // Raw HTTP response; suitable for custom response parsing + RawResponse *http.Response +} + +func (g *GetFilesInFolderResponse) GetTwoHundredApplicationJSONClasses() []shared.FileEntity { + if g == nil { + return nil + } + return g.TwoHundredApplicationJSONClasses +} + +func (g *GetFilesInFolderResponse) GetFourHundredAndThreeApplicationJSONObject() *GetFilesInFolderResponseBody { + if g == nil { + return nil + } + return g.FourHundredAndThreeApplicationJSONObject +} + +func (g *GetFilesInFolderResponse) GetFourHundredAndFourApplicationJSONObject() *GetFilesInFolderFileFoldersResponseBody { + if g == nil { + return nil + } + return g.FourHundredAndFourApplicationJSONObject +} + +func (g *GetFilesInFolderResponse) GetContentType() string { + if g == nil { + return "" + } + return g.ContentType +} + +func (g *GetFilesInFolderResponse) GetStatusCode() int { + if g == nil { + return 0 + } + return g.StatusCode +} + +func (g *GetFilesInFolderResponse) GetRawResponse() *http.Response { + if g == nil { + return nil + } + return g.RawResponse +} diff --git a/internal/sdk/models/operations/getsession.go b/internal/sdk/models/operations/getsession.go index 5501fa7..d2e085b 100644 --- a/internal/sdk/models/operations/getsession.go +++ b/internal/sdk/models/operations/getsession.go @@ -15,23 +15,23 @@ type GetSessionResponse struct { RawResponse *http.Response } -func (o *GetSessionResponse) GetContentType() string { - if o == nil { +func (g *GetSessionResponse) GetContentType() string { + if g == nil { return "" } - return o.ContentType + return g.ContentType } -func (o *GetSessionResponse) GetStatusCode() int { - if o == nil { +func (g *GetSessionResponse) GetStatusCode() int { + if g == nil { return 0 } - return o.StatusCode + return g.StatusCode } -func (o *GetSessionResponse) GetRawResponse() *http.Response { - if o == nil { +func (g *GetSessionResponse) GetRawResponse() *http.Response { + if g == nil { return nil } - return o.RawResponse + return g.RawResponse } diff --git a/internal/sdk/models/operations/listpubliclinksforfile.go b/internal/sdk/models/operations/listpubliclinksforfile.go index 3b646f1..6371492 100644 --- a/internal/sdk/models/operations/listpubliclinksforfile.go +++ b/internal/sdk/models/operations/listpubliclinksforfile.go @@ -11,11 +11,11 @@ type ListPublicLinksForFileRequest struct { ID string `pathParam:"style=simple,explode=false,name=id"` } -func (o *ListPublicLinksForFileRequest) GetID() string { - if o == nil { +func (l *ListPublicLinksForFileRequest) GetID() string { + if l == nil { return "" } - return o.ID + return l.ID } // ListPublicLinksForFileResponseBody - Public links of a file retrieved successfully @@ -23,11 +23,11 @@ type ListPublicLinksForFileResponseBody struct { Results []shared.PublicLink `json:"results,omitempty"` } -func (o *ListPublicLinksForFileResponseBody) GetResults() []shared.PublicLink { - if o == nil { +func (l *ListPublicLinksForFileResponseBody) GetResults() []shared.PublicLink { + if l == nil { return nil } - return o.Results + return l.Results } type ListPublicLinksForFileResponse struct { @@ -41,30 +41,30 @@ type ListPublicLinksForFileResponse struct { Object *ListPublicLinksForFileResponseBody } -func (o *ListPublicLinksForFileResponse) GetContentType() string { - if o == nil { +func (l *ListPublicLinksForFileResponse) GetContentType() string { + if l == nil { return "" } - return o.ContentType + return l.ContentType } -func (o *ListPublicLinksForFileResponse) GetStatusCode() int { - if o == nil { +func (l *ListPublicLinksForFileResponse) GetStatusCode() int { + if l == nil { return 0 } - return o.StatusCode + return l.StatusCode } -func (o *ListPublicLinksForFileResponse) GetRawResponse() *http.Response { - if o == nil { +func (l *ListPublicLinksForFileResponse) GetRawResponse() *http.Response { + if l == nil { return nil } - return o.RawResponse + return l.RawResponse } -func (o *ListPublicLinksForFileResponse) GetObject() *ListPublicLinksForFileResponseBody { - if o == nil { +func (l *ListPublicLinksForFileResponse) GetObject() *ListPublicLinksForFileResponseBody { + if l == nil { return nil } - return o.Object + return l.Object } diff --git a/internal/sdk/models/operations/options.go b/internal/sdk/models/operations/options.go index 984085a..8894336 100644 --- a/internal/sdk/models/operations/options.go +++ b/internal/sdk/models/operations/options.go @@ -12,7 +12,6 @@ import ( var ErrUnsupportedOption = errors.New("unsupported option") const ( - SupportedOptionServerURL = "serverURL" SupportedOptionRetries = "retries" SupportedOptionTimeout = "timeout" SupportedOptionAcceptHeaderOverride = "acceptHeaderOverride" @@ -22,8 +21,8 @@ const ( type AcceptHeaderEnum string const ( - AcceptHeaderEnumApplicationJson AcceptHeaderEnum = "application/json" - AcceptHeaderEnumWildcardWildcard AcceptHeaderEnum = "*/*" + AcceptHeaderEnumApplicationJson AcceptHeaderEnum = "application/json" + AcceptHeaderEnumWildcardRootWildcard AcceptHeaderEnum = "*/*" ) func (e AcceptHeaderEnum) ToPointer() *AcceptHeaderEnum { @@ -36,6 +35,7 @@ type Options struct { Timeout *time.Duration AcceptHeaderOverride *AcceptHeaderEnum URLOverride *string + SetHeaders map[string]string } type Option func(*Options, ...string) error @@ -43,10 +43,6 @@ type Option func(*Options, ...string) error // WithServerURL allows providing an alternative server URL. func WithServerURL(serverURL string) Option { return func(opts *Options, supportedOptions ...string) error { - if !utils.Contains(supportedOptions, SupportedOptionServerURL) { - return ErrUnsupportedOption - } - opts.ServerURL = &serverURL return nil } @@ -55,10 +51,6 @@ func WithServerURL(serverURL string) Option { // WithTemplatedServerURL allows providing an alternative server URL with templated parameters. func WithTemplatedServerURL(serverURL string, params map[string]string) Option { return func(opts *Options, supportedOptions ...string) error { - if !utils.Contains(supportedOptions, SupportedOptionServerURL) { - return ErrUnsupportedOption - } - if params != nil { serverURL = utils.ReplaceParameters(serverURL, params) } @@ -114,3 +106,12 @@ func WithURLOverride(urlOverride string) Option { return nil } } + +// WithSetHeaders takes a map of headers that will applied to a request. If the +// request contains headers that are in the map then they will be overwritten. +func WithSetHeaders(hdrs map[string]string) Option { + return func(opts *Options, supportedOptions ...string) error { + opts.SetHeaders = hdrs + return nil + } +} diff --git a/internal/sdk/models/operations/previewfile.go b/internal/sdk/models/operations/previewfile.go index ee3df50..5afa2e9 100644 --- a/internal/sdk/models/operations/previewfile.go +++ b/internal/sdk/models/operations/previewfile.go @@ -22,38 +22,38 @@ func (p PreviewFileRequest) MarshalJSON() ([]byte, error) { } func (p *PreviewFileRequest) UnmarshalJSON(data []byte) error { - if err := utils.UnmarshalJSON(data, &p, "", false, false); err != nil { + if err := utils.UnmarshalJSON(data, &p, "", false, []string{"id"}); err != nil { return err } return nil } -func (o *PreviewFileRequest) GetH() *int64 { - if o == nil { +func (p *PreviewFileRequest) GetH() *int64 { + if p == nil { return nil } - return o.H + return p.H } -func (o *PreviewFileRequest) GetID() string { - if o == nil { +func (p *PreviewFileRequest) GetID() string { + if p == nil { return "" } - return o.ID + return p.ID } -func (o *PreviewFileRequest) GetVersion() *int64 { - if o == nil { +func (p *PreviewFileRequest) GetVersion() *int64 { + if p == nil { return nil } - return o.Version + return p.Version } -func (o *PreviewFileRequest) GetW() *int64 { - if o == nil { +func (p *PreviewFileRequest) GetW() *int64 { + if p == nil { return nil } - return o.W + return p.W } type PreviewFileResponse struct { @@ -65,23 +65,23 @@ type PreviewFileResponse struct { RawResponse *http.Response } -func (o *PreviewFileResponse) GetContentType() string { - if o == nil { +func (p *PreviewFileResponse) GetContentType() string { + if p == nil { return "" } - return o.ContentType + return p.ContentType } -func (o *PreviewFileResponse) GetStatusCode() int { - if o == nil { +func (p *PreviewFileResponse) GetStatusCode() int { + if p == nil { return 0 } - return o.StatusCode + return p.StatusCode } -func (o *PreviewFileResponse) GetRawResponse() *http.Response { - if o == nil { +func (p *PreviewFileResponse) GetRawResponse() *http.Response { + if p == nil { return nil } - return o.RawResponse + return p.RawResponse } diff --git a/internal/sdk/models/operations/previewpublicfile.go b/internal/sdk/models/operations/previewpublicfile.go index ea8bce7..aa87c2e 100644 --- a/internal/sdk/models/operations/previewpublicfile.go +++ b/internal/sdk/models/operations/previewpublicfile.go @@ -24,45 +24,45 @@ func (p PreviewPublicFileRequest) MarshalJSON() ([]byte, error) { } func (p *PreviewPublicFileRequest) UnmarshalJSON(data []byte) error { - if err := utils.UnmarshalJSON(data, &p, "", false, false); err != nil { + if err := utils.UnmarshalJSON(data, &p, "", false, []string{"id"}); err != nil { return err } return nil } -func (o *PreviewPublicFileRequest) GetH() *int64 { - if o == nil { +func (p *PreviewPublicFileRequest) GetH() *int64 { + if p == nil { return nil } - return o.H + return p.H } -func (o *PreviewPublicFileRequest) GetID() string { - if o == nil { +func (p *PreviewPublicFileRequest) GetID() string { + if p == nil { return "" } - return o.ID + return p.ID } -func (o *PreviewPublicFileRequest) GetOrgID() *string { - if o == nil { +func (p *PreviewPublicFileRequest) GetOrgID() *string { + if p == nil { return nil } - return o.OrgID + return p.OrgID } -func (o *PreviewPublicFileRequest) GetVersion() *int64 { - if o == nil { +func (p *PreviewPublicFileRequest) GetVersion() *int64 { + if p == nil { return nil } - return o.Version + return p.Version } -func (o *PreviewPublicFileRequest) GetW() *int64 { - if o == nil { +func (p *PreviewPublicFileRequest) GetW() *int64 { + if p == nil { return nil } - return o.W + return p.W } type PreviewPublicFileResponse struct { @@ -74,23 +74,23 @@ type PreviewPublicFileResponse struct { RawResponse *http.Response } -func (o *PreviewPublicFileResponse) GetContentType() string { - if o == nil { +func (p *PreviewPublicFileResponse) GetContentType() string { + if p == nil { return "" } - return o.ContentType + return p.ContentType } -func (o *PreviewPublicFileResponse) GetStatusCode() int { - if o == nil { +func (p *PreviewPublicFileResponse) GetStatusCode() int { + if p == nil { return 0 } - return o.StatusCode + return p.StatusCode } -func (o *PreviewPublicFileResponse) GetRawResponse() *http.Response { - if o == nil { +func (p *PreviewPublicFileResponse) GetRawResponse() *http.Response { + if p == nil { return nil } - return o.RawResponse + return p.RawResponse } diff --git a/internal/sdk/models/operations/previews3file.go b/internal/sdk/models/operations/previews3file.go index bb67901..7b4b00c 100644 --- a/internal/sdk/models/operations/previews3file.go +++ b/internal/sdk/models/operations/previews3file.go @@ -15,25 +15,25 @@ type PreviewS3FileRequest struct { W *int64 `queryParam:"style=form,explode=true,name=w"` } -func (o *PreviewS3FileRequest) GetS3Ref() *shared.S3Ref { - if o == nil { +func (p *PreviewS3FileRequest) GetS3Ref() *shared.S3Ref { + if p == nil { return nil } - return o.S3Ref + return p.S3Ref } -func (o *PreviewS3FileRequest) GetH() *int64 { - if o == nil { +func (p *PreviewS3FileRequest) GetH() *int64 { + if p == nil { return nil } - return o.H + return p.H } -func (o *PreviewS3FileRequest) GetW() *int64 { - if o == nil { +func (p *PreviewS3FileRequest) GetW() *int64 { + if p == nil { return nil } - return o.W + return p.W } type PreviewS3FileResponse struct { @@ -45,23 +45,23 @@ type PreviewS3FileResponse struct { RawResponse *http.Response } -func (o *PreviewS3FileResponse) GetContentType() string { - if o == nil { +func (p *PreviewS3FileResponse) GetContentType() string { + if p == nil { return "" } - return o.ContentType + return p.ContentType } -func (o *PreviewS3FileResponse) GetStatusCode() int { - if o == nil { +func (p *PreviewS3FileResponse) GetStatusCode() int { + if p == nil { return 0 } - return o.StatusCode + return p.StatusCode } -func (o *PreviewS3FileResponse) GetRawResponse() *http.Response { - if o == nil { +func (p *PreviewS3FileResponse) GetRawResponse() *http.Response { + if p == nil { return nil } - return o.RawResponse + return p.RawResponse } diff --git a/internal/sdk/models/operations/previews3fileget.go b/internal/sdk/models/operations/previews3fileget.go index 8121355..5067705 100644 --- a/internal/sdk/models/operations/previews3fileget.go +++ b/internal/sdk/models/operations/previews3fileget.go @@ -17,32 +17,32 @@ type PreviewS3FileGetRequest struct { W *int64 `queryParam:"style=form,explode=true,name=w"` } -func (o *PreviewS3FileGetRequest) GetBucket() string { - if o == nil { +func (p *PreviewS3FileGetRequest) GetBucket() string { + if p == nil { return "" } - return o.Bucket + return p.Bucket } -func (o *PreviewS3FileGetRequest) GetH() *int64 { - if o == nil { +func (p *PreviewS3FileGetRequest) GetH() *int64 { + if p == nil { return nil } - return o.H + return p.H } -func (o *PreviewS3FileGetRequest) GetKey() string { - if o == nil { +func (p *PreviewS3FileGetRequest) GetKey() string { + if p == nil { return "" } - return o.Key + return p.Key } -func (o *PreviewS3FileGetRequest) GetW() *int64 { - if o == nil { +func (p *PreviewS3FileGetRequest) GetW() *int64 { + if p == nil { return nil } - return o.W + return p.W } type PreviewS3FileGetResponse struct { @@ -54,23 +54,23 @@ type PreviewS3FileGetResponse struct { RawResponse *http.Response } -func (o *PreviewS3FileGetResponse) GetContentType() string { - if o == nil { +func (p *PreviewS3FileGetResponse) GetContentType() string { + if p == nil { return "" } - return o.ContentType + return p.ContentType } -func (o *PreviewS3FileGetResponse) GetStatusCode() int { - if o == nil { +func (p *PreviewS3FileGetResponse) GetStatusCode() int { + if p == nil { return 0 } - return o.StatusCode + return p.StatusCode } -func (o *PreviewS3FileGetResponse) GetRawResponse() *http.Response { - if o == nil { +func (p *PreviewS3FileGetResponse) GetRawResponse() *http.Response { + if p == nil { return nil } - return o.RawResponse + return p.RawResponse } diff --git a/internal/sdk/models/operations/revokepubliclink.go b/internal/sdk/models/operations/revokepubliclink.go index fc79857..8bcb031 100644 --- a/internal/sdk/models/operations/revokepubliclink.go +++ b/internal/sdk/models/operations/revokepubliclink.go @@ -10,11 +10,11 @@ type RevokePublicLinkRequest struct { ID string `pathParam:"style=simple,explode=false,name=id"` } -func (o *RevokePublicLinkRequest) GetID() string { - if o == nil { +func (r *RevokePublicLinkRequest) GetID() string { + if r == nil { return "" } - return o.ID + return r.ID } type RevokePublicLinkResponse struct { @@ -28,30 +28,30 @@ type RevokePublicLinkResponse struct { String *string } -func (o *RevokePublicLinkResponse) GetContentType() string { - if o == nil { +func (r *RevokePublicLinkResponse) GetContentType() string { + if r == nil { return "" } - return o.ContentType + return r.ContentType } -func (o *RevokePublicLinkResponse) GetStatusCode() int { - if o == nil { +func (r *RevokePublicLinkResponse) GetStatusCode() int { + if r == nil { return 0 } - return o.StatusCode + return r.StatusCode } -func (o *RevokePublicLinkResponse) GetRawResponse() *http.Response { - if o == nil { +func (r *RevokePublicLinkResponse) GetRawResponse() *http.Response { + if r == nil { return nil } - return o.RawResponse + return r.RawResponse } -func (o *RevokePublicLinkResponse) GetString() *string { - if o == nil { +func (r *RevokePublicLinkResponse) GetString() *string { + if r == nil { return nil } - return o.String + return r.String } diff --git a/internal/sdk/models/operations/savefile.go b/internal/sdk/models/operations/savefile.go index 61189a0..01cdd01 100644 --- a/internal/sdk/models/operations/savefile.go +++ b/internal/sdk/models/operations/savefile.go @@ -21,31 +21,31 @@ func (s SaveFileRequest) MarshalJSON() ([]byte, error) { } func (s *SaveFileRequest) UnmarshalJSON(data []byte) error { - if err := utils.UnmarshalJSON(data, &s, "", false, false); err != nil { + if err := utils.UnmarshalJSON(data, &s, "", false, nil); err != nil { return err } return nil } -func (o *SaveFileRequest) GetSaveFilePayload() *shared.SaveFilePayload { - if o == nil { +func (s *SaveFileRequest) GetSaveFilePayload() *shared.SaveFilePayload { + if s == nil { return nil } - return o.SaveFilePayload + return s.SaveFilePayload } -func (o *SaveFileRequest) GetActivityID() *string { - if o == nil { +func (s *SaveFileRequest) GetActivityID() *string { + if s == nil { return nil } - return o.ActivityID + return s.ActivityID } -func (o *SaveFileRequest) GetAsync() *bool { - if o == nil { +func (s *SaveFileRequest) GetAsync() *bool { + if s == nil { return nil } - return o.Async + return s.Async } type SaveFileResponse struct { @@ -59,30 +59,30 @@ type SaveFileResponse struct { RawResponse *http.Response } -func (o *SaveFileResponse) GetContentType() string { - if o == nil { +func (s *SaveFileResponse) GetContentType() string { + if s == nil { return "" } - return o.ContentType + return s.ContentType } -func (o *SaveFileResponse) GetFileEntity() *shared.FileEntity { - if o == nil { +func (s *SaveFileResponse) GetFileEntity() *shared.FileEntity { + if s == nil { return nil } - return o.FileEntity + return s.FileEntity } -func (o *SaveFileResponse) GetStatusCode() int { - if o == nil { +func (s *SaveFileResponse) GetStatusCode() int { + if s == nil { return 0 } - return o.StatusCode + return s.StatusCode } -func (o *SaveFileResponse) GetRawResponse() *http.Response { - if o == nil { +func (s *SaveFileResponse) GetRawResponse() *http.Response { + if s == nil { return nil } - return o.RawResponse + return s.RawResponse } diff --git a/internal/sdk/models/operations/savefilev2.go b/internal/sdk/models/operations/savefilev2.go index 6058be1..1f2c86b 100644 --- a/internal/sdk/models/operations/savefilev2.go +++ b/internal/sdk/models/operations/savefilev2.go @@ -14,6 +14,8 @@ type SaveFileV2Request struct { ActivityID *string `queryParam:"style=form,explode=true,name=activity_id"` // Don't wait for updated entity to become available in Search API. Useful for large migrations Async *bool `default:"false" queryParam:"style=form,explode=true,name=async"` + // Delete the temp file from S3 after copying it permanently + DeleteTempFile *bool `default:"true" queryParam:"style=form,explode=true,name=delete_temp_file"` // Update the diff and entity for the custom activity included in the query. // Pending state on activity is automatically ended when activity is filled. // @@ -27,45 +29,52 @@ func (s SaveFileV2Request) MarshalJSON() ([]byte, error) { } func (s *SaveFileV2Request) UnmarshalJSON(data []byte) error { - if err := utils.UnmarshalJSON(data, &s, "", false, false); err != nil { + if err := utils.UnmarshalJSON(data, &s, "", false, nil); err != nil { return err } return nil } -func (o *SaveFileV2Request) GetSaveFilePayloadV2() *shared.SaveFilePayloadV2 { - if o == nil { +func (s *SaveFileV2Request) GetSaveFilePayloadV2() *shared.SaveFilePayloadV2 { + if s == nil { return nil } - return o.SaveFilePayloadV2 + return s.SaveFilePayloadV2 } -func (o *SaveFileV2Request) GetActivityID() *string { - if o == nil { +func (s *SaveFileV2Request) GetActivityID() *string { + if s == nil { return nil } - return o.ActivityID + return s.ActivityID } -func (o *SaveFileV2Request) GetAsync() *bool { - if o == nil { +func (s *SaveFileV2Request) GetAsync() *bool { + if s == nil { return nil } - return o.Async + return s.Async } -func (o *SaveFileV2Request) GetFillActivity() *bool { - if o == nil { +func (s *SaveFileV2Request) GetDeleteTempFile() *bool { + if s == nil { return nil } - return o.FillActivity + return s.DeleteTempFile } -func (o *SaveFileV2Request) GetStrict() *bool { - if o == nil { +func (s *SaveFileV2Request) GetFillActivity() *bool { + if s == nil { return nil } - return o.Strict + return s.FillActivity +} + +func (s *SaveFileV2Request) GetStrict() *bool { + if s == nil { + return nil + } + return s.Strict } type SaveFileV2Response struct { @@ -79,30 +88,30 @@ type SaveFileV2Response struct { RawResponse *http.Response } -func (o *SaveFileV2Response) GetContentType() string { - if o == nil { +func (s *SaveFileV2Response) GetContentType() string { + if s == nil { return "" } - return o.ContentType + return s.ContentType } -func (o *SaveFileV2Response) GetFileEntity() *shared.FileEntity { - if o == nil { +func (s *SaveFileV2Response) GetFileEntity() *shared.FileEntity { + if s == nil { return nil } - return o.FileEntity + return s.FileEntity } -func (o *SaveFileV2Response) GetStatusCode() int { - if o == nil { +func (s *SaveFileV2Response) GetStatusCode() int { + if s == nil { return 0 } - return o.StatusCode + return s.StatusCode } -func (o *SaveFileV2Response) GetRawResponse() *http.Response { - if o == nil { +func (s *SaveFileV2Response) GetRawResponse() *http.Response { + if s == nil { return nil } - return o.RawResponse + return s.RawResponse } diff --git a/internal/sdk/models/operations/updatefilefolder.go b/internal/sdk/models/operations/updatefilefolder.go new file mode 100644 index 0000000..4bb6c68 --- /dev/null +++ b/internal/sdk/models/operations/updatefilefolder.go @@ -0,0 +1,107 @@ +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + +package operations + +import ( + "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/models/shared" + "net/http" +) + +type UpdateFileFolderRequest struct { + FileFolderAttributes shared.FileFolderAttributes `request:"mediaType=application/json"` + // The slug identifier for the folder + FolderSlug string `pathParam:"style=simple,explode=false,name=folderSlug"` + // Entity id + ID string `pathParam:"style=simple,explode=false,name=id"` +} + +func (u *UpdateFileFolderRequest) GetFileFolderAttributes() shared.FileFolderAttributes { + if u == nil { + return shared.FileFolderAttributes{} + } + return u.FileFolderAttributes +} + +func (u *UpdateFileFolderRequest) GetFolderSlug() string { + if u == nil { + return "" + } + return u.FolderSlug +} + +func (u *UpdateFileFolderRequest) GetID() string { + if u == nil { + return "" + } + return u.ID +} + +// UpdateFileFolderResponseBody - A generic error returned by the API +type UpdateFileFolderResponseBody struct { + // The error message + Error *string `json:"error,omitempty"` + // The HTTP status code of the error + Status *int64 `json:"status,omitempty"` +} + +func (u *UpdateFileFolderResponseBody) GetError() *string { + if u == nil { + return nil + } + return u.Error +} + +func (u *UpdateFileFolderResponseBody) GetStatus() *int64 { + if u == nil { + return nil + } + return u.Status +} + +type UpdateFileFolderResponse struct { + // HTTP response content type for this operation + ContentType string + // File folder updated successfully + FileFolderItem *shared.FileFolderItem + // HTTP response status code for this operation + StatusCode int + // Raw HTTP response; suitable for custom response parsing + RawResponse *http.Response + // The requested resource was not found + Object *UpdateFileFolderResponseBody +} + +func (u *UpdateFileFolderResponse) GetContentType() string { + if u == nil { + return "" + } + return u.ContentType +} + +func (u *UpdateFileFolderResponse) GetFileFolderItem() *shared.FileFolderItem { + if u == nil { + return nil + } + return u.FileFolderItem +} + +func (u *UpdateFileFolderResponse) GetStatusCode() int { + if u == nil { + return 0 + } + return u.StatusCode +} + +func (u *UpdateFileFolderResponse) GetRawResponse() *http.Response { + if u == nil { + return nil + } + return u.RawResponse +} + +func (u *UpdateFileFolderResponse) GetObject() *UpdateFileFolderResponseBody { + if u == nil { + return nil + } + return u.Object +} diff --git a/internal/sdk/models/operations/uploadfile.go b/internal/sdk/models/operations/uploadfile.go index 3e88db6..4efd7c1 100644 --- a/internal/sdk/models/operations/uploadfile.go +++ b/internal/sdk/models/operations/uploadfile.go @@ -13,18 +13,18 @@ type UploadFileRequest struct { FileEntityID *string `queryParam:"style=form,explode=true,name=file_entity_id"` } -func (o *UploadFileRequest) GetUploadFilePayload() *shared.UploadFilePayload { - if o == nil { +func (u *UploadFileRequest) GetUploadFilePayload() *shared.UploadFilePayload { + if u == nil { return nil } - return o.UploadFilePayload + return u.UploadFilePayload } -func (o *UploadFileRequest) GetFileEntityID() *string { - if o == nil { +func (u *UploadFileRequest) GetFileEntityID() *string { + if u == nil { return nil } - return o.FileEntityID + return u.FileEntityID } type S3ref struct { @@ -32,18 +32,18 @@ type S3ref struct { Key string `json:"key"` } -func (o *S3ref) GetBucket() string { - if o == nil { +func (s *S3ref) GetBucket() string { + if s == nil { return "" } - return o.Bucket + return s.Bucket } -func (o *S3ref) GetKey() string { - if o == nil { +func (s *S3ref) GetKey() string { + if s == nil { return "" } - return o.Key + return s.Key } // UploadFileResponseBody - Pre-signed URL for POST / PUT upload @@ -54,25 +54,25 @@ type UploadFileResponseBody struct { UploadURL *string `json:"upload_url,omitempty"` } -func (o *UploadFileResponseBody) GetPublicURL() *string { - if o == nil { +func (u *UploadFileResponseBody) GetPublicURL() *string { + if u == nil { return nil } - return o.PublicURL + return u.PublicURL } -func (o *UploadFileResponseBody) GetS3ref() *S3ref { - if o == nil { +func (u *UploadFileResponseBody) GetS3ref() *S3ref { + if u == nil { return nil } - return o.S3ref + return u.S3ref } -func (o *UploadFileResponseBody) GetUploadURL() *string { - if o == nil { +func (u *UploadFileResponseBody) GetUploadURL() *string { + if u == nil { return nil } - return o.UploadURL + return u.UploadURL } type UploadFileResponse struct { @@ -86,30 +86,30 @@ type UploadFileResponse struct { Object *UploadFileResponseBody } -func (o *UploadFileResponse) GetContentType() string { - if o == nil { +func (u *UploadFileResponse) GetContentType() string { + if u == nil { return "" } - return o.ContentType + return u.ContentType } -func (o *UploadFileResponse) GetStatusCode() int { - if o == nil { +func (u *UploadFileResponse) GetStatusCode() int { + if u == nil { return 0 } - return o.StatusCode + return u.StatusCode } -func (o *UploadFileResponse) GetRawResponse() *http.Response { - if o == nil { +func (u *UploadFileResponse) GetRawResponse() *http.Response { + if u == nil { return nil } - return o.RawResponse + return u.RawResponse } -func (o *UploadFileResponse) GetObject() *UploadFileResponseBody { - if o == nil { +func (u *UploadFileResponse) GetObject() *UploadFileResponseBody { + if u == nil { return nil } - return o.Object + return u.Object } diff --git a/internal/sdk/models/operations/uploadfilepublic.go b/internal/sdk/models/operations/uploadfilepublic.go index 6cb488a..060a8c1 100644 --- a/internal/sdk/models/operations/uploadfilepublic.go +++ b/internal/sdk/models/operations/uploadfilepublic.go @@ -11,38 +11,46 @@ type UploadFilePublicS3ref struct { Key string `json:"key"` } -func (o *UploadFilePublicS3ref) GetBucket() string { - if o == nil { +func (u *UploadFilePublicS3ref) GetBucket() string { + if u == nil { return "" } - return o.Bucket + return u.Bucket } -func (o *UploadFilePublicS3ref) GetKey() string { - if o == nil { +func (u *UploadFilePublicS3ref) GetKey() string { + if u == nil { return "" } - return o.Key + return u.Key } // UploadFilePublicResponseBody - Pre-signed URL for POST / PUT upload type UploadFilePublicResponseBody struct { + Error *string `json:"error,omitempty"` S3ref *UploadFilePublicS3ref `json:"s3ref,omitempty"` UploadURL *string `json:"upload_url,omitempty"` } -func (o *UploadFilePublicResponseBody) GetS3ref() *UploadFilePublicS3ref { - if o == nil { +func (u *UploadFilePublicResponseBody) GetError() *string { + if u == nil { return nil } - return o.S3ref + return u.Error } -func (o *UploadFilePublicResponseBody) GetUploadURL() *string { - if o == nil { +func (u *UploadFilePublicResponseBody) GetS3ref() *UploadFilePublicS3ref { + if u == nil { return nil } - return o.UploadURL + return u.S3ref +} + +func (u *UploadFilePublicResponseBody) GetUploadURL() *string { + if u == nil { + return nil + } + return u.UploadURL } type UploadFilePublicResponse struct { @@ -56,30 +64,30 @@ type UploadFilePublicResponse struct { Object *UploadFilePublicResponseBody } -func (o *UploadFilePublicResponse) GetContentType() string { - if o == nil { +func (u *UploadFilePublicResponse) GetContentType() string { + if u == nil { return "" } - return o.ContentType + return u.ContentType } -func (o *UploadFilePublicResponse) GetStatusCode() int { - if o == nil { +func (u *UploadFilePublicResponse) GetStatusCode() int { + if u == nil { return 0 } - return o.StatusCode + return u.StatusCode } -func (o *UploadFilePublicResponse) GetRawResponse() *http.Response { - if o == nil { +func (u *UploadFilePublicResponse) GetRawResponse() *http.Response { + if u == nil { return nil } - return o.RawResponse + return u.RawResponse } -func (o *UploadFilePublicResponse) GetObject() *UploadFilePublicResponseBody { - if o == nil { +func (u *UploadFilePublicResponse) GetObject() *UploadFilePublicResponseBody { + if u == nil { return nil } - return o.Object + return u.Object } diff --git a/internal/sdk/models/operations/uploadfilev2.go b/internal/sdk/models/operations/uploadfilev2.go index a7cbb4d..b9a3f76 100644 --- a/internal/sdk/models/operations/uploadfilev2.go +++ b/internal/sdk/models/operations/uploadfilev2.go @@ -16,18 +16,18 @@ type UploadFileV2Request struct { FileEntityID *string `queryParam:"style=form,explode=true,name=file_entity_id"` } -func (o *UploadFileV2Request) GetUploadFilePayload() *shared.UploadFilePayload { - if o == nil { +func (u *UploadFileV2Request) GetUploadFilePayload() *shared.UploadFilePayload { + if u == nil { return nil } - return o.UploadFilePayload + return u.UploadFilePayload } -func (o *UploadFileV2Request) GetFileEntityID() *string { - if o == nil { +func (u *UploadFileV2Request) GetFileEntityID() *string { + if u == nil { return nil } - return o.FileEntityID + return u.FileEntityID } type UploadFileV2Response struct { @@ -41,30 +41,30 @@ type UploadFileV2Response struct { RawResponse *http.Response } -func (o *UploadFileV2Response) GetContentType() string { - if o == nil { +func (u *UploadFileV2Response) GetContentType() string { + if u == nil { return "" } - return o.ContentType + return u.ContentType } -func (o *UploadFileV2Response) GetFileUpload() *shared.FileUpload { - if o == nil { +func (u *UploadFileV2Response) GetFileUpload() *shared.FileUpload { + if u == nil { return nil } - return o.FileUpload + return u.FileUpload } -func (o *UploadFileV2Response) GetStatusCode() int { - if o == nil { +func (u *UploadFileV2Response) GetStatusCode() int { + if u == nil { return 0 } - return o.StatusCode + return u.StatusCode } -func (o *UploadFileV2Response) GetRawResponse() *http.Response { - if o == nil { +func (u *UploadFileV2Response) GetRawResponse() *http.Response { + if u == nil { return nil } - return o.RawResponse + return u.RawResponse } diff --git a/internal/sdk/models/operations/verifycustomdownloadurl.go b/internal/sdk/models/operations/verifycustomdownloadurl.go index fbe683c..793d22b 100644 --- a/internal/sdk/models/operations/verifycustomdownloadurl.go +++ b/internal/sdk/models/operations/verifycustomdownloadurl.go @@ -11,11 +11,11 @@ type VerifyCustomDownloadURLResponseBody struct { Valid *bool `json:"valid,omitempty"` } -func (o *VerifyCustomDownloadURLResponseBody) GetValid() *bool { - if o == nil { +func (v *VerifyCustomDownloadURLResponseBody) GetValid() *bool { + if v == nil { return nil } - return o.Valid + return v.Valid } type VerifyCustomDownloadURLResponse struct { @@ -29,30 +29,30 @@ type VerifyCustomDownloadURLResponse struct { Object *VerifyCustomDownloadURLResponseBody } -func (o *VerifyCustomDownloadURLResponse) GetContentType() string { - if o == nil { +func (v *VerifyCustomDownloadURLResponse) GetContentType() string { + if v == nil { return "" } - return o.ContentType + return v.ContentType } -func (o *VerifyCustomDownloadURLResponse) GetStatusCode() int { - if o == nil { +func (v *VerifyCustomDownloadURLResponse) GetStatusCode() int { + if v == nil { return 0 } - return o.StatusCode + return v.StatusCode } -func (o *VerifyCustomDownloadURLResponse) GetRawResponse() *http.Response { - if o == nil { +func (v *VerifyCustomDownloadURLResponse) GetRawResponse() *http.Response { + if v == nil { return nil } - return o.RawResponse + return v.RawResponse } -func (o *VerifyCustomDownloadURLResponse) GetObject() *VerifyCustomDownloadURLResponseBody { - if o == nil { +func (v *VerifyCustomDownloadURLResponse) GetObject() *VerifyCustomDownloadURLResponseBody { + if v == nil { return nil } - return o.Object + return v.Object } diff --git a/internal/sdk/models/shared/baseentityacl.go b/internal/sdk/models/shared/baseentityacl.go index 9998b66..2ca93dc 100644 --- a/internal/sdk/models/shared/baseentityacl.go +++ b/internal/sdk/models/shared/baseentityacl.go @@ -9,23 +9,23 @@ type BaseEntityACL struct { View []string `json:"view,omitempty"` } -func (o *BaseEntityACL) GetDelete() []string { - if o == nil { +func (b *BaseEntityACL) GetDelete() []string { + if b == nil { return nil } - return o.Delete + return b.Delete } -func (o *BaseEntityACL) GetEdit() []string { - if o == nil { +func (b *BaseEntityACL) GetEdit() []string { + if b == nil { return nil } - return o.Edit + return b.Edit } -func (o *BaseEntityACL) GetView() []string { - if o == nil { +func (b *BaseEntityACL) GetView() []string { + if b == nil { return nil } - return o.View + return b.View } diff --git a/internal/sdk/models/shared/baseentityowner.go b/internal/sdk/models/shared/baseentityowner.go index 8f359c1..baf296d 100644 --- a/internal/sdk/models/shared/baseentityowner.go +++ b/internal/sdk/models/shared/baseentityowner.go @@ -10,16 +10,16 @@ type BaseEntityOwner struct { UserID *string `json:"user_id,omitempty"` } -func (o *BaseEntityOwner) GetOrgID() string { - if o == nil { +func (b *BaseEntityOwner) GetOrgID() string { + if b == nil { return "" } - return o.OrgID + return b.OrgID } -func (o *BaseEntityOwner) GetUserID() *string { - if o == nil { +func (b *BaseEntityOwner) GetUserID() *string { + if b == nil { return nil } - return o.UserID + return b.UserID } diff --git a/internal/sdk/models/shared/downloadfilespayload.go b/internal/sdk/models/shared/downloadfilespayload.go index e66dc4b..e21db64 100644 --- a/internal/sdk/models/shared/downloadfilespayload.go +++ b/internal/sdk/models/shared/downloadfilespayload.go @@ -8,16 +8,16 @@ type DownloadFilesPayload struct { Version *int64 `json:"version,omitempty"` } -func (o *DownloadFilesPayload) GetID() string { - if o == nil { +func (d *DownloadFilesPayload) GetID() string { + if d == nil { return "" } - return o.ID + return d.ID } -func (o *DownloadFilesPayload) GetVersion() *int64 { - if o == nil { +func (d *DownloadFilesPayload) GetVersion() *int64 { + if d == nil { return nil } - return o.Version + return d.Version } diff --git a/internal/sdk/models/shared/fileentity.go b/internal/sdk/models/shared/fileentity.go index 710f620..981ea96 100644 --- a/internal/sdk/models/shared/fileentity.go +++ b/internal/sdk/models/shared/fileentity.go @@ -58,39 +58,58 @@ func (e *AccessControl) UnmarshalJSON(data []byte) error { } } +type FileEntityS3ref struct { + Bucket string `json:"bucket"` + Key string `json:"key"` +} + +func (f *FileEntityS3ref) GetBucket() string { + if f == nil { + return "" + } + return f.Bucket +} + +func (f *FileEntityS3ref) GetKey() string { + if f == nil { + return "" + } + return f.Key +} + type FileEntity struct { // Additional fields that are not part of the schema Additional map[string]any `json:"__additional,omitempty"` // Access control list (ACL) for an entity. Defines sharing access to external orgs or users. ACL *BaseEntityACL `json:"_acl,omitempty"` CreatedAt *time.Time `json:"_created_at,omitempty"` - ID *string `json:"_id,omitempty"` + ID string `json:"_id"` // Manifest ID used to create/update the entity Manifest []string `json:"_manifest,omitempty"` - Org *string `json:"_org,omitempty"` + Org string `json:"_org"` Owners []BaseEntityOwner `json:"_owners,omitempty"` Purpose []string `json:"_purpose,omitempty"` - Schema *Schema `json:"_schema,omitempty"` + Schema Schema `json:"_schema"` Tags []string `json:"_tags,omitempty"` - Title *string `json:"_title,omitempty"` + Title string `json:"_title"` UpdatedAt *time.Time `json:"_updated_at,omitempty"` AccessControl *AccessControl `default:"private" json:"access_control"` // Custom external download url used for the file CustomDownloadURL *string `json:"custom_download_url,omitempty"` - Filename *string `json:"filename,omitempty"` + Filename string `json:"filename"` // MIME type of the file MimeType *string `json:"mime_type,omitempty"` // Direct URL for file (public only if file access control is public-read) PublicURL *string `json:"public_url,omitempty"` // Human readable file size - ReadableSize *string `json:"readable_size,omitempty"` - S3ref *S3Ref `json:"s3ref,omitempty"` + ReadableSize *string `json:"readable_size,omitempty"` + S3ref *FileEntityS3ref `json:"s3ref,omitempty"` // File size in bytes SizeBytes *int64 `json:"size_bytes,omitempty"` // Source URL for the file. Included if the entity was created from source_url, or when ?source_url=true SourceURL *string `json:"source_url,omitempty"` - Type *FileType `json:"type,omitempty"` - Versions []FileItem `json:"versions,omitempty"` + Type FileType `json:"type"` + Versions []FileItem `json:"versions"` } func (f FileEntity) MarshalJSON() ([]byte, error) { @@ -98,169 +117,169 @@ func (f FileEntity) MarshalJSON() ([]byte, error) { } func (f *FileEntity) UnmarshalJSON(data []byte) error { - if err := utils.UnmarshalJSON(data, &f, "", false, false); err != nil { + if err := utils.UnmarshalJSON(data, &f, "", false, []string{"_id", "_org", "_schema", "_title", "filename", "type", "versions"}); err != nil { return err } return nil } -func (o *FileEntity) GetAdditional() map[string]any { - if o == nil { +func (f *FileEntity) GetAdditional() map[string]any { + if f == nil { return nil } - return o.Additional + return f.Additional } -func (o *FileEntity) GetACL() *BaseEntityACL { - if o == nil { +func (f *FileEntity) GetACL() *BaseEntityACL { + if f == nil { return nil } - return o.ACL + return f.ACL } -func (o *FileEntity) GetCreatedAt() *time.Time { - if o == nil { +func (f *FileEntity) GetCreatedAt() *time.Time { + if f == nil { return nil } - return o.CreatedAt + return f.CreatedAt } -func (o *FileEntity) GetID() *string { - if o == nil { - return nil +func (f *FileEntity) GetID() string { + if f == nil { + return "" } - return o.ID + return f.ID } -func (o *FileEntity) GetManifest() []string { - if o == nil { +func (f *FileEntity) GetManifest() []string { + if f == nil { return nil } - return o.Manifest + return f.Manifest } -func (o *FileEntity) GetOrg() *string { - if o == nil { - return nil +func (f *FileEntity) GetOrg() string { + if f == nil { + return "" } - return o.Org + return f.Org } -func (o *FileEntity) GetOwners() []BaseEntityOwner { - if o == nil { +func (f *FileEntity) GetOwners() []BaseEntityOwner { + if f == nil { return nil } - return o.Owners + return f.Owners } -func (o *FileEntity) GetPurpose() []string { - if o == nil { +func (f *FileEntity) GetPurpose() []string { + if f == nil { return nil } - return o.Purpose + return f.Purpose } -func (o *FileEntity) GetSchema() *Schema { - if o == nil { - return nil +func (f *FileEntity) GetSchema() Schema { + if f == nil { + return Schema("") } - return o.Schema + return f.Schema } -func (o *FileEntity) GetTags() []string { - if o == nil { +func (f *FileEntity) GetTags() []string { + if f == nil { return nil } - return o.Tags + return f.Tags } -func (o *FileEntity) GetTitle() *string { - if o == nil { - return nil +func (f *FileEntity) GetTitle() string { + if f == nil { + return "" } - return o.Title + return f.Title } -func (o *FileEntity) GetUpdatedAt() *time.Time { - if o == nil { +func (f *FileEntity) GetUpdatedAt() *time.Time { + if f == nil { return nil } - return o.UpdatedAt + return f.UpdatedAt } -func (o *FileEntity) GetAccessControl() *AccessControl { - if o == nil { +func (f *FileEntity) GetAccessControl() *AccessControl { + if f == nil { return nil } - return o.AccessControl + return f.AccessControl } -func (o *FileEntity) GetCustomDownloadURL() *string { - if o == nil { +func (f *FileEntity) GetCustomDownloadURL() *string { + if f == nil { return nil } - return o.CustomDownloadURL + return f.CustomDownloadURL } -func (o *FileEntity) GetFilename() *string { - if o == nil { - return nil +func (f *FileEntity) GetFilename() string { + if f == nil { + return "" } - return o.Filename + return f.Filename } -func (o *FileEntity) GetMimeType() *string { - if o == nil { +func (f *FileEntity) GetMimeType() *string { + if f == nil { return nil } - return o.MimeType + return f.MimeType } -func (o *FileEntity) GetPublicURL() *string { - if o == nil { +func (f *FileEntity) GetPublicURL() *string { + if f == nil { return nil } - return o.PublicURL + return f.PublicURL } -func (o *FileEntity) GetReadableSize() *string { - if o == nil { +func (f *FileEntity) GetReadableSize() *string { + if f == nil { return nil } - return o.ReadableSize + return f.ReadableSize } -func (o *FileEntity) GetS3ref() *S3Ref { - if o == nil { +func (f *FileEntity) GetS3ref() *FileEntityS3ref { + if f == nil { return nil } - return o.S3ref + return f.S3ref } -func (o *FileEntity) GetSizeBytes() *int64 { - if o == nil { +func (f *FileEntity) GetSizeBytes() *int64 { + if f == nil { return nil } - return o.SizeBytes + return f.SizeBytes } -func (o *FileEntity) GetSourceURL() *string { - if o == nil { +func (f *FileEntity) GetSourceURL() *string { + if f == nil { return nil } - return o.SourceURL + return f.SourceURL } -func (o *FileEntity) GetType() *FileType { - if o == nil { - return nil +func (f *FileEntity) GetType() FileType { + if f == nil { + return FileType("") } - return o.Type + return f.Type } -func (o *FileEntity) GetVersions() []FileItem { - if o == nil { - return nil +func (f *FileEntity) GetVersions() []FileItem { + if f == nil { + return []FileItem{} } - return o.Versions + return f.Versions } diff --git a/internal/sdk/models/shared/filefolderattributes.go b/internal/sdk/models/shared/filefolderattributes.go new file mode 100644 index 0000000..461b1a3 --- /dev/null +++ b/internal/sdk/models/shared/filefolderattributes.go @@ -0,0 +1,48 @@ +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + +package shared + +import ( + "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/internal/utils" +) + +type FileFolderAttributes struct { + // Name of the folder + Name *string `json:"name,omitempty"` + // Array of parent folder slugs, empty array if top-level folder + Parents []string `json:"parents,omitempty"` + // Whether the folder is starred / favorited + Starred *bool `default:"false" json:"starred"` +} + +func (f FileFolderAttributes) MarshalJSON() ([]byte, error) { + return utils.MarshalJSON(f, "", false) +} + +func (f *FileFolderAttributes) UnmarshalJSON(data []byte) error { + if err := utils.UnmarshalJSON(data, &f, "", false, nil); err != nil { + return err + } + return nil +} + +func (f *FileFolderAttributes) GetName() *string { + if f == nil { + return nil + } + return f.Name +} + +func (f *FileFolderAttributes) GetParents() []string { + if f == nil { + return nil + } + return f.Parents +} + +func (f *FileFolderAttributes) GetStarred() *bool { + if f == nil { + return nil + } + return f.Starred +} diff --git a/internal/sdk/models/shared/filefoldercreaterequest.go b/internal/sdk/models/shared/filefoldercreaterequest.go new file mode 100644 index 0000000..c0db893 --- /dev/null +++ b/internal/sdk/models/shared/filefoldercreaterequest.go @@ -0,0 +1,49 @@ +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + +package shared + +import ( + "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/internal/utils" +) + +// FileFolderCreateRequest - Request body for creating a file folder +type FileFolderCreateRequest struct { + // Name of the folder + Name string `json:"name"` + // Array of parent folder slugs, empty array if top-level folder + Parents []string `json:"parents,omitempty"` + // Whether the folder is starred / favorited + Starred *bool `default:"false" json:"starred"` +} + +func (f FileFolderCreateRequest) MarshalJSON() ([]byte, error) { + return utils.MarshalJSON(f, "", false) +} + +func (f *FileFolderCreateRequest) UnmarshalJSON(data []byte) error { + if err := utils.UnmarshalJSON(data, &f, "", false, []string{"name"}); err != nil { + return err + } + return nil +} + +func (f *FileFolderCreateRequest) GetName() string { + if f == nil { + return "" + } + return f.Name +} + +func (f *FileFolderCreateRequest) GetParents() []string { + if f == nil { + return nil + } + return f.Parents +} + +func (f *FileFolderCreateRequest) GetStarred() *bool { + if f == nil { + return nil + } + return f.Starred +} diff --git a/internal/sdk/models/shared/filefolderitem.go b/internal/sdk/models/shared/filefolderitem.go new file mode 100644 index 0000000..82ff822 --- /dev/null +++ b/internal/sdk/models/shared/filefolderitem.go @@ -0,0 +1,86 @@ +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + +package shared + +import ( + "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/internal/utils" + "time" +) + +// FileFolderItem - A file folder with identifiers and timestamps +type FileFolderItem struct { + // Timestamp when the folder was created + CreatedAt *time.Time `json:"created_at,omitempty"` + // Generated uuid for a file folder + ID *string `json:"id,omitempty"` + // Display name of the folder + Name string `json:"name"` + // Array of parent folder slugs, empty array if top-level folder + Parents []string `json:"parents,omitempty"` + // Full slug for the folder + Slug *string `json:"slug,omitempty"` + // Whether the folder is starred / favorited + Starred *bool `json:"starred,omitempty"` + // Timestamp when the folder was last updated + UpdatedAt *time.Time `json:"updated_at,omitempty"` +} + +func (f FileFolderItem) MarshalJSON() ([]byte, error) { + return utils.MarshalJSON(f, "", false) +} + +func (f *FileFolderItem) UnmarshalJSON(data []byte) error { + if err := utils.UnmarshalJSON(data, &f, "", false, []string{"name"}); err != nil { + return err + } + return nil +} + +func (f *FileFolderItem) GetCreatedAt() *time.Time { + if f == nil { + return nil + } + return f.CreatedAt +} + +func (f *FileFolderItem) GetID() *string { + if f == nil { + return nil + } + return f.ID +} + +func (f *FileFolderItem) GetName() string { + if f == nil { + return "" + } + return f.Name +} + +func (f *FileFolderItem) GetParents() []string { + if f == nil { + return nil + } + return f.Parents +} + +func (f *FileFolderItem) GetSlug() *string { + if f == nil { + return nil + } + return f.Slug +} + +func (f *FileFolderItem) GetStarred() *bool { + if f == nil { + return nil + } + return f.Starred +} + +func (f *FileFolderItem) GetUpdatedAt() *time.Time { + if f == nil { + return nil + } + return f.UpdatedAt +} diff --git a/internal/sdk/models/shared/fileitem.go b/internal/sdk/models/shared/fileitem.go index 789897e..6c07b07 100644 --- a/internal/sdk/models/shared/fileitem.go +++ b/internal/sdk/models/shared/fileitem.go @@ -10,37 +10,37 @@ type FileItem struct { SizeBytes *int64 `json:"size_bytes,omitempty"` } -func (o *FileItem) GetFilename() *string { - if o == nil { +func (f *FileItem) GetFilename() *string { + if f == nil { return nil } - return o.Filename + return f.Filename } -func (o *FileItem) GetMimeType() *string { - if o == nil { +func (f *FileItem) GetMimeType() *string { + if f == nil { return nil } - return o.MimeType + return f.MimeType } -func (o *FileItem) GetReadableSize() *string { - if o == nil { +func (f *FileItem) GetReadableSize() *string { + if f == nil { return nil } - return o.ReadableSize + return f.ReadableSize } -func (o *FileItem) GetS3ref() *S3Ref { - if o == nil { +func (f *FileItem) GetS3ref() *S3Ref { + if f == nil { return nil } - return o.S3ref + return f.S3ref } -func (o *FileItem) GetSizeBytes() *int64 { - if o == nil { +func (f *FileItem) GetSizeBytes() *int64 { + if f == nil { return nil } - return o.SizeBytes + return f.SizeBytes } diff --git a/internal/sdk/models/shared/filerelationitem.go b/internal/sdk/models/shared/filerelationitem.go index 52b6df0..013c003 100644 --- a/internal/sdk/models/shared/filerelationitem.go +++ b/internal/sdk/models/shared/filerelationitem.go @@ -2,6 +2,10 @@ package shared +import ( + "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/internal/utils" +) + type FileRelationItem struct { // URL-friendly identifier for the entity schema Schema *string `json:"_schema,omitempty"` @@ -9,23 +13,34 @@ type FileRelationItem struct { EntityID string `json:"entity_id"` } -func (o *FileRelationItem) GetSchema() *string { - if o == nil { +func (f FileRelationItem) MarshalJSON() ([]byte, error) { + return utils.MarshalJSON(f, "", false) +} + +func (f *FileRelationItem) UnmarshalJSON(data []byte) error { + if err := utils.UnmarshalJSON(data, &f, "", false, []string{"entity_id"}); err != nil { + return err + } + return nil +} + +func (f *FileRelationItem) GetSchema() *string { + if f == nil { return nil } - return o.Schema + return f.Schema } -func (o *FileRelationItem) GetTags() []string { - if o == nil { +func (f *FileRelationItem) GetTags() []string { + if f == nil { return nil } - return o.Tags + return f.Tags } -func (o *FileRelationItem) GetEntityID() string { - if o == nil { +func (f *FileRelationItem) GetEntityID() string { + if f == nil { return "" } - return o.EntityID + return f.EntityID } diff --git a/internal/sdk/models/shared/fileupload.go b/internal/sdk/models/shared/fileupload.go index 9183ae7..1f431db 100644 --- a/internal/sdk/models/shared/fileupload.go +++ b/internal/sdk/models/shared/fileupload.go @@ -7,18 +7,18 @@ type FileUploadS3ref struct { Key string `json:"key"` } -func (o *FileUploadS3ref) GetBucket() string { - if o == nil { +func (f *FileUploadS3ref) GetBucket() string { + if f == nil { return "" } - return o.Bucket + return f.Bucket } -func (o *FileUploadS3ref) GetKey() string { - if o == nil { +func (f *FileUploadS3ref) GetKey() string { + if f == nil { return "" } - return o.Key + return f.Key } type FileUpload struct { @@ -28,23 +28,23 @@ type FileUpload struct { UploadURL *string `json:"upload_url,omitempty"` } -func (o *FileUpload) GetPublicURL() *string { - if o == nil { +func (f *FileUpload) GetPublicURL() *string { + if f == nil { return nil } - return o.PublicURL + return f.PublicURL } -func (o *FileUpload) GetS3ref() *FileUploadS3ref { - if o == nil { +func (f *FileUpload) GetS3ref() *FileUploadS3ref { + if f == nil { return nil } - return o.S3ref + return f.S3ref } -func (o *FileUpload) GetUploadURL() *string { - if o == nil { +func (f *FileUpload) GetUploadURL() *string { + if f == nil { return nil } - return o.UploadURL + return f.UploadURL } diff --git a/internal/sdk/models/shared/publiclink.go b/internal/sdk/models/shared/publiclink.go index 1b14cf2..5880763 100644 --- a/internal/sdk/models/shared/publiclink.go +++ b/internal/sdk/models/shared/publiclink.go @@ -11,23 +11,23 @@ type PublicLink struct { Link *string `json:"link,omitempty"` } -func (o *PublicLink) GetID() *string { - if o == nil { +func (p *PublicLink) GetID() *string { + if p == nil { return nil } - return o.ID + return p.ID } -func (o *PublicLink) GetLastAccessedAt() *string { - if o == nil { +func (p *PublicLink) GetLastAccessedAt() *string { + if p == nil { return nil } - return o.LastAccessedAt + return p.LastAccessedAt } -func (o *PublicLink) GetLink() *string { - if o == nil { +func (p *PublicLink) GetLink() *string { + if p == nil { return nil } - return o.Link + return p.Link } diff --git a/internal/sdk/models/shared/s3ref.go b/internal/sdk/models/shared/s3ref.go index 212dcfa..dc0f910 100644 --- a/internal/sdk/models/shared/s3ref.go +++ b/internal/sdk/models/shared/s3ref.go @@ -2,21 +2,36 @@ package shared +import ( + "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/internal/utils" +) + type S3Ref struct { Bucket string `json:"bucket"` Key string `json:"key"` } -func (o *S3Ref) GetBucket() string { - if o == nil { +func (s S3Ref) MarshalJSON() ([]byte, error) { + return utils.MarshalJSON(s, "", false) +} + +func (s *S3Ref) UnmarshalJSON(data []byte) error { + if err := utils.UnmarshalJSON(data, &s, "", false, []string{"bucket", "key"}); err != nil { + return err + } + return nil +} + +func (s *S3Ref) GetBucket() string { + if s == nil { return "" } - return o.Bucket + return s.Bucket } -func (o *S3Ref) GetKey() string { - if o == nil { +func (s *S3Ref) GetKey() string { + if s == nil { return "" } - return o.Key + return s.Key } diff --git a/internal/sdk/models/shared/savecustomfilepayload.go b/internal/sdk/models/shared/savecustomfilepayload.go index 27f2497..2a96124 100644 --- a/internal/sdk/models/shared/savecustomfilepayload.go +++ b/internal/sdk/models/shared/savecustomfilepayload.go @@ -46,7 +46,7 @@ type SaveCustomFilePayload struct { CustomDownloadURL *string `json:"custom_download_url,omitempty"` // Deprecated, use _id instead // - // Deprecated field: This will be removed in a future release, please migrate away from it as soon as possible. + // Deprecated: This will be removed in a future release, please migrate away from it as soon as possible. FileEntityID *string `json:"file_entity_id,omitempty"` Filename *string `json:"filename,omitempty"` // MIME type of the file @@ -61,92 +61,92 @@ func (s SaveCustomFilePayload) MarshalJSON() ([]byte, error) { } func (s *SaveCustomFilePayload) UnmarshalJSON(data []byte) error { - if err := utils.UnmarshalJSON(data, &s, "", false, true); err != nil { + if err := utils.UnmarshalJSON(data, &s, "", false, nil); err != nil { return err } return nil } -func (o *SaveCustomFilePayload) GetAdditionalProperties() any { - if o == nil { +func (s *SaveCustomFilePayload) GetAdditionalProperties() any { + if s == nil { return nil } - return o.AdditionalProperties + return s.AdditionalProperties } -func (o *SaveCustomFilePayload) GetID() *string { - if o == nil { +func (s *SaveCustomFilePayload) GetID() *string { + if s == nil { return nil } - return o.ID + return s.ID } -func (o *SaveCustomFilePayload) GetManifest() []string { - if o == nil { +func (s *SaveCustomFilePayload) GetManifest() []string { + if s == nil { return nil } - return o.Manifest + return s.Manifest } -func (o *SaveCustomFilePayload) GetPurpose() []string { - if o == nil { +func (s *SaveCustomFilePayload) GetPurpose() []string { + if s == nil { return nil } - return o.Purpose + return s.Purpose } -func (o *SaveCustomFilePayload) GetTags() []string { - if o == nil { +func (s *SaveCustomFilePayload) GetTags() []string { + if s == nil { return nil } - return o.Tags + return s.Tags } -func (o *SaveCustomFilePayload) GetAccessControl() *SaveCustomFilePayloadAccessControl { - if o == nil { +func (s *SaveCustomFilePayload) GetAccessControl() *SaveCustomFilePayloadAccessControl { + if s == nil { return nil } - return o.AccessControl + return s.AccessControl } -func (o *SaveCustomFilePayload) GetCustomDownloadURL() *string { - if o == nil { +func (s *SaveCustomFilePayload) GetCustomDownloadURL() *string { + if s == nil { return nil } - return o.CustomDownloadURL + return s.CustomDownloadURL } -func (o *SaveCustomFilePayload) GetFileEntityID() *string { - if o == nil { +func (s *SaveCustomFilePayload) GetFileEntityID() *string { + if s == nil { return nil } - return o.FileEntityID + return s.FileEntityID } -func (o *SaveCustomFilePayload) GetFilename() *string { - if o == nil { +func (s *SaveCustomFilePayload) GetFilename() *string { + if s == nil { return nil } - return o.Filename + return s.Filename } -func (o *SaveCustomFilePayload) GetMimeType() *string { - if o == nil { +func (s *SaveCustomFilePayload) GetMimeType() *string { + if s == nil { return nil } - return o.MimeType + return s.MimeType } -func (o *SaveCustomFilePayload) GetRelations() []FileRelationItem { - if o == nil { +func (s *SaveCustomFilePayload) GetRelations() []FileRelationItem { + if s == nil { return nil } - return o.Relations + return s.Relations } -func (o *SaveCustomFilePayload) GetType() *FileType { - if o == nil { +func (s *SaveCustomFilePayload) GetType() *FileType { + if s == nil { return nil } - return o.Type + return s.Type } diff --git a/internal/sdk/models/shared/savefilefromsourceurlpayload.go b/internal/sdk/models/shared/savefilefromsourceurlpayload.go index d1b4c22..73e2261 100644 --- a/internal/sdk/models/shared/savefilefromsourceurlpayload.go +++ b/internal/sdk/models/shared/savefilefromsourceurlpayload.go @@ -46,7 +46,7 @@ type SaveFileFromSourceURLPayload struct { CustomDownloadURL *string `json:"custom_download_url,omitempty"` // Deprecated, use _id instead // - // Deprecated field: This will be removed in a future release, please migrate away from it as soon as possible. + // Deprecated: This will be removed in a future release, please migrate away from it as soon as possible. FileEntityID *string `json:"file_entity_id,omitempty"` Filename *string `json:"filename,omitempty"` // MIME type of the file @@ -63,99 +63,99 @@ func (s SaveFileFromSourceURLPayload) MarshalJSON() ([]byte, error) { } func (s *SaveFileFromSourceURLPayload) UnmarshalJSON(data []byte) error { - if err := utils.UnmarshalJSON(data, &s, "", false, true); err != nil { + if err := utils.UnmarshalJSON(data, &s, "", false, nil); err != nil { return err } return nil } -func (o *SaveFileFromSourceURLPayload) GetAdditionalProperties() any { - if o == nil { +func (s *SaveFileFromSourceURLPayload) GetAdditionalProperties() any { + if s == nil { return nil } - return o.AdditionalProperties + return s.AdditionalProperties } -func (o *SaveFileFromSourceURLPayload) GetID() *string { - if o == nil { +func (s *SaveFileFromSourceURLPayload) GetID() *string { + if s == nil { return nil } - return o.ID + return s.ID } -func (o *SaveFileFromSourceURLPayload) GetManifest() []string { - if o == nil { +func (s *SaveFileFromSourceURLPayload) GetManifest() []string { + if s == nil { return nil } - return o.Manifest + return s.Manifest } -func (o *SaveFileFromSourceURLPayload) GetPurpose() []string { - if o == nil { +func (s *SaveFileFromSourceURLPayload) GetPurpose() []string { + if s == nil { return nil } - return o.Purpose + return s.Purpose } -func (o *SaveFileFromSourceURLPayload) GetTags() []string { - if o == nil { +func (s *SaveFileFromSourceURLPayload) GetTags() []string { + if s == nil { return nil } - return o.Tags + return s.Tags } -func (o *SaveFileFromSourceURLPayload) GetAccessControl() *SaveFileFromSourceURLPayloadAccessControl { - if o == nil { +func (s *SaveFileFromSourceURLPayload) GetAccessControl() *SaveFileFromSourceURLPayloadAccessControl { + if s == nil { return nil } - return o.AccessControl + return s.AccessControl } -func (o *SaveFileFromSourceURLPayload) GetCustomDownloadURL() *string { - if o == nil { +func (s *SaveFileFromSourceURLPayload) GetCustomDownloadURL() *string { + if s == nil { return nil } - return o.CustomDownloadURL + return s.CustomDownloadURL } -func (o *SaveFileFromSourceURLPayload) GetFileEntityID() *string { - if o == nil { +func (s *SaveFileFromSourceURLPayload) GetFileEntityID() *string { + if s == nil { return nil } - return o.FileEntityID + return s.FileEntityID } -func (o *SaveFileFromSourceURLPayload) GetFilename() *string { - if o == nil { +func (s *SaveFileFromSourceURLPayload) GetFilename() *string { + if s == nil { return nil } - return o.Filename + return s.Filename } -func (o *SaveFileFromSourceURLPayload) GetMimeType() *string { - if o == nil { +func (s *SaveFileFromSourceURLPayload) GetMimeType() *string { + if s == nil { return nil } - return o.MimeType + return s.MimeType } -func (o *SaveFileFromSourceURLPayload) GetRelations() []FileRelationItem { - if o == nil { +func (s *SaveFileFromSourceURLPayload) GetRelations() []FileRelationItem { + if s == nil { return nil } - return o.Relations + return s.Relations } -func (o *SaveFileFromSourceURLPayload) GetSourceURL() *string { - if o == nil { +func (s *SaveFileFromSourceURLPayload) GetSourceURL() *string { + if s == nil { return nil } - return o.SourceURL + return s.SourceURL } -func (o *SaveFileFromSourceURLPayload) GetType() *FileType { - if o == nil { +func (s *SaveFileFromSourceURLPayload) GetType() *FileType { + if s == nil { return nil } - return o.Type + return s.Type } diff --git a/internal/sdk/models/shared/savefilepayload.go b/internal/sdk/models/shared/savefilepayload.go index 9d725b3..c537a26 100644 --- a/internal/sdk/models/shared/savefilepayload.go +++ b/internal/sdk/models/shared/savefilepayload.go @@ -17,9 +17,9 @@ const ( ) type SaveFilePayload struct { - SaveS3FilePayload *SaveS3FilePayload - SaveFileFromSourceURLPayload *SaveFileFromSourceURLPayload - SaveCustomFilePayload *SaveCustomFilePayload + SaveS3FilePayload *SaveS3FilePayload `queryParam:"inline,name=SaveFilePayload"` + SaveFileFromSourceURLPayload *SaveFileFromSourceURLPayload `queryParam:"inline,name=SaveFilePayload"` + SaveCustomFilePayload *SaveCustomFilePayload `queryParam:"inline,name=SaveFilePayload"` Type SaveFilePayloadType } @@ -53,24 +53,54 @@ func CreateSaveFilePayloadSaveCustomFilePayload(saveCustomFilePayload SaveCustom func (u *SaveFilePayload) UnmarshalJSON(data []byte) error { - var saveCustomFilePayload SaveCustomFilePayload = SaveCustomFilePayload{} - if err := utils.UnmarshalJSON(data, &saveCustomFilePayload, "", true, true); err == nil { - u.SaveCustomFilePayload = &saveCustomFilePayload - u.Type = SaveFilePayloadTypeSaveCustomFilePayload - return nil - } + var candidates []utils.UnionCandidate + // Collect all valid candidates var saveS3FilePayload SaveS3FilePayload = SaveS3FilePayload{} - if err := utils.UnmarshalJSON(data, &saveS3FilePayload, "", true, true); err == nil { - u.SaveS3FilePayload = &saveS3FilePayload - u.Type = SaveFilePayloadTypeSaveS3FilePayload - return nil + if err := utils.UnmarshalJSON(data, &saveS3FilePayload, "", true, nil); err == nil { + candidates = append(candidates, utils.UnionCandidate{ + Type: SaveFilePayloadTypeSaveS3FilePayload, + Value: &saveS3FilePayload, + }) } var saveFileFromSourceURLPayload SaveFileFromSourceURLPayload = SaveFileFromSourceURLPayload{} - if err := utils.UnmarshalJSON(data, &saveFileFromSourceURLPayload, "", true, true); err == nil { - u.SaveFileFromSourceURLPayload = &saveFileFromSourceURLPayload - u.Type = SaveFilePayloadTypeSaveFileFromSourceURLPayload + if err := utils.UnmarshalJSON(data, &saveFileFromSourceURLPayload, "", true, nil); err == nil { + candidates = append(candidates, utils.UnionCandidate{ + Type: SaveFilePayloadTypeSaveFileFromSourceURLPayload, + Value: &saveFileFromSourceURLPayload, + }) + } + + var saveCustomFilePayload SaveCustomFilePayload = SaveCustomFilePayload{} + if err := utils.UnmarshalJSON(data, &saveCustomFilePayload, "", true, nil); err == nil { + candidates = append(candidates, utils.UnionCandidate{ + Type: SaveFilePayloadTypeSaveCustomFilePayload, + Value: &saveCustomFilePayload, + }) + } + + if len(candidates) == 0 { + return fmt.Errorf("could not unmarshal `%s` into any supported union types for SaveFilePayload", string(data)) + } + + // Pick the best candidate using multi-stage filtering + best := utils.PickBestCandidate(candidates) + if best == nil { + return fmt.Errorf("could not unmarshal `%s` into any supported union types for SaveFilePayload", string(data)) + } + + // Set the union type and value based on the best candidate + u.Type = best.Type.(SaveFilePayloadType) + switch best.Type { + case SaveFilePayloadTypeSaveS3FilePayload: + u.SaveS3FilePayload = best.Value.(*SaveS3FilePayload) + return nil + case SaveFilePayloadTypeSaveFileFromSourceURLPayload: + u.SaveFileFromSourceURLPayload = best.Value.(*SaveFileFromSourceURLPayload) + return nil + case SaveFilePayloadTypeSaveCustomFilePayload: + u.SaveCustomFilePayload = best.Value.(*SaveCustomFilePayload) return nil } diff --git a/internal/sdk/models/shared/savefilepayloadv2.go b/internal/sdk/models/shared/savefilepayloadv2.go index 08527a9..346cbb3 100644 --- a/internal/sdk/models/shared/savefilepayloadv2.go +++ b/internal/sdk/models/shared/savefilepayloadv2.go @@ -3,165 +3,122 @@ package shared import ( - "encoding/json" + "errors" "fmt" "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/internal/utils" ) -type SaveFilePayloadV2AccessControl string +type SaveFilePayloadV2Type string const ( - SaveFilePayloadV2AccessControlPrivate SaveFilePayloadV2AccessControl = "private" - SaveFilePayloadV2AccessControlPublicRead SaveFilePayloadV2AccessControl = "public-read" + SaveFilePayloadV2TypeSaveS3FilePayload SaveFilePayloadV2Type = "SaveS3FilePayload" + SaveFilePayloadV2TypeSaveFileFromSourceURLPayload SaveFilePayloadV2Type = "SaveFileFromSourceURLPayload" + SaveFilePayloadV2TypeSaveCustomFilePayload SaveFilePayloadV2Type = "SaveCustomFilePayload" ) -func (e SaveFilePayloadV2AccessControl) ToPointer() *SaveFilePayloadV2AccessControl { - return &e -} -func (e *SaveFilePayloadV2AccessControl) UnmarshalJSON(data []byte) error { - var v string - if err := json.Unmarshal(data, &v); err != nil { - return err - } - switch v { - case "private": - fallthrough - case "public-read": - *e = SaveFilePayloadV2AccessControl(v) - return nil - default: - return fmt.Errorf("invalid value for SaveFilePayloadV2AccessControl: %v", v) - } -} - type SaveFilePayloadV2 struct { - // Additional fields that are not part of the schema - Additional map[string]any `json:"__additional,omitempty"` - // Access control list (ACL) for an entity. Defines sharing access to external orgs or users. - ACL *BaseEntityACL `json:"_acl,omitempty"` - ID *string `json:"_id,omitempty"` - // Manifest ID used to create/update the entity - Manifest []string `json:"_manifest,omitempty"` - Purpose []string `json:"_purpose,omitempty"` - Tags []string `json:"_tags,omitempty"` - Title *string `json:"_title,omitempty"` - AccessControl *SaveFilePayloadV2AccessControl `default:"private" json:"access_control"` - // Custom external download url used for the file - CustomDownloadURL *string `json:"custom_download_url,omitempty"` - Filename *string `json:"filename,omitempty"` - // MIME type of the file - MimeType *string `json:"mime_type,omitempty"` - S3ref *S3Ref `json:"s3ref,omitempty"` - // Source URL for the file. Included if the entity was created from source_url, or when ?source_url=true - SourceURL *string `json:"source_url,omitempty"` - Type *FileType `json:"type,omitempty"` -} + SaveS3FilePayload *SaveS3FilePayload `queryParam:"inline,name=SaveFilePayloadV2"` + SaveFileFromSourceURLPayload *SaveFileFromSourceURLPayload `queryParam:"inline,name=SaveFilePayloadV2"` + SaveCustomFilePayload *SaveCustomFilePayload `queryParam:"inline,name=SaveFilePayloadV2"` -func (s SaveFilePayloadV2) MarshalJSON() ([]byte, error) { - return utils.MarshalJSON(s, "", false) + Type SaveFilePayloadV2Type } -func (s *SaveFilePayloadV2) UnmarshalJSON(data []byte) error { - if err := utils.UnmarshalJSON(data, &s, "", false, false); err != nil { - return err - } - return nil -} +func CreateSaveFilePayloadV2SaveS3FilePayload(saveS3FilePayload SaveS3FilePayload) SaveFilePayloadV2 { + typ := SaveFilePayloadV2TypeSaveS3FilePayload -func (o *SaveFilePayloadV2) GetAdditional() map[string]any { - if o == nil { - return nil + return SaveFilePayloadV2{ + SaveS3FilePayload: &saveS3FilePayload, + Type: typ, } - return o.Additional } -func (o *SaveFilePayloadV2) GetACL() *BaseEntityACL { - if o == nil { - return nil - } - return o.ACL -} +func CreateSaveFilePayloadV2SaveFileFromSourceURLPayload(saveFileFromSourceURLPayload SaveFileFromSourceURLPayload) SaveFilePayloadV2 { + typ := SaveFilePayloadV2TypeSaveFileFromSourceURLPayload -func (o *SaveFilePayloadV2) GetID() *string { - if o == nil { - return nil + return SaveFilePayloadV2{ + SaveFileFromSourceURLPayload: &saveFileFromSourceURLPayload, + Type: typ, } - return o.ID } -func (o *SaveFilePayloadV2) GetManifest() []string { - if o == nil { - return nil - } - return o.Manifest -} +func CreateSaveFilePayloadV2SaveCustomFilePayload(saveCustomFilePayload SaveCustomFilePayload) SaveFilePayloadV2 { + typ := SaveFilePayloadV2TypeSaveCustomFilePayload -func (o *SaveFilePayloadV2) GetPurpose() []string { - if o == nil { - return nil + return SaveFilePayloadV2{ + SaveCustomFilePayload: &saveCustomFilePayload, + Type: typ, } - return o.Purpose } -func (o *SaveFilePayloadV2) GetTags() []string { - if o == nil { - return nil +func (u *SaveFilePayloadV2) UnmarshalJSON(data []byte) error { + + var candidates []utils.UnionCandidate + + // Collect all valid candidates + var saveS3FilePayload SaveS3FilePayload = SaveS3FilePayload{} + if err := utils.UnmarshalJSON(data, &saveS3FilePayload, "", true, nil); err == nil { + candidates = append(candidates, utils.UnionCandidate{ + Type: SaveFilePayloadV2TypeSaveS3FilePayload, + Value: &saveS3FilePayload, + }) } - return o.Tags -} -func (o *SaveFilePayloadV2) GetTitle() *string { - if o == nil { - return nil + var saveFileFromSourceURLPayload SaveFileFromSourceURLPayload = SaveFileFromSourceURLPayload{} + if err := utils.UnmarshalJSON(data, &saveFileFromSourceURLPayload, "", true, nil); err == nil { + candidates = append(candidates, utils.UnionCandidate{ + Type: SaveFilePayloadV2TypeSaveFileFromSourceURLPayload, + Value: &saveFileFromSourceURLPayload, + }) } - return o.Title -} -func (o *SaveFilePayloadV2) GetAccessControl() *SaveFilePayloadV2AccessControl { - if o == nil { - return nil + var saveCustomFilePayload SaveCustomFilePayload = SaveCustomFilePayload{} + if err := utils.UnmarshalJSON(data, &saveCustomFilePayload, "", true, nil); err == nil { + candidates = append(candidates, utils.UnionCandidate{ + Type: SaveFilePayloadV2TypeSaveCustomFilePayload, + Value: &saveCustomFilePayload, + }) } - return o.AccessControl -} -func (o *SaveFilePayloadV2) GetCustomDownloadURL() *string { - if o == nil { - return nil + if len(candidates) == 0 { + return fmt.Errorf("could not unmarshal `%s` into any supported union types for SaveFilePayloadV2", string(data)) } - return o.CustomDownloadURL -} -func (o *SaveFilePayloadV2) GetFilename() *string { - if o == nil { - return nil + // Pick the best candidate using multi-stage filtering + best := utils.PickBestCandidate(candidates) + if best == nil { + return fmt.Errorf("could not unmarshal `%s` into any supported union types for SaveFilePayloadV2", string(data)) } - return o.Filename -} -func (o *SaveFilePayloadV2) GetMimeType() *string { - if o == nil { + // Set the union type and value based on the best candidate + u.Type = best.Type.(SaveFilePayloadV2Type) + switch best.Type { + case SaveFilePayloadV2TypeSaveS3FilePayload: + u.SaveS3FilePayload = best.Value.(*SaveS3FilePayload) + return nil + case SaveFilePayloadV2TypeSaveFileFromSourceURLPayload: + u.SaveFileFromSourceURLPayload = best.Value.(*SaveFileFromSourceURLPayload) + return nil + case SaveFilePayloadV2TypeSaveCustomFilePayload: + u.SaveCustomFilePayload = best.Value.(*SaveCustomFilePayload) return nil } - return o.MimeType + + return fmt.Errorf("could not unmarshal `%s` into any supported union types for SaveFilePayloadV2", string(data)) } -func (o *SaveFilePayloadV2) GetS3ref() *S3Ref { - if o == nil { - return nil +func (u SaveFilePayloadV2) MarshalJSON() ([]byte, error) { + if u.SaveS3FilePayload != nil { + return utils.MarshalJSON(u.SaveS3FilePayload, "", true) } - return o.S3ref -} -func (o *SaveFilePayloadV2) GetSourceURL() *string { - if o == nil { - return nil + if u.SaveFileFromSourceURLPayload != nil { + return utils.MarshalJSON(u.SaveFileFromSourceURLPayload, "", true) } - return o.SourceURL -} -func (o *SaveFilePayloadV2) GetType() *FileType { - if o == nil { - return nil + if u.SaveCustomFilePayload != nil { + return utils.MarshalJSON(u.SaveCustomFilePayload, "", true) } - return o.Type + + return nil, errors.New("could not marshal union type SaveFilePayloadV2: all fields are null") } diff --git a/internal/sdk/models/shared/saves3filepayload.go b/internal/sdk/models/shared/saves3filepayload.go index b0a7373..833e4b2 100644 --- a/internal/sdk/models/shared/saves3filepayload.go +++ b/internal/sdk/models/shared/saves3filepayload.go @@ -46,7 +46,7 @@ type SaveS3FilePayload struct { CustomDownloadURL *string `json:"custom_download_url,omitempty"` // Deprecated, use _id instead // - // Deprecated field: This will be removed in a future release, please migrate away from it as soon as possible. + // Deprecated: This will be removed in a future release, please migrate away from it as soon as possible. FileEntityID *string `json:"file_entity_id,omitempty"` Filename *string `json:"filename,omitempty"` // MIME type of the file @@ -62,99 +62,99 @@ func (s SaveS3FilePayload) MarshalJSON() ([]byte, error) { } func (s *SaveS3FilePayload) UnmarshalJSON(data []byte) error { - if err := utils.UnmarshalJSON(data, &s, "", false, true); err != nil { + if err := utils.UnmarshalJSON(data, &s, "", false, nil); err != nil { return err } return nil } -func (o *SaveS3FilePayload) GetAdditionalProperties() any { - if o == nil { +func (s *SaveS3FilePayload) GetAdditionalProperties() any { + if s == nil { return nil } - return o.AdditionalProperties + return s.AdditionalProperties } -func (o *SaveS3FilePayload) GetID() *string { - if o == nil { +func (s *SaveS3FilePayload) GetID() *string { + if s == nil { return nil } - return o.ID + return s.ID } -func (o *SaveS3FilePayload) GetManifest() []string { - if o == nil { +func (s *SaveS3FilePayload) GetManifest() []string { + if s == nil { return nil } - return o.Manifest + return s.Manifest } -func (o *SaveS3FilePayload) GetPurpose() []string { - if o == nil { +func (s *SaveS3FilePayload) GetPurpose() []string { + if s == nil { return nil } - return o.Purpose + return s.Purpose } -func (o *SaveS3FilePayload) GetTags() []string { - if o == nil { +func (s *SaveS3FilePayload) GetTags() []string { + if s == nil { return nil } - return o.Tags + return s.Tags } -func (o *SaveS3FilePayload) GetAccessControl() *SaveS3FilePayloadAccessControl { - if o == nil { +func (s *SaveS3FilePayload) GetAccessControl() *SaveS3FilePayloadAccessControl { + if s == nil { return nil } - return o.AccessControl + return s.AccessControl } -func (o *SaveS3FilePayload) GetCustomDownloadURL() *string { - if o == nil { +func (s *SaveS3FilePayload) GetCustomDownloadURL() *string { + if s == nil { return nil } - return o.CustomDownloadURL + return s.CustomDownloadURL } -func (o *SaveS3FilePayload) GetFileEntityID() *string { - if o == nil { +func (s *SaveS3FilePayload) GetFileEntityID() *string { + if s == nil { return nil } - return o.FileEntityID + return s.FileEntityID } -func (o *SaveS3FilePayload) GetFilename() *string { - if o == nil { +func (s *SaveS3FilePayload) GetFilename() *string { + if s == nil { return nil } - return o.Filename + return s.Filename } -func (o *SaveS3FilePayload) GetMimeType() *string { - if o == nil { +func (s *SaveS3FilePayload) GetMimeType() *string { + if s == nil { return nil } - return o.MimeType + return s.MimeType } -func (o *SaveS3FilePayload) GetRelations() []FileRelationItem { - if o == nil { +func (s *SaveS3FilePayload) GetRelations() []FileRelationItem { + if s == nil { return nil } - return o.Relations + return s.Relations } -func (o *SaveS3FilePayload) GetS3ref() *S3Ref { - if o == nil { +func (s *SaveS3FilePayload) GetS3ref() *S3Ref { + if s == nil { return nil } - return o.S3ref + return s.S3ref } -func (o *SaveS3FilePayload) GetType() *FileType { - if o == nil { +func (s *SaveS3FilePayload) GetType() *FileType { + if s == nil { return nil } - return o.Type + return s.Type } diff --git a/internal/sdk/models/shared/security.go b/internal/sdk/models/shared/security.go index 5ea979f..fbb7744 100644 --- a/internal/sdk/models/shared/security.go +++ b/internal/sdk/models/shared/security.go @@ -7,16 +7,16 @@ type Security struct { EpilotAuth *string `security:"scheme,type=http,subtype=bearer,name=Authorization"` } -func (o *Security) GetCookieAuth() *string { - if o == nil { +func (s *Security) GetCookieAuth() *string { + if s == nil { return nil } - return o.CookieAuth + return s.CookieAuth } -func (o *Security) GetEpilotAuth() *string { - if o == nil { +func (s *Security) GetEpilotAuth() *string { + if s == nil { return nil } - return o.EpilotAuth + return s.EpilotAuth } diff --git a/internal/sdk/models/shared/uploadfilepayload.go b/internal/sdk/models/shared/uploadfilepayload.go index c79c9e4..532613e 100644 --- a/internal/sdk/models/shared/uploadfilepayload.go +++ b/internal/sdk/models/shared/uploadfilepayload.go @@ -21,36 +21,36 @@ func (u UploadFilePayload) MarshalJSON() ([]byte, error) { } func (u *UploadFilePayload) UnmarshalJSON(data []byte) error { - if err := utils.UnmarshalJSON(data, &u, "", false, false); err != nil { + if err := utils.UnmarshalJSON(data, &u, "", false, []string{"filename"}); err != nil { return err } return nil } -func (o *UploadFilePayload) GetFilename() string { - if o == nil { +func (u *UploadFilePayload) GetFilename() string { + if u == nil { return "" } - return o.Filename + return u.Filename } -func (o *UploadFilePayload) GetIndexTag() *string { - if o == nil { +func (u *UploadFilePayload) GetIndexTag() *string { + if u == nil { return nil } - return o.IndexTag + return u.IndexTag } -func (o *UploadFilePayload) GetMetadata() map[string]string { - if o == nil { +func (u *UploadFilePayload) GetMetadata() map[string]string { + if u == nil { return nil } - return o.Metadata + return u.Metadata } -func (o *UploadFilePayload) GetMimeType() *string { - if o == nil { +func (u *UploadFilePayload) GetMimeType() *string { + if u == nil { return nil } - return o.MimeType + return u.MimeType } diff --git a/internal/sdk/models/shared/verifycustomdownloadurlpayload.go b/internal/sdk/models/shared/verifycustomdownloadurlpayload.go index d714173..8810b70 100644 --- a/internal/sdk/models/shared/verifycustomdownloadurlpayload.go +++ b/internal/sdk/models/shared/verifycustomdownloadurlpayload.go @@ -7,9 +7,9 @@ type VerifyCustomDownloadURLPayload struct { CustomDownloadURL string `json:"custom_download_url"` } -func (o *VerifyCustomDownloadURLPayload) GetCustomDownloadURL() string { - if o == nil { +func (v *VerifyCustomDownloadURLPayload) GetCustomDownloadURL() string { + if v == nil { return "" } - return o.CustomDownloadURL + return v.CustomDownloadURL } diff --git a/internal/sdk/optionalnullable/optionalnullable.go b/internal/sdk/optionalnullable/optionalnullable.go new file mode 100644 index 0000000..c6739be --- /dev/null +++ b/internal/sdk/optionalnullable/optionalnullable.go @@ -0,0 +1,233 @@ +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + +package optionalnullable + +import ( + "bytes" + "encoding/json" + "reflect" +) + +// OptionalNullable represents a field that can distinguish between three states: +// 1. Set to a value: field is present with a non-nil value +// 2. Set to nil: field is present but explicitly set to null in JSON +// 3. Unset: field is omitted from JSON entirely +// +// This type is designed to work with JSON marshaling/unmarshaling and supports +// the `omitempty` struct tag to properly omit unset fields from JSON output. +// +// Usage: +// +// type User struct { +// Name OptionalNullable[string] `json:"name,omitempty"` +// Age OptionalNullable[int] `json:"age,omitempty"` +// Tags OptionalNullable[[]string] `json:"tags,omitempty"` +// } +// +// // Set to value +// name := "John" +// user.Name = From(&name) +// +// // Set to nil (will appear as "name": null in JSON) +// user.Name = From[string](nil) +// +// // Leave unset (will be omitted from JSON with omitempty) +// user := User{} +// +// WARNING: Do NOT use *OptionalNullable[T] as a field type. Always use OptionalNullable[T] directly. +// Using *OptionalNullable[T] will break the omitempty behavior and JSON marshaling. +// +// The type is implemented as a map[bool]*T where: +// - nil map represents unset state +// - Map with true key represents set state (value may be nil) +type OptionalNullable[T any] map[bool]*T + +// From creates a new OptionalNullable with the given value. +// Pass nil to create a OptionalNullable that is set to null. +// Pass a pointer to a value to create a OptionalNullable with that value. +// +// Examples: +// +// hello := "hello" +// From(&hello) // set to "hello" +// From[string](nil) // set to null +func From[T any](value *T) OptionalNullable[T] { + return map[bool]*T{ + true: value, + } +} + +// IsNull returns true if the OptionalNullable is explicitly set to nil. +// Returns false if the OptionalNullable is unset or has a value. +// +// Note: This differs from traditional null checks because unset fields +// return false, not true. Use IsSet() to check if a field was provided. +func (n OptionalNullable[T]) IsNull() bool { + v, ok := n[true] + return ok && v == nil +} + +// IsSet returns true if the OptionalNullable has been explicitly set (to either a value or nil). +// Returns false if the OptionalNullable is unset (omitted from JSON). +// +// This is the key method for distinguishing between: +// - Set to nil: IsSet() = true, IsNull() = true +// - Unset: IsSet() = false, IsNull() = false +func (n OptionalNullable[T]) IsSet() bool { + _, ok := n[true] + return ok +} + +// Get returns the internal pointer and whether the field was set. +// +// Return values: +// - (ptr, true): field was set (ptr may be nil if set to null) +// - (nil, false): field was unset/omitted +// +// This method provides direct access to the internal pointer representation. +func (n OptionalNullable[T]) Get() (*T, bool) { + v, ok := n[true] + return v, ok +} + +// GetOrZero returns the value and whether it was set. +// +// Return values: +// - (value, true): field was set to a non-nil value +// - (zero, true): field was explicitly set to nil +// - (zero, false): field was unset/omitted +// +// Examples: +// +// val, ok := nullable.GetOrZero() +// if !ok { +// // Field was unset/omitted +// } else if nullable.IsNull() { +// // Field was explicitly set to null +// } else { +// // Field has a value: val +// } +func (n OptionalNullable[T]) GetOrZero() (T, bool) { + var zero T + + if v, ok := n[true]; ok { + if v == nil { + return zero, true + } + return *v, true + } + return zero, false +} + +// GetUntyped returns the value as interface{} and whether it was set. +// This is useful for reflection-based code that needs to work with the value +// without knowing the specific type T. +// +// Return values: +// - (value, true): field was set to a non-nil value +// - (nil, true): field was explicitly set to nil +// - (nil, false): field was unset/omitted +func (n OptionalNullable[T]) GetUntyped() (interface{}, bool) { + if v, ok := n[true]; ok { + if v == nil { + return nil, true + } + return *v, true + } + return nil, false +} + +// Set sets the OptionalNullable to the given value pointer. +// Pass nil to set the field to null. +// Pass a pointer to a value to set the field to that value. +// +// Examples: +// +// nullable.Set(ptrFrom("hello")) // set to "hello" +// nullable.Set(nil) // set to null +func (n *OptionalNullable[T]) Set(value *T) { + *n = map[bool]*T{ + true: value, + } +} + +// Unset removes the value, making the field unset/omitted. +// After calling Unset(), IsSet() will return false and the field +// will be omitted from JSON output when using omitempty. +func (n *OptionalNullable[T]) Unset() { + *n = map[bool]*T{} +} + +// MarshalJSON implements json.Marshaler. +// +// Behavior: +// - Unset fields: omitted from JSON when struct field has omitempty tag +// - Null fields: serialized as "null" +// - Value fields: serialized as the actual value +// +// The omitempty behavior works because an empty map is considered +// a zero value by Go's JSON package. +func (n OptionalNullable[T]) MarshalJSON() ([]byte, error) { + if n.IsNull() { + return []byte("null"), nil + } + + return json.Marshal(n[true]) +} + +// UnmarshalJSON implements json.Unmarshaler. +// +// Behavior: +// - "null" in JSON: sets the field to null (IsSet=true, IsNull=true) +// - Any other value: sets the field to that value (IsSet=true, IsNull=false) +// - Missing from JSON: field remains unset (IsSet=false, IsNull=false) +func (n *OptionalNullable[T]) UnmarshalJSON(data []byte) error { + if bytes.Equal(data, []byte("null")) { + n.Set(nil) + return nil + } + var v T + if err := json.Unmarshal(data, &v); err != nil { + return err + } + n.Set(&v) + return nil +} + +// NullableInterface defines the interface that all OptionalNullable[T] types implement. +// This interface provides untyped access to optional nullable values for reflection-based code. +type OptionalNullableInterface interface { + GetUntyped() (interface{}, bool) +} + +// AsOptionalNullable attempts to convert a reflect.Value to a OptionalNullableInterface. +// This is a helper function for reflection-based code that needs to check +// if a value implements the optional nullable interface pattern. +// +// Returns: +// - (nullable, true): if the value implements OptionalNullableInterface +// - (nil, false): if the value does not implement OptionalNullableInterface +// +// Example usage: +// +// if nullable, ok := AsOptionalNullable(reflectValue); ok { +// if value, isSet := nullable.GetUntyped(); isSet { +// // Handle the nullable value +// } +// } +func AsOptionalNullable(v reflect.Value) (OptionalNullableInterface, bool) { + // Check if the value can be converted to an interface first + if !v.CanInterface() { + return nil, false + } + + // Check if the underlying value is a nil map (unset nullable) + if v.Kind() == reflect.Map && v.IsNil() { + return nil, false + } + + if nullable, ok := v.Interface().(OptionalNullableInterface); ok { + return nullable, true + } + return nil, false +} diff --git a/internal/sdk/optionalnullable/optionalnullable_test.go b/internal/sdk/optionalnullable/optionalnullable_test.go new file mode 100644 index 0000000..e6e5a01 --- /dev/null +++ b/internal/sdk/optionalnullable/optionalnullable_test.go @@ -0,0 +1,1806 @@ +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + +package optionalnullable + +import ( + "encoding/json" + "reflect" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +// Test helper function to create pointers from values +func ptrFrom[T any](value T) *T { + return &value +} + +// Test helper types for comprehensive testing +type TestStruct struct { + Name string `json:"name"` + Age int `json:"age"` +} + +type TestContainer struct { + StringField OptionalNullable[string] `json:"string_field,omitempty"` + IntField OptionalNullable[int] `json:"int_field,omitempty"` + SliceField OptionalNullable[[]string] `json:"slice_field,omitempty"` + StructField OptionalNullable[TestStruct] `json:"struct_field,omitempty"` +} + +// TestNewNullable tests the From constructor +func TestNewNullable(t *testing.T) { + t.Parallel() + t.Run("with string value", func(t *testing.T) { + t.Parallel() + nullable := From(ptrFrom("test")) + + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, "test", got) + }) + + t.Run("with nil pointer", func(t *testing.T) { + t.Parallel() + nullable := From[string](nil) + + assert.True(t, nullable.IsSet()) + assert.True(t, nullable.IsNull()) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, "", got) // zero value for string + }) + + t.Run("with int value", func(t *testing.T) { + t.Parallel() + nullable := From(ptrFrom(42)) + + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, 42, got) + }) + + t.Run("with slice value", func(t *testing.T) { + t.Parallel() + nullable := From(ptrFrom([]string{"a", "b", "c"})) + + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, []string{"a", "b", "c"}, got) + }) + + t.Run("with empty slice", func(t *testing.T) { + t.Parallel() + nullable := From(ptrFrom([]string{})) + + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, []string{}, got) + }) + + t.Run("with struct value", func(t *testing.T) { + t.Parallel() + val := TestStruct{Name: "John", Age: 30} + nullable := From(&val) + + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + v, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, val, v) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, TestStruct{Name: "John", Age: 30}, got) + }) +} + +// TestNewNullableUnset tests the NewNullableUnset constructor +func TestNewNullableUnset(t *testing.T) { + t.Parallel() + t.Run("string type", func(t *testing.T) { + t.Parallel() + var nullable OptionalNullable[string] + + assert.False(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) // Unset is not null + + got, ok := nullable.GetOrZero() + assert.False(t, ok) + assert.Equal(t, "", got) // zero value for string + }) + + t.Run("int type", func(t *testing.T) { + t.Parallel() + var nullable OptionalNullable[int] + + assert.False(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) // Unset is not null + + got, ok := nullable.GetOrZero() + assert.False(t, ok) + assert.Equal(t, 0, got) // zero value for int + }) + + t.Run("slice type", func(t *testing.T) { + t.Parallel() + var nullable OptionalNullable[[]string] + + assert.False(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) // Unset is not null + + got, ok := nullable.GetOrZero() + assert.False(t, ok) + assert.Nil(t, got) // zero value for slice is nil + }) +} + +// TestIsNull tests the IsNull method +func TestIsNull(t *testing.T) { + t.Parallel() + t.Run("with value", func(t *testing.T) { + t.Parallel() + nullable := From(ptrFrom("test")) + assert.False(t, nullable.IsNull()) + }) + + t.Run("with nil pointer", func(t *testing.T) { + t.Parallel() + nullable := From[string](nil) + assert.True(t, nullable.IsNull()) + }) + + t.Run("unset", func(t *testing.T) { + t.Parallel() + var nullable OptionalNullable[string] + assert.False(t, nullable.IsNull()) + }) +} + +// TestIsSet tests the IsSet method +func TestIsSet(t *testing.T) { + t.Parallel() + t.Run("with value", func(t *testing.T) { + t.Parallel() + nullable := From(ptrFrom("test")) + assert.True(t, nullable.IsSet()) + }) + + t.Run("with nil pointer", func(t *testing.T) { + t.Parallel() + nullable := From[string](nil) + assert.True(t, nullable.IsSet()) + }) + + t.Run("unset", func(t *testing.T) { + t.Parallel() + var nullable OptionalNullable[string] + assert.False(t, nullable.IsSet()) + }) +} + +// TestGet tests the Get method +func TestGet(t *testing.T) { + t.Parallel() + t.Run("with string value", func(t *testing.T) { + t.Parallel() + nullable := From(ptrFrom("test")) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, "test", got) + }) + + t.Run("with nil pointer", func(t *testing.T) { + t.Parallel() + nullable := From[string](nil) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, "", got) // zero value + }) + + t.Run("unset", func(t *testing.T) { + t.Parallel() + var nullable OptionalNullable[string] + + got, ok := nullable.GetOrZero() + assert.False(t, ok) + assert.Equal(t, "", got) // zero value + }) + + t.Run("with slice value", func(t *testing.T) { + t.Parallel() + nullable := From(ptrFrom([]string{"a", "b"})) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, []string{"a", "b"}, got) + }) + + t.Run("with nil slice pointer", func(t *testing.T) { + t.Parallel() + nullable := From[[]string](nil) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Nil(t, got) // zero value for slice is nil + }) +} + +// TestPointer tests the Pointer method +func TestPointer(t *testing.T) { + t.Parallel() + t.Run("with value", func(t *testing.T) { + t.Parallel() + nullable := From(ptrFrom("test")) + + ptr, ok := nullable.Get() + assert.True(t, ok) + assert.NotNil(t, ptr) + assert.Equal(t, "test", *ptr) + }) + + t.Run("with nil pointer", func(t *testing.T) { + t.Parallel() + nullable := From[string](nil) + + ptr, ok := nullable.Get() + assert.True(t, ok) + assert.Nil(t, ptr) + }) + + t.Run("unset", func(t *testing.T) { + t.Parallel() + var nullable OptionalNullable[string] + + ptr, ok := nullable.Get() + assert.False(t, ok) + assert.Nil(t, ptr) + }) +} + +// TestSet tests the Set method +func TestSet(t *testing.T) { + t.Parallel() + t.Run("set string value", func(t *testing.T) { + t.Parallel() + var nullable OptionalNullable[string] + + // Initially unset + assert.False(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) // Unset is not null + + // Set a value + nullable.Set(ptrFrom("test")) + + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, "test", got) + }) + + t.Run("set int value", func(t *testing.T) { + t.Parallel() + nullable := OptionalNullable[int]{} + + nullable.Set(ptrFrom(42)) + + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, 42, got) + }) + + t.Run("set slice value", func(t *testing.T) { + t.Parallel() + nullable := OptionalNullable[[]string]{} + + slice := []string{"a", "b"} + nullable.Set(ptrFrom(slice)) + + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, []string{"a", "b"}, got) + }) + + t.Run("set empty slice", func(t *testing.T) { + t.Parallel() + nullable := OptionalNullable[[]string]{} + + slice := []string{} + nullable.Set(ptrFrom(slice)) + + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, []string{}, got) + }) + + t.Run("overwrite existing value", func(t *testing.T) { + t.Parallel() + nullable := From(ptrFrom("original")) + + // Verify original value + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, "original", got) + + // Set new value + nullable.Set(ptrFrom("new")) + + got, ok = nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, "new", got) + }) +} + +// TestUnset tests the Unset method +func TestUnset(t *testing.T) { + t.Parallel() + t.Run("unset from value", func(t *testing.T) { + t.Parallel() + nullable := From(ptrFrom("test")) + + // Initially set + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + + // Unset + nullable.Unset() + + assert.False(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) // After unset is not null + // Value is now internal to the map implementation + + got, ok := nullable.GetOrZero() + assert.False(t, ok) + assert.Equal(t, "", got) // zero value + }) + + t.Run("unset from nil", func(t *testing.T) { + t.Parallel() + nullable := From[string](nil) + + // Initially set to nil + assert.True(t, nullable.IsSet()) + assert.True(t, nullable.IsNull()) // Set to nil should be null + + // Unset + nullable.Unset() + + assert.False(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) // After unset is not null + }) + + t.Run("unset already unset", func(t *testing.T) { + t.Parallel() + var nullable OptionalNullable[string] + + // Initially unset + assert.False(t, nullable.IsSet()) + + // Unset again + nullable.Unset() + + assert.False(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) // Empty map is not null + }) +} + +// TestMarshalJSON tests JSON marshaling +func TestMarshalJSON(t *testing.T) { + t.Parallel() + t.Run("marshal string value", func(t *testing.T) { + t.Parallel() + nullable := From(ptrFrom("test")) + + data, err := json.Marshal(nullable) + require.NoError(t, err) + assert.Equal(t, `"test"`, string(data)) + }) + + t.Run("marshal int value", func(t *testing.T) { + t.Parallel() + nullable := From(ptrFrom(42)) + + data, err := json.Marshal(nullable) + require.NoError(t, err) + assert.Equal(t, `42`, string(data)) + }) + + t.Run("marshal nil value", func(t *testing.T) { + t.Parallel() + nullable := From[string](nil) + + data, err := json.Marshal(nullable) + require.NoError(t, err) + assert.Equal(t, `null`, string(data)) + }) + + t.Run("marshal slice value", func(t *testing.T) { + t.Parallel() + nullable := From(ptrFrom([]string{"a", "b", "c"})) + + data, err := json.Marshal(nullable) + require.NoError(t, err) + assert.Equal(t, `["a","b","c"]`, string(data)) + }) + + t.Run("marshal empty slice", func(t *testing.T) { + t.Parallel() + nullable := From(ptrFrom([]string{})) + + data, err := json.Marshal(nullable) + require.NoError(t, err) + assert.Equal(t, `[]`, string(data)) + }) + + t.Run("marshal struct value", func(t *testing.T) { + t.Parallel() + nullable := From(ptrFrom(TestStruct{Name: "John", Age: 30})) + + data, err := json.Marshal(nullable) + require.NoError(t, err) + assert.Equal(t, `{"name":"John","age":30}`, string(data)) + }) + + // Note: Unset values are not tested here because the current implementation + // doesn't handle unset fields in marshaling (see TODO in the code) +} + +// TestUnmarshalJSON tests JSON unmarshaling +func TestUnmarshalJSON(t *testing.T) { + t.Parallel() + t.Run("unmarshal string value", func(t *testing.T) { + t.Parallel() + var nullable OptionalNullable[string] + err := json.Unmarshal([]byte(`"test"`), &nullable) + require.NoError(t, err) + + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, "test", got) + }) + + t.Run("unmarshal int value", func(t *testing.T) { + t.Parallel() + var nullable OptionalNullable[int] + err := json.Unmarshal([]byte(`42`), &nullable) + require.NoError(t, err) + + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, 42, got) + }) + + t.Run("unmarshal null value", func(t *testing.T) { + t.Parallel() + var nullable OptionalNullable[string] + err := json.Unmarshal([]byte(`null`), &nullable) + require.NoError(t, err) + + assert.True(t, nullable.IsSet()) + assert.True(t, nullable.IsNull()) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, "", got) // zero value + }) + + t.Run("unmarshal slice value", func(t *testing.T) { + t.Parallel() + var nullable OptionalNullable[[]string] + err := json.Unmarshal([]byte(`["a","b","c"]`), &nullable) + require.NoError(t, err) + + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, []string{"a", "b", "c"}, got) + }) + + t.Run("unmarshal empty slice", func(t *testing.T) { + t.Parallel() + var nullable OptionalNullable[[]string] + err := json.Unmarshal([]byte(`[]`), &nullable) + require.NoError(t, err) + + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, []string{}, got) + }) + + t.Run("unmarshal struct value", func(t *testing.T) { + t.Parallel() + var nullable OptionalNullable[TestStruct] + err := json.Unmarshal([]byte(`{"name":"John","age":30}`), &nullable) + require.NoError(t, err) + + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, TestStruct{Name: "John", Age: 30}, got) + }) + + t.Run("unmarshal invalid JSON", func(t *testing.T) { + t.Parallel() + var nullable OptionalNullable[string] + err := json.Unmarshal([]byte(`invalid`), &nullable) + assert.Error(t, err) + + // Ensure the nullable remains unset after error + assert.False(t, nullable.IsSet()) + }) + + t.Run("unmarshal invalid JSON for int", func(t *testing.T) { + t.Parallel() + var nullable OptionalNullable[int] + err := json.Unmarshal([]byte(`"not_a_number"`), &nullable) + assert.Error(t, err) + + // Ensure the nullable remains unset after error + assert.False(t, nullable.IsSet()) + }) + + t.Run("unmarshal malformed JSON", func(t *testing.T) { + t.Parallel() + var nullable OptionalNullable[TestStruct] + err := json.Unmarshal([]byte(`{invalid json`), &nullable) + assert.Error(t, err) + + // Ensure the nullable remains unset after error + assert.False(t, nullable.IsSet()) + }) +} + +// TestJSONRoundTrip tests marshaling and unmarshaling together +func TestJSONRoundTrip(t *testing.T) { + t.Parallel() + t.Run("string value round trip", func(t *testing.T) { + t.Parallel() + nullable1 := From(ptrFrom("test value")) + + // Marshal + data, err := json.Marshal(nullable1) + require.NoError(t, err) + + // Unmarshal + var nullable2 OptionalNullable[string] + err = json.Unmarshal(data, &nullable2) + require.NoError(t, err) + + // Compare + assert.Equal(t, nullable1.IsSet(), nullable2.IsSet()) + assert.Equal(t, nullable1.IsNull(), nullable2.IsNull()) + + got1, ok1 := nullable1.GetOrZero() + got2, ok2 := nullable2.GetOrZero() + assert.Equal(t, ok1, ok2) + assert.Equal(t, got1, got2) + }) + + t.Run("nil value round trip", func(t *testing.T) { + t.Parallel() + nullable1 := From[string](nil) + + // Marshal + data, err := json.Marshal(nullable1) + require.NoError(t, err) + + // Unmarshal + var nullable2 OptionalNullable[string] + err = json.Unmarshal(data, &nullable2) + require.NoError(t, err) + + // Compare + assert.Equal(t, nullable1.IsSet(), nullable2.IsSet()) + assert.Equal(t, nullable1.IsNull(), nullable2.IsNull()) + + got1, ok1 := nullable1.GetOrZero() + got2, ok2 := nullable2.GetOrZero() + assert.Equal(t, ok1, ok2) + assert.Equal(t, got1, got2) + }) + + t.Run("slice round trip", func(t *testing.T) { + t.Parallel() + nullable1 := From(ptrFrom([]string{"a", "b", "c"})) + + // Marshal + data, err := json.Marshal(nullable1) + require.NoError(t, err) + + // Unmarshal + var nullable2 OptionalNullable[[]string] + err = json.Unmarshal(data, &nullable2) + require.NoError(t, err) + + // Compare + assert.Equal(t, nullable1.IsSet(), nullable2.IsSet()) + assert.Equal(t, nullable1.IsNull(), nullable2.IsNull()) + + got1, ok1 := nullable1.GetOrZero() + got2, ok2 := nullable2.GetOrZero() + assert.Equal(t, ok1, ok2) + assert.Equal(t, got1, got2) + }) +} + +// TestJSONToJSONRoundTrip tests starting with JSON and ensuring we can serialize back to the same JSON +func TestJSONToJSONRoundTrip(t *testing.T) { + t.Parallel() + t.Run("string value JSON round trip", func(t *testing.T) { + t.Parallel() + originalJSON := `"hello world"` + + // Unmarshal from JSON + var nullable OptionalNullable[string] + err := json.Unmarshal([]byte(originalJSON), &nullable) + require.NoError(t, err) + + // Verify state + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, "hello world", got) + + // Marshal back to JSON + resultJSON, err := json.Marshal(nullable) + require.NoError(t, err) + assert.Equal(t, originalJSON, string(resultJSON)) + }) + + t.Run("null value JSON round trip", func(t *testing.T) { + t.Parallel() + originalJSON := `null` + + // Unmarshal from JSON + var nullable OptionalNullable[string] + err := json.Unmarshal([]byte(originalJSON), &nullable) + require.NoError(t, err) + + // Verify state + assert.True(t, nullable.IsSet()) + assert.True(t, nullable.IsNull()) + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, "", got) // zero value + + // Marshal back to JSON + resultJSON, err := json.Marshal(nullable) + require.NoError(t, err) + assert.Equal(t, originalJSON, string(resultJSON)) + }) + + t.Run("int value JSON round trip", func(t *testing.T) { + t.Parallel() + originalJSON := `42` + + // Unmarshal from JSON + var nullable OptionalNullable[int] + err := json.Unmarshal([]byte(originalJSON), &nullable) + require.NoError(t, err) + + // Verify state + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, 42, got) + + // Marshal back to JSON + resultJSON, err := json.Marshal(nullable) + require.NoError(t, err) + assert.Equal(t, originalJSON, string(resultJSON)) + }) + + t.Run("slice value JSON round trip", func(t *testing.T) { + t.Parallel() + originalJSON := `["a","b","c"]` + + // Unmarshal from JSON + var nullable OptionalNullable[[]string] + err := json.Unmarshal([]byte(originalJSON), &nullable) + require.NoError(t, err) + + // Verify state + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, []string{"a", "b", "c"}, got) + + // Marshal back to JSON + resultJSON, err := json.Marshal(nullable) + require.NoError(t, err) + assert.Equal(t, originalJSON, string(resultJSON)) + }) + + t.Run("empty slice JSON round trip", func(t *testing.T) { + t.Parallel() + originalJSON := `[]` + + // Unmarshal from JSON + var nullable OptionalNullable[[]string] + err := json.Unmarshal([]byte(originalJSON), &nullable) + require.NoError(t, err) + + // Verify state + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, []string{}, got) + + // Marshal back to JSON + resultJSON, err := json.Marshal(nullable) + require.NoError(t, err) + assert.Equal(t, originalJSON, string(resultJSON)) + }) + + t.Run("struct value JSON round trip", func(t *testing.T) { + t.Parallel() + originalJSON := `{"name":"Alice","age":25}` + + // Unmarshal from JSON + var nullable OptionalNullable[TestStruct] + err := json.Unmarshal([]byte(originalJSON), &nullable) + require.NoError(t, err) + + // Verify state + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, TestStruct{Name: "Alice", Age: 25}, got) + + // Marshal back to JSON + resultJSON, err := json.Marshal(nullable) + require.NoError(t, err) + assert.Equal(t, originalJSON, string(resultJSON)) + }) +} + +// TestContainerStates tests comprehensive state detection and serialization with TestContainer +func TestContainerStates(t *testing.T) { + t.Parallel() + t.Run("all fields set to values", func(t *testing.T) { + t.Parallel() + container := TestContainer{ + StringField: From(ptrFrom("hello")), + IntField: From(ptrFrom(42)), + SliceField: From(ptrFrom([]string{"a", "b"})), + StructField: From(ptrFrom(TestStruct{Name: "John", Age: 30})), + } + + // Verify all fields are set and not null + assert.True(t, container.StringField.IsSet()) + assert.False(t, container.StringField.IsNull()) + assert.True(t, container.IntField.IsSet()) + assert.False(t, container.IntField.IsNull()) + assert.True(t, container.SliceField.IsSet()) + assert.False(t, container.SliceField.IsNull()) + assert.True(t, container.StructField.IsSet()) + assert.False(t, container.StructField.IsNull()) + + // Verify values + stringVal, ok := container.StringField.GetOrZero() + assert.True(t, ok) + assert.Equal(t, "hello", stringVal) + + intVal, ok := container.IntField.GetOrZero() + assert.True(t, ok) + assert.Equal(t, 42, intVal) + + sliceVal, ok := container.SliceField.GetOrZero() + assert.True(t, ok) + assert.Equal(t, []string{"a", "b"}, sliceVal) + + structVal, ok := container.StructField.GetOrZero() + assert.True(t, ok) + assert.Equal(t, TestStruct{Name: "John", Age: 30}, structVal) + + // Test JSON serialization + data, err := json.Marshal(container) + require.NoError(t, err) + + var result map[string]interface{} + err = json.Unmarshal(data, &result) + require.NoError(t, err) + + assert.Equal(t, "hello", result["string_field"]) + assert.Equal(t, float64(42), result["int_field"]) // JSON numbers are float64 + assert.Equal(t, []interface{}{"a", "b"}, result["slice_field"]) + structResult := result["struct_field"].(map[string]interface{}) + assert.Equal(t, "John", structResult["name"]) + assert.Equal(t, float64(30), structResult["age"]) + }) + + t.Run("all fields set to nil", func(t *testing.T) { + t.Parallel() + container := TestContainer{ + StringField: From[string](nil), + IntField: From[int](nil), + SliceField: From[[]string](nil), + StructField: From[TestStruct](nil), + } + + // Verify all fields are set but null + assert.True(t, container.StringField.IsSet()) + assert.True(t, container.StringField.IsNull()) + assert.True(t, container.IntField.IsSet()) + assert.True(t, container.IntField.IsNull()) + assert.True(t, container.SliceField.IsSet()) + assert.True(t, container.SliceField.IsNull()) + assert.True(t, container.StructField.IsSet()) + assert.True(t, container.StructField.IsNull()) + + // Verify GetOrZero() behavior for nil values + stringVal, ok := container.StringField.GetOrZero() + assert.True(t, ok) // set to nil still returns true + assert.Equal(t, "", stringVal) // zero value + + intVal, ok := container.IntField.GetOrZero() + assert.True(t, ok) + assert.Equal(t, 0, intVal) // zero value + + sliceVal, ok := container.SliceField.GetOrZero() + assert.True(t, ok) + assert.Nil(t, sliceVal) // zero value for slice is nil + + structVal, ok := container.StructField.GetOrZero() + assert.True(t, ok) + assert.Equal(t, TestStruct{}, structVal) // zero value + + // Test JSON serialization - all should be null + data, err := json.Marshal(container) + require.NoError(t, err) + + var result map[string]interface{} + err = json.Unmarshal(data, &result) + require.NoError(t, err) + + assert.Nil(t, result["string_field"]) + assert.Nil(t, result["int_field"]) + assert.Nil(t, result["slice_field"]) + assert.Nil(t, result["struct_field"]) + }) + + t.Run("all fields unset", func(t *testing.T) { + t.Parallel() + container := TestContainer{} + + // Verify all fields are unset + assert.False(t, container.StringField.IsSet()) + assert.False(t, container.StringField.IsNull()) // unset is not null in new implementation + assert.False(t, container.IntField.IsSet()) + assert.False(t, container.IntField.IsNull()) + assert.False(t, container.SliceField.IsSet()) + assert.False(t, container.SliceField.IsNull()) + assert.False(t, container.StructField.IsSet()) + assert.False(t, container.StructField.IsNull()) + + // Verify GetOrZero() behavior for unset values + stringVal, ok := container.StringField.GetOrZero() + assert.False(t, ok) // unset returns false + assert.Equal(t, "", stringVal) // zero value + + intVal, ok := container.IntField.GetOrZero() + assert.False(t, ok) + assert.Equal(t, 0, intVal) // zero value + + sliceVal, ok := container.SliceField.GetOrZero() + assert.False(t, ok) + assert.Nil(t, sliceVal) // zero value + + structVal, ok := container.StructField.GetOrZero() + assert.False(t, ok) + assert.Equal(t, TestStruct{}, structVal) // zero value + + // Test JSON serialization - unset fields should be omitted due to omitempty + data, err := json.Marshal(container) + require.NoError(t, err) + + var result map[string]interface{} + err = json.Unmarshal(data, &result) + require.NoError(t, err) + + // With omitempty, unset fields should not appear in JSON + assert.NotContains(t, result, "string_field") + assert.NotContains(t, result, "int_field") + assert.NotContains(t, result, "slice_field") + assert.NotContains(t, result, "struct_field") + }) + + t.Run("slice field states: nil vs unset vs empty vs set", func(t *testing.T) { + t.Parallel() + // Test all possible slice states + nilSlice := TestContainer{ + SliceField: From[[]string](nil), // explicitly set to nil + } + unsetSlice := TestContainer{} // unset + emptySlice := TestContainer{ + SliceField: From(ptrFrom([]string{})), // empty slice + } + setSlice := TestContainer{ + SliceField: From(ptrFrom([]string{"a", "b"})), // slice with values + } + + // Verify nil slice + assert.True(t, nilSlice.SliceField.IsSet()) + assert.True(t, nilSlice.SliceField.IsNull()) + val, ok := nilSlice.SliceField.GetOrZero() + assert.True(t, ok) + assert.Nil(t, val) + + // Verify unset slice + assert.False(t, unsetSlice.SliceField.IsSet()) + assert.False(t, unsetSlice.SliceField.IsNull()) // Unset is not null + val, ok = unsetSlice.SliceField.GetOrZero() + assert.False(t, ok) + assert.Nil(t, val) + + // Verify empty slice + assert.True(t, emptySlice.SliceField.IsSet()) + assert.False(t, emptySlice.SliceField.IsNull()) + val, ok = emptySlice.SliceField.GetOrZero() + assert.True(t, ok) + assert.Equal(t, []string{}, val) + + // Verify set slice + assert.True(t, setSlice.SliceField.IsSet()) + assert.False(t, setSlice.SliceField.IsNull()) + val, ok = setSlice.SliceField.GetOrZero() + assert.True(t, ok) + assert.Equal(t, []string{"a", "b"}, val) + + // Test JSON serialization for each state + nilData, err := json.Marshal(nilSlice) + require.NoError(t, err) + assert.Contains(t, string(nilData), `"slice_field":null`) + + unsetData, err := json.Marshal(unsetSlice) + require.NoError(t, err) + assert.NotContains(t, string(unsetData), "slice_field") // omitted due to omitempty + + emptyData, err := json.Marshal(emptySlice) + require.NoError(t, err) + assert.Contains(t, string(emptyData), `"slice_field":[]`) + + setData, err := json.Marshal(setSlice) + require.NoError(t, err) + assert.Contains(t, string(setData), `"slice_field":["a","b"]`) + }) + + t.Run("mixed states container", func(t *testing.T) { + t.Parallel() + container := TestContainer{ + StringField: From(ptrFrom("hello")), // set to value + IntField: From[int](nil), // set to nil + StructField: From(ptrFrom(TestStruct{Name: "Alice", Age: 25})), // set to value + } + + // Verify states + assert.True(t, container.StringField.IsSet()) + assert.False(t, container.StringField.IsNull()) + + assert.True(t, container.IntField.IsSet()) + assert.True(t, container.IntField.IsNull()) + + assert.False(t, container.SliceField.IsSet()) + assert.False(t, container.SliceField.IsNull()) // Unset is not null + + assert.True(t, container.StructField.IsSet()) + assert.False(t, container.StructField.IsNull()) + + // Test JSON serialization + data, err := json.Marshal(container) + require.NoError(t, err) + + var result map[string]interface{} + err = json.Unmarshal(data, &result) + require.NoError(t, err) + + assert.Equal(t, "hello", result["string_field"]) + assert.Nil(t, result["int_field"]) + assert.NotContains(t, result, "slice_field") // unset, so omitted + structResult := result["struct_field"].(map[string]interface{}) + assert.Equal(t, "Alice", structResult["name"]) + assert.Equal(t, float64(25), structResult["age"]) + }) + + t.Run("JSON unmarshaling preserves states", func(t *testing.T) { + t.Parallel() + // JSON with some fields missing, some null, some with values + jsonData := `{ + "string_field": "test", + "int_field": null, + "struct_field": {"name": "Bob", "age": 35} + }` + + var container TestContainer + err := json.Unmarshal([]byte(jsonData), &container) + require.NoError(t, err) + + // string_field: present with value + assert.True(t, container.StringField.IsSet()) + assert.False(t, container.StringField.IsNull()) + stringVal, ok := container.StringField.GetOrZero() + assert.True(t, ok) + assert.Equal(t, "test", stringVal) + + // int_field: present but null + assert.True(t, container.IntField.IsSet()) + assert.True(t, container.IntField.IsNull()) + intVal, ok := container.IntField.GetOrZero() + assert.True(t, ok) + assert.Equal(t, 0, intVal) // zero value + + // slice_field: missing from JSON, should remain unset + assert.False(t, container.SliceField.IsSet()) + assert.False(t, container.SliceField.IsNull()) // Unset is not null + sliceVal, ok := container.SliceField.GetOrZero() + assert.False(t, ok) + assert.Nil(t, sliceVal) + + // struct_field: present with value + assert.True(t, container.StructField.IsSet()) + assert.False(t, container.StructField.IsNull()) + structVal, ok := container.StructField.GetOrZero() + assert.True(t, ok) + assert.Equal(t, TestStruct{Name: "Bob", Age: 35}, structVal) + }) +} + +// TestNilVsUnsetDistinction tests the key feature of distinguishing nil from unset +func TestNilVsUnsetDistinction(t *testing.T) { + t.Parallel() + t.Run("explicit nil vs unset", func(t *testing.T) { + t.Parallel() + // Explicitly set to nil + explicitNil := From[string](nil) + + // Unset + var unset OptionalNullable[string] + + // Both are null, but only one is set + assert.True(t, explicitNil.IsNull()) + assert.True(t, explicitNil.IsSet()) + + assert.False(t, unset.IsNull()) // Unset is not null + assert.False(t, unset.IsSet()) + + // Get behavior differs + got1, ok1 := explicitNil.GetOrZero() + got2, ok2 := unset.GetOrZero() + + assert.True(t, ok1) // explicitly set to nil returns true + assert.False(t, ok2) // unset returns false + assert.Equal(t, "", got1) // both return zero value + assert.Equal(t, "", got2) + + // Get behavior differs + ptr1, ok1 := explicitNil.Get() + ptr2, ok2 := unset.Get() + + assert.True(t, ok1) // explicitly set to nil returns true + assert.False(t, ok2) // unset returns false + assert.Nil(t, ptr1) // both return nil pointer + assert.Nil(t, ptr2) + }) + + t.Run("empty slice vs nil slice vs unset", func(t *testing.T) { + t.Parallel() + // Empty slice + emptyNullable := From(ptrFrom([]string{})) + + // Nil slice + nilNullable := From[[]string](nil) + + // Unset + var unsetNullable OptionalNullable[[]string] + + // All have different characteristics + assert.True(t, emptyNullable.IsSet()) + assert.False(t, emptyNullable.IsNull()) + + assert.True(t, nilNullable.IsSet()) + assert.True(t, nilNullable.IsNull()) + + assert.False(t, unsetNullable.IsSet()) + assert.False(t, unsetNullable.IsNull()) // Unset is not null + + // Get behavior + got1, ok1 := emptyNullable.GetOrZero() + got2, ok2 := nilNullable.GetOrZero() + got3, ok3 := unsetNullable.GetOrZero() + + assert.True(t, ok1) + assert.Equal(t, []string{}, got1) + + assert.True(t, ok2) + assert.Nil(t, got2) + + assert.False(t, ok3) + assert.Nil(t, got3) + }) +} + +// TestJSONOmitEmpty tests behavior with omitempty tag +func TestJSONOmitEmpty(t *testing.T) { + t.Parallel() + t.Run("marshal with omitempty", func(t *testing.T) { + t.Parallel() + // Test container with various nullable states + container := TestContainer{ + StringField: From(ptrFrom("test")), + IntField: From(ptrFrom(42)), + StructField: From[TestStruct](nil), // explicitly nil + } + + data, err := json.Marshal(container) + require.NoError(t, err) + + // Parse back to verify structure + var result map[string]interface{} + err = json.Unmarshal(data, &result) + require.NoError(t, err) + + // Should contain set fields + assert.Contains(t, result, "string_field") + assert.Contains(t, result, "int_field") + assert.Contains(t, result, "struct_field") + + // Should not contain unset field (due to omitempty) + // Note: This depends on how the marshaling handles unset fields + // The current implementation doesn't handle this case properly (see TODO) + }) + + t.Run("unmarshal missing fields", func(t *testing.T) { + t.Parallel() + // JSON with some fields missing + jsonData := `{"string_field": "test", "int_field": null}` + + var container TestContainer + err := json.Unmarshal([]byte(jsonData), &container) + require.NoError(t, err) + + // Present fields should be set + assert.True(t, container.StringField.IsSet()) + assert.False(t, container.StringField.IsNull()) + got, ok := container.StringField.GetOrZero() + assert.True(t, ok) + assert.Equal(t, "test", got) + + // Null field should be set to nil + assert.True(t, container.IntField.IsSet()) + assert.True(t, container.IntField.IsNull()) + + // Missing fields should remain unset + assert.False(t, container.SliceField.IsSet()) + assert.False(t, container.StructField.IsSet()) + }) +} + +// TestEdgeCases tests various edge cases +func TestEdgeCases(t *testing.T) { + t.Parallel() + t.Run("zero values", func(t *testing.T) { + t.Parallel() + // Test with zero values that are not nil + intNullable := From(ptrFrom(0)) + stringNullable := From(ptrFrom("")) + + assert.True(t, intNullable.IsSet()) + assert.False(t, intNullable.IsNull()) + got, ok := intNullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, 0, got) + + assert.True(t, stringNullable.IsSet()) + assert.False(t, stringNullable.IsNull()) + got2, ok2 := stringNullable.GetOrZero() + assert.True(t, ok2) + assert.Equal(t, "", got2) + }) + + t.Run("pointer to pointer", func(t *testing.T) { + t.Parallel() + // Test with pointer to pointer type + inner := "test" + nullable := From(ptrFrom(&inner)) + + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, &inner, got) + assert.Equal(t, "test", *got) + }) + + t.Run("complex struct", func(t *testing.T) { + t.Parallel() + complexStruct := struct { + Name string + Values []int + Metadata map[string]string + }{ + Name: "complex", + Values: []int{1, 2, 3}, + Metadata: map[string]string{ + "key1": "value1", + "key2": "value2", + }, + } + + nullable := From(ptrFrom(complexStruct)) + + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, complexStruct, got) + }) +} + +// TestDoublePointers tests comprehensive double pointer scenarios +func TestDoublePointers(t *testing.T) { + t.Parallel() + + t.Run("string double pointer with value", func(t *testing.T) { + t.Parallel() + inner := "hello world" + ptr := &inner + nullable := From(ptrFrom(ptr)) + + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, ptr, got) + assert.Equal(t, &inner, got) + assert.Equal(t, "hello world", *got) + }) + + t.Run("int double pointer with value", func(t *testing.T) { + t.Parallel() + inner := 42 + ptr := &inner + nullable := From(ptrFrom(ptr)) + + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, ptr, got) + assert.Equal(t, &inner, got) + assert.Equal(t, 42, *got) + }) + + t.Run("double pointer to nil", func(t *testing.T) { + t.Parallel() + var ptr *string = nil + nullable := From(ptrFrom(ptr)) + + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, ptr, got) + assert.Nil(t, got) + }) + + t.Run("nil double pointer", func(t *testing.T) { + t.Parallel() + nullable := From[*string](nil) + + assert.True(t, nullable.IsSet()) + assert.True(t, nullable.IsNull()) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Nil(t, got) // zero value for **string is nil + }) + + t.Run("unset double pointer", func(t *testing.T) { + t.Parallel() + var nullable OptionalNullable[*string] + + assert.False(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + + got, ok := nullable.GetOrZero() + assert.False(t, ok) + assert.Nil(t, got) // zero value for **string is nil + }) + + t.Run("double pointer modification", func(t *testing.T) { + t.Parallel() + inner := "original" + ptr := &inner + nullable := From(ptrFrom(ptr)) + + // Verify original value + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, "original", *got) + + // Modify through double pointer + *got = "modified" + assert.Equal(t, "modified", inner) + assert.Equal(t, "modified", *got) + }) + + t.Run("double pointer to struct", func(t *testing.T) { + t.Parallel() + inner := TestStruct{Name: "Alice", Age: 30} + ptr := &inner + nullable := From(ptrFrom(ptr)) + + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, ptr, got) + assert.Equal(t, TestStruct{Name: "Alice", Age: 30}, *got) + + // Modify through double pointer + (*got).Name = "Bob" + assert.Equal(t, "Bob", inner.Name) + assert.Equal(t, "Bob", (*got).Name) + }) + + t.Run("double pointer to slice", func(t *testing.T) { + t.Parallel() + inner := []string{"a", "b", "c"} + ptr := &inner + nullable := From(ptrFrom(ptr)) + + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, ptr, got) + assert.Equal(t, []string{"a", "b", "c"}, *got) + + // Modify through double pointer + *got = append(*got, "d") + assert.Equal(t, []string{"a", "b", "c", "d"}, inner) + assert.Equal(t, []string{"a", "b", "c", "d"}, *got) + }) + + t.Run("double pointer to empty slice", func(t *testing.T) { + t.Parallel() + inner := []string{} + ptr := &inner + nullable := From(ptrFrom(ptr)) + + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, ptr, got) + assert.Equal(t, []string{}, *got) + }) + + t.Run("double pointer to nil slice", func(t *testing.T) { + t.Parallel() + var inner []string = nil + ptr := &inner + nullable := From(ptrFrom(ptr)) + + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, ptr, got) + assert.Nil(t, *got) + }) + + t.Run("double pointer JSON marshaling", func(t *testing.T) { + t.Parallel() + inner := "json test" + ptr := &inner + nullable := From(ptrFrom(ptr)) + + data, err := json.Marshal(nullable) + require.NoError(t, err) + assert.Equal(t, `"json test"`, string(data)) + }) + + t.Run("double pointer JSON unmarshaling", func(t *testing.T) { + t.Parallel() + var nullable OptionalNullable[*string] + err := json.Unmarshal([]byte(`"json test"`), &nullable) + require.NoError(t, err) + + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.NotNil(t, got) + assert.Equal(t, "json test", *got) + }) + + t.Run("double pointer JSON null marshaling", func(t *testing.T) { + t.Parallel() + nullable := From[*string](nil) + + data, err := json.Marshal(nullable) + require.NoError(t, err) + assert.Equal(t, `null`, string(data)) + }) + + t.Run("double pointer JSON null unmarshaling", func(t *testing.T) { + t.Parallel() + var nullable OptionalNullable[*string] + err := json.Unmarshal([]byte(`null`), &nullable) + require.NoError(t, err) + + assert.True(t, nullable.IsSet()) + assert.True(t, nullable.IsNull()) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Nil(t, got) + }) + + t.Run("double pointer round trip", func(t *testing.T) { + t.Parallel() + inner := "round trip test" + ptr := &inner + nullable1 := From(ptrFrom(ptr)) + + // Marshal + data, err := json.Marshal(nullable1) + require.NoError(t, err) + + // Unmarshal + var nullable2 OptionalNullable[*string] + err = json.Unmarshal(data, &nullable2) + require.NoError(t, err) + + // Compare states + assert.Equal(t, nullable1.IsSet(), nullable2.IsSet()) + assert.Equal(t, nullable1.IsNull(), nullable2.IsNull()) + + got1, ok1 := nullable1.GetOrZero() + got2, ok2 := nullable2.GetOrZero() + assert.Equal(t, ok1, ok2) + + // Values should be equal + assert.Equal(t, *got1, *got2) + }) + + t.Run("triple pointer", func(t *testing.T) { + t.Parallel() + inner := "triple" + ptr1 := &inner + ptr2 := &ptr1 + nullable := From(ptrFrom(ptr2)) + + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, ptr2, got) + assert.Equal(t, ptr1, *got) + assert.Equal(t, "triple", **got) + }) + + t.Run("double pointer set and unset", func(t *testing.T) { + t.Parallel() + var nullable OptionalNullable[*string] + + // Initially unset + assert.False(t, nullable.IsSet()) + + // Set to double pointer + inner := "set test" + ptr := &inner + nullable.Set(ptrFrom(ptr)) + + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, "set test", *got) + + // Set to nil + nullable.Set(nil) + + assert.True(t, nullable.IsSet()) + assert.True(t, nullable.IsNull()) + + got, ok = nullable.GetOrZero() + assert.True(t, ok) + assert.Nil(t, got) + + // Unset + nullable.Unset() + + assert.False(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + + got, ok = nullable.GetOrZero() + assert.False(t, ok) + assert.Nil(t, got) + }) + + t.Run("double pointer Get method", func(t *testing.T) { + t.Parallel() + inner := "get test" + ptr := &inner + nullable := From(ptrFrom(ptr)) + + // Test Get method + gotPtr, ok := nullable.Get() + assert.True(t, ok) + assert.NotNil(t, gotPtr) + assert.Equal(t, ptr, *gotPtr) + assert.Equal(t, "get test", **gotPtr) + + // Test with nil + nilNullable := From[*string](nil) + gotPtr, ok = nilNullable.Get() + assert.True(t, ok) + assert.Nil(t, gotPtr) + + // Test with unset + var unsetNullable OptionalNullable[*string] + gotPtr, ok = unsetNullable.Get() + assert.False(t, ok) + assert.Nil(t, gotPtr) + }) + + t.Run("double pointer zero values", func(t *testing.T) { + t.Parallel() + // Test with zero value string + inner := "" + ptr := &inner + nullable := From(ptrFrom(ptr)) + + assert.True(t, nullable.IsSet()) + assert.False(t, nullable.IsNull()) + + got, ok := nullable.GetOrZero() + assert.True(t, ok) + assert.Equal(t, "", *got) + + // Test with zero value int + innerInt := 0 + ptrInt := &innerInt + nullableInt := From(ptrFrom(ptrInt)) + + assert.True(t, nullableInt.IsSet()) + assert.False(t, nullableInt.IsNull()) + + gotInt, okInt := nullableInt.GetOrZero() + assert.True(t, okInt) + assert.Equal(t, 0, *gotInt) + }) +} + +// TestAsOptionalNullable tests the AsOptionalNullable helper function +func TestAsOptionalNullable(t *testing.T) { + t.Parallel() + + t.Run("with nullable string", func(t *testing.T) { + t.Parallel() + nullable := From(ptrFrom("test")) + reflectValue := reflect.ValueOf(nullable) + + result, ok := AsOptionalNullable(reflectValue) + assert.True(t, ok) + assert.NotNil(t, result) + + value, isSet := result.GetUntyped() + assert.True(t, isSet) + assert.Equal(t, "test", value) + }) + + t.Run("with nullable int", func(t *testing.T) { + t.Parallel() + nullable := From(ptrFrom(42)) + reflectValue := reflect.ValueOf(nullable) + + result, ok := AsOptionalNullable(reflectValue) + assert.True(t, ok) + assert.NotNil(t, result) + + value, isSet := result.GetUntyped() + assert.True(t, isSet) + assert.Equal(t, 42, value) + }) + + t.Run("with nullable nil", func(t *testing.T) { + t.Parallel() + nullable := From[string](nil) + reflectValue := reflect.ValueOf(nullable) + + result, ok := AsOptionalNullable(reflectValue) + assert.True(t, ok) + assert.NotNil(t, result) + + value, isSet := result.GetUntyped() + assert.True(t, isSet) + assert.Nil(t, value) + }) + + t.Run("with unset nullable", func(t *testing.T) { + t.Parallel() + var nullable OptionalNullable[string] + reflectValue := reflect.ValueOf(nullable) + + result, ok := AsOptionalNullable(reflectValue) + assert.False(t, ok) + assert.Nil(t, result) + }) + + t.Run("with non-nullable string", func(t *testing.T) { + t.Parallel() + regularString := "not nullable" + reflectValue := reflect.ValueOf(regularString) + + result, ok := AsOptionalNullable(reflectValue) + assert.False(t, ok) + assert.Nil(t, result) + }) + + t.Run("with non-nullable int", func(t *testing.T) { + t.Parallel() + regularInt := 42 + reflectValue := reflect.ValueOf(regularInt) + + result, ok := AsOptionalNullable(reflectValue) + assert.False(t, ok) + assert.Nil(t, result) + }) + + t.Run("with non-nullable map", func(t *testing.T) { + t.Parallel() + regularMap := map[string]int{"key": 42} + reflectValue := reflect.ValueOf(regularMap) + + result, ok := AsOptionalNullable(reflectValue) + assert.False(t, ok) + assert.Nil(t, result) + }) + + t.Run("with non-nullable struct", func(t *testing.T) { + t.Parallel() + regularStruct := TestStruct{Name: "test", Age: 30} + reflectValue := reflect.ValueOf(regularStruct) + + result, ok := AsOptionalNullable(reflectValue) + assert.False(t, ok) + assert.Nil(t, result) + }) + + t.Run("with nullable double pointer", func(t *testing.T) { + t.Parallel() + inner := "test" + ptr := &inner + nullable := From(ptrFrom(ptr)) + reflectValue := reflect.ValueOf(nullable) + + result, ok := AsOptionalNullable(reflectValue) + assert.True(t, ok) + assert.NotNil(t, result) + + value, isSet := result.GetUntyped() + assert.True(t, isSet) + assert.Equal(t, ptr, value) + assert.Equal(t, "test", *value.(*string)) + }) + + t.Run("with nullable slice", func(t *testing.T) { + t.Parallel() + nullable := From(ptrFrom([]string{"a", "b", "c"})) + reflectValue := reflect.ValueOf(nullable) + + result, ok := AsOptionalNullable(reflectValue) + assert.True(t, ok) + assert.NotNil(t, result) + + value, isSet := result.GetUntyped() + assert.True(t, isSet) + assert.Equal(t, []string{"a", "b", "c"}, value) + }) + + t.Run("with nullable struct", func(t *testing.T) { + t.Parallel() + testStruct := TestStruct{Name: "Alice", Age: 25} + nullable := From(ptrFrom(testStruct)) + reflectValue := reflect.ValueOf(nullable) + + result, ok := AsOptionalNullable(reflectValue) + assert.True(t, ok) + assert.NotNil(t, result) + + value, isSet := result.GetUntyped() + assert.True(t, isSet) + assert.Equal(t, testStruct, value) + }) + + t.Run("with pointer to nullable", func(t *testing.T) { + t.Parallel() + nullable := From(ptrFrom("test")) + ptrToNullable := &nullable + reflectValue := reflect.ValueOf(ptrToNullable) + + // This should work since the pointer to nullable still contains a nullable + result, ok := AsOptionalNullable(reflectValue) + assert.True(t, ok) + assert.NotNil(t, result) + + value, isSet := result.GetUntyped() + assert.True(t, isSet) + assert.Equal(t, "test", value) + }) + + t.Run("with interface containing nullable", func(t *testing.T) { + t.Parallel() + nullable := From(ptrFrom("test")) + var iface interface{} = nullable + reflectValue := reflect.ValueOf(iface) + + result, ok := AsOptionalNullable(reflectValue) + assert.True(t, ok) + assert.NotNil(t, result) + + value, isSet := result.GetUntyped() + assert.True(t, isSet) + assert.Equal(t, "test", value) + }) +} diff --git a/internal/sdk/preview.go b/internal/sdk/preview.go index 31b2e44..d48bd44 100644 --- a/internal/sdk/preview.go +++ b/internal/sdk/preview.go @@ -5,40 +5,35 @@ package sdk import ( "context" "fmt" - "github.com/cenkalti/backoff/v4" + "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/internal/config" "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/internal/hooks" "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/internal/utils" "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/models/errors" "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/models/operations" - "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/retry" "net/http" "net/url" ) // Preview APIs type Preview struct { - sdkConfiguration sdkConfiguration + rootSDK *SDK + sdkConfiguration config.SDKConfiguration + hooks *hooks.Hooks } -func newPreview(sdkConfig sdkConfiguration) *Preview { +func newPreview(rootSDK *SDK, sdkConfig config.SDKConfiguration, hooks *hooks.Hooks) *Preview { return &Preview{ + rootSDK: rootSDK, sdkConfiguration: sdkConfig, + hooks: hooks, } } // PreviewFile - previewFile // Generate thumbnail preview for a file entity func (s *Preview) PreviewFile(ctx context.Context, request operations.PreviewFileRequest, opts ...operations.Option) (*operations.PreviewFileResponse, error) { - hookCtx := hooks.HookContext{ - Context: ctx, - OperationID: "previewFile", - OAuth2Scopes: []string{}, - SecuritySource: s.sdkConfiguration.Security, - } - o := operations.Options{} supportedOptions := []string{ - operations.SupportedOptionRetries, operations.SupportedOptionTimeout, } @@ -48,12 +43,27 @@ func (s *Preview) PreviewFile(ctx context.Context, request operations.PreviewFil } } - baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + var baseURL string + if o.ServerURL == nil { + baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + } else { + baseURL = *o.ServerURL + } opURL, err := utils.GenerateURL(ctx, baseURL, "/v1/files/{id}/preview", request, nil) if err != nil { return nil, fmt.Errorf("error generating URL: %w", err) } + hookCtx := hooks.HookContext{ + SDK: s.rootSDK, + SDKConfiguration: s.sdkConfiguration, + BaseURL: baseURL, + Context: ctx, + OperationID: "previewFile", + OAuth2Scopes: nil, + SecuritySource: s.sdkConfiguration.Security, + } + timeout := o.Timeout if timeout == nil { timeout = s.sdkConfiguration.Timeout @@ -80,94 +90,36 @@ func (s *Preview) PreviewFile(ctx context.Context, request operations.PreviewFil return nil, err } - globalRetryConfig := s.sdkConfiguration.RetryConfig - retryConfig := o.Retries - if retryConfig == nil { - if globalRetryConfig != nil { - retryConfig = globalRetryConfig - } else { - retryConfig = &retry.Config{ - Strategy: "backoff", Backoff: &retry.BackoffStrategy{ - InitialInterval: 5000, - MaxInterval: 60000, - Exponent: 1.5, - MaxElapsedTime: 3600000, - }, - RetryConnectionErrors: true, - } - } + for k, v := range o.SetHeaders { + req.Header.Set(k, v) } - var httpRes *http.Response - if retryConfig != nil { - httpRes, err = utils.Retry(ctx, utils.Retries{ - Config: retryConfig, - StatusCodes: []string{ - "5XX", - }, - }, func() (*http.Response, error) { - if req.Body != nil { - copyBody, err := req.GetBody() - if err != nil { - return nil, err - } - req.Body = copyBody - } - - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) - if err != nil { - return nil, backoff.Permanent(err) - } - - httpRes, err := s.sdkConfiguration.Client.Do(req) - if err != nil || httpRes == nil { - if err != nil { - err = fmt.Errorf("error sending request: %w", err) - } else { - err = fmt.Errorf("error sending request: no response") - } - - _, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) - } - return httpRes, err - }) + req, err = s.hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + if err != nil { + return nil, err + } + httpRes, err := s.sdkConfiguration.Client.Do(req) + if err != nil || httpRes == nil { if err != nil { - return nil, err + err = fmt.Errorf("error sending request: %w", err) } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } + err = fmt.Errorf("error sending request: no response") } - } else { - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + + _, err = s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + return nil, err + } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { + _httpRes, err := s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) if err != nil { return nil, err + } else if _httpRes != nil { + httpRes = _httpRes } - - httpRes, err = s.sdkConfiguration.Client.Do(req) - if err != nil || httpRes == nil { - if err != nil { - err = fmt.Errorf("error sending request: %w", err) - } else { - err = fmt.Errorf("error sending request: no response") - } - - _, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + } else { + httpRes, err = s.hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) + if err != nil { return nil, err - } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { - _httpRes, err := s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) - if err != nil { - return nil, err - } else if _httpRes != nil { - httpRes = _httpRes - } - } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } } } @@ -194,16 +146,8 @@ func (s *Preview) PreviewFile(ctx context.Context, request operations.PreviewFil // PreviewPublicFile - previewPublicFile // Generate thumbnail preview for a public file entity func (s *Preview) PreviewPublicFile(ctx context.Context, request operations.PreviewPublicFileRequest, opts ...operations.Option) (*operations.PreviewPublicFileResponse, error) { - hookCtx := hooks.HookContext{ - Context: ctx, - OperationID: "previewPublicFile", - OAuth2Scopes: []string{}, - SecuritySource: nil, - } - o := operations.Options{} supportedOptions := []string{ - operations.SupportedOptionRetries, operations.SupportedOptionTimeout, } @@ -213,12 +157,27 @@ func (s *Preview) PreviewPublicFile(ctx context.Context, request operations.Prev } } - baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + var baseURL string + if o.ServerURL == nil { + baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + } else { + baseURL = *o.ServerURL + } opURL, err := utils.GenerateURL(ctx, baseURL, "/v1/files/public/{id}/preview", request, nil) if err != nil { return nil, fmt.Errorf("error generating URL: %w", err) } + hookCtx := hooks.HookContext{ + SDK: s.rootSDK, + SDKConfiguration: s.sdkConfiguration, + BaseURL: baseURL, + Context: ctx, + OperationID: "previewPublicFile", + OAuth2Scopes: nil, + SecuritySource: nil, + } + timeout := o.Timeout if timeout == nil { timeout = s.sdkConfiguration.Timeout @@ -241,94 +200,36 @@ func (s *Preview) PreviewPublicFile(ctx context.Context, request operations.Prev return nil, fmt.Errorf("error populating query params: %w", err) } - globalRetryConfig := s.sdkConfiguration.RetryConfig - retryConfig := o.Retries - if retryConfig == nil { - if globalRetryConfig != nil { - retryConfig = globalRetryConfig - } else { - retryConfig = &retry.Config{ - Strategy: "backoff", Backoff: &retry.BackoffStrategy{ - InitialInterval: 5000, - MaxInterval: 60000, - Exponent: 1.5, - MaxElapsedTime: 3600000, - }, - RetryConnectionErrors: true, - } - } + for k, v := range o.SetHeaders { + req.Header.Set(k, v) } - var httpRes *http.Response - if retryConfig != nil { - httpRes, err = utils.Retry(ctx, utils.Retries{ - Config: retryConfig, - StatusCodes: []string{ - "5XX", - }, - }, func() (*http.Response, error) { - if req.Body != nil { - copyBody, err := req.GetBody() - if err != nil { - return nil, err - } - req.Body = copyBody - } - - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) - if err != nil { - return nil, backoff.Permanent(err) - } - - httpRes, err := s.sdkConfiguration.Client.Do(req) - if err != nil || httpRes == nil { - if err != nil { - err = fmt.Errorf("error sending request: %w", err) - } else { - err = fmt.Errorf("error sending request: no response") - } - - _, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) - } - return httpRes, err - }) + req, err = s.hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + if err != nil { + return nil, err + } + httpRes, err := s.sdkConfiguration.Client.Do(req) + if err != nil || httpRes == nil { if err != nil { - return nil, err + err = fmt.Errorf("error sending request: %w", err) } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } + err = fmt.Errorf("error sending request: no response") } - } else { - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + + _, err = s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + return nil, err + } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { + _httpRes, err := s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) if err != nil { return nil, err + } else if _httpRes != nil { + httpRes = _httpRes } - - httpRes, err = s.sdkConfiguration.Client.Do(req) - if err != nil || httpRes == nil { - if err != nil { - err = fmt.Errorf("error sending request: %w", err) - } else { - err = fmt.Errorf("error sending request: no response") - } - - _, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + } else { + httpRes, err = s.hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) + if err != nil { return nil, err - } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { - _httpRes, err := s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) - if err != nil { - return nil, err - } else if _httpRes != nil { - httpRes = _httpRes - } - } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } } } @@ -355,16 +256,8 @@ func (s *Preview) PreviewPublicFile(ctx context.Context, request operations.Prev // PreviewS3File - previewS3File // Generate thumbnail preview from an s3 reference for a file entity func (s *Preview) PreviewS3File(ctx context.Context, request operations.PreviewS3FileRequest, opts ...operations.Option) (*operations.PreviewS3FileResponse, error) { - hookCtx := hooks.HookContext{ - Context: ctx, - OperationID: "previewS3File", - OAuth2Scopes: []string{}, - SecuritySource: s.sdkConfiguration.Security, - } - o := operations.Options{} supportedOptions := []string{ - operations.SupportedOptionRetries, operations.SupportedOptionTimeout, } @@ -374,12 +267,26 @@ func (s *Preview) PreviewS3File(ctx context.Context, request operations.PreviewS } } - baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + var baseURL string + if o.ServerURL == nil { + baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + } else { + baseURL = *o.ServerURL + } opURL, err := url.JoinPath(baseURL, "/v1/files:previewS3") if err != nil { return nil, fmt.Errorf("error generating URL: %w", err) } + hookCtx := hooks.HookContext{ + SDK: s.rootSDK, + SDKConfiguration: s.sdkConfiguration, + BaseURL: baseURL, + Context: ctx, + OperationID: "previewS3File", + OAuth2Scopes: nil, + SecuritySource: s.sdkConfiguration.Security, + } bodyReader, reqContentType, err := utils.SerializeRequestBody(ctx, request, false, true, "S3Ref", "json", `request:"mediaType=application/json"`) if err != nil { return nil, err @@ -402,7 +309,9 @@ func (s *Preview) PreviewS3File(ctx context.Context, request operations.PreviewS } req.Header.Set("Accept", "*/*") req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent) - req.Header.Set("Content-Type", reqContentType) + if reqContentType != "" { + req.Header.Set("Content-Type", reqContentType) + } if err := utils.PopulateQueryParams(ctx, req, request, nil); err != nil { return nil, fmt.Errorf("error populating query params: %w", err) @@ -412,94 +321,36 @@ func (s *Preview) PreviewS3File(ctx context.Context, request operations.PreviewS return nil, err } - globalRetryConfig := s.sdkConfiguration.RetryConfig - retryConfig := o.Retries - if retryConfig == nil { - if globalRetryConfig != nil { - retryConfig = globalRetryConfig - } else { - retryConfig = &retry.Config{ - Strategy: "backoff", Backoff: &retry.BackoffStrategy{ - InitialInterval: 5000, - MaxInterval: 60000, - Exponent: 1.5, - MaxElapsedTime: 3600000, - }, - RetryConnectionErrors: true, - } - } + for k, v := range o.SetHeaders { + req.Header.Set(k, v) } - var httpRes *http.Response - if retryConfig != nil { - httpRes, err = utils.Retry(ctx, utils.Retries{ - Config: retryConfig, - StatusCodes: []string{ - "5XX", - }, - }, func() (*http.Response, error) { - if req.Body != nil { - copyBody, err := req.GetBody() - if err != nil { - return nil, err - } - req.Body = copyBody - } - - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) - if err != nil { - return nil, backoff.Permanent(err) - } - - httpRes, err := s.sdkConfiguration.Client.Do(req) - if err != nil || httpRes == nil { - if err != nil { - err = fmt.Errorf("error sending request: %w", err) - } else { - err = fmt.Errorf("error sending request: no response") - } - - _, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) - } - return httpRes, err - }) + req, err = s.hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + if err != nil { + return nil, err + } + httpRes, err := s.sdkConfiguration.Client.Do(req) + if err != nil || httpRes == nil { if err != nil { - return nil, err + err = fmt.Errorf("error sending request: %w", err) } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } + err = fmt.Errorf("error sending request: no response") } - } else { - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + + _, err = s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + return nil, err + } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { + _httpRes, err := s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) if err != nil { return nil, err + } else if _httpRes != nil { + httpRes = _httpRes } - - httpRes, err = s.sdkConfiguration.Client.Do(req) - if err != nil || httpRes == nil { - if err != nil { - err = fmt.Errorf("error sending request: %w", err) - } else { - err = fmt.Errorf("error sending request: no response") - } - - _, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + } else { + httpRes, err = s.hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) + if err != nil { return nil, err - } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { - _httpRes, err := s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) - if err != nil { - return nil, err - } else if _httpRes != nil { - httpRes = _httpRes - } - } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } } } @@ -526,16 +377,8 @@ func (s *Preview) PreviewS3File(ctx context.Context, request operations.PreviewS // PreviewS3FileGet - previewS3FileGet // Get thumbnail preview from an s3 reference for a file entity func (s *Preview) PreviewS3FileGet(ctx context.Context, request operations.PreviewS3FileGetRequest, opts ...operations.Option) (*operations.PreviewS3FileGetResponse, error) { - hookCtx := hooks.HookContext{ - Context: ctx, - OperationID: "previewS3FileGet", - OAuth2Scopes: []string{}, - SecuritySource: s.sdkConfiguration.Security, - } - o := operations.Options{} supportedOptions := []string{ - operations.SupportedOptionRetries, operations.SupportedOptionTimeout, } @@ -545,12 +388,27 @@ func (s *Preview) PreviewS3FileGet(ctx context.Context, request operations.Previ } } - baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + var baseURL string + if o.ServerURL == nil { + baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + } else { + baseURL = *o.ServerURL + } opURL, err := url.JoinPath(baseURL, "/v1/files:previewS3") if err != nil { return nil, fmt.Errorf("error generating URL: %w", err) } + hookCtx := hooks.HookContext{ + SDK: s.rootSDK, + SDKConfiguration: s.sdkConfiguration, + BaseURL: baseURL, + Context: ctx, + OperationID: "previewS3FileGet", + OAuth2Scopes: nil, + SecuritySource: s.sdkConfiguration.Security, + } + timeout := o.Timeout if timeout == nil { timeout = s.sdkConfiguration.Timeout @@ -577,94 +435,36 @@ func (s *Preview) PreviewS3FileGet(ctx context.Context, request operations.Previ return nil, err } - globalRetryConfig := s.sdkConfiguration.RetryConfig - retryConfig := o.Retries - if retryConfig == nil { - if globalRetryConfig != nil { - retryConfig = globalRetryConfig - } else { - retryConfig = &retry.Config{ - Strategy: "backoff", Backoff: &retry.BackoffStrategy{ - InitialInterval: 5000, - MaxInterval: 60000, - Exponent: 1.5, - MaxElapsedTime: 3600000, - }, - RetryConnectionErrors: true, - } - } + for k, v := range o.SetHeaders { + req.Header.Set(k, v) } - var httpRes *http.Response - if retryConfig != nil { - httpRes, err = utils.Retry(ctx, utils.Retries{ - Config: retryConfig, - StatusCodes: []string{ - "5XX", - }, - }, func() (*http.Response, error) { - if req.Body != nil { - copyBody, err := req.GetBody() - if err != nil { - return nil, err - } - req.Body = copyBody - } - - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) - if err != nil { - return nil, backoff.Permanent(err) - } - - httpRes, err := s.sdkConfiguration.Client.Do(req) - if err != nil || httpRes == nil { - if err != nil { - err = fmt.Errorf("error sending request: %w", err) - } else { - err = fmt.Errorf("error sending request: no response") - } - - _, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) - } - return httpRes, err - }) + req, err = s.hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + if err != nil { + return nil, err + } + httpRes, err := s.sdkConfiguration.Client.Do(req) + if err != nil || httpRes == nil { if err != nil { - return nil, err + err = fmt.Errorf("error sending request: %w", err) } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } + err = fmt.Errorf("error sending request: no response") } - } else { - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + + _, err = s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + return nil, err + } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { + _httpRes, err := s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) if err != nil { return nil, err + } else if _httpRes != nil { + httpRes = _httpRes } - - httpRes, err = s.sdkConfiguration.Client.Do(req) - if err != nil || httpRes == nil { - if err != nil { - err = fmt.Errorf("error sending request: %w", err) - } else { - err = fmt.Errorf("error sending request: no response") - } - - _, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + } else { + httpRes, err = s.hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) + if err != nil { return nil, err - } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { - _httpRes, err := s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) - if err != nil { - return nil, err - } else if _httpRes != nil { - httpRes = _httpRes - } - } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } } } diff --git a/internal/sdk/publiclinks.go b/internal/sdk/publiclinks.go index fabc7b6..fc90ac9 100644 --- a/internal/sdk/publiclinks.go +++ b/internal/sdk/publiclinks.go @@ -6,39 +6,34 @@ import ( "bytes" "context" "fmt" - "github.com/cenkalti/backoff/v4" + "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/internal/config" "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/internal/hooks" "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/internal/utils" "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/models/errors" "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/models/operations" - "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/retry" "net/http" ) // PublicLinks - Create and Manage Public Links for Files type PublicLinks struct { - sdkConfiguration sdkConfiguration + rootSDK *SDK + sdkConfiguration config.SDKConfiguration + hooks *hooks.Hooks } -func newPublicLinks(sdkConfig sdkConfiguration) *PublicLinks { +func newPublicLinks(rootSDK *SDK, sdkConfig config.SDKConfiguration, hooks *hooks.Hooks) *PublicLinks { return &PublicLinks{ + rootSDK: rootSDK, sdkConfiguration: sdkConfig, + hooks: hooks, } } // AccessPublicLink - accessPublicLink // Redirects to a accessible signed url for the respective file associated to the public link func (s *PublicLinks) AccessPublicLink(ctx context.Context, request operations.AccessPublicLinkRequest, opts ...operations.Option) (*operations.AccessPublicLinkResponse, error) { - hookCtx := hooks.HookContext{ - Context: ctx, - OperationID: "accessPublicLink", - OAuth2Scopes: []string{}, - SecuritySource: nil, - } - o := operations.Options{} supportedOptions := []string{ - operations.SupportedOptionRetries, operations.SupportedOptionTimeout, } @@ -48,12 +43,27 @@ func (s *PublicLinks) AccessPublicLink(ctx context.Context, request operations.A } } - baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + var baseURL string + if o.ServerURL == nil { + baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + } else { + baseURL = *o.ServerURL + } opURL, err := utils.GenerateURL(ctx, baseURL, "/v1/files/public/links/{id}/{filename}", request, nil) if err != nil { return nil, fmt.Errorf("error generating URL: %w", err) } + hookCtx := hooks.HookContext{ + SDK: s.rootSDK, + SDKConfiguration: s.sdkConfiguration, + BaseURL: baseURL, + Context: ctx, + OperationID: "accessPublicLink", + OAuth2Scopes: nil, + SecuritySource: nil, + } + timeout := o.Timeout if timeout == nil { timeout = s.sdkConfiguration.Timeout @@ -72,94 +82,40 @@ func (s *PublicLinks) AccessPublicLink(ctx context.Context, request operations.A req.Header.Set("Accept", "*/*") req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent) - globalRetryConfig := s.sdkConfiguration.RetryConfig - retryConfig := o.Retries - if retryConfig == nil { - if globalRetryConfig != nil { - retryConfig = globalRetryConfig - } else { - retryConfig = &retry.Config{ - Strategy: "backoff", Backoff: &retry.BackoffStrategy{ - InitialInterval: 5000, - MaxInterval: 60000, - Exponent: 1.5, - MaxElapsedTime: 3600000, - }, - RetryConnectionErrors: true, - } - } + if err := utils.PopulateQueryParams(ctx, req, request, nil); err != nil { + return nil, fmt.Errorf("error populating query params: %w", err) } - var httpRes *http.Response - if retryConfig != nil { - httpRes, err = utils.Retry(ctx, utils.Retries{ - Config: retryConfig, - StatusCodes: []string{ - "5XX", - }, - }, func() (*http.Response, error) { - if req.Body != nil { - copyBody, err := req.GetBody() - if err != nil { - return nil, err - } - req.Body = copyBody - } - - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) - if err != nil { - return nil, backoff.Permanent(err) - } - - httpRes, err := s.sdkConfiguration.Client.Do(req) - if err != nil || httpRes == nil { - if err != nil { - err = fmt.Errorf("error sending request: %w", err) - } else { - err = fmt.Errorf("error sending request: no response") - } + for k, v := range o.SetHeaders { + req.Header.Set(k, v) + } - _, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) - } - return httpRes, err - }) + req, err = s.hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + if err != nil { + return nil, err + } + httpRes, err := s.sdkConfiguration.Client.Do(req) + if err != nil || httpRes == nil { if err != nil { - return nil, err + err = fmt.Errorf("error sending request: %w", err) } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } + err = fmt.Errorf("error sending request: no response") } - } else { - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + + _, err = s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + return nil, err + } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { + _httpRes, err := s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) if err != nil { return nil, err + } else if _httpRes != nil { + httpRes = _httpRes } - - httpRes, err = s.sdkConfiguration.Client.Do(req) - if err != nil || httpRes == nil { - if err != nil { - err = fmt.Errorf("error sending request: %w", err) - } else { - err = fmt.Errorf("error sending request: no response") - } - - _, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + } else { + httpRes, err = s.hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) + if err != nil { return nil, err - } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { - _httpRes, err := s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) - if err != nil { - return nil, err - } else if _httpRes != nil { - httpRes = _httpRes - } - } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } } } @@ -186,16 +142,8 @@ func (s *PublicLinks) AccessPublicLink(ctx context.Context, request operations.A // GeneratePublicLink - generatePublicLink // Generates a public link to access a private file func (s *PublicLinks) GeneratePublicLink(ctx context.Context, request operations.GeneratePublicLinkRequest, opts ...operations.Option) (*operations.GeneratePublicLinkResponse, error) { - hookCtx := hooks.HookContext{ - Context: ctx, - OperationID: "generatePublicLink", - OAuth2Scopes: []string{}, - SecuritySource: s.sdkConfiguration.Security, - } - o := operations.Options{} supportedOptions := []string{ - operations.SupportedOptionRetries, operations.SupportedOptionTimeout, } @@ -205,12 +153,27 @@ func (s *PublicLinks) GeneratePublicLink(ctx context.Context, request operations } } - baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + var baseURL string + if o.ServerURL == nil { + baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + } else { + baseURL = *o.ServerURL + } opURL, err := utils.GenerateURL(ctx, baseURL, "/v1/files/{id}/public/links", request, nil) if err != nil { return nil, fmt.Errorf("error generating URL: %w", err) } + hookCtx := hooks.HookContext{ + SDK: s.rootSDK, + SDKConfiguration: s.sdkConfiguration, + BaseURL: baseURL, + Context: ctx, + OperationID: "generatePublicLink", + OAuth2Scopes: nil, + SecuritySource: s.sdkConfiguration.Security, + } + timeout := o.Timeout if timeout == nil { timeout = s.sdkConfiguration.Timeout @@ -233,94 +196,36 @@ func (s *PublicLinks) GeneratePublicLink(ctx context.Context, request operations return nil, err } - globalRetryConfig := s.sdkConfiguration.RetryConfig - retryConfig := o.Retries - if retryConfig == nil { - if globalRetryConfig != nil { - retryConfig = globalRetryConfig - } else { - retryConfig = &retry.Config{ - Strategy: "backoff", Backoff: &retry.BackoffStrategy{ - InitialInterval: 5000, - MaxInterval: 60000, - Exponent: 1.5, - MaxElapsedTime: 3600000, - }, - RetryConnectionErrors: true, - } - } + for k, v := range o.SetHeaders { + req.Header.Set(k, v) } - var httpRes *http.Response - if retryConfig != nil { - httpRes, err = utils.Retry(ctx, utils.Retries{ - Config: retryConfig, - StatusCodes: []string{ - "5XX", - }, - }, func() (*http.Response, error) { - if req.Body != nil { - copyBody, err := req.GetBody() - if err != nil { - return nil, err - } - req.Body = copyBody - } - - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) - if err != nil { - return nil, backoff.Permanent(err) - } - - httpRes, err := s.sdkConfiguration.Client.Do(req) - if err != nil || httpRes == nil { - if err != nil { - err = fmt.Errorf("error sending request: %w", err) - } else { - err = fmt.Errorf("error sending request: no response") - } - - _, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) - } - return httpRes, err - }) + req, err = s.hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + if err != nil { + return nil, err + } + httpRes, err := s.sdkConfiguration.Client.Do(req) + if err != nil || httpRes == nil { if err != nil { - return nil, err + err = fmt.Errorf("error sending request: %w", err) } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } + err = fmt.Errorf("error sending request: no response") } - } else { - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + + _, err = s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + return nil, err + } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { + _httpRes, err := s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) if err != nil { return nil, err + } else if _httpRes != nil { + httpRes = _httpRes } - - httpRes, err = s.sdkConfiguration.Client.Do(req) - if err != nil || httpRes == nil { - if err != nil { - err = fmt.Errorf("error sending request: %w", err) - } else { - err = fmt.Errorf("error sending request: no response") - } - - _, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + } else { + httpRes, err = s.hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) + if err != nil { return nil, err - } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { - _httpRes, err := s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) - if err != nil { - return nil, err - } else if _httpRes != nil { - httpRes = _httpRes - } - } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } } } @@ -367,16 +272,8 @@ func (s *PublicLinks) GeneratePublicLink(ctx context.Context, request operations // ListPublicLinksForFile - listPublicLinksForFile // Not yet implemented; This API would fetch all the public links that are previously generated for a file func (s *PublicLinks) ListPublicLinksForFile(ctx context.Context, request operations.ListPublicLinksForFileRequest, opts ...operations.Option) (*operations.ListPublicLinksForFileResponse, error) { - hookCtx := hooks.HookContext{ - Context: ctx, - OperationID: "listPublicLinksForFile", - OAuth2Scopes: []string{}, - SecuritySource: s.sdkConfiguration.Security, - } - o := operations.Options{} supportedOptions := []string{ - operations.SupportedOptionRetries, operations.SupportedOptionTimeout, } @@ -386,12 +283,27 @@ func (s *PublicLinks) ListPublicLinksForFile(ctx context.Context, request operat } } - baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + var baseURL string + if o.ServerURL == nil { + baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + } else { + baseURL = *o.ServerURL + } opURL, err := utils.GenerateURL(ctx, baseURL, "/v1/files/{id}/public/links", request, nil) if err != nil { return nil, fmt.Errorf("error generating URL: %w", err) } + hookCtx := hooks.HookContext{ + SDK: s.rootSDK, + SDKConfiguration: s.sdkConfiguration, + BaseURL: baseURL, + Context: ctx, + OperationID: "listPublicLinksForFile", + OAuth2Scopes: nil, + SecuritySource: s.sdkConfiguration.Security, + } + timeout := o.Timeout if timeout == nil { timeout = s.sdkConfiguration.Timeout @@ -414,94 +326,36 @@ func (s *PublicLinks) ListPublicLinksForFile(ctx context.Context, request operat return nil, err } - globalRetryConfig := s.sdkConfiguration.RetryConfig - retryConfig := o.Retries - if retryConfig == nil { - if globalRetryConfig != nil { - retryConfig = globalRetryConfig - } else { - retryConfig = &retry.Config{ - Strategy: "backoff", Backoff: &retry.BackoffStrategy{ - InitialInterval: 5000, - MaxInterval: 60000, - Exponent: 1.5, - MaxElapsedTime: 3600000, - }, - RetryConnectionErrors: true, - } - } + for k, v := range o.SetHeaders { + req.Header.Set(k, v) } - var httpRes *http.Response - if retryConfig != nil { - httpRes, err = utils.Retry(ctx, utils.Retries{ - Config: retryConfig, - StatusCodes: []string{ - "5XX", - }, - }, func() (*http.Response, error) { - if req.Body != nil { - copyBody, err := req.GetBody() - if err != nil { - return nil, err - } - req.Body = copyBody - } - - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) - if err != nil { - return nil, backoff.Permanent(err) - } - - httpRes, err := s.sdkConfiguration.Client.Do(req) - if err != nil || httpRes == nil { - if err != nil { - err = fmt.Errorf("error sending request: %w", err) - } else { - err = fmt.Errorf("error sending request: no response") - } - - _, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) - } - return httpRes, err - }) + req, err = s.hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + if err != nil { + return nil, err + } + httpRes, err := s.sdkConfiguration.Client.Do(req) + if err != nil || httpRes == nil { if err != nil { - return nil, err + err = fmt.Errorf("error sending request: %w", err) } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } + err = fmt.Errorf("error sending request: no response") } - } else { - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + + _, err = s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + return nil, err + } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { + _httpRes, err := s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) if err != nil { return nil, err + } else if _httpRes != nil { + httpRes = _httpRes } - - httpRes, err = s.sdkConfiguration.Client.Do(req) - if err != nil || httpRes == nil { - if err != nil { - err = fmt.Errorf("error sending request: %w", err) - } else { - err = fmt.Errorf("error sending request: no response") - } - - _, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + } else { + httpRes, err = s.hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) + if err != nil { return nil, err - } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { - _httpRes, err := s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) - if err != nil { - return nil, err - } else if _httpRes != nil { - httpRes = _httpRes - } - } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } } } @@ -548,16 +402,8 @@ func (s *PublicLinks) ListPublicLinksForFile(ctx context.Context, request operat // RevokePublicLink - revokePublicLink // Not yet implemented; This operation would revoke a given public link by ID func (s *PublicLinks) RevokePublicLink(ctx context.Context, request operations.RevokePublicLinkRequest, opts ...operations.Option) (*operations.RevokePublicLinkResponse, error) { - hookCtx := hooks.HookContext{ - Context: ctx, - OperationID: "revokePublicLink", - OAuth2Scopes: []string{}, - SecuritySource: s.sdkConfiguration.Security, - } - o := operations.Options{} supportedOptions := []string{ - operations.SupportedOptionRetries, operations.SupportedOptionTimeout, } @@ -567,12 +413,27 @@ func (s *PublicLinks) RevokePublicLink(ctx context.Context, request operations.R } } - baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + var baseURL string + if o.ServerURL == nil { + baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + } else { + baseURL = *o.ServerURL + } opURL, err := utils.GenerateURL(ctx, baseURL, "/v1/files/public/links/{id}", request, nil) if err != nil { return nil, fmt.Errorf("error generating URL: %w", err) } + hookCtx := hooks.HookContext{ + SDK: s.rootSDK, + SDKConfiguration: s.sdkConfiguration, + BaseURL: baseURL, + Context: ctx, + OperationID: "revokePublicLink", + OAuth2Scopes: nil, + SecuritySource: s.sdkConfiguration.Security, + } + timeout := o.Timeout if timeout == nil { timeout = s.sdkConfiguration.Timeout @@ -595,94 +456,36 @@ func (s *PublicLinks) RevokePublicLink(ctx context.Context, request operations.R return nil, err } - globalRetryConfig := s.sdkConfiguration.RetryConfig - retryConfig := o.Retries - if retryConfig == nil { - if globalRetryConfig != nil { - retryConfig = globalRetryConfig - } else { - retryConfig = &retry.Config{ - Strategy: "backoff", Backoff: &retry.BackoffStrategy{ - InitialInterval: 5000, - MaxInterval: 60000, - Exponent: 1.5, - MaxElapsedTime: 3600000, - }, - RetryConnectionErrors: true, - } - } + for k, v := range o.SetHeaders { + req.Header.Set(k, v) } - var httpRes *http.Response - if retryConfig != nil { - httpRes, err = utils.Retry(ctx, utils.Retries{ - Config: retryConfig, - StatusCodes: []string{ - "5XX", - }, - }, func() (*http.Response, error) { - if req.Body != nil { - copyBody, err := req.GetBody() - if err != nil { - return nil, err - } - req.Body = copyBody - } - - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) - if err != nil { - return nil, backoff.Permanent(err) - } - - httpRes, err := s.sdkConfiguration.Client.Do(req) - if err != nil || httpRes == nil { - if err != nil { - err = fmt.Errorf("error sending request: %w", err) - } else { - err = fmt.Errorf("error sending request: no response") - } - - _, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) - } - return httpRes, err - }) + req, err = s.hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + if err != nil { + return nil, err + } + httpRes, err := s.sdkConfiguration.Client.Do(req) + if err != nil || httpRes == nil { if err != nil { - return nil, err + err = fmt.Errorf("error sending request: %w", err) } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } + err = fmt.Errorf("error sending request: no response") } - } else { - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + + _, err = s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + return nil, err + } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { + _httpRes, err := s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) if err != nil { return nil, err + } else if _httpRes != nil { + httpRes = _httpRes } - - httpRes, err = s.sdkConfiguration.Client.Do(req) - if err != nil || httpRes == nil { - if err != nil { - err = fmt.Errorf("error sending request: %w", err) - } else { - err = fmt.Errorf("error sending request: no response") - } - - _, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + } else { + httpRes, err = s.hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) + if err != nil { return nil, err - } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { - _httpRes, err := s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) - if err != nil { - return nil, err - } else if _httpRes != nil { - httpRes = _httpRes - } - } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } } } diff --git a/internal/sdk/retry/config.go b/internal/sdk/retry/config.go index c051b0a..aa809fc 100644 --- a/internal/sdk/retry/config.go +++ b/internal/sdk/retry/config.go @@ -2,6 +2,15 @@ package retry +import ( + "errors" + "net/http" + "strconv" + "time" +) + +// BackoffStrategy defines the parameters for exponential backoff. This can be +// used to drive a retry loop for example. type BackoffStrategy struct { InitialInterval int MaxInterval int @@ -9,8 +18,131 @@ type BackoffStrategy struct { MaxElapsedTime int } +// Config configures a retry policy. type Config struct { + // Strategy sets the algorithm to use for a retry loop. It can be one of: + // - "backoff": retry with exponential backoff and random jitter. + // - "none" or "": disables retries. Strategy string Backoff *BackoffStrategy RetryConnectionErrors bool } + +// PermanentError is an error that signals that some operation has terminally +// failed and should not be retried. +type PermanentError struct { + cause error +} + +// Permanent creates a PermanentError that signals to a retry loop that it +// should stop retrying an operation and return the underlying error. +func Permanent(cause error) error { + if IsPermanentError(cause) { + return cause + } + + return &PermanentError{ + cause: cause, + } +} + +func (e *PermanentError) Error() string { + return e.cause.Error() +} + +func (e *PermanentError) Unwrap() error { + return e.cause +} + +// TemporaryError represents a retryable error and signals to a retry loop that +// an operation may be retried with an optional wait interval. +type TemporaryError struct { + wait time.Duration + message string +} + +// Temporary creates a TemporaryError that signals to a retry loop that an +// operation can be retried. The error may also carry details about how long to +// wait before retrying. This wait interval may be used to override the retry +// policy in use. +func Temporary(message string) error { + return &TemporaryError{ + message: message, + } +} + +// TemporaryFromResponse creates a TemporaryError similar to Temporary but +// additionally parses the Retry-After header from a response to determine the +// wait interval before the next retry attempt. +func TemporaryFromResponse(message string, res *http.Response) error { + return &TemporaryError{ + wait: retryIntervalFromResponse(res), + message: message, + } +} + +func (e *TemporaryError) Error() string { + return e.message +} + +// RetryAfter returns the time to wait before retrying the request. The zero +// value should be interpreted by retry loops to mean they should fallback on +// their default policy whether expenonential, constant backoff or something +// else. It does not mean that an operation should be retried immediately. +func (e *TemporaryError) RetryAfter() time.Duration { + return e.wait +} + +func retryIntervalFromResponse(res *http.Response) time.Duration { + if res == nil { + return 0 + } + + retryVal := res.Header.Get("retry-after") + if retryVal == "" { + return 0 + } + + parsedNumber, err := strconv.ParseInt(retryVal, 10, 64) + if err == nil { + if parsedNumber < 0 { + return 0 + } else { + return time.Duration(parsedNumber) * time.Second + } + } + + parsedDate, err := time.Parse(time.RFC1123, retryVal) + if err == nil { + delta := parsedDate.Sub(time.Now()) + if delta < 0 { + return 0 + } else { + return delta + } + } + + return 0 +} + +// IsPermanentError returns true if an error value is or contains a +// PermanentError in its chain of errors. +func IsPermanentError(err error) bool { + if err == nil { + return false + } + + var pe *PermanentError + return errors.As(err, &pe) +} + +// IsTemporaryError returns true if an error value is or contains a +// TemporaryError in its chain of errors. +func IsTemporaryError(err error) bool { + if err == nil { + return false + } + + var pe *TemporaryError + return errors.As(err, &pe) +} diff --git a/internal/sdk/sdk.go b/internal/sdk/sdk.go index 465b28f..ffcacaf 100644 --- a/internal/sdk/sdk.go +++ b/internal/sdk/sdk.go @@ -2,9 +2,12 @@ package sdk +// Generated from OpenAPI doc version 1.0.0 and generator version 2.730.5 + import ( "context" "fmt" + "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/internal/config" "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/internal/hooks" "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/internal/utils" "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/models/shared" @@ -18,7 +21,7 @@ var ServerList = []string{ "https://file.sls.epilot.io", } -// HTTPClient provides an interface for suplying the SDK with a custom HTTP client +// HTTPClient provides an interface for supplying the SDK with a custom HTTP client type HTTPClient interface { Do(req *http.Request) (*http.Response, error) } @@ -44,31 +47,14 @@ func Float64(f float64) *float64 { return &f } // Pointer provides a helper function to return a pointer to a type func Pointer[T any](v T) *T { return &v } -type sdkConfiguration struct { - Client HTTPClient - Security func(context.Context) (interface{}, error) - ServerURL string - ServerIndex int - Language string - OpenAPIDocVersion string - SDKVersion string - GenVersion string - UserAgent string - RetryConfig *retry.Config - Hooks *hooks.Hooks - Timeout *time.Duration -} - -func (c *sdkConfiguration) GetServerDetails() (string, map[string]string) { - if c.ServerURL != "" { - return c.ServerURL, nil - } - - return ServerList[c.ServerIndex], nil -} - // SDK - File API: Upload and manage epilot Files +// +// ## Changelog +// View API Changelog type SDK struct { + SDKVersion string + // Folder management for organizing files within entities + FileFolders *FileFolders // Deprecated APIs Deprecated *Deprecated // Upload and Manage File Entities @@ -80,7 +66,8 @@ type SDK struct { // Session API for cookie authentication Session *Session - sdkConfiguration sdkConfiguration + sdkConfiguration config.SDKConfiguration + hooks *hooks.Hooks } type SDKOption func(*SDK) @@ -153,14 +140,12 @@ func WithTimeout(timeout time.Duration) SDKOption { // New creates a new instance of the SDK with the provided options func New(opts ...SDKOption) *SDK { sdk := &SDK{ - sdkConfiguration: sdkConfiguration{ - Language: "go", - OpenAPIDocVersion: "0.2.0", - SDKVersion: "0.0.1", - GenVersion: "2.438.15", - UserAgent: "speakeasy-sdk/go 0.0.1 2.438.15 0.2.0 github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk", - Hooks: hooks.New(), + SDKVersion: "0.6.0", + sdkConfiguration: config.SDKConfiguration{ + UserAgent: "speakeasy-sdk/terraform 0.6.0 2.730.5 1.0.0 github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk", + ServerList: ServerList, }, + hooks: hooks.New(), } for _, opt := range opts { opt(sdk) @@ -173,20 +158,17 @@ func New(opts ...SDKOption) *SDK { currentServerURL, _ := sdk.sdkConfiguration.GetServerDetails() serverURL := currentServerURL - serverURL, sdk.sdkConfiguration.Client = sdk.sdkConfiguration.Hooks.SDKInit(currentServerURL, sdk.sdkConfiguration.Client) - if serverURL != currentServerURL { + serverURL, sdk.sdkConfiguration.Client = sdk.hooks.SDKInit(currentServerURL, sdk.sdkConfiguration.Client) + if currentServerURL != serverURL { sdk.sdkConfiguration.ServerURL = serverURL } - sdk.Deprecated = newDeprecated(sdk.sdkConfiguration) - - sdk.File = newFile(sdk.sdkConfiguration) - - sdk.PublicLinks = newPublicLinks(sdk.sdkConfiguration) - - sdk.Preview = newPreview(sdk.sdkConfiguration) - - sdk.Session = newSession(sdk.sdkConfiguration) + sdk.FileFolders = newFileFolders(sdk, sdk.sdkConfiguration, sdk.hooks) + sdk.Deprecated = newDeprecated(sdk, sdk.sdkConfiguration, sdk.hooks) + sdk.File = newFile(sdk, sdk.sdkConfiguration, sdk.hooks) + sdk.PublicLinks = newPublicLinks(sdk, sdk.sdkConfiguration, sdk.hooks) + sdk.Preview = newPreview(sdk, sdk.sdkConfiguration, sdk.hooks) + sdk.Session = newSession(sdk, sdk.sdkConfiguration, sdk.hooks) return sdk } diff --git a/internal/sdk/session.go b/internal/sdk/session.go index e802025..d753723 100644 --- a/internal/sdk/session.go +++ b/internal/sdk/session.go @@ -5,40 +5,35 @@ package sdk import ( "context" "fmt" - "github.com/cenkalti/backoff/v4" + "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/internal/config" "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/internal/hooks" "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/internal/utils" "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/models/errors" "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/models/operations" - "github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk/retry" "net/http" "net/url" ) // Session API for cookie authentication type Session struct { - sdkConfiguration sdkConfiguration + rootSDK *SDK + sdkConfiguration config.SDKConfiguration + hooks *hooks.Hooks } -func newSession(sdkConfig sdkConfiguration) *Session { +func newSession(rootSDK *SDK, sdkConfig config.SDKConfiguration, hooks *hooks.Hooks) *Session { return &Session{ + rootSDK: rootSDK, sdkConfiguration: sdkConfig, + hooks: hooks, } } // DeleteSession - deleteSession // End browser session by deleting token cookie func (s *Session) DeleteSession(ctx context.Context, opts ...operations.Option) (*operations.DeleteSessionResponse, error) { - hookCtx := hooks.HookContext{ - Context: ctx, - OperationID: "deleteSession", - OAuth2Scopes: []string{}, - SecuritySource: s.sdkConfiguration.Security, - } - o := operations.Options{} supportedOptions := []string{ - operations.SupportedOptionRetries, operations.SupportedOptionTimeout, } @@ -48,12 +43,27 @@ func (s *Session) DeleteSession(ctx context.Context, opts ...operations.Option) } } - baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + var baseURL string + if o.ServerURL == nil { + baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + } else { + baseURL = *o.ServerURL + } opURL, err := url.JoinPath(baseURL, "/v1/files/session") if err != nil { return nil, fmt.Errorf("error generating URL: %w", err) } + hookCtx := hooks.HookContext{ + SDK: s.rootSDK, + SDKConfiguration: s.sdkConfiguration, + BaseURL: baseURL, + Context: ctx, + OperationID: "deleteSession", + OAuth2Scopes: nil, + SecuritySource: s.sdkConfiguration.Security, + } + timeout := o.Timeout if timeout == nil { timeout = s.sdkConfiguration.Timeout @@ -76,94 +86,36 @@ func (s *Session) DeleteSession(ctx context.Context, opts ...operations.Option) return nil, err } - globalRetryConfig := s.sdkConfiguration.RetryConfig - retryConfig := o.Retries - if retryConfig == nil { - if globalRetryConfig != nil { - retryConfig = globalRetryConfig - } else { - retryConfig = &retry.Config{ - Strategy: "backoff", Backoff: &retry.BackoffStrategy{ - InitialInterval: 5000, - MaxInterval: 60000, - Exponent: 1.5, - MaxElapsedTime: 3600000, - }, - RetryConnectionErrors: true, - } - } + for k, v := range o.SetHeaders { + req.Header.Set(k, v) } - var httpRes *http.Response - if retryConfig != nil { - httpRes, err = utils.Retry(ctx, utils.Retries{ - Config: retryConfig, - StatusCodes: []string{ - "5XX", - }, - }, func() (*http.Response, error) { - if req.Body != nil { - copyBody, err := req.GetBody() - if err != nil { - return nil, err - } - req.Body = copyBody - } - - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) - if err != nil { - return nil, backoff.Permanent(err) - } - - httpRes, err := s.sdkConfiguration.Client.Do(req) - if err != nil || httpRes == nil { - if err != nil { - err = fmt.Errorf("error sending request: %w", err) - } else { - err = fmt.Errorf("error sending request: no response") - } - - _, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) - } - return httpRes, err - }) + req, err = s.hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + if err != nil { + return nil, err + } + httpRes, err := s.sdkConfiguration.Client.Do(req) + if err != nil || httpRes == nil { if err != nil { - return nil, err + err = fmt.Errorf("error sending request: %w", err) } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } + err = fmt.Errorf("error sending request: no response") } - } else { - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + + _, err = s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + return nil, err + } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { + _httpRes, err := s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) if err != nil { return nil, err + } else if _httpRes != nil { + httpRes = _httpRes } - - httpRes, err = s.sdkConfiguration.Client.Do(req) - if err != nil || httpRes == nil { - if err != nil { - err = fmt.Errorf("error sending request: %w", err) - } else { - err = fmt.Errorf("error sending request: no response") - } - - _, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + } else { + httpRes, err = s.hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) + if err != nil { return nil, err - } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { - _httpRes, err := s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) - if err != nil { - return nil, err - } else if _httpRes != nil { - httpRes = _httpRes - } - } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } } } @@ -192,16 +144,8 @@ func (s *Session) DeleteSession(ctx context.Context, opts ...operations.Option) // // Allows using preview urls directly in img src for private files using cookie authentication. func (s *Session) GetSession(ctx context.Context, opts ...operations.Option) (*operations.GetSessionResponse, error) { - hookCtx := hooks.HookContext{ - Context: ctx, - OperationID: "getSession", - OAuth2Scopes: []string{}, - SecuritySource: s.sdkConfiguration.Security, - } - o := operations.Options{} supportedOptions := []string{ - operations.SupportedOptionRetries, operations.SupportedOptionTimeout, } @@ -211,12 +155,27 @@ func (s *Session) GetSession(ctx context.Context, opts ...operations.Option) (*o } } - baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + var baseURL string + if o.ServerURL == nil { + baseURL = utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + } else { + baseURL = *o.ServerURL + } opURL, err := url.JoinPath(baseURL, "/v1/files/session") if err != nil { return nil, fmt.Errorf("error generating URL: %w", err) } + hookCtx := hooks.HookContext{ + SDK: s.rootSDK, + SDKConfiguration: s.sdkConfiguration, + BaseURL: baseURL, + Context: ctx, + OperationID: "getSession", + OAuth2Scopes: nil, + SecuritySource: s.sdkConfiguration.Security, + } + timeout := o.Timeout if timeout == nil { timeout = s.sdkConfiguration.Timeout @@ -239,94 +198,36 @@ func (s *Session) GetSession(ctx context.Context, opts ...operations.Option) (*o return nil, err } - globalRetryConfig := s.sdkConfiguration.RetryConfig - retryConfig := o.Retries - if retryConfig == nil { - if globalRetryConfig != nil { - retryConfig = globalRetryConfig - } else { - retryConfig = &retry.Config{ - Strategy: "backoff", Backoff: &retry.BackoffStrategy{ - InitialInterval: 5000, - MaxInterval: 60000, - Exponent: 1.5, - MaxElapsedTime: 3600000, - }, - RetryConnectionErrors: true, - } - } + for k, v := range o.SetHeaders { + req.Header.Set(k, v) } - var httpRes *http.Response - if retryConfig != nil { - httpRes, err = utils.Retry(ctx, utils.Retries{ - Config: retryConfig, - StatusCodes: []string{ - "5XX", - }, - }, func() (*http.Response, error) { - if req.Body != nil { - copyBody, err := req.GetBody() - if err != nil { - return nil, err - } - req.Body = copyBody - } - - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) - if err != nil { - return nil, backoff.Permanent(err) - } - - httpRes, err := s.sdkConfiguration.Client.Do(req) - if err != nil || httpRes == nil { - if err != nil { - err = fmt.Errorf("error sending request: %w", err) - } else { - err = fmt.Errorf("error sending request: no response") - } - - _, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) - } - return httpRes, err - }) + req, err = s.hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + if err != nil { + return nil, err + } + httpRes, err := s.sdkConfiguration.Client.Do(req) + if err != nil || httpRes == nil { if err != nil { - return nil, err + err = fmt.Errorf("error sending request: %w", err) } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } + err = fmt.Errorf("error sending request: no response") } - } else { - req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req) + + _, err = s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + return nil, err + } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { + _httpRes, err := s.hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) if err != nil { return nil, err + } else if _httpRes != nil { + httpRes = _httpRes } - - httpRes, err = s.sdkConfiguration.Client.Do(req) - if err != nil || httpRes == nil { - if err != nil { - err = fmt.Errorf("error sending request: %w", err) - } else { - err = fmt.Errorf("error sending request: no response") - } - - _, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err) + } else { + httpRes, err = s.hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) + if err != nil { return nil, err - } else if utils.MatchStatusCodes([]string{}, httpRes.StatusCode) { - _httpRes, err := s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil) - if err != nil { - return nil, err - } else if _httpRes != nil { - httpRes = _httpRes - } - } else { - httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes) - if err != nil { - return nil, err - } } } diff --git a/internal/sdk/types/decimal.go b/internal/sdk/types/decimal.go deleted file mode 100644 index d8429bc..0000000 --- a/internal/sdk/types/decimal.go +++ /dev/null @@ -1,20 +0,0 @@ -// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. - -package types - -import ( - "fmt" - - "github.com/ericlagergren/decimal" -) - -// MustNewDecimalFromString returns an instance of Decimal from a string -// Avoid using this function in production code. -func MustNewDecimalFromString(s string) *decimal.Big { - d, ok := new(decimal.Big).SetString(s) - if !ok { - panic(fmt.Errorf("failed to parse string as decimal.Big")) - } - - return d -} diff --git a/internal/validators/float32validators/not_null.go b/internal/validators/float32validators/not_null.go new file mode 100644 index 0000000..c9a8973 --- /dev/null +++ b/internal/validators/float32validators/not_null.go @@ -0,0 +1,49 @@ +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + +package float32validators + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-framework/schema/validator" +) + +var _ validator.Float32 = Float32NotNullValidator{} + +// Float32NotNullValidator validates that an attribute is not null. Most +// attributes should set Required: true instead, however in certain scenarios, +// such as a computed nested attribute, all underlying attributes must also be +// computed for planning to not show unexpected differences. +type Float32NotNullValidator struct{} + +// Description describes the validation in plain text formatting. +func (v Float32NotNullValidator) Description(_ context.Context) string { + return "value must be configured" +} + +// MarkdownDescription describes the validation in Markdown formatting. +func (v Float32NotNullValidator) MarkdownDescription(ctx context.Context) string { + return v.Description(ctx) +} + +// Validate performs the validation. +func (v Float32NotNullValidator) ValidateFloat32(ctx context.Context, req validator.Float32Request, resp *validator.Float32Response) { + if !req.ConfigValue.IsNull() { + return + } + + resp.Diagnostics.AddAttributeError( + req.Path, + "Missing Attribute Value", + req.Path.String()+": "+v.Description(ctx), + ) +} + +// NotNull returns an validator which ensures that the attribute is +// configured. Most attributes should set Required: true instead, however in +// certain scenarios, such as a computed nested attribute, all underlying +// attributes must also be computed for planning to not show unexpected +// differences. +func NotNull() validator.Float32 { + return Float32NotNullValidator{} +} diff --git a/internal/validators/int32validators/not_null.go b/internal/validators/int32validators/not_null.go new file mode 100644 index 0000000..ec9a3f1 --- /dev/null +++ b/internal/validators/int32validators/not_null.go @@ -0,0 +1,49 @@ +// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + +package int32validators + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-framework/schema/validator" +) + +var _ validator.Int32 = Int32NotNullValidator{} + +// Int32NotNullValidator validates that an attribute is not null. Most +// attributes should set Required: true instead, however in certain scenarios, +// such as a computed nested attribute, all underlying attributes must also be +// computed for planning to not show unexpected differences. +type Int32NotNullValidator struct{} + +// Description describes the validation in plain text formatting. +func (v Int32NotNullValidator) Description(_ context.Context) string { + return "value must be configured" +} + +// MarkdownDescription describes the validation in Markdown formatting. +func (v Int32NotNullValidator) MarkdownDescription(ctx context.Context) string { + return v.Description(ctx) +} + +// Validate performs the validation. +func (v Int32NotNullValidator) ValidateInt32(ctx context.Context, req validator.Int32Request, resp *validator.Int32Response) { + if !req.ConfigValue.IsNull() { + return + } + + resp.Diagnostics.AddAttributeError( + req.Path, + "Missing Attribute Value", + req.Path.String()+": "+v.Description(ctx), + ) +} + +// NotNull returns an validator which ensures that the attribute is +// configured. Most attributes should set Required: true instead, however in +// certain scenarios, such as a computed nested attribute, all underlying +// attributes must also be computed for planning to not show unexpected +// differences. +func NotNull() validator.Int32 { + return Int32NotNullValidator{} +}