0
0
mirror of https://github.com/thegeeklab/wp-s3-action.git synced 2024-11-22 01:00:40 +00:00
This commit is contained in:
Robert Kaussow 2023-08-21 12:50:44 +02:00
parent 4ea3f429ed
commit d17aede4bb
Signed by: xoxys
GPG Key ID: 4E692A2EAECC03C0
6 changed files with 52 additions and 53 deletions

View File

@ -1,6 +1,7 @@
package main package main
import ( import (
"github.com/thegeeklab/wp-plugin-go/types"
"github.com/thegeeklab/wp-s3-action/plugin" "github.com/thegeeklab/wp-s3-action/plugin"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
@ -82,42 +83,42 @@ func settingsFlags(settings *plugin.Settings, category string) []cli.Flag {
Name: "acl", Name: "acl",
Usage: "access control list", Usage: "access control list",
EnvVars: []string{"PLUGIN_ACL"}, EnvVars: []string{"PLUGIN_ACL"},
Destination: &settings.ACL, Value: &types.StringMapFlag{},
Category: category, Category: category,
}, },
&cli.GenericFlag{ &cli.GenericFlag{
Name: "content-type", Name: "content-type",
Usage: "content-type settings for uploads", Usage: "content-type settings for uploads",
EnvVars: []string{"PLUGIN_CONTENT_TYPE"}, EnvVars: []string{"PLUGIN_CONTENT_TYPE"},
Destination: &settings.ContentType, Value: &types.StringMapFlag{},
Category: category, Category: category,
}, },
&cli.GenericFlag{ &cli.GenericFlag{
Name: "content-encoding", Name: "content-encoding",
Usage: "content-encoding settings for uploads", Usage: "content-encoding settings for uploads",
EnvVars: []string{"PLUGIN_CONTENT_ENCODING"}, EnvVars: []string{"PLUGIN_CONTENT_ENCODING"},
Destination: &settings.ContentEncoding, Value: &types.StringMapFlag{},
Category: category, Category: category,
}, },
&cli.GenericFlag{ &cli.GenericFlag{
Name: "cache-control", Name: "cache-control",
Usage: "cache-control settings for uploads", Usage: "cache-control settings for uploads",
EnvVars: []string{"PLUGIN_CACHE_CONTROL"}, EnvVars: []string{"PLUGIN_CACHE_CONTROL"},
Destination: &settings.CacheControl, Value: &types.StringMapFlag{},
Category: category, Category: category,
}, },
&cli.GenericFlag{ &cli.GenericFlag{
Name: "metadata", Name: "metadata",
Usage: "additional metadata for uploads", Usage: "additional metadata for uploads",
EnvVars: []string{"PLUGIN_METADATA"}, EnvVars: []string{"PLUGIN_METADATA"},
Destination: &settings.Metadata, Value: &types.DeepStringMapFlag{},
Category: category, Category: category,
}, },
&cli.GenericFlag{ &cli.GenericFlag{
Name: "redirects", Name: "redirects",
Usage: "redirects to create", Usage: "redirects to create",
EnvVars: []string{"PLUGIN_REDIRECTS"}, EnvVars: []string{"PLUGIN_REDIRECTS"},
Destination: &settings.Redirects, Value: &types.MapFlag{},
Category: category, Category: category,
}, },
&cli.StringFlag{ &cli.StringFlag{

2
go.mod
View File

@ -6,7 +6,7 @@ require (
github.com/aws/aws-sdk-go v1.44.327 github.com/aws/aws-sdk-go v1.44.327
github.com/rs/zerolog v1.30.0 github.com/rs/zerolog v1.30.0
github.com/ryanuber/go-glob v1.0.0 github.com/ryanuber/go-glob v1.0.0
github.com/thegeeklab/wp-plugin-go v0.4.0 github.com/thegeeklab/wp-plugin-go v0.5.0
github.com/urfave/cli/v2 v2.25.7 github.com/urfave/cli/v2 v2.25.7
) )

4
go.sum
View File

@ -28,8 +28,8 @@ github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQD
github.com/ryanuber/go-glob v1.0.0 h1:iQh3xXAumdQ+4Ufa5b25cRpC5TYKlno6hsv6Cb3pkBk= 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/ryanuber/go-glob v1.0.0/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/thegeeklab/wp-plugin-go v0.4.0 h1:eTkRH04gAAsYgCUekk8RBmPrIXk+UG+EJtRkoUFllLs= github.com/thegeeklab/wp-plugin-go v0.5.0 h1:PEORQl365YxqqYSu8rFoQ3hltTcFYSJCs8s9MDCej8A=
github.com/thegeeklab/wp-plugin-go v0.4.0/go.mod h1:y0k5zaKWjdGbgkaOHhEPFEL6p+yOLOjqHy0LWOrv0MM= github.com/thegeeklab/wp-plugin-go v0.5.0/go.mod h1:y0k5zaKWjdGbgkaOHhEPFEL6p+yOLOjqHy0LWOrv0MM=
github.com/urfave/cli/v2 v2.25.7 h1:VAzn5oq403l5pHjc4OhD54+XGO9cdKVL/7lDjF+iKUs= github.com/urfave/cli/v2 v2.25.7 h1:VAzn5oq403l5pHjc4OhD54+XGO9cdKVL/7lDjF+iKUs=
github.com/urfave/cli/v2 v2.25.7/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ= github.com/urfave/cli/v2 v2.25.7/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 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=

View File

@ -73,9 +73,9 @@ func (a *AWS) Upload(local, remote string) error {
var acl string var acl string
for pattern := range plugin.Settings.ACL.Get() { for pattern := range plugin.Settings.ACL {
if match := glob.Glob(pattern, local); match { if match := glob.Glob(pattern, local); match {
acl = plugin.Settings.ACL.Get()[pattern] acl = plugin.Settings.ACL[pattern]
break break
} }
@ -89,9 +89,9 @@ func (a *AWS) Upload(local, remote string) error {
var contentType string var contentType string
for patternExt := range plugin.Settings.ContentType.Get() { for patternExt := range plugin.Settings.ContentType {
if patternExt == fileExt { if patternExt == fileExt {
contentType = plugin.Settings.ContentType.Get()[patternExt] contentType = plugin.Settings.ContentType[patternExt]
break break
} }
@ -103,9 +103,9 @@ func (a *AWS) Upload(local, remote string) error {
var contentEncoding string var contentEncoding string
for patternExt := range plugin.Settings.ContentEncoding.Get() { for patternExt := range plugin.Settings.ContentEncoding {
if patternExt == fileExt { if patternExt == fileExt {
contentEncoding = plugin.Settings.ContentEncoding.Get()[patternExt] contentEncoding = plugin.Settings.ContentEncoding[patternExt]
break break
} }
@ -113,9 +113,9 @@ func (a *AWS) Upload(local, remote string) error {
var cacheControl string var cacheControl string
for pattern := range plugin.Settings.CacheControl.Get() { for pattern := range plugin.Settings.CacheControl {
if match := glob.Glob(pattern, local); match { if match := glob.Glob(pattern, local); match {
cacheControl = plugin.Settings.CacheControl.Get()[pattern] cacheControl = plugin.Settings.CacheControl[pattern]
break break
} }
@ -123,9 +123,9 @@ func (a *AWS) Upload(local, remote string) error {
metadata := map[string]*string{} metadata := map[string]*string{}
for pattern := range plugin.Settings.Metadata.Get() { for pattern := range plugin.Settings.Metadata {
if match := glob.Glob(pattern, local); match { if match := glob.Glob(pattern, local); match {
for k, v := range plugin.Settings.Metadata.Get()[pattern] { for k, v := range plugin.Settings.Metadata[pattern] {
metadata[k] = aws.String(v) metadata[k] = aws.String(v)
} }

View File

@ -9,7 +9,6 @@ import (
"strings" "strings"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"github.com/urfave/cli/v2"
) )
var ErrTypeAssertionFailed = errors.New("type assertion failed") var ErrTypeAssertionFailed = errors.New("type assertion failed")
@ -17,7 +16,7 @@ var ErrTypeAssertionFailed = errors.New("type assertion failed")
// Execute provides the implementation of the plugin. // Execute provides the implementation of the plugin.
// //
//nolint:revive //nolint:revive
func (p *Plugin) run(ctx context.Context, cCtx *cli.Context) error { func (p *Plugin) run(ctx context.Context) error {
if err := p.Validate(); err != nil { if err := p.Validate(); err != nil {
return fmt.Errorf("validation failed: %w", err) return fmt.Errorf("validation failed: %w", err)
} }
@ -97,7 +96,7 @@ func (p *Plugin) createSyncJobs() error {
return err return err
} }
for path, location := range p.Settings.Redirects.Get() { for path, location := range p.Settings.Redirects {
path = strings.TrimPrefix(path, "/") path = strings.TrimPrefix(path, "/")
local = append(local, path) local = append(local, path)
p.Settings.Jobs = append(p.Settings.Jobs, Job{ p.Settings.Jobs = append(p.Settings.Jobs, Job{

View File

@ -2,7 +2,6 @@ package plugin
import ( import (
wp "github.com/thegeeklab/wp-plugin-go/plugin" wp "github.com/thegeeklab/wp-plugin-go/plugin"
"github.com/thegeeklab/wp-plugin-go/types"
) )
// Plugin implements provide the plugin implementation. // Plugin implements provide the plugin implementation.
@ -21,12 +20,12 @@ type Settings struct {
Source string Source string
Target string Target string
Delete bool Delete bool
ACL types.StringMapFlag ACL map[string]string
CacheControl types.StringMapFlag CacheControl map[string]string
ContentType types.StringMapFlag ContentType map[string]string
ContentEncoding types.StringMapFlag ContentEncoding map[string]string
Metadata types.DeepStringMapFlag Metadata map[string]map[string]string
Redirects types.StringMapFlag Redirects map[string]string
CloudFrontDistribution string CloudFrontDistribution string
DryRun bool DryRun bool
PathStyle bool PathStyle bool