Skip to content

Commit

Permalink
Add require signature auth (#21)
Browse files Browse the repository at this point in the history
* Update go-sdk to 1.2.0

* Add require_signature_auth parameter to template resource

* Fix

* go fmt

* Update doc
  • Loading branch information
Etienne-Carriere authored Oct 23, 2020
1 parent ba5df0d commit c7b8865
Show file tree
Hide file tree
Showing 12 changed files with 112 additions and 18 deletions.
1 change: 1 addition & 0 deletions docs/resources/template.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ The following arguments are supported:

- `name` - (Required) name of the Template to be added
- `template` - (Required) JSON string of the Template's Assembly Instructions. The top-level object must be the JSON object with a `"steps"` key. For more details, see [Assembly Instructions](https://transloadit.com/docs/#assembly-instructions)
- `require_signature_auth` - (Optional - boolean) Use true to deny requests that do not include a signature. With [Signature Authentication](https://transloadit.com/docs/#signature-authentication) you can ensure no one else is sending requests on your behalf. Default value: false

## Attributes Reference

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ go 1.12

require (
github.com/hashicorp/terraform-plugin-sdk v1.11.0
gopkg.in/transloadit/go-sdk.v1 v1.1.1
gopkg.in/transloadit/go-sdk.v1 v1.2.0
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/cheggaaa/pb.v1 v1.0.27/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw=
gopkg.in/transloadit/go-sdk.v1 v1.1.1 h1:8VU2p+9uHb7mFWvozsmLwubO8dj85x7AlruV70C5Y/M=
gopkg.in/transloadit/go-sdk.v1 v1.1.1/go.mod h1:0r/j+IlqMRif2ZcWiicnvrPu5UwhL7EXQ/UUB9WMU0c=
gopkg.in/transloadit/go-sdk.v1 v1.2.0 h1:wWHRODbLA2OFijm94DVwUH5n5k+kgDWIa+01icHDf2c=
gopkg.in/transloadit/go-sdk.v1 v1.2.0/go.mod h1:0r/j+IlqMRif2ZcWiicnvrPu5UwhL7EXQ/UUB9WMU0c=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
Expand Down
18 changes: 14 additions & 4 deletions transloadit/resource_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ func resourceTemplate() *schema.Resource {
ForceNew: false,
Description: "name",
},
"require_signature_auth": &schema.Schema{
Type: schema.TypeBool,
Optional: true,
ForceNew: false,
Description: "Use true to deny requests that do not include a signature",
Default: false,
},
"template": &schema.Schema{
Type: schema.TypeString,
Required: true,
Expand All @@ -46,8 +53,9 @@ func resourceTemplateCreate(d *schema.ResourceData, meta interface{}) error {
return err
}
payload := transloadit.Template{
Name: d.Get("name").(string),
Content: *templateContent,
Name: d.Get("name").(string),
Content: *templateContent,
RequireSignatureAuth: d.Get("require_signature_auth").(bool),
}
templateId, err := client.CreateTemplate(context.Background(), payload)
if err != nil {
Expand Down Expand Up @@ -75,6 +83,7 @@ func resourceTemplateRead(d *schema.ResourceData, meta interface{}) error {
return fmt.Errorf("Content field can't be marshalled to json +%v", template.Content)
}
d.Set("template", string(result))
d.Set("require_signature_auth", template.RequireSignatureAuth)
return nil
}

Expand All @@ -85,8 +94,9 @@ func resourceTemplateUpdate(d *schema.ResourceData, meta interface{}) error {
return err
}
payload := transloadit.Template{
Name: d.Get("name").(string),
Content: *templateContent,
Name: d.Get("name").(string),
Content: *templateContent,
RequireSignatureAuth: d.Get("require_signature_auth").(bool),
}
err = client.UpdateTemplate(context.Background(), d.Id(), payload)
return err
Expand Down
26 changes: 23 additions & 3 deletions transloadit/resource_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,23 @@ import (

func TestAccTemplate_basic(t *testing.T) {

resource_name := fmt.Sprintf("templatebasic%d", rand.Int()%1000)
randInt := rand.Int() % 1000
template1_name := fmt.Sprintf("templatebasic%d", randInt)
template2_name := fmt.Sprintf("templatebasic%d", randInt+1)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: nil,
Steps: []resource.TestStep{
{
Config: fmt.Sprintf(testAccTemplate_basic_1, resource_name),
Config: fmt.Sprintf(testAccTemplate_basic_1, template1_name, template2_name),
Check: resource.ComposeTestCheckFunc(
testAccCheckExistingResource("transloadit_template.test"),
resource.TestCheckResourceAttr("transloadit_template.test", "name", resource_name),
testAccCheckExistingResource("transloadit_template.require_auth"),
resource.TestCheckResourceAttr("transloadit_template.test", "name", template1_name),
resource.TestCheckResourceAttr("transloadit_template.test", "require_signature_auth", "false"),
resource.TestCheckResourceAttr("transloadit_template.require_auth", "name", template2_name),
resource.TestCheckResourceAttr("transloadit_template.require_auth", "require_signature_auth", "true"),
),
},
},
Expand Down Expand Up @@ -59,4 +65,18 @@ resource "transloadit_template" "test" {
}
EOT
}
resource "transloadit_template" "require_auth" {
name = "%s"
require_signature_auth = true
template = <<EOT
{
"steps": {
":original": {
"robot": "/upload/handle"
}
}
}
EOT
}
`
1 change: 1 addition & 0 deletions vendor/gopkg.in/transloadit/go-sdk.v1/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions vendor/gopkg.in/transloadit/go-sdk.v1/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/gopkg.in/transloadit/go-sdk.v1/Makefile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/gopkg.in/transloadit/go-sdk.v1/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

67 changes: 63 additions & 4 deletions vendor/gopkg.in/transloadit/go-sdk.v1/template.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/gopkg.in/transloadit/go-sdk.v1/version.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -348,5 +348,5 @@ google.golang.org/grpc/stats
google.golang.org/grpc/status
google.golang.org/grpc/tap
google.golang.org/grpc/test/bufconn
# gopkg.in/transloadit/go-sdk.v1 v1.1.1
# gopkg.in/transloadit/go-sdk.v1 v1.2.0
gopkg.in/transloadit/go-sdk.v1

0 comments on commit c7b8865

Please sign in to comment.