diff --git a/.speakeasy/gen.lock b/.speakeasy/gen.lock index f330d93..ccbe7e1 100755 --- a/.speakeasy/gen.lock +++ b/.speakeasy/gen.lock @@ -15,7 +15,7 @@ features: additionalDependencies: 0.1.0 additionalProperties: 0.1.2 constsAndDefaults: 0.1.4 - core: 3.24.6 + core: 3.24.7 deprecations: 2.81.1 envVarSecurityUsage: 0.1.0 globalSecurity: 2.81.8 diff --git a/README.md b/README.md index ebfdcbc..609a694 100644 --- a/README.md +++ b/README.md @@ -91,12 +91,6 @@ TF_REATTACH_PROVIDERS=... terraform apply ``` - -## Available Resources and Operations - - - - Terraform allows you to use local provider builds by setting a `dev_overrides` block in a configuration file called `.terraformrc`. This block overrides all other configured installation methods. diff --git a/docs/data-sources/file.md b/docs/data-sources/file.md index 5cd6133..c2bd2a4 100644 --- a/docs/data-sources/file.md +++ b/docs/data-sources/file.md @@ -32,6 +32,7 @@ data "epilot-file_file" "my_file" { - `mime_type` (String) MIME type of the file - `org` (String) - `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) must be one of ["file"] diff --git a/docs/resources/file.md b/docs/resources/file.md index b0bc5f4..88c32d6 100644 --- a/docs/resources/file.md +++ b/docs/resources/file.md @@ -34,6 +34,7 @@ resource "epilot-file_file" "my_file" { - `custom_download_url` (String) Custom external download url used for the file - `filename` (String) - `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 - `tags` (List of String) diff --git a/examples/resources/epilot-file_file-import/resource.tf b/examples/resources/epilot-file_file-import/resource.tf index 308b194..ba972a5 100644 --- a/examples/resources/epilot-file_file-import/resource.tf +++ b/examples/resources/epilot-file_file-import/resource.tf @@ -7,11 +7,32 @@ # } # epilot-file_file.my_file: -# resource "epilot-file_file" "my_file" { -# access_control = "private" -# filename = "8z87al.jpg" -# mime_type = "image/jpeg" -# source_url = "https://file.dev.sls.epilot.io/v1/files/public/links/739224-taqDBUyNjSX7c_n2v6Zvv/8z87al.jpg" -# title = "8z87al.jpg" -# type = "image" -# } +resource "epilot-file_file" "my_file" { + access_control = "private" + filename = "8z87al.jpg" + mime_type = "image/jpeg" + source_url = "https://file.dev.sls.epilot.io/v1/files/public/links/739224-taqDBUyNjSX7c_n2v6Zvv/8z87al.jpg" + title = "8z87al.jpg" + type = "image" +} + +terraform { + required_providers { + epilot-file = { + source = "epilot-dev/epilot-file" + version = "2.1.1" + } + } +} + +variable "epilot_auth" { + type = string + description = "epilot_auth" +} + + +provider "epilot-file" { + # Configuration options + epilot_auth = var.epilot_auth + server_url = "https://file.dev.sls.epilot.io" +} diff --git a/examples/test/file.tf b/examples/test/file.tf new file mode 100644 index 0000000..0928321 --- /dev/null +++ b/examples/test/file.tf @@ -0,0 +1,19 @@ +# epilot-file_file.my_file: +resource "epilot-file_file" "my_file" { + access_control = "private" + custom_download_url = "https://ucarecdn.com/05f649bf-b70b-4cf8-90f7-2588ce404a08/-/format/auto/" + filename = "3rd-party-api-flow.jpg" + mime_type = "image/jpeg" + purpose = [ + "22fba2b3-9e40-40c1-bb06-e9cd20cea6cf", + "c12409a0-770a-4009-b725-c84d6f3ccb5b", + ] + s3ref = { + bucket = "epilot-dev-user-content" + key = "739224/7daa1de4-fc77-48b3-8906-8e5a9129be07/3rd-party-api-flow.jpg" + } + source_url = "https://file.dev.sls.epilot.io/v1/files/public/links/739224-yImePD8pFE1k1II0UumDl/3rd-party-api-flow.jpg" + tags = [] + title = "3rd-party-api-flow.jpg" + type = "image" +} diff --git a/examples/test/res.tf b/examples/test/res.tf new file mode 100644 index 0000000..18e9144 --- /dev/null +++ b/examples/test/res.tf @@ -0,0 +1,30 @@ +# epilot-file_file.my_file: +# resource "epilot-file_file" "my_file" { + # access_control = "private" + # filename = "8z87al.jpg" + # mime_type = "image/jpeg" + # source_url = "https://file.dev.sls.epilot.io/v1/files/public/links/739224-taqDBUyNjSX7c_n2v6Zvv/8z87al.jpg" + # title = "8z87al.jpg" + # type = "image" +# } + +terraform { + required_providers { + epilot-file = { + source = "epilot-dev/epilot-file" + version = "2.1.1" + } + } +} + +variable "epilot_auth" { + type = string + description = "epilot_auth" +} + + +provider "epilot-file" { + # Configuration options + epilot_auth = var.epilot_auth + server_url = "https://file.sls.epilot.io" +} diff --git a/internal/provider/file_data_source.go b/internal/provider/file_data_source.go index 587c39b..cb538dc 100644 --- a/internal/provider/file_data_source.go +++ b/internal/provider/file_data_source.go @@ -38,6 +38,7 @@ type FileDataSourceModel struct { MimeType types.String `tfsdk:"mime_type"` Org types.String `tfsdk:"org"` 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"` @@ -107,6 +108,10 @@ func (r *FileDataSource) Schema(ctx context.Context, req datasource.SchemaReques 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`, diff --git a/internal/provider/file_data_source_sdk.go b/internal/provider/file_data_source_sdk.go index 403f314..f3a7ed6 100644 --- a/internal/provider/file_data_source_sdk.go +++ b/internal/provider/file_data_source_sdk.go @@ -34,6 +34,10 @@ func (r *FileDataSourceModel) RefreshFromSharedFileEntity(resp *shared.FileEntit r.CreatedAt = types.StringNull() } r.Org = types.StringPointerValue(resp.Org) + 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 { diff --git a/internal/provider/file_resource.go b/internal/provider/file_resource.go index 7b69441..ab34236 100644 --- a/internal/provider/file_resource.go +++ b/internal/provider/file_resource.go @@ -44,6 +44,7 @@ type FileResourceModel struct { MimeType types.String `tfsdk:"mime_type"` Org types.String `tfsdk:"org"` 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"` @@ -125,6 +126,11 @@ func (r *FileResource) Schema(ctx context.Context, req resource.SchemaRequest, r Computed: true, Description: `Direct URL for file (public only if file access control is public-read)`, }, + "purpose": schema.ListAttribute{ + Computed: true, + Optional: true, + ElementType: types.StringType, + }, "readable_size": schema.StringAttribute{ Computed: true, Description: `Human readable file size`, diff --git a/internal/provider/file_resource_sdk.go b/internal/provider/file_resource_sdk.go index 764a794..bc9e395 100644 --- a/internal/provider/file_resource_sdk.go +++ b/internal/provider/file_resource_sdk.go @@ -16,6 +16,10 @@ func (r *FileResourceModel) ToSharedSaveFilePayloadV2() *shared.SaveFilePayloadV } else { id = nil } + 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()) @@ -77,6 +81,7 @@ func (r *FileResourceModel) ToSharedSaveFilePayloadV2() *shared.SaveFilePayloadV } out := shared.SaveFilePayloadV2{ ID: id, + Purpose: purpose, Tags: tags, Title: title, AccessControl: accessControl, @@ -116,6 +121,10 @@ func (r *FileResourceModel) RefreshFromSharedFileEntity(resp *shared.FileEntity) } r.ID = types.StringPointerValue(resp.ID) r.Org = types.StringPointerValue(resp.Org) + 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 { diff --git a/internal/sdk/internal/utils/requestbody.go b/internal/sdk/internal/utils/requestbody.go index 0fd33cf..cee9da2 100644 --- a/internal/sdk/internal/utils/requestbody.go +++ b/internal/sdk/internal/utils/requestbody.go @@ -82,7 +82,7 @@ func serializeRequestBody(request interface{}, nullable, optional bool, requestF return serializeContentType(requestFieldName, SerializationMethodToContentType[serializationMethod], reflect.ValueOf(request), tag) } -func serializeContentType(fieldName string, mediaType string, val reflect.Value, tag string) (*bytes.Buffer, string, error) { +func serializeContentType(fieldName string, mediaType string, val reflect.Value, tag string) (io.Reader, string, error) { buf := &bytes.Buffer{} if isNil(val.Type(), val) { @@ -116,6 +116,8 @@ func serializeContentType(fieldName string, mediaType string, val reflect.Value, if err := encodeFormData(fieldName, buf, val.Interface()); err != nil { return nil, "", err } + case val.Type().Implements(reflect.TypeOf((*io.Reader)(nil)).Elem()): + return val.Interface().(io.Reader), mediaType, nil default: val = reflect.Indirect(val) @@ -124,8 +126,8 @@ func serializeContentType(fieldName string, mediaType string, val reflect.Value, if _, err := buf.WriteString(valToString(val.Interface())); err != nil { return nil, "", err } - case val.Type() == reflect.TypeOf([]byte(nil)): - if _, err := buf.Write(val.Bytes()); err != nil { + case reflect.TypeOf(val.Interface()) == reflect.TypeOf([]byte(nil)): + if _, err := buf.Write(val.Interface().([]byte)); err != nil { return nil, "", err } default: @@ -215,7 +217,7 @@ func encodeMultipartFormDataFile(w *multipart.Writer, fieldType reflect.Type, va var fieldName string var fileName string - var content []byte + var reader io.Reader for i := 0; i < fieldType.NumField(); i++ { field := fieldType.Field(i) @@ -226,15 +228,19 @@ func encodeMultipartFormDataFile(w *multipart.Writer, fieldType reflect.Type, va continue } - if tag.Content { - content = val.Bytes() + if tag.Content && val.CanInterface() { + if reflect.TypeOf(val.Interface()) == reflect.TypeOf([]byte(nil)) { + reader = bytes.NewReader(val.Interface().([]byte)) + } else if reflect.TypeOf(val.Interface()).Implements(reflect.TypeOf((*io.Reader)(nil)).Elem()) { + reader = val.Interface().(io.Reader) + } } else { fieldName = tag.Name fileName = val.String() } } - if fieldName == "" || fileName == "" || content == nil { + if fieldName == "" || fileName == "" || reader == nil { return fmt.Errorf("invalid multipart/form-data file") } @@ -242,7 +248,7 @@ func encodeMultipartFormDataFile(w *multipart.Writer, fieldType reflect.Type, va if err != nil { return err } - if _, err := fw.Write(content); err != nil { + if _, err := io.Copy(fw, reader); err != nil { return err } diff --git a/internal/sdk/models/shared/fileentity.go b/internal/sdk/models/shared/fileentity.go index 47c9370..afb85af 100644 --- a/internal/sdk/models/shared/fileentity.go +++ b/internal/sdk/models/shared/fileentity.go @@ -92,6 +92,7 @@ type FileEntity struct { CreatedAt *time.Time `json:"_created_at,omitempty"` ID *string `json:"_id,omitempty"` Org *string `json:"_org,omitempty"` + Purpose []string `json:"_purpose,omitempty"` Schema *Schema `json:"_schema,omitempty"` Tags []string `json:"_tags,omitempty"` Title *string `json:"_title,omitempty"` @@ -154,6 +155,13 @@ func (o *FileEntity) GetOrg() *string { return o.Org } +func (o *FileEntity) GetPurpose() []string { + if o == nil { + return nil + } + return o.Purpose +} + func (o *FileEntity) GetSchema() *Schema { if o == nil { return nil diff --git a/internal/sdk/models/shared/savecustomfilepayload.go b/internal/sdk/models/shared/savecustomfilepayload.go index da81f72..adf06b5 100644 --- a/internal/sdk/models/shared/savecustomfilepayload.go +++ b/internal/sdk/models/shared/savecustomfilepayload.go @@ -37,6 +37,7 @@ func (e *SaveCustomFilePayloadAccessControl) UnmarshalJSON(data []byte) error { type SaveCustomFilePayload struct { AdditionalProperties any `additionalProperties:"true" json:"-"` ID *string `json:"_id,omitempty"` + Purpose []string `json:"_purpose,omitempty"` Tags []string `json:"_tags,omitempty"` AccessControl *SaveCustomFilePayloadAccessControl `default:"private" json:"access_control"` // Custom external download url used for the file @@ -78,6 +79,13 @@ func (o *SaveCustomFilePayload) GetID() *string { return o.ID } +func (o *SaveCustomFilePayload) GetPurpose() []string { + if o == nil { + return nil + } + return o.Purpose +} + func (o *SaveCustomFilePayload) GetTags() []string { if o == nil { return nil diff --git a/internal/sdk/models/shared/savefilefromsourceurlpayload.go b/internal/sdk/models/shared/savefilefromsourceurlpayload.go index 35a266e..95685c7 100644 --- a/internal/sdk/models/shared/savefilefromsourceurlpayload.go +++ b/internal/sdk/models/shared/savefilefromsourceurlpayload.go @@ -37,6 +37,7 @@ func (e *SaveFileFromSourceURLPayloadAccessControl) UnmarshalJSON(data []byte) e type SaveFileFromSourceURLPayload struct { AdditionalProperties any `additionalProperties:"true" json:"-"` ID *string `json:"_id,omitempty"` + Purpose []string `json:"_purpose,omitempty"` Tags []string `json:"_tags,omitempty"` AccessControl *SaveFileFromSourceURLPayloadAccessControl `default:"private" json:"access_control"` // Custom external download url used for the file @@ -80,6 +81,13 @@ func (o *SaveFileFromSourceURLPayload) GetID() *string { return o.ID } +func (o *SaveFileFromSourceURLPayload) GetPurpose() []string { + if o == nil { + return nil + } + return o.Purpose +} + func (o *SaveFileFromSourceURLPayload) GetTags() []string { if o == nil { return nil diff --git a/internal/sdk/models/shared/savefilepayloadv2.go b/internal/sdk/models/shared/savefilepayloadv2.go index 01a0e92..8aed1c1 100644 --- a/internal/sdk/models/shared/savefilepayloadv2.go +++ b/internal/sdk/models/shared/savefilepayloadv2.go @@ -36,6 +36,7 @@ func (e *SaveFilePayloadV2AccessControl) UnmarshalJSON(data []byte) error { type SaveFilePayloadV2 struct { ID *string `json:"_id,omitempty"` + Purpose []string `json:"_purpose,omitempty"` Tags []string `json:"_tags,omitempty"` Title *string `json:"_title,omitempty"` AccessControl *SaveFilePayloadV2AccessControl `default:"private" json:"access_control"` @@ -68,6 +69,13 @@ func (o *SaveFilePayloadV2) GetID() *string { return o.ID } +func (o *SaveFilePayloadV2) GetPurpose() []string { + if o == nil { + return nil + } + return o.Purpose +} + func (o *SaveFilePayloadV2) GetTags() []string { if o == nil { return nil diff --git a/internal/sdk/models/shared/saves3filepayload.go b/internal/sdk/models/shared/saves3filepayload.go index d0958ee..15f44a4 100644 --- a/internal/sdk/models/shared/saves3filepayload.go +++ b/internal/sdk/models/shared/saves3filepayload.go @@ -37,6 +37,7 @@ func (e *SaveS3FilePayloadAccessControl) UnmarshalJSON(data []byte) error { type SaveS3FilePayload struct { AdditionalProperties any `additionalProperties:"true" json:"-"` ID *string `json:"_id,omitempty"` + Purpose []string `json:"_purpose,omitempty"` Tags []string `json:"_tags,omitempty"` AccessControl *SaveS3FilePayloadAccessControl `default:"private" json:"access_control"` // Custom external download url used for the file @@ -79,6 +80,13 @@ func (o *SaveS3FilePayload) GetID() *string { return o.ID } +func (o *SaveS3FilePayload) GetPurpose() []string { + if o == nil { + return nil + } + return o.Purpose +} + func (o *SaveS3FilePayload) GetTags() []string { if o == nil { return nil diff --git a/internal/sdk/sdk.go b/internal/sdk/sdk.go index db1037d..a0d87bd 100644 --- a/internal/sdk/sdk.go +++ b/internal/sdk/sdk.go @@ -154,8 +154,8 @@ func New(opts ...SDKOption) *SDK { Language: "go", OpenAPIDocVersion: "0.2.0", SDKVersion: "0.0.1", - GenVersion: "2.396.0", - UserAgent: "speakeasy-sdk/go 0.0.1 2.396.0 0.2.0 github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk", + GenVersion: "2.404.3", + UserAgent: "speakeasy-sdk/go 0.0.1 2.404.3 0.2.0 github.com/epilot-dev/terraform-provider-epilot-file/internal/sdk", Hooks: hooks.New(), }, } diff --git a/openapi.yml b/openapi.yml index cf0963f..942825c 100644 --- a/openapi.yml +++ b/openapi.yml @@ -709,6 +709,11 @@ components: items: type: string example: ["tag1", "tag2"] + _purpose: + type: array + items: + type: string + example: ["8d396871-95a0-4c9d-bb4d-9eda9c35776c", "da7cdf9a-01be-40c9-a29c-9a8f9f0de6f8"] filename: type: string example: document.pdf