0
0
mirror of https://github.com/thegeeklab/wp-s3-action.git synced 2024-11-21 14:50:39 +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
import (
"github.com/thegeeklab/wp-plugin-go/types"
"github.com/thegeeklab/wp-s3-action/plugin"
"github.com/urfave/cli/v2"
@ -79,46 +80,46 @@ func settingsFlags(settings *plugin.Settings, category string) []cli.Flag {
Category: category,
},
&cli.GenericFlag{
Name: "acl",
Usage: "access control list",
EnvVars: []string{"PLUGIN_ACL"},
Destination: &settings.ACL,
Category: category,
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"},
Destination: &settings.ContentType,
Category: category,
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"},
Destination: &settings.ContentEncoding,
Category: category,
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"},
Destination: &settings.CacheControl,
Category: category,
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"},
Destination: &settings.Metadata,
Category: category,
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"},
Destination: &settings.Redirects,
Category: category,
Name: "redirects",
Usage: "redirects to create",
EnvVars: []string{"PLUGIN_REDIRECTS"},
Value: &types.MapFlag{},
Category: category,
},
&cli.StringFlag{
Name: "cloudfront-distribution",

2
go.mod
View File

@ -6,7 +6,7 @@ require (
github.com/aws/aws-sdk-go v1.44.327
github.com/rs/zerolog v1.30.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
)

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/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc=
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.4.0/go.mod h1:y0k5zaKWjdGbgkaOHhEPFEL6p+yOLOjqHy0LWOrv0MM=
github.com/thegeeklab/wp-plugin-go v0.5.0 h1:PEORQl365YxqqYSu8rFoQ3hltTcFYSJCs8s9MDCej8A=
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/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ=
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
for pattern := range plugin.Settings.ACL.Get() {
for pattern := range plugin.Settings.ACL {
if match := glob.Glob(pattern, local); match {
acl = plugin.Settings.ACL.Get()[pattern]
acl = plugin.Settings.ACL[pattern]
break
}
@ -89,9 +89,9 @@ func (a *AWS) Upload(local, remote string) error {
var contentType string
for patternExt := range plugin.Settings.ContentType.Get() {
for patternExt := range plugin.Settings.ContentType {
if patternExt == fileExt {
contentType = plugin.Settings.ContentType.Get()[patternExt]
contentType = plugin.Settings.ContentType[patternExt]
break
}
@ -103,9 +103,9 @@ func (a *AWS) Upload(local, remote string) error {
var contentEncoding string
for patternExt := range plugin.Settings.ContentEncoding.Get() {
for patternExt := range plugin.Settings.ContentEncoding {
if patternExt == fileExt {
contentEncoding = plugin.Settings.ContentEncoding.Get()[patternExt]
contentEncoding = plugin.Settings.ContentEncoding[patternExt]
break
}
@ -113,9 +113,9 @@ func (a *AWS) Upload(local, remote string) error {
var cacheControl string
for pattern := range plugin.Settings.CacheControl.Get() {
for pattern := range plugin.Settings.CacheControl {
if match := glob.Glob(pattern, local); match {
cacheControl = plugin.Settings.CacheControl.Get()[pattern]
cacheControl = plugin.Settings.CacheControl[pattern]
break
}
@ -123,9 +123,9 @@ func (a *AWS) Upload(local, remote string) error {
metadata := map[string]*string{}
for pattern := range plugin.Settings.Metadata.Get() {
for pattern := range plugin.Settings.Metadata {
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)
}

View File

@ -9,7 +9,6 @@ import (
"strings"
"github.com/rs/zerolog/log"
"github.com/urfave/cli/v2"
)
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.
//
//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 {
return fmt.Errorf("validation failed: %w", err)
}
@ -97,7 +96,7 @@ func (p *Plugin) createSyncJobs() error {
return err
}
for path, location := range p.Settings.Redirects.Get() {
for path, location := range p.Settings.Redirects {
path = strings.TrimPrefix(path, "/")
local = append(local, path)
p.Settings.Jobs = append(p.Settings.Jobs, Job{

View File

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