Skip to content

Commit

Permalink
Upgrade minio-go to version 7
Browse files Browse the repository at this point in the history
  • Loading branch information
Lena Fuhrimann committed Aug 5, 2021
1 parent 6942c40 commit 64fbf73
Show file tree
Hide file tree
Showing 23 changed files with 254 additions and 191 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ jobs:
with:
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
9 changes: 2 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,10 @@ lint:
test:
go test -race -cover ./...

.PHONY: build-docker
build-docker:
.PHONY: build-image
build-image:
docker build -t s3manager .

.PHONY: deploy-cf
deploy-cf:
GOOS=linux go build -ldflags="-s -w" -o bin/s3manager
cf push -f deployments/cf/manifest.yml

.PHONY: clean
clean:
rm -rf bin
12 changes: 4 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ A Web GUI written in Go to manage S3 buckets from any provider.
The application can be configured with the following environment variables:

- `ENDPOINT`: The endpoint of your S3 server (defaults to `s3.amazonaws.com`)
- `REGION`: The region of your S3 server (defaults to `""`)
- `ACCESS_KEY_ID`: Your S3 access key ID (required)
- `SECRET_ACCESS_KEY`: Your S3 secret access key (required)
- `USE_SSL`: Whether your S3 server uses SSL or not (defaults to `true`)
Expand All @@ -26,15 +27,10 @@ The application can be configured with the following environment variables:
1. Run `make build`
1. Execute the created binary and visit <http://localhost:8080>

### Run Docker image
### Run Container image

1. Run `docker run -p 8080:8080 -e 'ACCESS_KEY_ID=XXX' -e 'SECRET_ACCESS_KEY=xxx' mastertinner/s3manager`

### Deploy to Cloud Foundry

1. Modify `deployments/cf/*` to your liking
1. Run `make deploy-cf`

## Development

### Lint Code
Expand All @@ -45,11 +41,11 @@ The application can be configured with the following environment variables:

1. Run `make test`

### Build Docker Image
### Build Container Image

The image is available on [Docker Hub](https://hub.docker.com/r/mastertinner/s3manager/)

1. Run `make build-docker`
1. Run `make build-image`

### Run Locally for Testing

Expand Down
26 changes: 0 additions & 26 deletions deployments/cf/entrypoint.sh

This file was deleted.

8 changes: 0 additions & 8 deletions deployments/cf/manifest.yml

This file was deleted.

11 changes: 9 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,22 @@ module github.com/mastertinner/s3manager
go 1.16

require (
github.com/go-ini/ini v1.62.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gopherjs/gopherjs v0.0.0-20210803090616-8f023c250c89 // indirect
github.com/json-iterator/go v1.1.11 // indirect
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
github.com/mastertinner/adapters v0.0.0-20210601115127-f9c5f1df5ec2
github.com/matryer/is v1.4.0
github.com/matryer/way v0.0.0-20180416093233-9632d0c407b0
github.com/minio/minio-go v6.0.14+incompatible
github.com/minio/md5-simd v1.1.2 // indirect
github.com/minio/minio-go/v7 v7.0.12
github.com/minio/sha256-simd v1.0.0 // indirect
github.com/rs/xid v1.3.0 // indirect
github.com/smartystreets/assertions v1.2.0 // indirect
github.com/stretchr/testify v1.7.0 // indirect
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97 // indirect
golang.org/x/net v0.0.0-20210726213435-c6fcb2dbf985 // indirect
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect
gopkg.in/ini.v1 v1.62.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)
50 changes: 46 additions & 4 deletions go.sum

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions internal/app/s3manager/bucket_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"path"

"github.com/matryer/way"
minio "github.com/minio/minio-go"
"github.com/minio/minio-go/v7"
)

// HandleBucketView shows the details page of a bucket.
Expand All @@ -29,7 +29,7 @@ func HandleBucketView(s3 S3, templates fs.FS) http.HandlerFunc {
var objs []objectWithIcon
doneCh := make(chan struct{})
defer close(doneCh)
objectCh := s3.ListObjectsV2(bucketName, "", true, doneCh)
objectCh := s3.ListObjects(r.Context(), bucketName, minio.ListObjectsOptions{})
for object := range objectCh {
if object.Err != nil {
handleHTTPError(w, fmt.Errorf("error listing objects: %w", object.Err))
Expand Down
21 changes: 11 additions & 10 deletions internal/app/s3manager/bucket_view_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package s3manager_test

import (
"context"
"fmt"
"io"
"net/http"
Expand All @@ -14,22 +15,22 @@ import (
"github.com/mastertinner/s3manager/internal/app/s3manager/mocks"
"github.com/matryer/is"
"github.com/matryer/way"
minio "github.com/minio/minio-go"
"github.com/minio/minio-go/v7"
)

func TestHandleBucketView(t *testing.T) {
t.Parallel()

cases := []struct {
it string
listObjectsV2Func func(string, string, bool, <-chan struct{}) <-chan minio.ObjectInfo
listObjectsFunc func(context.Context, string, minio.ListObjectsOptions) <-chan minio.ObjectInfo
bucketName string
expectedStatusCode int
expectedBodyContains string
}{
{
it: "renders a bucket containing a file",
listObjectsV2Func: func(string, string, bool, <-chan struct{}) <-chan minio.ObjectInfo {
listObjectsFunc: func(context.Context, string, minio.ListObjectsOptions) <-chan minio.ObjectInfo {
objCh := make(chan minio.ObjectInfo)
go func() {
objCh <- minio.ObjectInfo{Key: "testFile"}
Expand All @@ -43,7 +44,7 @@ func TestHandleBucketView(t *testing.T) {
},
{
it: "renders placeholder for an empty bucket",
listObjectsV2Func: func(string, string, bool, <-chan struct{}) <-chan minio.ObjectInfo {
listObjectsFunc: func(context.Context, string, minio.ListObjectsOptions) <-chan minio.ObjectInfo {
objCh := make(chan minio.ObjectInfo)
close(objCh)
return objCh
Expand All @@ -54,7 +55,7 @@ func TestHandleBucketView(t *testing.T) {
},
{
it: "renders a bucket containing an archive",
listObjectsV2Func: func(string, string, bool, <-chan struct{}) <-chan minio.ObjectInfo {
listObjectsFunc: func(context.Context, string, minio.ListObjectsOptions) <-chan minio.ObjectInfo {
objCh := make(chan minio.ObjectInfo)
go func() {
objCh <- minio.ObjectInfo{Key: "archive.tar.gz"}
Expand All @@ -68,7 +69,7 @@ func TestHandleBucketView(t *testing.T) {
},
{
it: "renders a bucket containing an image",
listObjectsV2Func: func(string, string, bool, <-chan struct{}) <-chan minio.ObjectInfo {
listObjectsFunc: func(context.Context, string, minio.ListObjectsOptions) <-chan minio.ObjectInfo {
objCh := make(chan minio.ObjectInfo)
go func() {
objCh <- minio.ObjectInfo{Key: "testImage.png"}
Expand All @@ -82,7 +83,7 @@ func TestHandleBucketView(t *testing.T) {
},
{
it: "renders a bucket containing a sound file",
listObjectsV2Func: func(string, string, bool, <-chan struct{}) <-chan minio.ObjectInfo {
listObjectsFunc: func(context.Context, string, minio.ListObjectsOptions) <-chan minio.ObjectInfo {
objCh := make(chan minio.ObjectInfo)
go func() {
objCh <- minio.ObjectInfo{Key: "testSound.mp3"}
Expand All @@ -96,7 +97,7 @@ func TestHandleBucketView(t *testing.T) {
},
{
it: "returns error if the bucket doesn't exist",
listObjectsV2Func: func(string, string, bool, <-chan struct{}) <-chan minio.ObjectInfo {
listObjectsFunc: func(context.Context, string, minio.ListObjectsOptions) <-chan minio.ObjectInfo {
objCh := make(chan minio.ObjectInfo)
go func() {
objCh <- minio.ObjectInfo{Err: errBucketDoesNotExist}
Expand All @@ -110,7 +111,7 @@ func TestHandleBucketView(t *testing.T) {
},
{
it: "returns error if there is an S3 error",
listObjectsV2Func: func(string, string, bool, <-chan struct{}) <-chan minio.ObjectInfo {
listObjectsFunc: func(context.Context, string, minio.ListObjectsOptions) <-chan minio.ObjectInfo {
objCh := make(chan minio.ObjectInfo)
go func() {
objCh <- minio.ObjectInfo{Err: errS3}
Expand All @@ -131,7 +132,7 @@ func TestHandleBucketView(t *testing.T) {
is := is.New(t)

s3 := &mocks.S3Mock{
ListObjectsV2Func: tc.listObjectsV2Func,
ListObjectsFunc: tc.listObjectsFunc,
}

templates := os.DirFS(filepath.Join("..", "..", "..", "web", "template"))
Expand Down
4 changes: 2 additions & 2 deletions internal/app/s3manager/buckets_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (

// HandleBucketsView renders all buckets on an HTML page.
func HandleBucketsView(s3 S3, templates fs.FS) http.HandlerFunc {
return func(w http.ResponseWriter, _ *http.Request) {
buckets, err := s3.ListBuckets()
return func(w http.ResponseWriter, r *http.Request) {
buckets, err := s3.ListBuckets(r.Context())
if err != nil {
handleHTTPError(w, fmt.Errorf("error listing buckets: %w", err))
return
Expand Down
11 changes: 6 additions & 5 deletions internal/app/s3manager/buckets_view_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package s3manager_test

import (
"context"
"io"
"net/http"
"net/http/httptest"
Expand All @@ -12,37 +13,37 @@ import (
"github.com/mastertinner/s3manager/internal/app/s3manager"
"github.com/mastertinner/s3manager/internal/app/s3manager/mocks"
"github.com/matryer/is"
minio "github.com/minio/minio-go"
"github.com/minio/minio-go/v7"
)

func TestHandleBucketsView(t *testing.T) {
t.Parallel()

cases := []struct {
it string
listBucketsFunc func() ([]minio.BucketInfo, error)
listBucketsFunc func(context.Context) ([]minio.BucketInfo, error)
expectedStatusCode int
expectedBodyContains string
}{
{
it: "renders a list of buckets",
listBucketsFunc: func() ([]minio.BucketInfo, error) {
listBucketsFunc: func(context.Context) ([]minio.BucketInfo, error) {
return []minio.BucketInfo{{Name: "testBucket"}}, nil
},
expectedStatusCode: http.StatusOK,
expectedBodyContains: "testBucket",
},
{
it: "renders placeholder if no buckets",
listBucketsFunc: func() ([]minio.BucketInfo, error) {
listBucketsFunc: func(context.Context) ([]minio.BucketInfo, error) {
return []minio.BucketInfo{}, nil
},
expectedStatusCode: http.StatusOK,
expectedBodyContains: "No buckets yet",
},
{
it: "returns error if there is an S3 error",
listBucketsFunc: func() ([]minio.BucketInfo, error) {
listBucketsFunc: func(context.Context) ([]minio.BucketInfo, error) {
return []minio.BucketInfo{}, errS3
},
expectedStatusCode: http.StatusInternalServerError,
Expand Down
4 changes: 2 additions & 2 deletions internal/app/s3manager/create_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"net/http"

minio "github.com/minio/minio-go"
"github.com/minio/minio-go/v7"
)

// HandleCreateBucket creates a new bucket.
Expand All @@ -18,7 +18,7 @@ func HandleCreateBucket(s3 S3) http.HandlerFunc {
return
}

err = s3.MakeBucket(bucket.Name, "")
err = s3.MakeBucket(r.Context(), bucket.Name, minio.MakeBucketOptions{})
if err != nil {
handleHTTPError(w, fmt.Errorf("error making bucket: %w", err))
return
Expand Down
12 changes: 7 additions & 5 deletions internal/app/s3manager/create_bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package s3manager_test

import (
"bytes"
"context"
"io"
"net/http"
"net/http/httptest"
Expand All @@ -11,21 +12,22 @@ import (
"github.com/mastertinner/s3manager/internal/app/s3manager"
"github.com/mastertinner/s3manager/internal/app/s3manager/mocks"
"github.com/matryer/is"
"github.com/minio/minio-go/v7"
)

func TestHandleCreateBucket(t *testing.T) {
t.Parallel()

cases := []struct {
it string
makeBucketFunc func(string, string) error
makeBucketFunc func(context.Context, string, minio.MakeBucketOptions) error
body string
expectedStatusCode int
expectedBodyContains string
}{
{
it: "creates a new bucket",
makeBucketFunc: func(string, string) error {
makeBucketFunc: func(context.Context, string, minio.MakeBucketOptions) error {
return nil
},
body: `{"name":"myBucket"}`,
Expand All @@ -34,7 +36,7 @@ func TestHandleCreateBucket(t *testing.T) {
},
{
it: "returns error for empty request",
makeBucketFunc: func(string, string) error {
makeBucketFunc: func(context.Context, string, minio.MakeBucketOptions) error {
return nil
},
body: "",
Expand All @@ -43,7 +45,7 @@ func TestHandleCreateBucket(t *testing.T) {
},
{
it: "returns error for malformed request",
makeBucketFunc: func(string, string) error {
makeBucketFunc: func(context.Context, string, minio.MakeBucketOptions) error {
return nil
},
body: "}",
Expand All @@ -52,7 +54,7 @@ func TestHandleCreateBucket(t *testing.T) {
},
{
it: "returns error if there is an S3 error",
makeBucketFunc: func(string, string) error {
makeBucketFunc: func(context.Context, string, minio.MakeBucketOptions) error {
return errS3
},
body: `{"name":"myBucket"}`,
Expand Down
4 changes: 2 additions & 2 deletions internal/app/s3manager/create_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"net/http"

"github.com/matryer/way"
minio "github.com/minio/minio-go"
"github.com/minio/minio-go/v7"
)

// HandleCreateObject uploads a new object.
Expand All @@ -26,7 +26,7 @@ func HandleCreateObject(s3 S3) http.HandlerFunc {
defer file.Close()

opts := minio.PutObjectOptions{ContentType: "application/octet-stream"}
_, err = s3.PutObject(bucketName, header.Filename, file, -1, opts)
_, err = s3.PutObject(r.Context(), bucketName, header.Filename, file, -1, opts)
if err != nil {
handleHTTPError(w, fmt.Errorf("error putting object: %w", err))
return
Expand Down
Loading

0 comments on commit 64fbf73

Please sign in to comment.