Skip to content

Commit

Permalink
update versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Nishu Goel committed Aug 27, 2024
1 parent 9b8da98 commit aa0e6fc
Show file tree
Hide file tree
Showing 19 changed files with 166 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .speakeasy/gen.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,6 @@ TF_REATTACH_PROVIDERS=... terraform apply
```
<!-- End SDK Example Usage [usage] -->

<!-- Start Available Resources and Operations [operations] -->
## Available Resources and Operations


<!-- End Available Resources and Operations [operations] -->

<!-- Placeholder for Future Speakeasy SDK Sections -->

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.
Expand Down
1 change: 1 addition & 0 deletions docs/data-sources/file.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
1 change: 1 addition & 0 deletions docs/resources/file.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
37 changes: 29 additions & 8 deletions examples/resources/epilot-file_file-import/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
19 changes: 19 additions & 0 deletions examples/test/file.tf
Original file line number Diff line number Diff line change
@@ -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"
}
30 changes: 30 additions & 0 deletions examples/test/res.tf
Original file line number Diff line number Diff line change
@@ -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"
}
5 changes: 5 additions & 0 deletions internal/provider/file_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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`,
Expand Down
4 changes: 4 additions & 0 deletions internal/provider/file_data_source_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions internal/provider/file_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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`,
Expand Down
9 changes: 9 additions & 0 deletions internal/provider/file_resource_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -77,6 +81,7 @@ func (r *FileResourceModel) ToSharedSaveFilePayloadV2() *shared.SaveFilePayloadV
}
out := shared.SaveFilePayloadV2{
ID: id,
Purpose: purpose,
Tags: tags,
Title: title,
AccessControl: accessControl,
Expand Down Expand Up @@ -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 {
Expand Down
22 changes: 14 additions & 8 deletions internal/sdk/internal/utils/requestbody.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)

Expand All @@ -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:
Expand Down Expand Up @@ -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)
Expand All @@ -226,23 +228,27 @@ 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")
}

fw, err := w.CreateFormFile(fieldName, fileName)
if err != nil {
return err
}
if _, err := fw.Write(content); err != nil {
if _, err := io.Copy(fw, reader); err != nil {
return err
}

Expand Down
8 changes: 8 additions & 0 deletions internal/sdk/models/shared/fileentity.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions internal/sdk/models/shared/savecustomfilepayload.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions internal/sdk/models/shared/savefilefromsourceurlpayload.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions internal/sdk/models/shared/savefilepayloadv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions internal/sdk/models/shared/saves3filepayload.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit aa0e6fc

Please sign in to comment.