Skip to content

Commit

Permalink
Support github actions (#4)
Browse files Browse the repository at this point in the history
* Support github actions

* fix directory

* fix

* fix

* add go.mod

* fix

* fix go.mod

* fix

* fix example

* fix filename

* fix pkg

* fix status badge
  • Loading branch information
kyokomi authored Feb 23, 2023
1 parent c63040f commit 3e00b14
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 27 deletions.
16 changes: 0 additions & 16 deletions .circleci/config.yml

This file was deleted.

20 changes: 20 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: go

on: [push]

jobs:
build_and_test:
timeout-minutes: 15
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
- run: go version
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: latest
- run: go test -v -coverprofile=profile.cov ./...
- uses: shogo82148/actions-goveralls@v1
with:
path-to-profile: profile.cov
4 changes: 0 additions & 4 deletions Makefile

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
s3gopolicy
=========================================

[![CircleCI](https://circleci.com/gh/kyokomi/s3gopolicy/tree/master.svg?style=svg)](https://circleci.com/gh/kyokomi/s3gopolicy/tree/master) [![codecov](https://codecov.io/gh/kyokomi/s3gopolicy/branch/master/graph/badge.svg)](https://codecov.io/gh/kyokomi/s3gopolicy)
[![go](https://github.com/kyokomi/s3gopolicy/actions/workflows/go.yml/badge.svg)](https://github.com/kyokomi/s3gopolicy/actions/workflows/go.yml) [![codecov](https://codecov.io/gh/kyokomi/s3gopolicy/branch/master/graph/badge.svg)](https://codecov.io/gh/kyokomi/s3gopolicy)

Authenticating Requests in Browser-Based Uploads Using POST (AWS Signature Version 2 or 4) for golang

Expand Down
11 changes: 11 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module github.com/kyokomi/s3gopolicy

go 1.19

require github.com/stretchr/testify v1.8.1

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
17 changes: 17 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
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/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
36 changes: 30 additions & 6 deletions v4/s3gopolicy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,15 @@ import (

"github.com/kyokomi/s3gopolicy/v4"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestCreatePolicies(t *testing.T) {
as := assert.New(t)
_ = as

s3gopolicy.NowTime = func() time.Time {
return time.Date(2016, time.December, 10, 0, 0, 0, 0, time.UTC)
}

policies, _ := s3gopolicy.CreatePolicies(s3gopolicy.AWSCredentials{
policies, err := s3gopolicy.CreatePolicies(s3gopolicy.AWSCredentials{
Region: "ap-northeast-1",
AWSAccessKeyID: "<AWS_ACCESS_KEY_ID>",
AWSSecretKeyID: "<AWS_SECRET_KEY_ID>",
Expand All @@ -38,13 +36,39 @@ func TestCreatePolicies(t *testing.T) {
"x-amz-meta-fileName": "test.mov",
},
})
require.NoError(t, err)

as.Equal("eyJleHBpcmF0aW9uIjoiMjAxNi0xMi0xMFQwMTowMDowMFpaIiwiY29uZGl0aW9ucyI6W3siYnVja2V0IjoidGVzdC5idWNrZXQifSx7ImtleSI6ImZpbGVzL2t5b2tvbWkvdGVzdC5tb3YifSx7IkNvbnRlbnQtVHlwZSI6InZpZGVvL3F1aWNrdGltZSJ9LFsiY29udGVudC1sZW5ndGgtcmFuZ2UiLDExMzM4MTU1OCwxMTMzODE1NThdLHsieC1hbXotY3JlZGVudGlhbCI6Ilx1MDAzY0FXU19BQ0NFU1NfS0VZX0lEXHUwMDNlLzIwMTYxMjEwL2FwLW5vcnRoZWFzdC0xL3MzL2F3czRfcmVxdWVzdCJ9LHsieC1hbXotYWxnb3JpdGhtIjoiQVdTNC1ITUFDLVNIQTI1NiJ9LHsieC1hbXotZGF0ZSI6IjIwMTYxMjEwVDAwMDAwMFoifSx7IngtYW16LW1ldGEtZmlsZU5hbWUiOiJ0ZXN0Lm1vdiJ9XX0=",
assert.Equal(t, "eyJleHBpcmF0aW9uIjoiMjAxNi0xMi0xMFQwMTowMDowMFpaIiwiY29uZGl0aW9ucyI6W3siYnVja2V0IjoidGVzdC5idWNrZXQifSx7ImtleSI6ImZpbGVzL2t5b2tvbWkvdGVzdC5tb3YifSx7IkNvbnRlbnQtVHlwZSI6InZpZGVvL3F1aWNrdGltZSJ9LFsiY29udGVudC1sZW5ndGgtcmFuZ2UiLDExMzM4MTU1OCwxMTMzODE1NThdLHsieC1hbXotY3JlZGVudGlhbCI6Ilx1MDAzY0FXU19BQ0NFU1NfS0VZX0lEXHUwMDNlLzIwMTYxMjEwL2FwLW5vcnRoZWFzdC0xL3MzL2F3czRfcmVxdWVzdCJ9LHsieC1hbXotYWxnb3JpdGhtIjoiQVdTNC1ITUFDLVNIQTI1NiJ9LHsieC1hbXotZGF0ZSI6IjIwMTYxMjEwVDAwMDAwMFoifSx7IngtYW16LW1ldGEtZmlsZU5hbWUiOiJ0ZXN0Lm1vdiJ9XX0=",
policies.Form["Policy"])
as.Equal("21678aaeddd0c8f3082c891321c18d89e4007b0ca20f2909268a87f0bf2522e9",
assert.Equal(t, "21678aaeddd0c8f3082c891321c18d89e4007b0ca20f2909268a87f0bf2522e9",
policies.Form["X-Amz-Signature"])
}

func ExampleCreatePolicies() {
policies, err := s3gopolicy.CreatePolicies(s3gopolicy.AWSCredentials{
Region: "ap-northeast-1",
AWSAccessKeyID: "<AWS_ACCESS_KEY_ID>",
AWSSecretKeyID: "<AWS_SECRET_KEY_ID>",
}, s3gopolicy.UploadConfig{
UploadURL: "https://s3-ap-northeast-1.amazonaws.com/test.bucket",
BucketName: "test.bucket",
ObjectKey: "files/kyokomi/test.mov",
ContentType: "video/quicktime",
FileSize: 113381558,
MetaData: map[string]string{
"x-amz-meta-fileName": "test.mov",
},
})

if err != nil {
log.Fatalln(err)
}

if err := testUpload(policies.URL, "files/kyokomi/test.mov", policies); err != nil {
log.Fatalln(err)
}
}

func testUpload(url, file string, policies s3gopolicy.UploadPolicies) (err error) {
// Add your image file
f, err := os.Open(file)
Expand Down

0 comments on commit 3e00b14

Please sign in to comment.