mirror of
https://github.com/thegeeklab/wp-s3-action.git
synced 2024-06-02 18:39:42 +02:00
Compare commits
15 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
2f2fdf1f7f | ||
|
c2a7f897c0 | ||
|
aacd23451e | ||
|
04d5df2fc7 | ||
e14a5011da | |||
|
ff97059f7f | ||
|
da9ffdab15 | ||
174d9ef5bb | |||
0752e23352 | |||
|
7852c706ae | ||
bcfd874890 | |||
|
fc098bd7d4 | ||
|
5b2336bb02 | ||
|
6820ec0661 | ||
|
5d22227635 |
|
@ -23,7 +23,6 @@ linters:
|
|||
- errchkjson
|
||||
- errname
|
||||
- errorlint
|
||||
- execinquery
|
||||
- exhaustive
|
||||
- exportloopref
|
||||
- forcetypeassert
|
||||
|
@ -37,12 +36,12 @@ linters:
|
|||
- gocyclo
|
||||
- godot
|
||||
- godox
|
||||
- goerr113
|
||||
- err113
|
||||
- gofmt
|
||||
- gofumpt
|
||||
- goheader
|
||||
- goimports
|
||||
- gomnd
|
||||
- mnd
|
||||
- gomoddirectives
|
||||
- gomodguard
|
||||
- goprintffuncname
|
||||
|
|
6
.mockery.yaml
Normal file
6
.mockery.yaml
Normal file
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
all: True
|
||||
dir: "{{.PackageName}}/mocks"
|
||||
outpkg: "mocks"
|
||||
packages:
|
||||
github.com/thegeeklab/wp-s3-action/aws:
|
|
@ -1,4 +1,4 @@
|
|||
FROM --platform=$BUILDPLATFORM docker.io/library/golang:1.22@sha256:450e3822c7a135e1463cd83e51c8e2eb03b86a02113c89424e6f0f8344bb4168 as build
|
||||
FROM --platform=$BUILDPLATFORM docker.io/library/golang:1.22@sha256:f43c6f049f04cbbaeb28f0aad3eea15274a7d0a7899a617d0037aec48d7ab010 as build
|
||||
|
||||
ARG TARGETOS
|
||||
ARG TARGETARCH
|
||||
|
@ -8,7 +8,7 @@ WORKDIR /src
|
|||
|
||||
RUN make build
|
||||
|
||||
FROM docker.io/library/alpine:3.19@sha256:c5b1261d6d3e43071626931fc004f70149baeba2c8ec672bd4f27761f8e1ad6b
|
||||
FROM docker.io/library/alpine:3.20@sha256:77726ef6b57ddf65bb551896826ec38bc3e53f75cdde31354fbffb4f25238ebd
|
||||
|
||||
LABEL maintainer="Robert Kaussow <mail@thegeeklab.de>"
|
||||
LABEL org.opencontainers.image.authors="Robert Kaussow <mail@thegeeklab.de>"
|
||||
|
|
11
Makefile
11
Makefile
|
@ -1,7 +1,7 @@
|
|||
# renovate: datasource=github-releases depName=mvdan/gofumpt
|
||||
GOFUMPT_PACKAGE_VERSION := v0.6.0
|
||||
# renovate: datasource=github-releases depName=golangci/golangci-lint
|
||||
GOLANGCI_LINT_PACKAGE_VERSION := v1.57.2
|
||||
GOLANGCI_LINT_PACKAGE_VERSION := v1.59.0
|
||||
|
||||
EXECUTABLE := wp-s3-action
|
||||
|
||||
|
@ -18,8 +18,8 @@ GOFUMPT_PACKAGE ?= mvdan.cc/gofumpt@$(GOFUMPT_PACKAGE_VERSION)
|
|||
GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_PACKAGE_VERSION)
|
||||
XGO_PACKAGE ?= src.techknowlogick.com/xgo@latest
|
||||
GOTESTSUM_PACKAGE ?= gotest.tools/gotestsum@latest
|
||||
MOCKERY_PACKAGE ?= github.com/vektra/mockery/v2@latest
|
||||
|
||||
GENERATE ?=
|
||||
XGO_VERSION := go-1.22.x
|
||||
XGO_TARGETS ?= linux/amd64,linux/arm-6,linux/arm-7,linux/arm64
|
||||
|
||||
|
@ -65,11 +65,8 @@ lint: golangci-lint
|
|||
|
||||
.PHONY: generate
|
||||
generate:
|
||||
$(GO) generate $(GENERATE)
|
||||
|
||||
.PHONY: generate-docs
|
||||
generate-docs:
|
||||
$(GO) generate ./cmd/$(EXECUTABLE)/flags.go
|
||||
$(GO) generate $(PACKAGES)
|
||||
$(GO) run $(MOCKERY_PACKAGE)
|
||||
|
||||
.PHONY: test
|
||||
test:
|
||||
|
|
24
aws/api.go
Normal file
24
aws/api.go
Normal file
|
@ -0,0 +1,24 @@
|
|||
package aws
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/service/cloudfront"
|
||||
"github.com/aws/aws-sdk-go-v2/service/s3"
|
||||
)
|
||||
|
||||
//nolint:lll
|
||||
type S3APIClient interface {
|
||||
HeadObject(ctx context.Context, params *s3.HeadObjectInput, optFns ...func(*s3.Options)) (*s3.HeadObjectOutput, error)
|
||||
PutObject(ctx context.Context, params *s3.PutObjectInput, optFns ...func(*s3.Options)) (*s3.PutObjectOutput, error)
|
||||
GetObject(ctx context.Context, params *s3.GetObjectInput, optFns ...func(*s3.Options)) (*s3.GetObjectOutput, error)
|
||||
CopyObject(ctx context.Context, params *s3.CopyObjectInput, optFns ...func(*s3.Options)) (*s3.CopyObjectOutput, error)
|
||||
GetObjectAcl(ctx context.Context, params *s3.GetObjectAclInput, optFns ...func(*s3.Options)) (*s3.GetObjectAclOutput, error)
|
||||
DeleteObject(ctx context.Context, params *s3.DeleteObjectInput, optFns ...func(*s3.Options)) (*s3.DeleteObjectOutput, error)
|
||||
ListObjects(ctx context.Context, params *s3.ListObjectsInput, optFns ...func(*s3.Options)) (*s3.ListObjectsOutput, error)
|
||||
}
|
||||
|
||||
//nolint:lll
|
||||
type CloudfrontAPIClient interface {
|
||||
CreateInvalidation(ctx context.Context, params *cloudfront.CreateInvalidationInput, optFns ...func(*cloudfront.Options)) (*cloudfront.CreateInvalidationOutput, error)
|
||||
}
|
44
aws/aws.go
Normal file
44
aws/aws.go
Normal file
|
@ -0,0 +1,44 @@
|
|||
package aws
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
"github.com/aws/aws-sdk-go-v2/config"
|
||||
"github.com/aws/aws-sdk-go-v2/credentials"
|
||||
"github.com/aws/aws-sdk-go-v2/service/cloudfront"
|
||||
"github.com/aws/aws-sdk-go-v2/service/s3"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
S3 *S3
|
||||
Cloudfront *Cloudfront
|
||||
}
|
||||
|
||||
// NewClient creates a new S3 client with the provided configuration.
|
||||
func NewClient(ctx context.Context, url, region, accessKey, secretKey string, pathStyle bool) (*Client, error) {
|
||||
cfg, err := config.LoadDefaultConfig(ctx, config.WithRegion(region))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error while loading AWS config: %w", err)
|
||||
}
|
||||
|
||||
if url != "" {
|
||||
cfg.BaseEndpoint = aws.String(url)
|
||||
}
|
||||
|
||||
// allowing to use the instance role or provide a key and secret
|
||||
if accessKey != "" && secretKey != "" {
|
||||
cfg.Credentials = credentials.NewStaticCredentialsProvider(accessKey, secretKey, "")
|
||||
}
|
||||
|
||||
c := s3.NewFromConfig(cfg, func(o *s3.Options) {
|
||||
o.UsePathStyle = pathStyle
|
||||
})
|
||||
cf := cloudfront.NewFromConfig(cfg)
|
||||
|
||||
return &Client{
|
||||
S3: &S3{client: c},
|
||||
Cloudfront: &Cloudfront{client: cf},
|
||||
}, nil
|
||||
}
|
40
aws/cloudfront.go
Normal file
40
aws/cloudfront.go
Normal file
|
@ -0,0 +1,40 @@
|
|||
package aws
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
"github.com/aws/aws-sdk-go-v2/service/cloudfront"
|
||||
"github.com/aws/aws-sdk-go-v2/service/cloudfront/types"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
type Cloudfront struct {
|
||||
client CloudfrontAPIClient
|
||||
Distribution string
|
||||
}
|
||||
|
||||
type CloudfrontInvalidateOptions struct {
|
||||
Path string
|
||||
}
|
||||
|
||||
// Invalidate invalidates the specified path in the CloudFront distribution.
|
||||
func (c *Cloudfront) Invalidate(ctx context.Context, opt CloudfrontInvalidateOptions) error {
|
||||
log.Debug().Msgf("invalidating '%s'", opt.Path)
|
||||
|
||||
_, err := c.client.CreateInvalidation(ctx, &cloudfront.CreateInvalidationInput{
|
||||
DistributionId: aws.String(c.Distribution),
|
||||
InvalidationBatch: &types.InvalidationBatch{
|
||||
CallerReference: aws.String(time.Now().Format(time.RFC3339Nano)),
|
||||
Paths: &types.Paths{
|
||||
Quantity: aws.Int32(1),
|
||||
Items: []string{
|
||||
opt.Path,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
return err
|
||||
}
|
86
aws/cloudfront_test.go
Normal file
86
aws/cloudfront_test.go
Normal file
|
@ -0,0 +1,86 @@
|
|||
package aws
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/service/cloudfront"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/mock"
|
||||
"github.com/thegeeklab/wp-s3-action/aws/mocks"
|
||||
)
|
||||
|
||||
var ErrCreateInvalidation = errors.New("create invalidation failed")
|
||||
|
||||
func TestCloudfront_Invalidate(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
setup func(t *testing.T) (*Cloudfront, CloudfrontInvalidateOptions, func())
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "invalidate path successfully",
|
||||
setup: func(t *testing.T) (*Cloudfront, CloudfrontInvalidateOptions, func()) {
|
||||
t.Helper()
|
||||
|
||||
mockClient := mocks.NewMockCloudfrontAPIClient(t)
|
||||
mockClient.
|
||||
On("CreateInvalidation", mock.Anything, mock.Anything).
|
||||
Return(&cloudfront.CreateInvalidationOutput{}, nil)
|
||||
|
||||
return &Cloudfront{
|
||||
client: mockClient,
|
||||
Distribution: "test-distribution",
|
||||
}, CloudfrontInvalidateOptions{
|
||||
Path: "/path/to/invalidate",
|
||||
}, func() {
|
||||
mockClient.AssertExpectations(t)
|
||||
}
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "error when create invalidation fails",
|
||||
setup: func(t *testing.T) (*Cloudfront, CloudfrontInvalidateOptions, func()) {
|
||||
t.Helper()
|
||||
|
||||
mockClient := mocks.NewMockCloudfrontAPIClient(t)
|
||||
mockClient.
|
||||
On("CreateInvalidation", mock.Anything, mock.Anything).
|
||||
Return(&cloudfront.CreateInvalidationOutput{}, ErrCreateInvalidation)
|
||||
|
||||
return &Cloudfront{
|
||||
client: mockClient,
|
||||
Distribution: "test-distribution",
|
||||
}, CloudfrontInvalidateOptions{
|
||||
Path: "/path/to/invalidate",
|
||||
}, func() {
|
||||
mockClient.AssertExpectations(t)
|
||||
}
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
cf, opt, teardown := tt.setup(t)
|
||||
defer teardown()
|
||||
|
||||
err := cf.Invalidate(context.Background(), opt)
|
||||
if tt.wantErr {
|
||||
assert.Error(t, err)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
assert.NoError(t, err)
|
||||
})
|
||||
}
|
||||
}
|
112
aws/mocks/mock_CloudfrontAPIClient.go
Normal file
112
aws/mocks/mock_CloudfrontAPIClient.go
Normal file
|
@ -0,0 +1,112 @@
|
|||
// Code generated by mockery v2.43.0. DO NOT EDIT.
|
||||
|
||||
package mocks
|
||||
|
||||
import (
|
||||
context "context"
|
||||
|
||||
cloudfront "github.com/aws/aws-sdk-go-v2/service/cloudfront"
|
||||
|
||||
mock "github.com/stretchr/testify/mock"
|
||||
)
|
||||
|
||||
// MockCloudfrontAPIClient is an autogenerated mock type for the CloudfrontAPIClient type
|
||||
type MockCloudfrontAPIClient struct {
|
||||
mock.Mock
|
||||
}
|
||||
|
||||
type MockCloudfrontAPIClient_Expecter struct {
|
||||
mock *mock.Mock
|
||||
}
|
||||
|
||||
func (_m *MockCloudfrontAPIClient) EXPECT() *MockCloudfrontAPIClient_Expecter {
|
||||
return &MockCloudfrontAPIClient_Expecter{mock: &_m.Mock}
|
||||
}
|
||||
|
||||
// CreateInvalidation provides a mock function with given fields: ctx, params, optFns
|
||||
func (_m *MockCloudfrontAPIClient) CreateInvalidation(ctx context.Context, params *cloudfront.CreateInvalidationInput, optFns ...func(*cloudfront.Options)) (*cloudfront.CreateInvalidationOutput, error) {
|
||||
_va := make([]interface{}, len(optFns))
|
||||
for _i := range optFns {
|
||||
_va[_i] = optFns[_i]
|
||||
}
|
||||
var _ca []interface{}
|
||||
_ca = append(_ca, ctx, params)
|
||||
_ca = append(_ca, _va...)
|
||||
ret := _m.Called(_ca...)
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for CreateInvalidation")
|
||||
}
|
||||
|
||||
var r0 *cloudfront.CreateInvalidationOutput
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *cloudfront.CreateInvalidationInput, ...func(*cloudfront.Options)) (*cloudfront.CreateInvalidationOutput, error)); ok {
|
||||
return rf(ctx, params, optFns...)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *cloudfront.CreateInvalidationInput, ...func(*cloudfront.Options)) *cloudfront.CreateInvalidationOutput); ok {
|
||||
r0 = rf(ctx, params, optFns...)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*cloudfront.CreateInvalidationOutput)
|
||||
}
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(context.Context, *cloudfront.CreateInvalidationInput, ...func(*cloudfront.Options)) error); ok {
|
||||
r1 = rf(ctx, params, optFns...)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// MockCloudfrontAPIClient_CreateInvalidation_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateInvalidation'
|
||||
type MockCloudfrontAPIClient_CreateInvalidation_Call struct {
|
||||
*mock.Call
|
||||
}
|
||||
|
||||
// CreateInvalidation is a helper method to define mock.On call
|
||||
// - ctx context.Context
|
||||
// - params *cloudfront.CreateInvalidationInput
|
||||
// - optFns ...func(*cloudfront.Options)
|
||||
func (_e *MockCloudfrontAPIClient_Expecter) CreateInvalidation(ctx interface{}, params interface{}, optFns ...interface{}) *MockCloudfrontAPIClient_CreateInvalidation_Call {
|
||||
return &MockCloudfrontAPIClient_CreateInvalidation_Call{Call: _e.mock.On("CreateInvalidation",
|
||||
append([]interface{}{ctx, params}, optFns...)...)}
|
||||
}
|
||||
|
||||
func (_c *MockCloudfrontAPIClient_CreateInvalidation_Call) Run(run func(ctx context.Context, params *cloudfront.CreateInvalidationInput, optFns ...func(*cloudfront.Options))) *MockCloudfrontAPIClient_CreateInvalidation_Call {
|
||||
_c.Call.Run(func(args mock.Arguments) {
|
||||
variadicArgs := make([]func(*cloudfront.Options), len(args)-2)
|
||||
for i, a := range args[2:] {
|
||||
if a != nil {
|
||||
variadicArgs[i] = a.(func(*cloudfront.Options))
|
||||
}
|
||||
}
|
||||
run(args[0].(context.Context), args[1].(*cloudfront.CreateInvalidationInput), variadicArgs...)
|
||||
})
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *MockCloudfrontAPIClient_CreateInvalidation_Call) Return(_a0 *cloudfront.CreateInvalidationOutput, _a1 error) *MockCloudfrontAPIClient_CreateInvalidation_Call {
|
||||
_c.Call.Return(_a0, _a1)
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *MockCloudfrontAPIClient_CreateInvalidation_Call) RunAndReturn(run func(context.Context, *cloudfront.CreateInvalidationInput, ...func(*cloudfront.Options)) (*cloudfront.CreateInvalidationOutput, error)) *MockCloudfrontAPIClient_CreateInvalidation_Call {
|
||||
_c.Call.Return(run)
|
||||
return _c
|
||||
}
|
||||
|
||||
// NewMockCloudfrontAPIClient creates a new instance of MockCloudfrontAPIClient. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
|
||||
// The first argument is typically a *testing.T value.
|
||||
func NewMockCloudfrontAPIClient(t interface {
|
||||
mock.TestingT
|
||||
Cleanup(func())
|
||||
}) *MockCloudfrontAPIClient {
|
||||
mock := &MockCloudfrontAPIClient{}
|
||||
mock.Mock.Test(t)
|
||||
|
||||
t.Cleanup(func() { mock.AssertExpectations(t) })
|
||||
|
||||
return mock
|
||||
}
|
555
aws/mocks/mock_S3APIClient.go
Normal file
555
aws/mocks/mock_S3APIClient.go
Normal file
|
@ -0,0 +1,555 @@
|
|||
// Code generated by mockery v2.43.0. DO NOT EDIT.
|
||||
|
||||
package mocks
|
||||
|
||||
import (
|
||||
context "context"
|
||||
|
||||
s3 "github.com/aws/aws-sdk-go-v2/service/s3"
|
||||
mock "github.com/stretchr/testify/mock"
|
||||
)
|
||||
|
||||
// MockS3APIClient is an autogenerated mock type for the S3APIClient type
|
||||
type MockS3APIClient struct {
|
||||
mock.Mock
|
||||
}
|
||||
|
||||
type MockS3APIClient_Expecter struct {
|
||||
mock *mock.Mock
|
||||
}
|
||||
|
||||
func (_m *MockS3APIClient) EXPECT() *MockS3APIClient_Expecter {
|
||||
return &MockS3APIClient_Expecter{mock: &_m.Mock}
|
||||
}
|
||||
|
||||
// CopyObject provides a mock function with given fields: ctx, params, optFns
|
||||
func (_m *MockS3APIClient) CopyObject(ctx context.Context, params *s3.CopyObjectInput, optFns ...func(*s3.Options)) (*s3.CopyObjectOutput, error) {
|
||||
_va := make([]interface{}, len(optFns))
|
||||
for _i := range optFns {
|
||||
_va[_i] = optFns[_i]
|
||||
}
|
||||
var _ca []interface{}
|
||||
_ca = append(_ca, ctx, params)
|
||||
_ca = append(_ca, _va...)
|
||||
ret := _m.Called(_ca...)
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for CopyObject")
|
||||
}
|
||||
|
||||
var r0 *s3.CopyObjectOutput
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *s3.CopyObjectInput, ...func(*s3.Options)) (*s3.CopyObjectOutput, error)); ok {
|
||||
return rf(ctx, params, optFns...)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *s3.CopyObjectInput, ...func(*s3.Options)) *s3.CopyObjectOutput); ok {
|
||||
r0 = rf(ctx, params, optFns...)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*s3.CopyObjectOutput)
|
||||
}
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(context.Context, *s3.CopyObjectInput, ...func(*s3.Options)) error); ok {
|
||||
r1 = rf(ctx, params, optFns...)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// MockS3APIClient_CopyObject_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CopyObject'
|
||||
type MockS3APIClient_CopyObject_Call struct {
|
||||
*mock.Call
|
||||
}
|
||||
|
||||
// CopyObject is a helper method to define mock.On call
|
||||
// - ctx context.Context
|
||||
// - params *s3.CopyObjectInput
|
||||
// - optFns ...func(*s3.Options)
|
||||
func (_e *MockS3APIClient_Expecter) CopyObject(ctx interface{}, params interface{}, optFns ...interface{}) *MockS3APIClient_CopyObject_Call {
|
||||
return &MockS3APIClient_CopyObject_Call{Call: _e.mock.On("CopyObject",
|
||||
append([]interface{}{ctx, params}, optFns...)...)}
|
||||
}
|
||||
|
||||
func (_c *MockS3APIClient_CopyObject_Call) Run(run func(ctx context.Context, params *s3.CopyObjectInput, optFns ...func(*s3.Options))) *MockS3APIClient_CopyObject_Call {
|
||||
_c.Call.Run(func(args mock.Arguments) {
|
||||
variadicArgs := make([]func(*s3.Options), len(args)-2)
|
||||
for i, a := range args[2:] {
|
||||
if a != nil {
|
||||
variadicArgs[i] = a.(func(*s3.Options))
|
||||
}
|
||||
}
|
||||
run(args[0].(context.Context), args[1].(*s3.CopyObjectInput), variadicArgs...)
|
||||
})
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *MockS3APIClient_CopyObject_Call) Return(_a0 *s3.CopyObjectOutput, _a1 error) *MockS3APIClient_CopyObject_Call {
|
||||
_c.Call.Return(_a0, _a1)
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *MockS3APIClient_CopyObject_Call) RunAndReturn(run func(context.Context, *s3.CopyObjectInput, ...func(*s3.Options)) (*s3.CopyObjectOutput, error)) *MockS3APIClient_CopyObject_Call {
|
||||
_c.Call.Return(run)
|
||||
return _c
|
||||
}
|
||||
|
||||
// DeleteObject provides a mock function with given fields: ctx, params, optFns
|
||||
func (_m *MockS3APIClient) DeleteObject(ctx context.Context, params *s3.DeleteObjectInput, optFns ...func(*s3.Options)) (*s3.DeleteObjectOutput, error) {
|
||||
_va := make([]interface{}, len(optFns))
|
||||
for _i := range optFns {
|
||||
_va[_i] = optFns[_i]
|
||||
}
|
||||
var _ca []interface{}
|
||||
_ca = append(_ca, ctx, params)
|
||||
_ca = append(_ca, _va...)
|
||||
ret := _m.Called(_ca...)
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for DeleteObject")
|
||||
}
|
||||
|
||||
var r0 *s3.DeleteObjectOutput
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *s3.DeleteObjectInput, ...func(*s3.Options)) (*s3.DeleteObjectOutput, error)); ok {
|
||||
return rf(ctx, params, optFns...)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *s3.DeleteObjectInput, ...func(*s3.Options)) *s3.DeleteObjectOutput); ok {
|
||||
r0 = rf(ctx, params, optFns...)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*s3.DeleteObjectOutput)
|
||||
}
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(context.Context, *s3.DeleteObjectInput, ...func(*s3.Options)) error); ok {
|
||||
r1 = rf(ctx, params, optFns...)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// MockS3APIClient_DeleteObject_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteObject'
|
||||
type MockS3APIClient_DeleteObject_Call struct {
|
||||
*mock.Call
|
||||
}
|
||||
|
||||
// DeleteObject is a helper method to define mock.On call
|
||||
// - ctx context.Context
|
||||
// - params *s3.DeleteObjectInput
|
||||
// - optFns ...func(*s3.Options)
|
||||
func (_e *MockS3APIClient_Expecter) DeleteObject(ctx interface{}, params interface{}, optFns ...interface{}) *MockS3APIClient_DeleteObject_Call {
|
||||
return &MockS3APIClient_DeleteObject_Call{Call: _e.mock.On("DeleteObject",
|
||||
append([]interface{}{ctx, params}, optFns...)...)}
|
||||
}
|
||||
|
||||
func (_c *MockS3APIClient_DeleteObject_Call) Run(run func(ctx context.Context, params *s3.DeleteObjectInput, optFns ...func(*s3.Options))) *MockS3APIClient_DeleteObject_Call {
|
||||
_c.Call.Run(func(args mock.Arguments) {
|
||||
variadicArgs := make([]func(*s3.Options), len(args)-2)
|
||||
for i, a := range args[2:] {
|
||||
if a != nil {
|
||||
variadicArgs[i] = a.(func(*s3.Options))
|
||||
}
|
||||
}
|
||||
run(args[0].(context.Context), args[1].(*s3.DeleteObjectInput), variadicArgs...)
|
||||
})
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *MockS3APIClient_DeleteObject_Call) Return(_a0 *s3.DeleteObjectOutput, _a1 error) *MockS3APIClient_DeleteObject_Call {
|
||||
_c.Call.Return(_a0, _a1)
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *MockS3APIClient_DeleteObject_Call) RunAndReturn(run func(context.Context, *s3.DeleteObjectInput, ...func(*s3.Options)) (*s3.DeleteObjectOutput, error)) *MockS3APIClient_DeleteObject_Call {
|
||||
_c.Call.Return(run)
|
||||
return _c
|
||||
}
|
||||
|
||||
// GetObject provides a mock function with given fields: ctx, params, optFns
|
||||
func (_m *MockS3APIClient) GetObject(ctx context.Context, params *s3.GetObjectInput, optFns ...func(*s3.Options)) (*s3.GetObjectOutput, error) {
|
||||
_va := make([]interface{}, len(optFns))
|
||||
for _i := range optFns {
|
||||
_va[_i] = optFns[_i]
|
||||
}
|
||||
var _ca []interface{}
|
||||
_ca = append(_ca, ctx, params)
|
||||
_ca = append(_ca, _va...)
|
||||
ret := _m.Called(_ca...)
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for GetObject")
|
||||
}
|
||||
|
||||
var r0 *s3.GetObjectOutput
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *s3.GetObjectInput, ...func(*s3.Options)) (*s3.GetObjectOutput, error)); ok {
|
||||
return rf(ctx, params, optFns...)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *s3.GetObjectInput, ...func(*s3.Options)) *s3.GetObjectOutput); ok {
|
||||
r0 = rf(ctx, params, optFns...)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*s3.GetObjectOutput)
|
||||
}
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(context.Context, *s3.GetObjectInput, ...func(*s3.Options)) error); ok {
|
||||
r1 = rf(ctx, params, optFns...)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// MockS3APIClient_GetObject_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetObject'
|
||||
type MockS3APIClient_GetObject_Call struct {
|
||||
*mock.Call
|
||||
}
|
||||
|
||||
// GetObject is a helper method to define mock.On call
|
||||
// - ctx context.Context
|
||||
// - params *s3.GetObjectInput
|
||||
// - optFns ...func(*s3.Options)
|
||||
func (_e *MockS3APIClient_Expecter) GetObject(ctx interface{}, params interface{}, optFns ...interface{}) *MockS3APIClient_GetObject_Call {
|
||||
return &MockS3APIClient_GetObject_Call{Call: _e.mock.On("GetObject",
|
||||
append([]interface{}{ctx, params}, optFns...)...)}
|
||||
}
|
||||
|
||||
func (_c *MockS3APIClient_GetObject_Call) Run(run func(ctx context.Context, params *s3.GetObjectInput, optFns ...func(*s3.Options))) *MockS3APIClient_GetObject_Call {
|
||||
_c.Call.Run(func(args mock.Arguments) {
|
||||
variadicArgs := make([]func(*s3.Options), len(args)-2)
|
||||
for i, a := range args[2:] {
|
||||
if a != nil {
|
||||
variadicArgs[i] = a.(func(*s3.Options))
|
||||
}
|
||||
}
|
||||
run(args[0].(context.Context), args[1].(*s3.GetObjectInput), variadicArgs...)
|
||||
})
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *MockS3APIClient_GetObject_Call) Return(_a0 *s3.GetObjectOutput, _a1 error) *MockS3APIClient_GetObject_Call {
|
||||
_c.Call.Return(_a0, _a1)
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *MockS3APIClient_GetObject_Call) RunAndReturn(run func(context.Context, *s3.GetObjectInput, ...func(*s3.Options)) (*s3.GetObjectOutput, error)) *MockS3APIClient_GetObject_Call {
|
||||
_c.Call.Return(run)
|
||||
return _c
|
||||
}
|
||||
|
||||
// GetObjectAcl provides a mock function with given fields: ctx, params, optFns
|
||||
func (_m *MockS3APIClient) GetObjectAcl(ctx context.Context, params *s3.GetObjectAclInput, optFns ...func(*s3.Options)) (*s3.GetObjectAclOutput, error) {
|
||||
_va := make([]interface{}, len(optFns))
|
||||
for _i := range optFns {
|
||||
_va[_i] = optFns[_i]
|
||||
}
|
||||
var _ca []interface{}
|
||||
_ca = append(_ca, ctx, params)
|
||||
_ca = append(_ca, _va...)
|
||||
ret := _m.Called(_ca...)
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for GetObjectAcl")
|
||||
}
|
||||
|
||||
var r0 *s3.GetObjectAclOutput
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *s3.GetObjectAclInput, ...func(*s3.Options)) (*s3.GetObjectAclOutput, error)); ok {
|
||||
return rf(ctx, params, optFns...)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *s3.GetObjectAclInput, ...func(*s3.Options)) *s3.GetObjectAclOutput); ok {
|
||||
r0 = rf(ctx, params, optFns...)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*s3.GetObjectAclOutput)
|
||||
}
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(context.Context, *s3.GetObjectAclInput, ...func(*s3.Options)) error); ok {
|
||||
r1 = rf(ctx, params, optFns...)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// MockS3APIClient_GetObjectAcl_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetObjectAcl'
|
||||
type MockS3APIClient_GetObjectAcl_Call struct {
|
||||
*mock.Call
|
||||
}
|
||||
|
||||
// GetObjectAcl is a helper method to define mock.On call
|
||||
// - ctx context.Context
|
||||
// - params *s3.GetObjectAclInput
|
||||
// - optFns ...func(*s3.Options)
|
||||
func (_e *MockS3APIClient_Expecter) GetObjectAcl(ctx interface{}, params interface{}, optFns ...interface{}) *MockS3APIClient_GetObjectAcl_Call {
|
||||
return &MockS3APIClient_GetObjectAcl_Call{Call: _e.mock.On("GetObjectAcl",
|
||||
append([]interface{}{ctx, params}, optFns...)...)}
|
||||
}
|
||||
|
||||
func (_c *MockS3APIClient_GetObjectAcl_Call) Run(run func(ctx context.Context, params *s3.GetObjectAclInput, optFns ...func(*s3.Options))) *MockS3APIClient_GetObjectAcl_Call {
|
||||
_c.Call.Run(func(args mock.Arguments) {
|
||||
variadicArgs := make([]func(*s3.Options), len(args)-2)
|
||||
for i, a := range args[2:] {
|
||||
if a != nil {
|
||||
variadicArgs[i] = a.(func(*s3.Options))
|
||||
}
|
||||
}
|
||||
run(args[0].(context.Context), args[1].(*s3.GetObjectAclInput), variadicArgs...)
|
||||
})
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *MockS3APIClient_GetObjectAcl_Call) Return(_a0 *s3.GetObjectAclOutput, _a1 error) *MockS3APIClient_GetObjectAcl_Call {
|
||||
_c.Call.Return(_a0, _a1)
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *MockS3APIClient_GetObjectAcl_Call) RunAndReturn(run func(context.Context, *s3.GetObjectAclInput, ...func(*s3.Options)) (*s3.GetObjectAclOutput, error)) *MockS3APIClient_GetObjectAcl_Call {
|
||||
_c.Call.Return(run)
|
||||
return _c
|
||||
}
|
||||
|
||||
// HeadObject provides a mock function with given fields: ctx, params, optFns
|
||||
func (_m *MockS3APIClient) HeadObject(ctx context.Context, params *s3.HeadObjectInput, optFns ...func(*s3.Options)) (*s3.HeadObjectOutput, error) {
|
||||
_va := make([]interface{}, len(optFns))
|
||||
for _i := range optFns {
|
||||
_va[_i] = optFns[_i]
|
||||
}
|
||||
var _ca []interface{}
|
||||
_ca = append(_ca, ctx, params)
|
||||
_ca = append(_ca, _va...)
|
||||
ret := _m.Called(_ca...)
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for HeadObject")
|
||||
}
|
||||
|
||||
var r0 *s3.HeadObjectOutput
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *s3.HeadObjectInput, ...func(*s3.Options)) (*s3.HeadObjectOutput, error)); ok {
|
||||
return rf(ctx, params, optFns...)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *s3.HeadObjectInput, ...func(*s3.Options)) *s3.HeadObjectOutput); ok {
|
||||
r0 = rf(ctx, params, optFns...)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*s3.HeadObjectOutput)
|
||||
}
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(context.Context, *s3.HeadObjectInput, ...func(*s3.Options)) error); ok {
|
||||
r1 = rf(ctx, params, optFns...)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// MockS3APIClient_HeadObject_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'HeadObject'
|
||||
type MockS3APIClient_HeadObject_Call struct {
|
||||
*mock.Call
|
||||
}
|
||||
|
||||
// HeadObject is a helper method to define mock.On call
|
||||
// - ctx context.Context
|
||||
// - params *s3.HeadObjectInput
|
||||
// - optFns ...func(*s3.Options)
|
||||
func (_e *MockS3APIClient_Expecter) HeadObject(ctx interface{}, params interface{}, optFns ...interface{}) *MockS3APIClient_HeadObject_Call {
|
||||
return &MockS3APIClient_HeadObject_Call{Call: _e.mock.On("HeadObject",
|
||||
append([]interface{}{ctx, params}, optFns...)...)}
|
||||
}
|
||||
|
||||
func (_c *MockS3APIClient_HeadObject_Call) Run(run func(ctx context.Context, params *s3.HeadObjectInput, optFns ...func(*s3.Options))) *MockS3APIClient_HeadObject_Call {
|
||||
_c.Call.Run(func(args mock.Arguments) {
|
||||
variadicArgs := make([]func(*s3.Options), len(args)-2)
|
||||
for i, a := range args[2:] {
|
||||
if a != nil {
|
||||
variadicArgs[i] = a.(func(*s3.Options))
|
||||
}
|
||||
}
|
||||
run(args[0].(context.Context), args[1].(*s3.HeadObjectInput), variadicArgs...)
|
||||
})
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *MockS3APIClient_HeadObject_Call) Return(_a0 *s3.HeadObjectOutput, _a1 error) *MockS3APIClient_HeadObject_Call {
|
||||
_c.Call.Return(_a0, _a1)
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *MockS3APIClient_HeadObject_Call) RunAndReturn(run func(context.Context, *s3.HeadObjectInput, ...func(*s3.Options)) (*s3.HeadObjectOutput, error)) *MockS3APIClient_HeadObject_Call {
|
||||
_c.Call.Return(run)
|
||||
return _c
|
||||
}
|
||||
|
||||
// ListObjects provides a mock function with given fields: ctx, params, optFns
|
||||
func (_m *MockS3APIClient) ListObjects(ctx context.Context, params *s3.ListObjectsInput, optFns ...func(*s3.Options)) (*s3.ListObjectsOutput, error) {
|
||||
_va := make([]interface{}, len(optFns))
|
||||
for _i := range optFns {
|
||||
_va[_i] = optFns[_i]
|
||||
}
|
||||
var _ca []interface{}
|
||||
_ca = append(_ca, ctx, params)
|
||||
_ca = append(_ca, _va...)
|
||||
ret := _m.Called(_ca...)
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for ListObjects")
|
||||
}
|
||||
|
||||
var r0 *s3.ListObjectsOutput
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *s3.ListObjectsInput, ...func(*s3.Options)) (*s3.ListObjectsOutput, error)); ok {
|
||||
return rf(ctx, params, optFns...)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *s3.ListObjectsInput, ...func(*s3.Options)) *s3.ListObjectsOutput); ok {
|
||||
r0 = rf(ctx, params, optFns...)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*s3.ListObjectsOutput)
|
||||
}
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(context.Context, *s3.ListObjectsInput, ...func(*s3.Options)) error); ok {
|
||||
r1 = rf(ctx, params, optFns...)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// MockS3APIClient_ListObjects_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListObjects'
|
||||
type MockS3APIClient_ListObjects_Call struct {
|
||||
*mock.Call
|
||||
}
|
||||
|
||||
// ListObjects is a helper method to define mock.On call
|
||||
// - ctx context.Context
|
||||
// - params *s3.ListObjectsInput
|
||||
// - optFns ...func(*s3.Options)
|
||||
func (_e *MockS3APIClient_Expecter) ListObjects(ctx interface{}, params interface{}, optFns ...interface{}) *MockS3APIClient_ListObjects_Call {
|
||||
return &MockS3APIClient_ListObjects_Call{Call: _e.mock.On("ListObjects",
|
||||
append([]interface{}{ctx, params}, optFns...)...)}
|
||||
}
|
||||
|
||||
func (_c *MockS3APIClient_ListObjects_Call) Run(run func(ctx context.Context, params *s3.ListObjectsInput, optFns ...func(*s3.Options))) *MockS3APIClient_ListObjects_Call {
|
||||
_c.Call.Run(func(args mock.Arguments) {
|
||||
variadicArgs := make([]func(*s3.Options), len(args)-2)
|
||||
for i, a := range args[2:] {
|
||||
if a != nil {
|
||||
variadicArgs[i] = a.(func(*s3.Options))
|
||||
}
|
||||
}
|
||||
run(args[0].(context.Context), args[1].(*s3.ListObjectsInput), variadicArgs...)
|
||||
})
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *MockS3APIClient_ListObjects_Call) Return(_a0 *s3.ListObjectsOutput, _a1 error) *MockS3APIClient_ListObjects_Call {
|
||||
_c.Call.Return(_a0, _a1)
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *MockS3APIClient_ListObjects_Call) RunAndReturn(run func(context.Context, *s3.ListObjectsInput, ...func(*s3.Options)) (*s3.ListObjectsOutput, error)) *MockS3APIClient_ListObjects_Call {
|
||||
_c.Call.Return(run)
|
||||
return _c
|
||||
}
|
||||
|
||||
// PutObject provides a mock function with given fields: ctx, params, optFns
|
||||
func (_m *MockS3APIClient) PutObject(ctx context.Context, params *s3.PutObjectInput, optFns ...func(*s3.Options)) (*s3.PutObjectOutput, error) {
|
||||
_va := make([]interface{}, len(optFns))
|
||||
for _i := range optFns {
|
||||
_va[_i] = optFns[_i]
|
||||
}
|
||||
var _ca []interface{}
|
||||
_ca = append(_ca, ctx, params)
|
||||
_ca = append(_ca, _va...)
|
||||
ret := _m.Called(_ca...)
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for PutObject")
|
||||
}
|
||||
|
||||
var r0 *s3.PutObjectOutput
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *s3.PutObjectInput, ...func(*s3.Options)) (*s3.PutObjectOutput, error)); ok {
|
||||
return rf(ctx, params, optFns...)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *s3.PutObjectInput, ...func(*s3.Options)) *s3.PutObjectOutput); ok {
|
||||
r0 = rf(ctx, params, optFns...)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*s3.PutObjectOutput)
|
||||
}
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(context.Context, *s3.PutObjectInput, ...func(*s3.Options)) error); ok {
|
||||
r1 = rf(ctx, params, optFns...)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// MockS3APIClient_PutObject_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PutObject'
|
||||
type MockS3APIClient_PutObject_Call struct {
|
||||
*mock.Call
|
||||
}
|
||||
|
||||
// PutObject is a helper method to define mock.On call
|
||||
// - ctx context.Context
|
||||
// - params *s3.PutObjectInput
|
||||
// - optFns ...func(*s3.Options)
|
||||
func (_e *MockS3APIClient_Expecter) PutObject(ctx interface{}, params interface{}, optFns ...interface{}) *MockS3APIClient_PutObject_Call {
|
||||
return &MockS3APIClient_PutObject_Call{Call: _e.mock.On("PutObject",
|
||||
append([]interface{}{ctx, params}, optFns...)...)}
|
||||
}
|
||||
|
||||
func (_c *MockS3APIClient_PutObject_Call) Run(run func(ctx context.Context, params *s3.PutObjectInput, optFns ...func(*s3.Options))) *MockS3APIClient_PutObject_Call {
|
||||
_c.Call.Run(func(args mock.Arguments) {
|
||||
variadicArgs := make([]func(*s3.Options), len(args)-2)
|
||||
for i, a := range args[2:] {
|
||||
if a != nil {
|
||||
variadicArgs[i] = a.(func(*s3.Options))
|
||||
}
|
||||
}
|
||||
run(args[0].(context.Context), args[1].(*s3.PutObjectInput), variadicArgs...)
|
||||
})
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *MockS3APIClient_PutObject_Call) Return(_a0 *s3.PutObjectOutput, _a1 error) *MockS3APIClient_PutObject_Call {
|
||||
_c.Call.Return(_a0, _a1)
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *MockS3APIClient_PutObject_Call) RunAndReturn(run func(context.Context, *s3.PutObjectInput, ...func(*s3.Options)) (*s3.PutObjectOutput, error)) *MockS3APIClient_PutObject_Call {
|
||||
_c.Call.Return(run)
|
||||
return _c
|
||||
}
|
||||
|
||||
// NewMockS3APIClient creates a new instance of MockS3APIClient. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
|
||||
// The first argument is typically a *testing.T value.
|
||||
func NewMockS3APIClient(t interface {
|
||||
mock.TestingT
|
||||
Cleanup(func())
|
||||
}) *MockS3APIClient {
|
||||
mock := &MockS3APIClient{}
|
||||
mock.Mock.Test(t)
|
||||
|
||||
t.Cleanup(func() { mock.AssertExpectations(t) })
|
||||
|
||||
return mock
|
||||
}
|
389
aws/s3.go
Normal file
389
aws/s3.go
Normal file
|
@ -0,0 +1,389 @@
|
|||
package aws
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/md5" //nolint:gosec
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"mime"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
"github.com/aws/aws-sdk-go-v2/service/s3"
|
||||
"github.com/aws/aws-sdk-go-v2/service/s3/types"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
type S3 struct {
|
||||
client S3APIClient
|
||||
Bucket string
|
||||
DryRun bool
|
||||
}
|
||||
|
||||
type S3UploadOptions struct {
|
||||
LocalFilePath string
|
||||
RemoteObjectKey string
|
||||
ACL map[string]string
|
||||
ContentType map[string]string
|
||||
ContentEncoding map[string]string
|
||||
CacheControl map[string]string
|
||||
Metadata map[string]map[string]string
|
||||
}
|
||||
|
||||
type S3RedirectOptions struct {
|
||||
Path string
|
||||
Location string
|
||||
}
|
||||
|
||||
type S3DeleteOptions struct {
|
||||
RemoteObjectKey string
|
||||
}
|
||||
|
||||
type S3ListOptions struct {
|
||||
Path string
|
||||
}
|
||||
|
||||
// Upload uploads a file to an S3 bucket. It first checks if the file already exists in the bucket
|
||||
// and compares the local file's content and metadata with the remote file. If the file has changed,
|
||||
// it updates the remote file's metadata. If the file does not exist or has changed,
|
||||
// it uploads the local file to the remote bucket.
|
||||
func (u *S3) Upload(ctx context.Context, opt S3UploadOptions) error {
|
||||
if opt.LocalFilePath == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
file, err := os.Open(opt.LocalFilePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
acl := getACL(opt.LocalFilePath, opt.ACL)
|
||||
contentType := getContentType(opt.LocalFilePath, opt.ContentType)
|
||||
contentEncoding := getContentEncoding(opt.LocalFilePath, opt.ContentEncoding)
|
||||
cacheControl := getCacheControl(opt.LocalFilePath, opt.CacheControl)
|
||||
metadata := getMetadata(opt.LocalFilePath, opt.Metadata)
|
||||
|
||||
head, err := u.client.HeadObject(ctx, &s3.HeadObjectInput{
|
||||
Bucket: &u.Bucket,
|
||||
Key: &opt.RemoteObjectKey,
|
||||
})
|
||||
if err != nil {
|
||||
var noSuchKeyError *types.NoSuchKey
|
||||
if !errors.As(err, &noSuchKeyError) {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Debug().Msgf(
|
||||
"'%s' not found in bucket, uploading with content-type '%s' and permissions '%s'",
|
||||
opt.LocalFilePath,
|
||||
contentType,
|
||||
acl,
|
||||
)
|
||||
|
||||
if u.DryRun {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err = u.client.PutObject(ctx, &s3.PutObjectInput{
|
||||
Bucket: &u.Bucket,
|
||||
Key: &opt.RemoteObjectKey,
|
||||
Body: file,
|
||||
ContentType: &contentType,
|
||||
ACL: types.ObjectCannedACL(acl),
|
||||
Metadata: metadata,
|
||||
CacheControl: &cacheControl,
|
||||
ContentEncoding: &contentEncoding,
|
||||
})
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
//nolint:gosec
|
||||
hash := md5.New()
|
||||
_, _ = io.Copy(hash, file)
|
||||
sum := fmt.Sprintf("'%x'", hash.Sum(nil))
|
||||
|
||||
if sum == *head.ETag {
|
||||
shouldCopy, reason := u.shouldCopyObject(
|
||||
ctx, head, opt.LocalFilePath, opt.RemoteObjectKey, contentType, acl, contentEncoding, cacheControl, metadata,
|
||||
)
|
||||
if !shouldCopy {
|
||||
log.Debug().Msgf("skipping '%s' because hashes and metadata match", opt.LocalFilePath)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
log.Debug().Msgf("updating metadata for '%s' %s", opt.LocalFilePath, reason)
|
||||
|
||||
if u.DryRun {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err = u.client.CopyObject(ctx, &s3.CopyObjectInput{
|
||||
Bucket: &u.Bucket,
|
||||
Key: &opt.RemoteObjectKey,
|
||||
CopySource: aws.String(fmt.Sprintf("%s/%s", u.Bucket, opt.RemoteObjectKey)),
|
||||
ACL: types.ObjectCannedACL(acl),
|
||||
ContentType: &contentType,
|
||||
Metadata: metadata,
|
||||
MetadataDirective: types.MetadataDirectiveReplace,
|
||||
CacheControl: &cacheControl,
|
||||
ContentEncoding: &contentEncoding,
|
||||
})
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = file.Seek(0, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Debug().Msgf("uploading '%s' with content-type '%s' and permissions '%s'", opt.LocalFilePath, contentType, acl)
|
||||
|
||||
if u.DryRun {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err = u.client.PutObject(ctx, &s3.PutObjectInput{
|
||||
Bucket: &u.Bucket,
|
||||
Key: &opt.RemoteObjectKey,
|
||||
Body: file,
|
||||
ContentType: &contentType,
|
||||
ACL: types.ObjectCannedACL(acl),
|
||||
Metadata: metadata,
|
||||
CacheControl: &cacheControl,
|
||||
ContentEncoding: &contentEncoding,
|
||||
})
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// shouldCopyObject determines whether an S3 object should be copied based on changes in content type,
|
||||
// content encoding, cache control, and metadata. It compares the existing object's metadata with the
|
||||
// provided metadata and returns a boolean indicating whether the object should be copied,
|
||||
// along with a string describing the reason for the copy if applicable.
|
||||
//
|
||||
//nolint:gocognit
|
||||
func (u *S3) shouldCopyObject(
|
||||
ctx context.Context, head *s3.HeadObjectOutput,
|
||||
local, remote, contentType, acl, contentEncoding, cacheControl string,
|
||||
metadata map[string]string,
|
||||
) (bool, string) {
|
||||
var reason string
|
||||
|
||||
if head.ContentType == nil && contentType != "" {
|
||||
reason = fmt.Sprintf("content-type has changed from unset to %s", contentType)
|
||||
|
||||
return true, reason
|
||||
}
|
||||
|
||||
if head.ContentType != nil && contentType != *head.ContentType {
|
||||
reason = fmt.Sprintf("content-type has changed from %s to %s", *head.ContentType, contentType)
|
||||
|
||||
return true, reason
|
||||
}
|
||||
|
||||
if head.ContentEncoding == nil && contentEncoding != "" {
|
||||
reason = fmt.Sprintf("Content-Encoding has changed from unset to %s", contentEncoding)
|
||||
|
||||
return true, reason
|
||||
}
|
||||
|
||||
if head.ContentEncoding != nil && contentEncoding != *head.ContentEncoding {
|
||||
reason = fmt.Sprintf("Content-Encoding has changed from %s to %s", *head.ContentEncoding, contentEncoding)
|
||||
|
||||
return true, reason
|
||||
}
|
||||
|
||||
if head.CacheControl == nil && cacheControl != "" {
|
||||
reason = fmt.Sprintf("cache-control has changed from unset to %s", cacheControl)
|
||||
|
||||
return true, reason
|
||||
}
|
||||
|
||||
if head.CacheControl != nil && cacheControl != *head.CacheControl {
|
||||
reason = fmt.Sprintf("cache-control has changed from %s to %s", *head.CacheControl, cacheControl)
|
||||
|
||||
return true, reason
|
||||
}
|
||||
|
||||
if len(head.Metadata) != len(metadata) {
|
||||
reason = fmt.Sprintf("count of metadata values has changed for %s", local)
|
||||
|
||||
return true, reason
|
||||
}
|
||||
|
||||
if len(metadata) > 0 {
|
||||
for k, v := range metadata {
|
||||
if hv, ok := head.Metadata[k]; ok {
|
||||
if v != hv {
|
||||
reason = fmt.Sprintf("metadata values have changed for %s", remote)
|
||||
|
||||
return true, reason
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
grant, err := u.client.GetObjectAcl(ctx, &s3.GetObjectAclInput{
|
||||
Bucket: &u.Bucket,
|
||||
Key: &remote,
|
||||
})
|
||||
if err != nil {
|
||||
return false, ""
|
||||
}
|
||||
|
||||
previousACL := "private"
|
||||
|
||||
for _, g := range grant.Grants {
|
||||
grantee := g.Grantee
|
||||
if grantee.URI != nil {
|
||||
switch *grantee.URI {
|
||||
case "http://acs.amazonaws.com/groups/global/AllUsers":
|
||||
if g.Permission == "READ" {
|
||||
previousACL = "public-read"
|
||||
} else if g.Permission == "WRITE" {
|
||||
previousACL = "public-read-write"
|
||||
}
|
||||
case "http://acs.amazonaws.com/groups/global/AuthenticatedUsers":
|
||||
if g.Permission == "READ" {
|
||||
previousACL = "authenticated-read"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if previousACL != acl {
|
||||
reason = fmt.Sprintf("permissions for '%s' have changed from '%s' to '%s'", remote, previousACL, acl)
|
||||
|
||||
return true, reason
|
||||
}
|
||||
|
||||
return false, ""
|
||||
}
|
||||
|
||||
// getACL returns the ACL for the given file based on the provided patterns.
|
||||
func getACL(file string, patterns map[string]string) string {
|
||||
for pattern, acl := range patterns {
|
||||
if match, _ := filepath.Match(pattern, file); match {
|
||||
return acl
|
||||
}
|
||||
}
|
||||
|
||||
return "private"
|
||||
}
|
||||
|
||||
// getContentType returns the content type for the given file based on the provided patterns.
|
||||
func getContentType(file string, patterns map[string]string) string {
|
||||
ext := filepath.Ext(file)
|
||||
if contentType, ok := patterns[ext]; ok {
|
||||
return contentType
|
||||
}
|
||||
|
||||
return mime.TypeByExtension(ext)
|
||||
}
|
||||
|
||||
// getContentEncoding returns the content encoding for the given file based on the provided patterns.
|
||||
func getContentEncoding(file string, patterns map[string]string) string {
|
||||
ext := filepath.Ext(file)
|
||||
if contentEncoding, ok := patterns[ext]; ok {
|
||||
return contentEncoding
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
// getCacheControl returns the cache control for the given file based on the provided patterns.
|
||||
func getCacheControl(file string, patterns map[string]string) string {
|
||||
for pattern, cacheControl := range patterns {
|
||||
if match, _ := filepath.Match(pattern, file); match {
|
||||
return cacheControl
|
||||
}
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
// getMetadata returns the metadata for the given file based on the provided patterns.
|
||||
func getMetadata(file string, patterns map[string]map[string]string) map[string]string {
|
||||
metadata := make(map[string]string)
|
||||
|
||||
for pattern, meta := range patterns {
|
||||
if match, _ := filepath.Match(pattern, file); match {
|
||||
for k, v := range meta {
|
||||
metadata[k] = v
|
||||
}
|
||||
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return metadata
|
||||
}
|
||||
|
||||
// Redirect adds a redirect from the specified path to the specified location in the S3 bucket.
|
||||
func (u *S3) Redirect(ctx context.Context, opt S3RedirectOptions) error {
|
||||
log.Debug().Msgf("adding redirect from '%s' to '%s'", opt.Path, opt.Location)
|
||||
|
||||
if u.DryRun {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := u.client.PutObject(ctx, &s3.PutObjectInput{
|
||||
Bucket: aws.String(u.Bucket),
|
||||
Key: aws.String(opt.Path),
|
||||
ACL: types.ObjectCannedACLPublicRead,
|
||||
WebsiteRedirectLocation: aws.String(opt.Location),
|
||||
})
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// Delete removes the specified object from the S3 bucket.
|
||||
func (u *S3) Delete(ctx context.Context, opt S3DeleteOptions) error {
|
||||
log.Debug().Msgf("removing remote file '%s'", opt.RemoteObjectKey)
|
||||
|
||||
if u.DryRun {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := u.client.DeleteObject(ctx, &s3.DeleteObjectInput{
|
||||
Bucket: aws.String(u.Bucket),
|
||||
Key: aws.String(opt.RemoteObjectKey),
|
||||
})
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// List retrieves a list of object keys in the S3 bucket under the specified path.
|
||||
func (u *S3) List(ctx context.Context, opt S3ListOptions) ([]string, error) {
|
||||
var remote []string
|
||||
|
||||
input := &s3.ListObjectsInput{
|
||||
Bucket: aws.String(u.Bucket),
|
||||
Prefix: aws.String(opt.Path),
|
||||
}
|
||||
|
||||
for {
|
||||
resp, err := u.client.ListObjects(ctx, input)
|
||||
if err != nil {
|
||||
return remote, err
|
||||
}
|
||||
|
||||
for _, item := range resp.Contents {
|
||||
remote = append(remote, *item.Key)
|
||||
}
|
||||
|
||||
if !*resp.IsTruncated {
|
||||
break
|
||||
}
|
||||
|
||||
input.Marker = aws.String(remote[len(remote)-1])
|
||||
}
|
||||
|
||||
return remote, nil
|
||||
}
|
562
aws/s3_test.go
Normal file
562
aws/s3_test.go
Normal file
|
@ -0,0 +1,562 @@
|
|||
package aws
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
"github.com/aws/aws-sdk-go-v2/service/s3"
|
||||
"github.com/aws/aws-sdk-go-v2/service/s3/types"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/mock"
|
||||
"github.com/thegeeklab/wp-s3-action/aws/mocks"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrPutObject = errors.New("put object failed")
|
||||
ErrDeleteObject = errors.New("delete object failed")
|
||||
ErrListObjects = errors.New("list objects failed")
|
||||
)
|
||||
|
||||
func createTempFile(t *testing.T, name string) string {
|
||||
t.Helper()
|
||||
|
||||
name = filepath.Join(t.TempDir(), name)
|
||||
_ = os.WriteFile(name, []byte("hello"), 0o600)
|
||||
|
||||
return name
|
||||
}
|
||||
|
||||
func TestS3_Upload(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
setup func(t *testing.T) (*S3, S3UploadOptions, func())
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "skip upload when local is empty",
|
||||
setup: func(t *testing.T) (*S3, S3UploadOptions, func()) {
|
||||
t.Helper()
|
||||
|
||||
return &S3{},
|
||||
S3UploadOptions{
|
||||
LocalFilePath: "",
|
||||
}, func() {}
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "error when local file does not exist",
|
||||
setup: func(t *testing.T) (*S3, S3UploadOptions, func()) {
|
||||
t.Helper()
|
||||
|
||||
return &S3{},
|
||||
S3UploadOptions{
|
||||
LocalFilePath: "/path/to/non-existent/file",
|
||||
}, func() {}
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "upload new file with default acl and content type",
|
||||
setup: func(t *testing.T) (*S3, S3UploadOptions, func()) {
|
||||
t.Helper()
|
||||
|
||||
mockS3Client := mocks.NewMockS3APIClient(t)
|
||||
mockS3Client.On("HeadObject", mock.Anything, mock.Anything).Return(&s3.HeadObjectOutput{}, &types.NoSuchKey{})
|
||||
mockS3Client.On("PutObject", mock.Anything, mock.Anything).Return(&s3.PutObjectOutput{}, nil)
|
||||
|
||||
return &S3{
|
||||
client: mockS3Client,
|
||||
Bucket: "test-bucket",
|
||||
}, S3UploadOptions{
|
||||
LocalFilePath: createTempFile(t, "file.txt"),
|
||||
RemoteObjectKey: "remote/path/file.txt",
|
||||
}, func() {
|
||||
mockS3Client.AssertExpectations(t)
|
||||
}
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "update metadata when content type changed",
|
||||
setup: func(t *testing.T) (*S3, S3UploadOptions, func()) {
|
||||
t.Helper()
|
||||
|
||||
mockS3Client := mocks.NewMockS3APIClient(t)
|
||||
mockS3Client.On("HeadObject", mock.Anything, mock.Anything).Return(&s3.HeadObjectOutput{
|
||||
ETag: aws.String("'5d41402abc4b2a76b9719d911017c592'"),
|
||||
ContentType: aws.String("application/octet-stream"),
|
||||
}, nil)
|
||||
mockS3Client.On("CopyObject", mock.Anything, mock.Anything).Return(&s3.CopyObjectOutput{}, nil)
|
||||
|
||||
return &S3{
|
||||
client: mockS3Client,
|
||||
Bucket: "test-bucket",
|
||||
}, S3UploadOptions{
|
||||
LocalFilePath: createTempFile(t, "file.txt"),
|
||||
RemoteObjectKey: "remote/path/file.txt",
|
||||
ContentType: map[string]string{"*.txt": "text/plain"},
|
||||
}, func() {
|
||||
mockS3Client.AssertExpectations(t)
|
||||
}
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "update metadata when acl changed",
|
||||
setup: func(t *testing.T) (*S3, S3UploadOptions, func()) {
|
||||
t.Helper()
|
||||
|
||||
mockS3Client := mocks.NewMockS3APIClient(t)
|
||||
mockS3Client.On("HeadObject", mock.Anything, mock.Anything).Return(&s3.HeadObjectOutput{
|
||||
ETag: aws.String("'5d41402abc4b2a76b9719d911017c592'"),
|
||||
ContentType: aws.String("text/plain; charset=utf-8"),
|
||||
}, nil)
|
||||
mockS3Client.On("GetObjectAcl", mock.Anything, mock.Anything).Return(&s3.GetObjectAclOutput{
|
||||
Grants: []types.Grant{
|
||||
{
|
||||
Grantee: &types.Grantee{
|
||||
URI: aws.String("http://acs.amazonaws.com/groups/global/AllUsers"),
|
||||
},
|
||||
Permission: types.PermissionWrite,
|
||||
},
|
||||
},
|
||||
}, nil)
|
||||
mockS3Client.On("CopyObject", mock.Anything, mock.Anything).Return(&s3.CopyObjectOutput{}, nil)
|
||||
|
||||
return &S3{
|
||||
client: mockS3Client,
|
||||
Bucket: "test-bucket",
|
||||
}, S3UploadOptions{
|
||||
LocalFilePath: createTempFile(t, "file.txt"),
|
||||
RemoteObjectKey: "remote/path/file.txt",
|
||||
ACL: map[string]string{"*.txt": "public-read"},
|
||||
}, func() {
|
||||
mockS3Client.AssertExpectations(t)
|
||||
}
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "update metadata when cache control changed",
|
||||
setup: func(t *testing.T) (*S3, S3UploadOptions, func()) {
|
||||
t.Helper()
|
||||
|
||||
mockS3Client := mocks.NewMockS3APIClient(t)
|
||||
mockS3Client.On("HeadObject", mock.Anything, mock.Anything).Return(&s3.HeadObjectOutput{
|
||||
ETag: aws.String("'5d41402abc4b2a76b9719d911017c592'"),
|
||||
ContentType: aws.String("text/plain; charset=utf-8"),
|
||||
CacheControl: aws.String("max-age=0"),
|
||||
}, nil)
|
||||
mockS3Client.On("CopyObject", mock.Anything, mock.Anything).Return(&s3.CopyObjectOutput{}, nil)
|
||||
|
||||
return &S3{
|
||||
client: mockS3Client,
|
||||
Bucket: "test-bucket",
|
||||
}, S3UploadOptions{
|
||||
LocalFilePath: createTempFile(t, "file.txt"),
|
||||
RemoteObjectKey: "remote/path/file.txt",
|
||||
CacheControl: map[string]string{"*.txt": "max-age=3600"},
|
||||
}, func() {
|
||||
mockS3Client.AssertExpectations(t)
|
||||
}
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "update metadata when content encoding changed",
|
||||
setup: func(t *testing.T) (*S3, S3UploadOptions, func()) {
|
||||
t.Helper()
|
||||
|
||||
mockS3Client := mocks.NewMockS3APIClient(t)
|
||||
mockS3Client.On("HeadObject", mock.Anything, mock.Anything).Return(&s3.HeadObjectOutput{
|
||||
ETag: aws.String("'5d41402abc4b2a76b9719d911017c592'"),
|
||||
ContentType: aws.String("text/plain; charset=utf-8"),
|
||||
ContentEncoding: aws.String("identity"),
|
||||
}, nil)
|
||||
mockS3Client.On("CopyObject", mock.Anything, mock.Anything).Return(&s3.CopyObjectOutput{}, nil)
|
||||
|
||||
return &S3{
|
||||
client: mockS3Client,
|
||||
Bucket: "test-bucket",
|
||||
}, S3UploadOptions{
|
||||
LocalFilePath: createTempFile(t, "file.txt"),
|
||||
RemoteObjectKey: "remote/path/file.txt",
|
||||
ContentEncoding: map[string]string{"*.txt": "gzip"},
|
||||
}, func() {
|
||||
mockS3Client.AssertExpectations(t)
|
||||
}
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "update metadata when metadata changed",
|
||||
setup: func(t *testing.T) (*S3, S3UploadOptions, func()) {
|
||||
t.Helper()
|
||||
|
||||
mockS3Client := mocks.NewMockS3APIClient(t)
|
||||
mockS3Client.On("HeadObject", mock.Anything, mock.Anything).Return(&s3.HeadObjectOutput{
|
||||
ETag: aws.String("'5d41402abc4b2a76b9719d911017c592'"),
|
||||
ContentType: aws.String("text/plain; charset=utf-8"),
|
||||
Metadata: map[string]string{"key": "old-value"},
|
||||
}, nil)
|
||||
mockS3Client.On("CopyObject", mock.Anything, mock.Anything).Return(&s3.CopyObjectOutput{}, nil)
|
||||
|
||||
return &S3{
|
||||
client: mockS3Client,
|
||||
Bucket: "test-bucket",
|
||||
}, S3UploadOptions{
|
||||
LocalFilePath: createTempFile(t, "file.txt"),
|
||||
RemoteObjectKey: "remote/path/file.txt",
|
||||
Metadata: map[string]map[string]string{"*.txt": {"key": "value"}},
|
||||
}, func() {
|
||||
mockS3Client.AssertExpectations(t)
|
||||
}
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "upload new file when dry run is true",
|
||||
setup: func(t *testing.T) (*S3, S3UploadOptions, func()) {
|
||||
t.Helper()
|
||||
|
||||
mockS3Client := mocks.NewMockS3APIClient(t)
|
||||
mockS3Client.On("HeadObject", mock.Anything, mock.Anything).Return(&s3.HeadObjectOutput{}, &types.NoSuchKey{})
|
||||
|
||||
return &S3{
|
||||
client: mockS3Client,
|
||||
Bucket: "test-bucket",
|
||||
DryRun: true,
|
||||
}, S3UploadOptions{
|
||||
LocalFilePath: createTempFile(t, "file1.txt"),
|
||||
RemoteObjectKey: "remote/path/file1.txt",
|
||||
}, func() {
|
||||
mockS3Client.AssertExpectations(t)
|
||||
}
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
s3, opt, teardown := tt.setup(t)
|
||||
defer teardown()
|
||||
|
||||
err := s3.Upload(context.Background(), opt)
|
||||
if tt.wantErr {
|
||||
assert.Error(t, err)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
assert.NoError(t, err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestS3_Redirect(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
setup func(t *testing.T) (*S3, S3RedirectOptions, func())
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "redirect with valid options",
|
||||
setup: func(t *testing.T) (*S3, S3RedirectOptions, func()) {
|
||||
t.Helper()
|
||||
|
||||
mockS3Client := mocks.NewMockS3APIClient(t)
|
||||
mockS3Client.On("PutObject", mock.Anything, mock.Anything).Return(&s3.PutObjectOutput{}, nil)
|
||||
|
||||
return &S3{
|
||||
client: mockS3Client,
|
||||
Bucket: "test-bucket",
|
||||
}, S3RedirectOptions{
|
||||
Path: "redirect/path",
|
||||
Location: "https://example.com",
|
||||
}, func() {
|
||||
mockS3Client.AssertExpectations(t)
|
||||
}
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "skip redirect when dry run is true",
|
||||
setup: func(t *testing.T) (*S3, S3RedirectOptions, func()) {
|
||||
t.Helper()
|
||||
|
||||
mockS3Client := mocks.NewMockS3APIClient(t)
|
||||
|
||||
return &S3{
|
||||
client: mockS3Client,
|
||||
Bucket: "test-bucket",
|
||||
DryRun: true,
|
||||
}, S3RedirectOptions{
|
||||
Path: "redirect/path",
|
||||
Location: "https://example.com",
|
||||
}, func() {
|
||||
mockS3Client.AssertExpectations(t)
|
||||
}
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "error when put object fails",
|
||||
setup: func(t *testing.T) (*S3, S3RedirectOptions, func()) {
|
||||
t.Helper()
|
||||
|
||||
mockS3Client := mocks.NewMockS3APIClient(t)
|
||||
mockS3Client.
|
||||
On("PutObject", mock.Anything, mock.Anything).
|
||||
Return(&s3.PutObjectOutput{}, ErrPutObject)
|
||||
|
||||
return &S3{
|
||||
client: mockS3Client,
|
||||
Bucket: "test-bucket",
|
||||
}, S3RedirectOptions{
|
||||
Path: "redirect/path",
|
||||
Location: "https://example.com",
|
||||
}, func() {
|
||||
mockS3Client.AssertExpectations(t)
|
||||
}
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
s3, opt, teardown := tt.setup(t)
|
||||
defer teardown()
|
||||
|
||||
err := s3.Redirect(context.Background(), opt)
|
||||
if tt.wantErr {
|
||||
assert.Error(t, err)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
assert.NoError(t, err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestS3_Delete(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
setup func(t *testing.T) (*S3, S3DeleteOptions, func())
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "delete existing object",
|
||||
setup: func(t *testing.T) (*S3, S3DeleteOptions, func()) {
|
||||
t.Helper()
|
||||
|
||||
mockS3Client := mocks.NewMockS3APIClient(t)
|
||||
mockS3Client.On("DeleteObject", mock.Anything, mock.Anything).Return(&s3.DeleteObjectOutput{}, nil)
|
||||
|
||||
return &S3{
|
||||
client: mockS3Client,
|
||||
Bucket: "test-bucket",
|
||||
}, S3DeleteOptions{
|
||||
RemoteObjectKey: "path/to/file.txt",
|
||||
}, func() {
|
||||
mockS3Client.AssertExpectations(t)
|
||||
}
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "skip delete when dry run is true",
|
||||
setup: func(t *testing.T) (*S3, S3DeleteOptions, func()) {
|
||||
t.Helper()
|
||||
|
||||
mockS3Client := mocks.NewMockS3APIClient(t)
|
||||
|
||||
return &S3{
|
||||
client: mockS3Client,
|
||||
Bucket: "test-bucket",
|
||||
DryRun: true,
|
||||
}, S3DeleteOptions{
|
||||
RemoteObjectKey: "path/to/file.txt",
|
||||
}, func() {
|
||||
mockS3Client.AssertExpectations(t)
|
||||
}
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "error when delete object fails",
|
||||
setup: func(t *testing.T) (*S3, S3DeleteOptions, func()) {
|
||||
t.Helper()
|
||||
|
||||
mockS3Client := mocks.NewMockS3APIClient(t)
|
||||
mockS3Client.
|
||||
On("DeleteObject", mock.Anything, mock.Anything).
|
||||
Return(&s3.DeleteObjectOutput{}, ErrDeleteObject)
|
||||
|
||||
return &S3{
|
||||
client: mockS3Client,
|
||||
Bucket: "test-bucket",
|
||||
}, S3DeleteOptions{
|
||||
RemoteObjectKey: "path/to/file.txt",
|
||||
}, func() {
|
||||
mockS3Client.AssertExpectations(t)
|
||||
}
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
s3, opt, teardown := tt.setup(t)
|
||||
defer teardown()
|
||||
|
||||
err := s3.Delete(context.Background(), opt)
|
||||
if tt.wantErr {
|
||||
assert.Error(t, err)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
assert.NoError(t, err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestS3_List(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
setup func(t *testing.T) (*S3, S3ListOptions, func())
|
||||
wantErr bool
|
||||
want []string
|
||||
}{
|
||||
{
|
||||
name: "list objects in prefix",
|
||||
setup: func(t *testing.T) (*S3, S3ListOptions, func()) {
|
||||
t.Helper()
|
||||
|
||||
mockS3Client := mocks.NewMockS3APIClient(t)
|
||||
mockS3Client.On("ListObjects", mock.Anything, mock.Anything).Return(&s3.ListObjectsOutput{
|
||||
Contents: []types.Object{
|
||||
{Key: aws.String("prefix/file1.txt")},
|
||||
{Key: aws.String("prefix/file2.txt")},
|
||||
},
|
||||
IsTruncated: aws.Bool(false),
|
||||
}, nil)
|
||||
|
||||
return &S3{
|
||||
client: mockS3Client,
|
||||
Bucket: "test-bucket",
|
||||
}, S3ListOptions{
|
||||
Path: "prefix/",
|
||||
}, func() {
|
||||
mockS3Client.AssertExpectations(t)
|
||||
}
|
||||
},
|
||||
wantErr: false,
|
||||
want: []string{"prefix/file1.txt", "prefix/file2.txt"},
|
||||
},
|
||||
{
|
||||
name: "list objects with pagination",
|
||||
setup: func(t *testing.T) (*S3, S3ListOptions, func()) {
|
||||
t.Helper()
|
||||
|
||||
mockS3Client := mocks.NewMockS3APIClient(t)
|
||||
mockS3Client.On("ListObjects", mock.Anything, mock.MatchedBy(func(input *s3.ListObjectsInput) bool {
|
||||
return input.Marker == nil
|
||||
})).Return(&s3.ListObjectsOutput{
|
||||
Contents: []types.Object{
|
||||
{Key: aws.String("prefix/file1.txt")},
|
||||
{Key: aws.String("prefix/file2.txt")},
|
||||
},
|
||||
IsTruncated: aws.Bool(true),
|
||||
}, nil)
|
||||
mockS3Client.On("ListObjects", mock.Anything, mock.MatchedBy(func(input *s3.ListObjectsInput) bool {
|
||||
return *input.Marker == "prefix/file2.txt"
|
||||
})).Return(&s3.ListObjectsOutput{
|
||||
Contents: []types.Object{
|
||||
{Key: aws.String("prefix/file3.txt")},
|
||||
},
|
||||
IsTruncated: aws.Bool(false),
|
||||
}, nil)
|
||||
|
||||
return &S3{
|
||||
client: mockS3Client,
|
||||
Bucket: "test-bucket",
|
||||
}, S3ListOptions{
|
||||
Path: "prefix/",
|
||||
}, func() {
|
||||
mockS3Client.AssertExpectations(t)
|
||||
}
|
||||
},
|
||||
wantErr: false,
|
||||
want: []string{"prefix/file1.txt", "prefix/file2.txt", "prefix/file3.txt"},
|
||||
},
|
||||
{
|
||||
name: "error when list objects fails",
|
||||
setup: func(t *testing.T) (*S3, S3ListOptions, func()) {
|
||||
t.Helper()
|
||||
|
||||
mockS3Client := mocks.NewMockS3APIClient(t)
|
||||
mockS3Client.
|
||||
On("ListObjects", mock.Anything, mock.Anything).
|
||||
Return(&s3.ListObjectsOutput{}, ErrListObjects)
|
||||
|
||||
return &S3{
|
||||
client: mockS3Client,
|
||||
Bucket: "test-bucket",
|
||||
}, S3ListOptions{
|
||||
Path: "prefix/",
|
||||
}, func() {
|
||||
mockS3Client.AssertExpectations(t)
|
||||
}
|
||||
},
|
||||
wantErr: true,
|
||||
want: nil,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
s3, opt, teardown := tt.setup(t)
|
||||
defer teardown()
|
||||
|
||||
got, err := s3.List(context.Background(), opt)
|
||||
if tt.wantErr {
|
||||
assert.Error(t, err)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.ElementsMatch(t, tt.want, got)
|
||||
})
|
||||
}
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
//go:build generate
|
||||
// +build generate
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"embed"
|
||||
"fmt"
|
||||
"os"
|
||||
"text/template"
|
||||
|
||||
"github.com/thegeeklab/wp-plugin-go/docs"
|
||||
wp "github.com/thegeeklab/wp-plugin-go/plugin"
|
||||
wp_template "github.com/thegeeklab/wp-plugin-go/template"
|
||||
"github.com/thegeeklab/wp-s3-action/plugin"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
//go:embed templates/docs-data.yaml.tmpl
|
||||
var yamlTemplate embed.FS
|
||||
|
||||
func main() {
|
||||
settings := &plugin.Settings{}
|
||||
app := &cli.App{
|
||||
Flags: settingsFlags(settings, wp.FlagsPluginCategory),
|
||||
}
|
||||
|
||||
out, err := toYAML(app)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fi, err := os.Create("../../docs/data/data-raw.yaml")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer fi.Close()
|
||||
if _, err := fi.WriteString(out); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func toYAML(app *cli.App) (string, error) {
|
||||
var w bytes.Buffer
|
||||
|
||||
yamlTmpl, err := template.New("docs").Funcs(wp_template.LoadFuncMap()).ParseFS(yamlTemplate, "templates/docs-data.yaml.tmpl")
|
||||
if err != nil {
|
||||
fmt.Println(yamlTmpl)
|
||||
return "", err
|
||||
}
|
||||
|
||||
if err := yamlTmpl.ExecuteTemplate(&w, "docs-data.yaml.tmpl", docs.GetTemplateData(app)); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return w.String(), nil
|
||||
}
|
|
@ -1,150 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/thegeeklab/wp-plugin-go/types"
|
||||
"github.com/thegeeklab/wp-s3-action/plugin"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
// settingsFlags has the cli.Flags for the plugin.Settings.
|
||||
//
|
||||
//go:generate go run docs.go flags.go
|
||||
func settingsFlags(settings *plugin.Settings, category string) []cli.Flag {
|
||||
return []cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "endpoint",
|
||||
Usage: "endpoint for the s3 connection",
|
||||
EnvVars: []string{"PLUGIN_ENDPOINT", "S3_ENDPOINT"},
|
||||
Destination: &settings.Endpoint,
|
||||
Category: category,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "access-key",
|
||||
Usage: "s3 access key",
|
||||
EnvVars: []string{"PLUGIN_ACCESS_KEY", "S3_ACCESS_KEY"},
|
||||
Destination: &settings.AccessKey,
|
||||
Required: true,
|
||||
Category: category,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "secret-key",
|
||||
Usage: "s3 secret key",
|
||||
EnvVars: []string{"PLUGIN_SECRET_KEY", "S3_SECRET_KEY"},
|
||||
Destination: &settings.SecretKey,
|
||||
Required: true,
|
||||
Category: category,
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "path-style",
|
||||
Usage: "enable path style for bucket paths",
|
||||
EnvVars: []string{"PLUGIN_PATH_STYLE"},
|
||||
Destination: &settings.PathStyle,
|
||||
Category: category,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "bucket",
|
||||
Usage: "name of the bucket",
|
||||
EnvVars: []string{"PLUGIN_BUCKET"},
|
||||
Destination: &settings.Bucket,
|
||||
Required: true,
|
||||
Category: category,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "region",
|
||||
Usage: "s3 region",
|
||||
Value: "us-east-1",
|
||||
EnvVars: []string{"PLUGIN_REGION"},
|
||||
Destination: &settings.Region,
|
||||
Category: category,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "source",
|
||||
Usage: "upload source path",
|
||||
Value: ".",
|
||||
EnvVars: []string{"PLUGIN_SOURCE"},
|
||||
Destination: &settings.Source,
|
||||
Category: category,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "target",
|
||||
Usage: "upload target path",
|
||||
Value: "/",
|
||||
EnvVars: []string{"PLUGIN_TARGET"},
|
||||
Destination: &settings.Target,
|
||||
Category: category,
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "delete",
|
||||
Usage: "delete locally removed files from the target",
|
||||
EnvVars: []string{"PLUGIN_DELETE"},
|
||||
Destination: &settings.Delete,
|
||||
Category: category,
|
||||
},
|
||||
&cli.GenericFlag{
|
||||
Name: "acl",
|
||||
Usage: "access control list",
|
||||
EnvVars: []string{"PLUGIN_ACL"},
|
||||
Value: &types.StringMapFlag{},
|
||||
Category: category,
|
||||
},
|
||||
&cli.GenericFlag{
|
||||
Name: "content-type",
|
||||
Usage: "content-type settings for uploads",
|
||||
EnvVars: []string{"PLUGIN_CONTENT_TYPE"},
|
||||
Value: &types.StringMapFlag{},
|
||||
Category: category,
|
||||
},
|
||||
&cli.GenericFlag{
|
||||
Name: "content-encoding",
|
||||
Usage: "content-encoding settings for uploads",
|
||||
EnvVars: []string{"PLUGIN_CONTENT_ENCODING"},
|
||||
Value: &types.StringMapFlag{},
|
||||
Category: category,
|
||||
},
|
||||
&cli.GenericFlag{
|
||||
Name: "cache-control",
|
||||
Usage: "cache-control settings for uploads",
|
||||
EnvVars: []string{"PLUGIN_CACHE_CONTROL"},
|
||||
Value: &types.StringMapFlag{},
|
||||
Category: category,
|
||||
},
|
||||
&cli.GenericFlag{
|
||||
Name: "metadata",
|
||||
Usage: "additional metadata for uploads",
|
||||
EnvVars: []string{"PLUGIN_METADATA"},
|
||||
Value: &types.DeepStringMapFlag{},
|
||||
Category: category,
|
||||
},
|
||||
&cli.GenericFlag{
|
||||
Name: "redirects",
|
||||
Usage: "redirects to create",
|
||||
EnvVars: []string{"PLUGIN_REDIRECTS"},
|
||||
Value: &types.MapFlag{},
|
||||
Category: category,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "cloudfront-distribution",
|
||||
Usage: "ID of cloudfront distribution to invalidate",
|
||||
EnvVars: []string{"PLUGIN_CLOUDFRONT_DISTRIBUTION"},
|
||||
Destination: &settings.CloudFrontDistribution,
|
||||
Category: category,
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "dry-run",
|
||||
Usage: "dry run disables api calls",
|
||||
EnvVars: []string{"DRY_RUN", "PLUGIN_DRY_RUN"},
|
||||
Destination: &settings.DryRun,
|
||||
Category: category,
|
||||
},
|
||||
&cli.IntFlag{
|
||||
Name: "max-concurrency",
|
||||
Usage: "customize number concurrent files to process",
|
||||
//nolint:gomnd
|
||||
Value: 100,
|
||||
EnvVars: []string{"PLUGIN_MAX_CONCURRENCY"},
|
||||
Destination: &settings.MaxConcurrency,
|
||||
Category: category,
|
||||
},
|
||||
}
|
||||
}
|
|
@ -1,11 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/thegeeklab/wp-s3-action/plugin"
|
||||
|
||||
wp "github.com/thegeeklab/wp-plugin-go/plugin"
|
||||
)
|
||||
|
||||
//nolint:gochecknoglobals
|
||||
|
@ -15,14 +11,5 @@ var (
|
|||
)
|
||||
|
||||
func main() {
|
||||
settings := &plugin.Settings{}
|
||||
options := wp.Options{
|
||||
Name: "wp-s3-action",
|
||||
Description: "Perform S3 actions",
|
||||
Version: BuildVersion,
|
||||
VersionMetadata: fmt.Sprintf("date=%s", BuildDate),
|
||||
Flags: settingsFlags(settings, wp.FlagsPluginCategory),
|
||||
}
|
||||
|
||||
plugin.New(options, settings).Run()
|
||||
plugin.New(nil, BuildVersion, BuildDate).Run()
|
||||
}
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
---
|
||||
{{- if .GlobalArgs }}
|
||||
properties:
|
||||
{{- range $v := .GlobalArgs }}
|
||||
- name: {{ $v.Name }}
|
||||
{{- with $v.Description }}
|
||||
description: |
|
||||
{{ . | ToSentence }}
|
||||
{{- end }}
|
||||
{{- with $v.Type }}
|
||||
type: {{ . }}
|
||||
{{- end }}
|
||||
{{- with $v.Default }}
|
||||
defaultValue: {{ . }}
|
||||
{{- end }}
|
||||
required: {{ default false $v.Required }}
|
||||
{{ end -}}
|
||||
{{ end -}}
|
|
@ -55,6 +55,20 @@ properties:
|
|||
type: string
|
||||
required: false
|
||||
|
||||
- name: insecure_skip_verify
|
||||
description: |
|
||||
Skip SSL verification.
|
||||
type: bool
|
||||
defaultValue: false
|
||||
required: false
|
||||
|
||||
- name: log_level
|
||||
description: |
|
||||
Plugin log level.
|
||||
type: string
|
||||
defaultValue: "info"
|
||||
required: false
|
||||
|
||||
- name: max_concurrency
|
||||
description: |
|
||||
Customize number concurrent files to process.
|
||||
|
|
42
go.mod
42
go.mod
|
@ -3,18 +3,37 @@ module github.com/thegeeklab/wp-s3-action
|
|||
go 1.22
|
||||
|
||||
require (
|
||||
github.com/aws/aws-sdk-go v1.51.25
|
||||
github.com/rs/zerolog v1.32.0
|
||||
github.com/ryanuber/go-glob v1.0.0
|
||||
github.com/thegeeklab/wp-plugin-go v1.7.1
|
||||
github.com/urfave/cli/v2 v2.27.1
|
||||
github.com/aws/aws-sdk-go-v2 v1.27.0
|
||||
github.com/aws/aws-sdk-go-v2/config v1.27.16
|
||||
github.com/aws/aws-sdk-go-v2/credentials v1.17.16
|
||||
github.com/aws/aws-sdk-go-v2/service/cloudfront v1.36.4
|
||||
github.com/aws/aws-sdk-go-v2/service/s3 v1.54.3
|
||||
github.com/rs/zerolog v1.33.0
|
||||
github.com/stretchr/testify v1.9.0
|
||||
github.com/thegeeklab/wp-plugin-go/v3 v3.0.2
|
||||
github.com/urfave/cli/v2 v2.27.2
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/Masterminds/goutils v1.1.1 // indirect
|
||||
github.com/Masterminds/semver/v3 v3.2.1 // indirect
|
||||
github.com/Masterminds/sprig/v3 v3.2.3 // indirect
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.2 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.3 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.7 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.7 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.7 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.2 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.3.9 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.9 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.7 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/sso v1.20.9 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.24.3 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/sts v1.28.10 // indirect
|
||||
github.com/aws/smithy-go v1.20.2 // indirect
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/google/uuid v1.1.1 // indirect
|
||||
github.com/huandu/xstrings v1.3.3 // indirect
|
||||
github.com/imdario/mergo v0.3.11 // indirect
|
||||
|
@ -24,11 +43,14 @@ require (
|
|||
github.com/mattn/go-isatty v0.0.19 // indirect
|
||||
github.com/mitchellh/copystructure v1.0.0 // indirect
|
||||
github.com/mitchellh/reflectwalk v1.0.0 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
||||
github.com/shopspring/decimal v1.2.0 // indirect
|
||||
github.com/spf13/cast v1.3.1 // indirect
|
||||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
|
||||
golang.org/x/crypto v0.22.0 // indirect
|
||||
golang.org/x/net v0.24.0 // indirect
|
||||
golang.org/x/sys v0.19.0 // indirect
|
||||
github.com/stretchr/objx v0.5.2 // indirect
|
||||
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 // indirect
|
||||
golang.org/x/crypto v0.23.0 // indirect
|
||||
golang.org/x/net v0.25.0 // indirect
|
||||
golang.org/x/sys v0.20.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
|
79
go.sum
79
go.sum
|
@ -5,11 +5,47 @@ github.com/Masterminds/semver/v3 v3.2.1 h1:RN9w6+7QoMeJVGyfmbcgs28Br8cvmnucEXnY0
|
|||
github.com/Masterminds/semver/v3 v3.2.1/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ=
|
||||
github.com/Masterminds/sprig/v3 v3.2.3 h1:eL2fZNezLomi0uOLqjQoN6BfsDD+fyLtgbJMAj9n6YA=
|
||||
github.com/Masterminds/sprig/v3 v3.2.3/go.mod h1:rXcFaZ2zZbLRJv/xSysmlgIM1u11eBaRMhvYXJNkGuM=
|
||||
github.com/aws/aws-sdk-go v1.51.25 h1:DjTT8mtmsachhV6yrXR8+yhnG6120dazr720nopRsls=
|
||||
github.com/aws/aws-sdk-go v1.51.25/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk=
|
||||
github.com/aws/aws-sdk-go-v2 v1.27.0 h1:7bZWKoXhzI+mMR/HjdMx8ZCC5+6fY0lS5tr0bbgiLlo=
|
||||
github.com/aws/aws-sdk-go-v2 v1.27.0/go.mod h1:ffIFB97e2yNsv4aTSGkqtHnppsIJzw7G7BReUZ3jCXM=
|
||||
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.2 h1:x6xsQXGSmW6frevwDA+vi/wqhp1ct18mVXYN08/93to=
|
||||
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.2/go.mod h1:lPprDr1e6cJdyYeGXnRaJoP4Md+cDBvi2eOj00BlGmg=
|
||||
github.com/aws/aws-sdk-go-v2/config v1.27.16 h1:knpCuH7laFVGYTNd99Ns5t+8PuRjDn4HnnZK48csipM=
|
||||
github.com/aws/aws-sdk-go-v2/config v1.27.16/go.mod h1:vutqgRhDUktwSge3hrC3nkuirzkJ4E/mLj5GvI0BQas=
|
||||
github.com/aws/aws-sdk-go-v2/credentials v1.17.16 h1:7d2QxY83uYl0l58ceyiSpxg9bSbStqBC6BeEeHEchwo=
|
||||
github.com/aws/aws-sdk-go-v2/credentials v1.17.16/go.mod h1:Ae6li/6Yc6eMzysRL2BXlPYvnrLLBg3D11/AmOjw50k=
|
||||
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.3 h1:dQLK4TjtnlRGb0czOht2CevZ5l6RSyRWAnKeGd7VAFE=
|
||||
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.3/go.mod h1:TL79f2P6+8Q7dTsILpiVST+AL9lkF6PPGI167Ny0Cjw=
|
||||
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.7 h1:lf/8VTF2cM+N4SLzaYJERKEWAXq8MOMpZfU6wEPWsPk=
|
||||
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.7/go.mod h1:4SjkU7QiqK2M9oozyMzfZ/23LmUY+h3oFqhdeP5OMiI=
|
||||
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.7 h1:4OYVp0705xu8yjdyoWix0r9wPIRXnIzzOoUpQVHIJ/g=
|
||||
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.7/go.mod h1:vd7ESTEvI76T2Na050gODNmNU7+OyKrIKroYTu4ABiI=
|
||||
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 h1:hT8rVHwugYE2lEfdFE0QWVo81lF7jMrYJVDWI+f+VxU=
|
||||
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0/go.mod h1:8tu/lYfQfFe6IGnaOdrpVgEL2IrrDOf6/m9RQum4NkY=
|
||||
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.7 h1:/FUtT3xsoHO3cfh+I/kCbcMCN98QZRsiFet/V8QkWSs=
|
||||
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.7/go.mod h1:MaCAgWpGooQoCWZnMur97rGn5dp350w2+CeiV5406wE=
|
||||
github.com/aws/aws-sdk-go-v2/service/cloudfront v1.36.4 h1:8qjQzwztUVdFJi/wrhPXxRgSbyAKDsnJuduHaw+yP30=
|
||||
github.com/aws/aws-sdk-go-v2/service/cloudfront v1.36.4/go.mod h1:lHdM6itntBCcjvqxEHDoHkXRicwgY9aoPRptXuMdbgk=
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.2 h1:Ji0DY1xUsUr3I8cHps0G+XM3WWU16lP6yG8qu1GAZAs=
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.2/go.mod h1:5CsjAbs3NlGQyZNFACh+zztPDI7fU6eW9QsxjfnuBKg=
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.3.9 h1:UXqEWQI0n+q0QixzU0yUUQBZXRd5037qdInTIHFTl98=
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.3.9/go.mod h1:xP6Gq6fzGZT8w/ZN+XvGMZ2RU1LeEs7b2yUP5DN8NY4=
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.9 h1:Wx0rlZoEJR7JwlSZcHnEa7CNjrSIyVxMFWGAaXy4fJY=
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.9/go.mod h1:aVMHdE0aHO3v+f/iw01fmXV/5DbfQ3Bi9nN7nd9bE9Y=
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.7 h1:uO5XR6QGBcmPyo2gxofYJLFkcVQ4izOoGDNenlZhTEk=
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.7/go.mod h1:feeeAYfAcwTReM6vbwjEyDmiGho+YgBhaFULuXDW8kc=
|
||||
github.com/aws/aws-sdk-go-v2/service/s3 v1.54.3 h1:57NtjG+WLims0TxIQbjTqebZUKDM03DfM11ANAekW0s=
|
||||
github.com/aws/aws-sdk-go-v2/service/s3 v1.54.3/go.mod h1:739CllldowZiPPsDFcJHNF4FXrVxaSGVnZ9Ez9Iz9hc=
|
||||
github.com/aws/aws-sdk-go-v2/service/sso v1.20.9 h1:aD7AGQhvPuAxlSUfo0CWU7s6FpkbyykMhGYMvlqTjVs=
|
||||
github.com/aws/aws-sdk-go-v2/service/sso v1.20.9/go.mod h1:c1qtZUWtygI6ZdvKppzCSXsDOq5I4luJPZ0Ud3juFCA=
|
||||
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.24.3 h1:Pav5q3cA260Zqez42T9UhIlsd9QeypszRPwC9LdSSsQ=
|
||||
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.24.3/go.mod h1:9lmoVDVLz/yUZwLaQ676TK02fhCu4+PgRSmMaKR1ozk=
|
||||
github.com/aws/aws-sdk-go-v2/service/sts v1.28.10 h1:69tpbPED7jKPyzMcrwSvhWcJ9bPnZsZs18NT40JwM0g=
|
||||
github.com/aws/aws-sdk-go-v2/service/sts v1.28.10/go.mod h1:0Aqn1MnEuitqfsCNyKsdKLhDUOr4txD/g19EfiUqgws=
|
||||
github.com/aws/smithy-go v1.20.2 h1:tbp628ireGtzcHDDmLT/6ADHidqnwgF57XOXZe6tp4Q=
|
||||
github.com/aws/smithy-go v1.20.2/go.mod h1:krry+ya/rV9RDcV/Q16kpu6ypI4K2czasz0NC3qS14E=
|
||||
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||
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=
|
||||
|
@ -39,40 +75,40 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
|
|||
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/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
|
||||
github.com/rs/zerolog v1.32.0 h1:keLypqrlIjaFsbmJOBdB/qvyF8KEtCWHwobLp5l/mQ0=
|
||||
github.com/rs/zerolog v1.32.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
|
||||
github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8=
|
||||
github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
|
||||
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
|
||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/ryanuber/go-glob v1.0.0 h1:iQh3xXAumdQ+4Ufa5b25cRpC5TYKlno6hsv6Cb3pkBk=
|
||||
github.com/ryanuber/go-glob v1.0.0/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc=
|
||||
github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ=
|
||||
github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
|
||||
github.com/spf13/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng=
|
||||
github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
|
||||
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/thegeeklab/wp-plugin-go v1.7.1 h1:zfR/rfNPuyVhXJu1fsLfp4+Mz2pTf6WwW/mIqw9750I=
|
||||
github.com/thegeeklab/wp-plugin-go v1.7.1/go.mod h1:Ixi5plt9tpFGTu6yc/Inm5DcDpp3xPTeohfr86gf2EU=
|
||||
github.com/urfave/cli/v2 v2.27.1 h1:8xSQ6szndafKVRmfyeUMxkNUJQMjL1F2zmsZ+qHpfho=
|
||||
github.com/urfave/cli/v2 v2.27.1/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ=
|
||||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
|
||||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
|
||||
github.com/thegeeklab/wp-plugin-go/v3 v3.0.2 h1:Mv5i8S1WY+BUNjTjX6lOnB3p8S9mvM+XwfY4R98gx0g=
|
||||
github.com/thegeeklab/wp-plugin-go/v3 v3.0.2/go.mod h1:ij1iJcAVgzerBTqXnmq0bu1VA+hhVVwzXKqiqfoGjjg=
|
||||
github.com/urfave/cli/v2 v2.27.2 h1:6e0H+AkS+zDckwPCUrZkKX38mRaau4nL2uipkJpbkcI=
|
||||
github.com/urfave/cli/v2 v2.27.2/go.mod h1:g0+79LmHHATl7DAcHO99smiR/T7uGLw84w8Y42x+4eM=
|
||||
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 h1:+qGGcbkzsfDQNPPe9UDgpxAWQrhbbBXOYJFQDq/dtJw=
|
||||
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913/go.mod h1:4aEEwZQutDLsQv2Deui4iYQ6DWTxR14g6m8Wv88+Xqk=
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
|
||||
golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30=
|
||||
golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M=
|
||||
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
|
||||
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
|
||||
golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w=
|
||||
golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8=
|
||||
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
|
||||
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
|
@ -84,8 +120,8 @@ golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBc
|
|||
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
|
||||
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
|
||||
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
|
||||
|
@ -93,12 +129,11 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
|||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
|
||||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
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.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
|
|
42
internal/doc/main.go
Normal file
42
internal/doc/main.go
Normal file
|
@ -0,0 +1,42 @@
|
|||
//go:build generate
|
||||
// +build generate
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
plugin_docs "github.com/thegeeklab/wp-plugin-go/v3/docs"
|
||||
plugin_template "github.com/thegeeklab/wp-plugin-go/v3/template"
|
||||
"github.com/thegeeklab/wp-s3-action/plugin"
|
||||
)
|
||||
|
||||
func main() {
|
||||
tmpl := "https://raw.githubusercontent.com/thegeeklab/woodpecker-plugins/main/templates/docs-data.yaml.tmpl"
|
||||
client := http.Client{
|
||||
Timeout: 30 * time.Second,
|
||||
}
|
||||
|
||||
p := plugin.New(nil)
|
||||
|
||||
out, err := plugin_template.Render(context.Background(), client, tmpl, plugin_docs.GetTemplateData(p.App))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
outputFile := flag.String("output", "", "Output file path")
|
||||
flag.Parse()
|
||||
|
||||
if *outputFile == "" {
|
||||
panic("no output file specified")
|
||||
}
|
||||
|
||||
err = os.WriteFile(*outputFile, []byte(out), 0o644)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
444
plugin/aws.go
444
plugin/aws.go
|
@ -1,444 +0,0 @@
|
|||
package plugin
|
||||
|
||||
import (
|
||||
//nolint:gosec
|
||||
"crypto/md5"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"mime"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/aws/awserr"
|
||||
"github.com/aws/aws-sdk-go/aws/credentials"
|
||||
"github.com/aws/aws-sdk-go/aws/session"
|
||||
"github.com/aws/aws-sdk-go/service/cloudfront"
|
||||
"github.com/aws/aws-sdk-go/service/s3"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/ryanuber/go-glob"
|
||||
)
|
||||
|
||||
type AWS struct {
|
||||
client *s3.S3
|
||||
cfClient *cloudfront.CloudFront
|
||||
remote []string
|
||||
local []string
|
||||
plugin *Plugin
|
||||
}
|
||||
|
||||
func NewAWS(plugin *Plugin) AWS {
|
||||
sessCfg := &aws.Config{
|
||||
S3ForcePathStyle: aws.Bool(plugin.Settings.PathStyle),
|
||||
Region: aws.String(plugin.Settings.Region),
|
||||
}
|
||||
|
||||
if plugin.Settings.Endpoint != "" {
|
||||
sessCfg.Endpoint = &plugin.Settings.Endpoint
|
||||
sessCfg.DisableSSL = aws.Bool(strings.HasPrefix(plugin.Settings.Endpoint, "http://"))
|
||||
}
|
||||
|
||||
// allowing to use the instance role or provide a key and secret
|
||||
if plugin.Settings.AccessKey != "" && plugin.Settings.SecretKey != "" {
|
||||
sessCfg.Credentials = credentials.NewStaticCredentials(plugin.Settings.AccessKey, plugin.Settings.SecretKey, "")
|
||||
}
|
||||
|
||||
sess, _ := session.NewSession(sessCfg)
|
||||
|
||||
c := s3.New(sess)
|
||||
cf := cloudfront.New(sess)
|
||||
r := make([]string, 1)
|
||||
l := make([]string, 1)
|
||||
|
||||
return AWS{c, cf, r, l, plugin}
|
||||
}
|
||||
|
||||
//nolint:gocognit,gocyclo,maintidx
|
||||
func (a *AWS) Upload(local, remote string) error {
|
||||
plugin := a.plugin
|
||||
|
||||
if local == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
file, err := os.Open(local)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer file.Close()
|
||||
|
||||
var acl string
|
||||
|
||||
for pattern := range plugin.Settings.ACL {
|
||||
if match := glob.Glob(pattern, local); match {
|
||||
acl = plugin.Settings.ACL[pattern]
|
||||
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if acl == "" {
|
||||
acl = "private"
|
||||
}
|
||||
|
||||
fileExt := filepath.Ext(local)
|
||||
|
||||
var contentType string
|
||||
|
||||
for patternExt := range plugin.Settings.ContentType {
|
||||
if patternExt == fileExt {
|
||||
contentType = plugin.Settings.ContentType[patternExt]
|
||||
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if contentType == "" {
|
||||
contentType = mime.TypeByExtension(fileExt)
|
||||
}
|
||||
|
||||
var contentEncoding string
|
||||
|
||||
for patternExt := range plugin.Settings.ContentEncoding {
|
||||
if patternExt == fileExt {
|
||||
contentEncoding = plugin.Settings.ContentEncoding[patternExt]
|
||||
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
var cacheControl string
|
||||
|
||||
for pattern := range plugin.Settings.CacheControl {
|
||||
if match := glob.Glob(pattern, local); match {
|
||||
cacheControl = plugin.Settings.CacheControl[pattern]
|
||||
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
metadata := map[string]*string{}
|
||||
|
||||
for pattern := range plugin.Settings.Metadata {
|
||||
if match := glob.Glob(pattern, local); match {
|
||||
for k, v := range plugin.Settings.Metadata[pattern] {
|
||||
metadata[k] = aws.String(v)
|
||||
}
|
||||
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
var AWSErr awserr.Error
|
||||
|
||||
head, err := a.client.HeadObject(&s3.HeadObjectInput{
|
||||
Bucket: aws.String(plugin.Settings.Bucket),
|
||||
Key: aws.String(remote),
|
||||
})
|
||||
if err != nil && errors.As(err, &AWSErr) {
|
||||
//nolint:errorlint,forcetypeassert
|
||||
if err.(awserr.Error).Code() == "404" {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Debug().Msgf(
|
||||
"'%s' not found in bucket, uploading with content-type '%s' and permissions '%s'",
|
||||
local,
|
||||
contentType,
|
||||
acl,
|
||||
)
|
||||
|
||||
putObject := &s3.PutObjectInput{
|
||||
Bucket: aws.String(plugin.Settings.Bucket),
|
||||
Key: aws.String(remote),
|
||||
Body: file,
|
||||
ContentType: aws.String(contentType),
|
||||
ACL: aws.String(acl),
|
||||
Metadata: metadata,
|
||||
}
|
||||
|
||||
if len(cacheControl) > 0 {
|
||||
putObject.CacheControl = aws.String(cacheControl)
|
||||
}
|
||||
|
||||
if len(contentEncoding) > 0 {
|
||||
putObject.ContentEncoding = aws.String(contentEncoding)
|
||||
}
|
||||
|
||||
// skip upload during dry run
|
||||
if a.plugin.Settings.DryRun {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err = a.client.PutObject(putObject)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
//nolint:gosec
|
||||
hash := md5.New()
|
||||
_, _ = io.Copy(hash, file)
|
||||
sum := fmt.Sprintf("'%x'", hash.Sum(nil))
|
||||
|
||||
//nolint:nestif
|
||||
if sum == *head.ETag {
|
||||
shouldCopy := false
|
||||
|
||||
if head.ContentType == nil && contentType != "" {
|
||||
log.Debug().Msgf("content-type has changed from unset to %s", contentType)
|
||||
|
||||
shouldCopy = true
|
||||
}
|
||||
|
||||
if !shouldCopy && head.ContentType != nil && contentType != *head.ContentType {
|
||||
log.Debug().Msgf("content-type has changed from %s to %s", *head.ContentType, contentType)
|
||||
|
||||
shouldCopy = true
|
||||
}
|
||||
|
||||
if !shouldCopy && head.ContentEncoding == nil && contentEncoding != "" {
|
||||
log.Debug().Msgf("Content-Encoding has changed from unset to %s", contentEncoding)
|
||||
|
||||
shouldCopy = true
|
||||
}
|
||||
|
||||
if !shouldCopy && head.ContentEncoding != nil && contentEncoding != *head.ContentEncoding {
|
||||
log.Debug().Msgf("Content-Encoding has changed from %s to %s", *head.ContentEncoding, contentEncoding)
|
||||
|
||||
shouldCopy = true
|
||||
}
|
||||
|
||||
if !shouldCopy && head.CacheControl == nil && cacheControl != "" {
|
||||
log.Debug().Msgf("cache-control has changed from unset to %s", cacheControl)
|
||||
|
||||
shouldCopy = true
|
||||
}
|
||||
|
||||
if !shouldCopy && head.CacheControl != nil && cacheControl != *head.CacheControl {
|
||||
log.Debug().Msgf("cache-control has changed from %s to %s", *head.CacheControl, cacheControl)
|
||||
|
||||
shouldCopy = true
|
||||
}
|
||||
|
||||
if !shouldCopy && len(head.Metadata) != len(metadata) {
|
||||
log.Debug().Msgf("count of metadata values has changed for %s", local)
|
||||
|
||||
shouldCopy = true
|
||||
}
|
||||
|
||||
if !shouldCopy && len(metadata) > 0 {
|
||||
for k, v := range metadata {
|
||||
if hv, ok := head.Metadata[k]; ok {
|
||||
if *v != *hv {
|
||||
log.Debug().Msgf("metadata values have changed for %s", local)
|
||||
|
||||
shouldCopy = true
|
||||
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !shouldCopy {
|
||||
grant, err := a.client.GetObjectAcl(&s3.GetObjectAclInput{
|
||||
Bucket: aws.String(plugin.Settings.Bucket),
|
||||
Key: aws.String(remote),
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
previousACL := "private"
|
||||
|
||||
for _, grant := range grant.Grants {
|
||||
grantee := *grant.Grantee
|
||||
if grantee.URI != nil {
|
||||
if *grantee.URI == "http://acs.amazonaws.com/groups/global/AllUsers" {
|
||||
if *grant.Permission == "READ" {
|
||||
previousACL = "public-read"
|
||||
} else if *grant.Permission == "WRITE" {
|
||||
previousACL = "public-read-write"
|
||||
}
|
||||
}
|
||||
|
||||
if *grantee.URI == "http://acs.amazonaws.com/groups/global/AuthenticatedUsers" {
|
||||
if *grant.Permission == "READ" {
|
||||
previousACL = "authenticated-read"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if previousACL != acl {
|
||||
log.Debug().Msgf("permissions for '%s' have changed from '%s' to '%s'", remote, previousACL, acl)
|
||||
|
||||
shouldCopy = true
|
||||
}
|
||||
}
|
||||
|
||||
if !shouldCopy {
|
||||
log.Debug().Msgf("skipping '%s' because hashes and metadata match", local)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
log.Debug().Msgf("updating metadata for '%s' content-type: '%s', ACL: '%s'", local, contentType, acl)
|
||||
|
||||
copyObject := &s3.CopyObjectInput{
|
||||
Bucket: aws.String(plugin.Settings.Bucket),
|
||||
Key: aws.String(remote),
|
||||
CopySource: aws.String(fmt.Sprintf("%s/%s", plugin.Settings.Bucket, remote)),
|
||||
ACL: aws.String(acl),
|
||||
ContentType: aws.String(contentType),
|
||||
Metadata: metadata,
|
||||
MetadataDirective: aws.String("REPLACE"),
|
||||
}
|
||||
|
||||
if len(cacheControl) > 0 {
|
||||
copyObject.CacheControl = aws.String(cacheControl)
|
||||
}
|
||||
|
||||
if len(contentEncoding) > 0 {
|
||||
copyObject.ContentEncoding = aws.String(contentEncoding)
|
||||
}
|
||||
|
||||
// skip update if dry run
|
||||
if a.plugin.Settings.DryRun {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err = a.client.CopyObject(copyObject)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = file.Seek(0, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Debug().Msgf("uploading '%s' with content-type '%s' and permissions '%s'", local, contentType, acl)
|
||||
|
||||
putObject := &s3.PutObjectInput{
|
||||
Bucket: aws.String(plugin.Settings.Bucket),
|
||||
Key: aws.String(remote),
|
||||
Body: file,
|
||||
ContentType: aws.String(contentType),
|
||||
ACL: aws.String(acl),
|
||||
Metadata: metadata,
|
||||
}
|
||||
|
||||
if len(cacheControl) > 0 {
|
||||
putObject.CacheControl = aws.String(cacheControl)
|
||||
}
|
||||
|
||||
if len(contentEncoding) > 0 {
|
||||
putObject.ContentEncoding = aws.String(contentEncoding)
|
||||
}
|
||||
|
||||
// skip upload if dry run
|
||||
if a.plugin.Settings.DryRun {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err = a.client.PutObject(putObject)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (a *AWS) Redirect(path, location string) error {
|
||||
plugin := a.plugin
|
||||
|
||||
log.Debug().Msgf("adding redirect from '%s' to '%s'", path, location)
|
||||
|
||||
if a.plugin.Settings.DryRun {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := a.client.PutObject(&s3.PutObjectInput{
|
||||
Bucket: aws.String(plugin.Settings.Bucket),
|
||||
Key: aws.String(path),
|
||||
ACL: aws.String("public-read"),
|
||||
WebsiteRedirectLocation: aws.String(location),
|
||||
})
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (a *AWS) Delete(remote string) error {
|
||||
plugin := a.plugin
|
||||
|
||||
log.Debug().Msgf("removing remote file '%s'", remote)
|
||||
|
||||
if a.plugin.Settings.DryRun {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := a.client.DeleteObject(&s3.DeleteObjectInput{
|
||||
Bucket: aws.String(plugin.Settings.Bucket),
|
||||
Key: aws.String(remote),
|
||||
})
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (a *AWS) List(path string) ([]string, error) {
|
||||
plugin := a.plugin
|
||||
|
||||
remote := make([]string, 0)
|
||||
|
||||
resp, err := a.client.ListObjects(&s3.ListObjectsInput{
|
||||
Bucket: aws.String(plugin.Settings.Bucket),
|
||||
Prefix: aws.String(path),
|
||||
})
|
||||
if err != nil {
|
||||
return remote, err
|
||||
}
|
||||
|
||||
for _, item := range resp.Contents {
|
||||
remote = append(remote, *item.Key)
|
||||
}
|
||||
|
||||
for *resp.IsTruncated {
|
||||
resp, err = a.client.ListObjects(&s3.ListObjectsInput{
|
||||
Bucket: aws.String(plugin.Settings.Bucket),
|
||||
Prefix: aws.String(path),
|
||||
Marker: aws.String(remote[len(remote)-1]),
|
||||
})
|
||||
if err != nil {
|
||||
return remote, err
|
||||
}
|
||||
|
||||
for _, item := range resp.Contents {
|
||||
remote = append(remote, *item.Key)
|
||||
}
|
||||
}
|
||||
|
||||
return remote, nil
|
||||
}
|
||||
|
||||
func (a *AWS) Invalidate(invalidatePath string) error {
|
||||
p := a.plugin
|
||||
|
||||
log.Debug().Msgf("invalidating '%s'", invalidatePath)
|
||||
|
||||
_, err := a.cfClient.CreateInvalidation(&cloudfront.CreateInvalidationInput{
|
||||
DistributionId: aws.String(p.Settings.CloudFrontDistribution),
|
||||
InvalidationBatch: &cloudfront.InvalidationBatch{
|
||||
CallerReference: aws.String(time.Now().Format(time.RFC3339Nano)),
|
||||
Paths: &cloudfront.Paths{
|
||||
Quantity: aws.Int64(1),
|
||||
Items: []*string{
|
||||
aws.String(invalidatePath),
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
return err
|
||||
}
|
|
@ -9,6 +9,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/thegeeklab/wp-s3-action/aws"
|
||||
)
|
||||
|
||||
var ErrTypeAssertionFailed = errors.New("type assertion failed")
|
||||
|
@ -44,9 +45,25 @@ func (p *Plugin) Validate() error {
|
|||
// Execute provides the implementation of the plugin.
|
||||
func (p *Plugin) Execute() error {
|
||||
p.Settings.Jobs = make([]Job, 1)
|
||||
p.Settings.Client = NewAWS(p)
|
||||
|
||||
if err := p.createSyncJobs(); err != nil {
|
||||
client, err := aws.NewClient(
|
||||
p.Network.Context,
|
||||
p.Settings.Endpoint,
|
||||
p.Settings.Region,
|
||||
p.Settings.AccessKey,
|
||||
p.Settings.SecretKey,
|
||||
p.Settings.PathStyle,
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error while creating AWS client: %w", err)
|
||||
}
|
||||
|
||||
client.S3.Bucket = p.Settings.Bucket
|
||||
client.S3.DryRun = p.Settings.DryRun
|
||||
|
||||
client.Cloudfront.Distribution = p.Settings.CloudFrontDistribution
|
||||
|
||||
if err := p.createSyncJobs(p.Network.Context, client); err != nil {
|
||||
return fmt.Errorf("error while creating sync job: %w", err)
|
||||
}
|
||||
|
||||
|
@ -58,15 +75,15 @@ func (p *Plugin) Execute() error {
|
|||
})
|
||||
}
|
||||
|
||||
if err := p.runJobs(); err != nil {
|
||||
if err := p.runJobs(p.Network.Context, client); err != nil {
|
||||
return fmt.Errorf("error while creating sync job: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Plugin) createSyncJobs() error {
|
||||
remote, err := p.Settings.Client.List(p.Settings.Target)
|
||||
func (p *Plugin) createSyncJobs(ctx context.Context, client *aws.Client) error {
|
||||
remote, err := client.S3.List(ctx, aws.S3ListOptions{Path: p.Settings.Target})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -134,8 +151,7 @@ func (p *Plugin) createSyncJobs() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (p *Plugin) runJobs() error {
|
||||
client := p.Settings.Client
|
||||
func (p *Plugin) runJobs(ctx context.Context, client *aws.Client) error {
|
||||
jobChan := make(chan struct{}, p.Settings.MaxConcurrency)
|
||||
results := make(chan *Result, len(p.Settings.Jobs))
|
||||
|
||||
|
@ -151,11 +167,27 @@ func (p *Plugin) runJobs() error {
|
|||
|
||||
switch job.action {
|
||||
case "upload":
|
||||
err = client.Upload(job.local, job.remote)
|
||||
opt := aws.S3UploadOptions{
|
||||
LocalFilePath: job.local,
|
||||
RemoteObjectKey: job.remote,
|
||||
ACL: p.Settings.ACL,
|
||||
ContentType: p.Settings.ContentType,
|
||||
ContentEncoding: p.Settings.ContentEncoding,
|
||||
CacheControl: p.Settings.CacheControl,
|
||||
Metadata: p.Settings.Metadata,
|
||||
}
|
||||
err = client.S3.Upload(ctx, opt)
|
||||
case "redirect":
|
||||
err = client.Redirect(job.local, job.remote)
|
||||
opt := aws.S3RedirectOptions{
|
||||
Path: job.local,
|
||||
Location: job.remote,
|
||||
}
|
||||
err = client.S3.Redirect(ctx, opt)
|
||||
case "delete":
|
||||
err = client.Delete(job.remote)
|
||||
opt := aws.S3DeleteOptions{
|
||||
RemoteObjectKey: job.remote,
|
||||
}
|
||||
err = client.S3.Delete(ctx, opt)
|
||||
case "invalidateCloudFront":
|
||||
invalidateJob = &job
|
||||
default:
|
||||
|
@ -175,7 +207,11 @@ func (p *Plugin) runJobs() error {
|
|||
}
|
||||
|
||||
if invalidateJob != nil {
|
||||
err := client.Invalidate(invalidateJob.remote)
|
||||
opt := aws.CloudfrontInvalidateOptions{
|
||||
Path: invalidateJob.remote,
|
||||
}
|
||||
|
||||
err := client.Cloudfront.Invalidate(ctx, opt)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to %s %s to %s: %w", invalidateJob.action, invalidateJob.local, invalidateJob.remote, err)
|
||||
}
|
||||
|
|
180
plugin/plugin.go
180
plugin/plugin.go
|
@ -1,12 +1,18 @@
|
|||
package plugin
|
||||
|
||||
import (
|
||||
wp "github.com/thegeeklab/wp-plugin-go/plugin"
|
||||
"fmt"
|
||||
|
||||
plugin_base "github.com/thegeeklab/wp-plugin-go/v3/plugin"
|
||||
plugin_types "github.com/thegeeklab/wp-plugin-go/v3/types"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
//go:generate go run ../internal/doc/main.go -output=../docs/data/data-raw.yaml
|
||||
|
||||
// Plugin implements provide the plugin implementation.
|
||||
type Plugin struct {
|
||||
*wp.Plugin
|
||||
*plugin_base.Plugin
|
||||
Settings *Settings
|
||||
}
|
||||
|
||||
|
@ -29,7 +35,6 @@ type Settings struct {
|
|||
CloudFrontDistribution string
|
||||
DryRun bool
|
||||
PathStyle bool
|
||||
Client AWS
|
||||
Jobs []Job
|
||||
MaxConcurrency int
|
||||
}
|
||||
|
@ -45,13 +50,172 @@ type Result struct {
|
|||
err error
|
||||
}
|
||||
|
||||
func New(options wp.Options, settings *Settings) *Plugin {
|
||||
p := &Plugin{}
|
||||
func New(e plugin_base.ExecuteFunc, build ...string) *Plugin {
|
||||
p := &Plugin{
|
||||
Settings: &Settings{},
|
||||
}
|
||||
|
||||
options.Execute = p.run
|
||||
options := plugin_base.Options{
|
||||
Name: "wp-s3-action",
|
||||
Description: "Perform S3 actions",
|
||||
Flags: Flags(p.Settings, plugin_base.FlagsPluginCategory),
|
||||
Execute: p.run,
|
||||
HideWoodpeckerFlags: true,
|
||||
}
|
||||
|
||||
p.Plugin = wp.New(options)
|
||||
p.Settings = settings
|
||||
if len(build) > 0 {
|
||||
options.Version = build[0]
|
||||
}
|
||||
|
||||
if len(build) > 1 {
|
||||
options.VersionMetadata = fmt.Sprintf("date=%s", build[1])
|
||||
}
|
||||
|
||||
if e != nil {
|
||||
options.Execute = e
|
||||
}
|
||||
|
||||
p.Plugin = plugin_base.New(options)
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
// Flags returns a slice of CLI flags for the plugin.
|
||||
func Flags(settings *Settings, category string) []cli.Flag {
|
||||
return []cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "endpoint",
|
||||
Usage: "endpoint for the s3 connection",
|
||||
EnvVars: []string{"PLUGIN_ENDPOINT", "S3_ENDPOINT"},
|
||||
Destination: &settings.Endpoint,
|
||||
Category: category,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "access-key",
|
||||
Usage: "s3 access key",
|
||||
EnvVars: []string{"PLUGIN_ACCESS_KEY", "S3_ACCESS_KEY"},
|
||||
Destination: &settings.AccessKey,
|
||||
Required: true,
|
||||
Category: category,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "secret-key",
|
||||
Usage: "s3 secret key",
|
||||
EnvVars: []string{"PLUGIN_SECRET_KEY", "S3_SECRET_KEY"},
|
||||
Destination: &settings.SecretKey,
|
||||
Required: true,
|
||||
Category: category,
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "path-style",
|
||||
Usage: "enable path style for bucket paths",
|
||||
EnvVars: []string{"PLUGIN_PATH_STYLE"},
|
||||
Destination: &settings.PathStyle,
|
||||
Category: category,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "bucket",
|
||||
Usage: "name of the bucket",
|
||||
EnvVars: []string{"PLUGIN_BUCKET"},
|
||||
Destination: &settings.Bucket,
|
||||
Required: true,
|
||||
Category: category,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "region",
|
||||
Usage: "s3 region",
|
||||
Value: "us-east-1",
|
||||
EnvVars: []string{"PLUGIN_REGION"},
|
||||
Destination: &settings.Region,
|
||||
Category: category,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "source",
|
||||
Usage: "upload source path",
|
||||
Value: ".",
|
||||
EnvVars: []string{"PLUGIN_SOURCE"},
|
||||
Destination: &settings.Source,
|
||||
Category: category,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "target",
|
||||
Usage: "upload target path",
|
||||
Value: "/",
|
||||
EnvVars: []string{"PLUGIN_TARGET"},
|
||||
Destination: &settings.Target,
|
||||
Category: category,
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "delete",
|
||||
Usage: "delete locally removed files from the target",
|
||||
EnvVars: []string{"PLUGIN_DELETE"},
|
||||
Destination: &settings.Delete,
|
||||
Category: category,
|
||||
},
|
||||
&cli.GenericFlag{
|
||||
Name: "acl",
|
||||
Usage: "access control list",
|
||||
EnvVars: []string{"PLUGIN_ACL"},
|
||||
Value: &plugin_types.StringMapFlag{},
|
||||
Category: category,
|
||||
},
|
||||
&cli.GenericFlag{
|
||||
Name: "content-type",
|
||||
Usage: "content-type settings for uploads",
|
||||
EnvVars: []string{"PLUGIN_CONTENT_TYPE"},
|
||||
Value: &plugin_types.StringMapFlag{},
|
||||
Category: category,
|
||||
},
|
||||
&cli.GenericFlag{
|
||||
Name: "content-encoding",
|
||||
Usage: "content-encoding settings for uploads",
|
||||
EnvVars: []string{"PLUGIN_CONTENT_ENCODING"},
|
||||
Value: &plugin_types.StringMapFlag{},
|
||||
Category: category,
|
||||
},
|
||||
&cli.GenericFlag{
|
||||
Name: "cache-control",
|
||||
Usage: "cache-control settings for uploads",
|
||||
EnvVars: []string{"PLUGIN_CACHE_CONTROL"},
|
||||
Value: &plugin_types.StringMapFlag{},
|
||||
Category: category,
|
||||
},
|
||||
&cli.GenericFlag{
|
||||
Name: "metadata",
|
||||
Usage: "additional metadata for uploads",
|
||||
EnvVars: []string{"PLUGIN_METADATA"},
|
||||
Value: &plugin_types.DeepStringMapFlag{},
|
||||
Category: category,
|
||||
},
|
||||
&cli.GenericFlag{
|
||||
Name: "redirects",
|
||||
Usage: "redirects to create",
|
||||
EnvVars: []string{"PLUGIN_REDIRECTS"},
|
||||
Value: &plugin_types.MapFlag{},
|
||||
Category: category,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "cloudfront-distribution",
|
||||
Usage: "ID of cloudfront distribution to invalidate",
|
||||
EnvVars: []string{"PLUGIN_CLOUDFRONT_DISTRIBUTION"},
|
||||
Destination: &settings.CloudFrontDistribution,
|
||||
Category: category,
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "dry-run",
|
||||
Usage: "dry run disables api calls",
|
||||
EnvVars: []string{"DRY_RUN", "PLUGIN_DRY_RUN"},
|
||||
Destination: &settings.DryRun,
|
||||
Category: category,
|
||||
},
|
||||
&cli.IntFlag{
|
||||
Name: "max-concurrency",
|
||||
Usage: "customize number concurrent files to process",
|
||||
//nolint:mnd
|
||||
Value: 100,
|
||||
EnvVars: []string{"PLUGIN_MAX_CONCURRENCY"},
|
||||
Destination: &settings.MaxConcurrency,
|
||||
Category: category,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user