0
0
mirror of https://github.com/thegeeklab/wp-s3-action.git synced 2024-06-02 18:39:42 +02:00

Compare commits

...

121 Commits
v1.0.0 ... main

Author SHA1 Message Date
renovate[bot]
2f2fdf1f7f
chore(deps): update docker.io/library/alpine docker tag to v3.20 (#119)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-06-01 13:21:47 +02:00
renovate[bot]
c2a7f897c0 chore(deps): update dependency golangci/golangci-lint to v1.59.0 2024-05-30 23:09:13 +00:00
renovate[bot]
aacd23451e
fix(deps): update aws-sdk-go-v2 monorepo (#115)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-05-30 20:23:39 +02:00
renovate[bot]
04d5df2fc7
fix(deps): update module github.com/rs/zerolog to v1.33.0 (#120)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-05-24 09:37:33 +02:00
e14a5011da
chore: migrate to wp-plugin-go v3 (#118) 2024-05-18 10:01:22 +02:00
renovate[bot]
ff97059f7f
chore(docker): update docker.io/library/golang:1.22 docker digest to f43c6f0 (#116)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-05-16 13:40:37 +02:00
renovate[bot]
da9ffdab15 chore(deps): update dependency golangci/golangci-lint to v1.58.1 2024-05-13 05:01:13 +00:00
174d9ef5bb
ci: fix golangci-lint deprecations 2024-05-12 11:08:28 +02:00
0752e23352
refactor: use dedicated aws package (#113) 2024-05-12 11:01:28 +02:00
renovate[bot]
7852c706ae
fix(deps): update module github.com/aws/aws-sdk-go to v1.53.0 (#105)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-05-11 11:08:54 +02:00
bcfd874890
docs: hide system flags and refactor generator (#112) 2024-05-11 11:08:34 +02:00
renovate[bot]
fc098bd7d4 chore(docker): update docker.io/library/golang:1.22 docker digest to b1e05e2 2024-05-08 04:53:58 +00:00
renovate[bot]
5b2336bb02 chore(deps): update dependency golangci/golangci-lint to v1.58.0 2024-05-06 04:34:45 +00:00
renovate[bot]
6820ec0661
fix(deps): update module github.com/urfave/cli/v2 to v2.27.2 (#107)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-04-29 10:25:45 +02:00
renovate[bot]
5d22227635 chore(docker): update docker.io/library/golang:1.22 docker digest to d5302d4 2024-04-25 05:05:55 +00:00
renovate[bot]
860f60a2c6
fix(deps): update module github.com/thegeeklab/wp-plugin-go to v1.7.1 (#104)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-04-22 12:38:40 +02:00
renovate[bot]
272d2635af
fix(deps): update module github.com/aws/aws-sdk-go to v1.51.25 (#99)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-04-20 14:21:12 +02:00
renovate[bot]
26a8a39736 chore(docker): update docker.io/library/golang:1.22 docker digest to 450e382 2024-04-11 04:58:50 +00:00
renovate[bot]
2d62cdf015 chore(docker): update docker.io/library/golang:1.22 docker digest to c4fb952 2024-04-04 04:25:30 +00:00
renovate[bot]
697fba7468 chore(deps): update dependency golangci/golangci-lint to v1.57.2 2024-04-01 04:08:24 +00:00
renovate[bot]
ca7f66d9ba
chore(deps): update quay.io/thegeeklab/wp-docker-buildx docker tag to v4 (#100)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-03-27 08:43:17 +01:00
renovate[bot]
a5a05fd0b3
fix(deps): update module github.com/thegeeklab/wp-plugin-go to v1.7.0 (#96)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-03-26 21:27:53 +01:00
renovate[bot]
f9d429dd82
fix(deps): update module github.com/aws/aws-sdk-go to v1.51.7 (#94)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-03-26 21:27:45 +01:00
renovate[bot]
92a244cead chore(deps): update dependency golangci/golangci-lint to v1.57.1 2024-03-25 04:53:38 +00:00
renovate[bot]
de5230fbe6 chore(docker): update docker.io/library/golang:1.22 docker digest to 0b55ab8 2024-03-13 07:28:02 +00:00
9c7a425afc
cleanup docs and examples 2024-03-12 20:43:37 +01:00
renovate[bot]
d364fe4c0a
fix(deps): update module github.com/thegeeklab/wp-plugin-go to v1.6.1 (#95)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-03-07 21:26:51 +01:00
renovate[bot]
6b7ac0d0ef
fix(deps): update module github.com/aws/aws-sdk-go to v1.50.32 (#92)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-03-06 14:43:27 +01:00
renovate[bot]
d5eee294c2 chore(docker): update docker.io/library/golang:1.22 docker digest to 34ce21a 2024-03-06 04:59:27 +00:00
renovate[bot]
f782d98ecd
fix(deps): update module github.com/aws/aws-sdk-go to v1.50.30 (#89)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-03-02 14:49:03 +01:00
renovate[bot]
808b06ad44 chore(deps): update dependency golangci/golangci-lint to v1.56.2 2024-02-19 04:48:48 +00:00
renovate[bot]
c69ed6d5d7 chore(docker): update docker.io/library/golang:1.22 docker digest to 7b297d9 2024-02-16 04:00:02 +00:00
0234d0dfe6
[skip ci] revert renovate automerge config 2024-02-15 12:19:29 +01:00
renovate[bot]
ee3c17903c
chore(deps): update dependency golangci/golangci-lint to v1.56.1 (#88)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Robert Kaussow <mail@thegeeklab.de>
2024-02-12 09:26:02 +01:00
renovate[bot]
4c2e212df3
fix(deps): update module github.com/aws/aws-sdk-go to v1.50.15 (#87)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-02-09 22:24:39 +01:00
renovate[bot]
bce0a719d0
fix(deps): update module github.com/aws/aws-sdk-go to v1.50.14 (#85)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-02-09 21:55:29 +01:00
renovate[bot]
a7f539439d
fix(deps): update module github.com/thegeeklab/wp-plugin-go to v1.6.0 (#86)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-02-09 21:55:17 +01:00
renovate[bot]
07567c6443
fix(deps): update module github.com/aws/aws-sdk-go to v1.50.13 (#80)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-02-08 08:33:12 +01:00
renovate[bot]
f21d851a4c
chore(deps): update docker.io/library/golang docker tag to v1.22 (#83)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Robert Kaussow <mail@thegeeklab.de>
2024-02-07 22:31:43 +01:00
9dd0cccf61
harmonize container image refs and use fqin 2024-02-07 09:40:50 +01:00
2e6e692d8e
run ci on renovate auto branches 2024-02-07 09:10:11 +01:00
7823adaefc
ci: enable ci run on renovate branches 2024-02-05 08:58:29 +01:00
renovate[bot]
e72612762c
fix(deps): update module github.com/rs/zerolog to v1.32.0 (#82)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-02-05 08:45:47 +01:00
renovate[bot]
5645e22bfa chore(docker): update golang:1.21 docker digest to 7b575fe 2024-02-03 08:00:36 +00:00
renovate[bot]
77bb42af96
fix(deps): update module github.com/aws/aws-sdk-go to v1.50.7 (#70)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-01-31 09:07:38 +01:00
renovate[bot]
356bb976f3 chore(deps): update dependency mvdan/gofumpt to v0.6.0 2024-01-30 04:56:18 +00:00
renovate[bot]
e69ade2f40 chore(docker): update alpine:3.19 docker digest to c5b1261 2024-01-28 09:11:21 +00:00
renovate[bot]
852bff2cab chore(docker): update golang:1.21 docker digest to 76aadd9 2024-01-25 07:35:01 +00:00
renovate[bot]
82ddca16e0
chore(deps): update quay.io/thegeeklab/wp-docker-buildx docker tag to v3 (#76)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-01-22 11:29:37 +01:00
renovate[bot]
199ca6e726 chore(docker): update golang:1.21 docker digest to 5f5d61d 2024-01-17 09:42:17 +00:00
renovate[bot]
4b1faac570 chore(docker): update golang:1.21 docker digest to 6fbd2d3 2024-01-12 02:04:39 +00:00
renovate[bot]
8e52b5aaf4 chore(docker): update golang:1.21 docker digest to 21260a4 2024-01-11 15:56:02 +00:00
renovate[bot]
5dc72ff2fc chore(docker): update golang:1.21 docker digest to ffbb0b8 2024-01-11 04:24:59 +00:00
renovate[bot]
82f434c852 chore(docker): update golang:1.21 docker digest to 7026fb7 2024-01-10 04:37:25 +00:00
renovate[bot]
e8549307e2
fix(deps): update module github.com/aws/aws-sdk-go to v1.49.14 (#66)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-01-03 23:39:25 +01:00
6bea1d319a
docs: fix default value property in data file 2024-01-03 23:26:16 +01:00
d3ae08217d
chore: cleanup docs (#69) 2024-01-03 23:04:13 +01:00
renovate[bot]
722e340be9
fix(deps): update module github.com/thegeeklab/wp-plugin-go to v1.5.0 (#68)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-01-03 21:24:33 +01:00
renovate[bot]
5977bc238d
fix(deps): update module github.com/urfave/cli/v2 to v2.27.1 (#67)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-01-01 16:21:23 +01:00
renovate[bot]
81f7db3dbd
fix(deps): update module github.com/aws/aws-sdk-go to v1.49.10 (#65)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-12-27 11:07:16 +01:00
256eded162
use list style synatx and cleanup (#64) 2023-12-23 23:45:12 +01:00
renovate[bot]
773ebc27cd
fix(deps): update module github.com/aws/aws-sdk-go to v1.49.8 (#63)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-12-22 09:00:13 +01:00
renovate[bot]
db5a587d7d
fix(deps): update module github.com/aws/aws-sdk-go to v1.49.7 (#54)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-12-21 13:48:31 +01:00
renovate[bot]
9de934fb4f
fix(deps): update module github.com/thegeeklab/wp-plugin-go to v1.3.0 (#62)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-12-21 13:41:42 +01:00
renovate[bot]
0b175d9a48 chore(docker): update golang:1.21 docker digest to 672a228 2023-12-21 06:34:02 +00:00
renovate[bot]
b52e92d70a chore(docker): update golang:1.21 docker digest to fb02af5 2023-12-20 19:23:23 +00:00
renovate[bot]
21ff4d084b chore(docker): update golang:1.21 docker digest to 1a9d253 2023-12-20 07:54:19 +00:00
renovate[bot]
f09502145a chore(docker): update golang:1.21 docker digest to b172263 2023-12-19 16:04:59 +00:00
a69b419a60
ci: add missing test group 2023-12-15 22:34:48 +01:00
renovate[bot]
dbb55b92d1 chore(docker): update golang:1.21 docker digest to 2ff79bc 2023-12-13 04:47:13 +00:00
renovate[bot]
5adced8f20 chore(docker): update golang:1.21 docker digest to ae34fbf 2023-12-09 12:51:56 +00:00
renovate[bot]
87899dedde
chore(deps): update alpine docker tag to v3.19 (#55)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-12-08 08:41:16 +01:00
renovate[bot]
35ae385521
chore(deps): update quay.io/thegeeklab/wp-docker-buildx docker tag to v2 (#53)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-12-07 08:40:00 +01:00
renovate[bot]
98bf65c78c
fix(deps): update module github.com/thegeeklab/wp-plugin-go to v1.2.0 (#52)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-12-06 23:26:10 +01:00
renovate[bot]
0d378a9b10
fix(deps): update module github.com/aws/aws-sdk-go to v1.48.14 (#48)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-12-06 23:20:11 +01:00
3dce49eaa7
fix: replace logrus by zerolog (#51) 2023-12-06 09:29:39 +01:00
renovate[bot]
7bd6754fda chore(docker): update golang:1.21 docker digest to 58e14a9 2023-12-06 00:58:39 +00:00
renovate[bot]
4a8072ca1a
fix(deps): update module github.com/thegeeklab/wp-plugin-go to v1.1.0 (#49)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-12-05 14:32:22 +01:00
38acd53d74
ci: exclude dockerhub from linkcheck due to rate limiting 2023-12-05 11:24:34 +01:00
renovate[bot]
75b77bd381
fix(deps): update module github.com/aws/aws-sdk-go to v1.48.11 (#46)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-12-04 09:01:41 +01:00
renovate[bot]
134e3cc93e
fix(deps): update module github.com/urfave/cli/v2 to v2.26.0 (#47)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-12-04 09:01:29 +01:00
renovate[bot]
641a4b1798 chore(docker): update alpine:3.18 docker digest to 34871e7 2023-12-01 07:22:29 +00:00
renovate[bot]
a27d60068d chore(docker): update golang:1.21 docker digest to 9baee0e 2023-11-22 21:57:24 +00:00
renovate[bot]
9d02c25ae5 chore(docker): update golang:1.21 docker digest to daa9d10 2023-11-22 14:16:57 +00:00
renovate[bot]
226134b092 chore(docker): update golang:1.21 docker digest to 4521f9d 2023-11-22 06:03:39 +00:00
renovate[bot]
5a33df6722 chore(docker): update golang:1.21 docker digest to 57bf74a 2023-11-16 10:04:47 +00:00
aafceff986
remove deprecated go version from golangci config 2023-11-08 09:25:30 +01:00
renovate[bot]
14866d79d5 chore(docker): update golang:1.21 docker digest to 81cd210 2023-11-08 00:02:10 +00:00
renovate[bot]
4a648b45f5 chore(deps): update dependency golangci/golangci-lint to v1.55.2 2023-11-06 04:57:35 +00:00
renovate[bot]
9f0d3dc6fb
fix(deps): update module github.com/aws/aws-sdk-go to v1.47.3 (#31)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-11-04 22:38:40 +01:00
renovate[bot]
2ab7300e19
chore(docker): update golang:1.21 docker digest to b113af1 (#37)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-11-04 16:02:54 +01:00
renovate[bot]
144fa06bd4 chore(docker): update golang:1.21 docker digest to 5206873 2023-11-02 07:35:15 +00:00
renovate[bot]
71611484d6 chore(docker): update golang:1.21 docker digest to 84e41b3 2023-11-02 00:22:35 +00:00
renovate[bot]
c59040f1ee chore(deps): update dependency golangci/golangci-lint to v1.55.1 2023-10-30 04:29:03 +00:00
58ed6a8f30
ci: use gotestsum for better test output (#33) 2023-10-29 16:04:58 +01:00
9dd6ebda20
use uppercase title for breaking changes in changelog 2023-10-28 22:59:52 +02:00
renovate[bot]
68962be52a chore(deps): update dependency golangci/golangci-lint to v1.55.0 2023-10-23 04:51:40 +00:00
43439934a4
ci: fix changelog generation for tag events (#29) 2023-10-17 14:04:09 +02:00
renovate[bot]
b4296d3cad
fix(deps): update module github.com/thegeeklab/wp-plugin-go to v1.0.2 (#28)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-10-17 08:56:43 +02:00
renovate[bot]
348d9d3e7f
fix(deps): update module github.com/aws/aws-sdk-go to v1.45.26 (#21)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-10-17 00:40:47 +02:00
3a6b0182b3
ci: fix releases and add linkcheck (#27) 2023-10-17 00:40:38 +02:00
renovate[bot]
780958170f chore(docker): update golang:1.21 docker digest to 24a0937 2023-10-13 03:10:28 +00:00
renovate[bot]
7a65dd1180 chore(docker): update golang:1.21 docker digest to f94cb10 2023-10-12 22:00:12 +00:00
renovate[bot]
c903221950 chore(docker): update golang:1.21 docker digest to 02d7116 2023-10-11 10:41:48 +00:00
renovate[bot]
94533cd82a chore(docker): update golang:1.21 docker digest to 4d5cf6c 2023-10-11 01:24:05 +00:00
renovate[bot]
879f5f6d11 chore(docker): update docker digests 2023-10-06 07:22:49 +00:00
renovate[bot]
82be12b39a
chore(docker): update golang:1.21 docker digest to 19600fd (#20)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-09-27 15:15:21 +02:00
renovate[bot]
fc5b978664
fix(deps): update module github.com/rs/zerolog to v1.31.0 (#19)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-09-27 15:15:12 +02:00
renovate[bot]
23303eec3a
fix(deps): update module github.com/aws/aws-sdk-go to v1.45.17 (#14)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-09-27 13:48:38 +02:00
renovate[bot]
b1c9910190 chore(docker): update golang:1.21 docker digest to c416cee 2023-09-22 10:53:06 +00:00
renovate[bot]
d68abc76f3 chore(docker): update golang:1.21 docker digest to afccce4 2023-09-21 15:25:54 +00:00
renovate[bot]
cc2944d8d5 chore(docker): update golang:1.21 docker digest to 2270a40 2023-09-21 04:02:31 +00:00
renovate[bot]
4bee5d3266 chore(docker): update golang:1.21 docker digest to 6974950 2023-09-20 21:29:41 +00:00
renovate[bot]
630d25258d
fix(deps): update module github.com/aws/aws-sdk-go to v1.45.11 (#8)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-09-18 08:46:19 +02:00
renovate[bot]
f5e444dc24 chore(docker): update golang:1.21 docker digest to cffaba7 2023-09-13 08:28:24 +00:00
renovate[bot]
2da26947ea chore(docker): update golang:1.21 docker digest to d2aad22 2023-09-08 23:04:19 +00:00
renovate[bot]
6795f86813 chore(docker): update golang:1.21 docker digest to 62e5883 2023-09-08 08:13:24 +00:00
renovate[bot]
35e8ab9571 chore(docker): update golang:1.21 docker digest to 1c545bb 2023-09-07 12:09:44 +00:00
renovate[bot]
fddb08b056 chore(docker): update golang:1.21 docker digest to 970907c 2023-09-07 01:45:01 +00:00
renovate[bot]
65657644ba
fix(deps): update module github.com/aws/aws-sdk-go to v1.45.2 (#5)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-09-03 23:50:34 +02:00
renovate[bot]
e3b256a9ab
fix(deps): update module github.com/thegeeklab/wp-plugin-go to v1 (#7)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-09-03 23:50:09 +02:00
33 changed files with 2463 additions and 878 deletions

View File

@ -1,23 +0,0 @@
# Changelog
{{ range .Versions -}}
## {{ if .Tag.Previous }}[{{ .Tag.Name }}]({{ $.Info.RepositoryURL }}/compare/{{ .Tag.Previous.Name }}...{{ .Tag.Name }}){{ else }}{{ .Tag.Name }}{{ end }} ({{ datetime "2006-01-02" .Tag.Date }})
{{ range .CommitGroups -}}
### {{ .Title }}
{{ range .Commits -}}
- {{ if .Scope }}**{{ .Scope }}:** {{ end }}{{ (regexReplaceAll "(.*)/issues/(.*)" (regexReplaceAll "(Co-\\w*-by.*)" .Subject "") "${1}/pull/${2}") | trim }}
{{ end }}
{{- end -}}
{{- if .NoteGroups -}}
{{ range .NoteGroups -}}
### {{ .Title }}
{{ range .Notes }}
{{ .Body }}
{{ end }}
{{ end -}}
{{ end -}}
{{ end -}}

View File

@ -1,25 +0,0 @@
style: github
template: CHANGELOG.tpl.md
info:
title: CHANGELOG
repository_url: https://github.com/thegeeklab/wp-s3-action
options:
commit_groups:
title_maps:
feat: Features
fix: Bug Fixes
perf: Performance Improvements
refactor: Code Refactoring
chore: Others
test: Testing
ci: CI Pipeline
docs: Documentation
header:
pattern: "^(\\w*)(?:\\(([\\w\\$\\.\\-\\*\\s]*)\\))?\\:\\s(.*)$"
pattern_maps:
- Type
- Scope
- Subject
notes:
keywords:
- BREAKING CHANGE

1
.gitignore vendored
View File

@ -1,6 +1,7 @@
/dist
/release
/wp-s3-action*
docs/data/data-raw.yaml
coverage.out
CHANGELOG.md

47
.gitsv/config.yml Normal file
View File

@ -0,0 +1,47 @@
---
version: "1.1"
versioning:
update-major: []
update-minor: [feat]
update-patch: [fix, perf, refactor, chore, test, ci, docs]
tag:
pattern: "v%d.%d.%d"
release-notes:
sections:
- name: Features
commit-types: [feat]
section-type: commits
- name: Bug Fixes
commit-types: [fix]
section-type: commits
- name: Performance Improvements
commit-types: [perf]
section-type: commits
- name: Code Refactoring
commit-types: [refactor]
section-type: commits
- name: Others
commit-types: [chore]
section-type: commits
- name: Testing
commit-types: [test]
section-type: commits
- name: CI Pipeline
commit-types: [ci]
section-type: commits
- name: Documentation
commit-types: [docs]
section-type: commits
- name: BREAKING CHANGES
section-type: breaking-changes
commit-message:
footer:
issue:
key: issue
add-value-prefix: "#"
issue:
regex: "#?[0-9]+"

View File

@ -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
@ -86,6 +85,7 @@ linters:
# - wastedassign
- whitespace
- wsl
- zerologlint
fast: false
run:
@ -94,4 +94,3 @@ run:
linters-settings:
gofumpt:
extra-rules: true
lang-version: "1.21"

1
.lycheeignore Normal file
View File

@ -0,0 +1 @@
https://hub.docker.com/r/thegeeklab/*

6
.mockery.yaml Normal file
View File

@ -0,0 +1,6 @@
---
all: True
dir: "{{.PackageName}}/mocks"
outpkg: "mocks"
packages:
github.com/thegeeklab/wp-s3-action/aws:

View File

@ -6,8 +6,8 @@ when:
- ${CI_REPO_DEFAULT_BRANCH}
steps:
dryrun:
image: quay.io/thegeeklab/wp-docker-buildx:1
- name: dryrun
image: quay.io/thegeeklab/wp-docker-buildx:4
settings:
containerfile: Containerfile.multiarch
dry_run: true
@ -19,9 +19,9 @@ steps:
when:
- event: [pull_request]
publish-dockerhub:
- name: publish-dockerhub
image: quay.io/thegeeklab/wp-docker-buildx:4
group: container
image: quay.io/thegeeklab/wp-docker-buildx:1
settings:
auto_tag: true
containerfile: Containerfile.multiarch
@ -40,9 +40,9 @@ steps:
branch:
- ${CI_REPO_DEFAULT_BRANCH}
publish-quay:
- name: publish-quay
image: quay.io/thegeeklab/wp-docker-buildx:4
group: container
image: quay.io/thegeeklab/wp-docker-buildx:1
settings:
auto_tag: true
containerfile: Containerfile.multiarch

View File

@ -6,39 +6,36 @@ when:
- ${CI_REPO_DEFAULT_BRANCH}
steps:
build:
image: docker.io/techknowlogick/xgo:go-1.21.x
- name: build
image: docker.io/techknowlogick/xgo:go-1.22.x
commands:
- ln -s $(pwd) /source
- make release
executable:
- name: executable
image: quay.io/thegeeklab/alpine-tools
commands:
- $(find dist/ -executable -type f -iname ${CI_REPO_NAME}-linux-amd64) --help
changelog-generate:
image: quay.io/thegeeklab/git-chglog
- name: changelog
image: quay.io/thegeeklab/git-sv
commands:
- git fetch -tq
- git-chglog --no-color --no-emoji -o CHANGELOG.md ${CI_COMMIT_TAG:---next-tag unreleased unreleased}
- git sv current-version
- git sv release-notes -t ${CI_COMMIT_TAG:-next} -o CHANGELOG.md
- cat CHANGELOG.md
changelog-format:
image: quay.io/thegeeklab/alpine-tools
commands:
- prettier CHANGELOG.md
- prettier -w CHANGELOG.md
publish-github:
- name: publish-github
image: docker.io/plugins/github-release
settings:
api_key:
from_secret: github_token
files:
- dist/*
note: CHANGELOG.md
overwrite: true
title: ${CI_COMMIT_TAG}
when:
- event: [tag]
- event: [tag]
depends_on:
- test

View File

@ -6,20 +6,27 @@ when:
- ${CI_REPO_DEFAULT_BRANCH}
steps:
markdownlint:
- name: markdownlint
image: quay.io/thegeeklab/markdownlint-cli
group: test
commands:
- markdownlint 'README.md' 'CONTRIBUTING.md'
spellcheck:
- name: spellcheck
image: quay.io/thegeeklab/alpine-tools
group: test
commands:
- spellchecker --files '_docs/**/*.md' 'README.md' 'CONTRIBUTING.md' -d .dictionary -p spell indefinite-article syntax-urls
- spellchecker --files 'docs/**/*.md' 'README.md' 'CONTRIBUTING.md' -d .dictionary -p spell indefinite-article syntax-urls
environment:
FORCE_COLOR: "true"
NPM_CONFIG_LOGLEVEL: "error"
publish:
- name: link-validation
image: docker.io/lycheeverse/lychee
group: test
commands:
- lychee --no-progress --format detailed docs/content README.md
- name: publish
image: quay.io/thegeeklab/wp-git-action
settings:
action:
@ -30,19 +37,20 @@ steps:
message: "[skip ci] auto-update documentation"
netrc_password:
from_secret: github_token
pages_directory: _docs/
pages_directory: docs/
when:
- event: [push, manual]
branch:
- ${CI_REPO_DEFAULT_BRANCH}
status: [success, failure]
pushrm-dockerhub:
- name: pushrm-dockerhub
image: docker.io/chko/docker-pushrm:1
secrets:
- source: docker_password
target: DOCKER_PASS
target: DOCKER_PASS
- source: docker_username
target: DOCKER_USER
target: DOCKER_USER
environment:
PUSHRM_FILE: README.md
PUSHRM_SHORT: Woodpecker CI plugin to perform S3 actions
@ -53,7 +61,7 @@ steps:
- ${CI_REPO_DEFAULT_BRANCH}
status: [success]
pushrm-quay:
- name: pushrm-quay
image: docker.io/chko/docker-pushrm:1
secrets:
- source: quay_token

View File

@ -8,7 +8,7 @@ when:
runs_on: [success, failure]
steps:
matrix:
- name: matrix
image: quay.io/thegeeklab/wp-matrix
settings:
homeserver:

View File

@ -6,12 +6,12 @@ when:
- ${CI_REPO_DEFAULT_BRANCH}
steps:
lint:
image: docker.io/library/golang:1.21
- name: lint
image: docker.io/library/golang:1.22
commands:
- make lint
test:
image: docker.io/library/golang:1.21
- name: test
image: docker.io/library/golang:1.22
commands:
- make test

View File

@ -1,4 +1,4 @@
FROM --platform=$BUILDPLATFORM golang:1.21@sha256:b490ae1f0ece153648dd3c5d25be59a63f966b5f9e1311245c947de4506981aa 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 alpine:3.18@sha256:7144f7bab3d4c2648d7e59409f15ec52a18006a128c733fcff20d3a4a54ba44a
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>"

View File

@ -1,7 +1,7 @@
# renovate: datasource=github-releases depName=mvdan/gofumpt
GOFUMPT_PACKAGE_VERSION := v0.5.0
GOFUMPT_PACKAGE_VERSION := v0.6.0
# renovate: datasource=github-releases depName=golangci/golangci-lint
GOLANGCI_LINT_PACKAGE_VERSION := v1.54.2
GOLANGCI_LINT_PACKAGE_VERSION := v1.59.0
EXECUTABLE := wp-s3-action
@ -17,9 +17,10 @@ SOURCES ?= $(shell find . -name "*.go" -type f)
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.21.x
XGO_VERSION := go-1.22.x
XGO_TARGETS ?= linux/amd64,linux/arm-6,linux/arm-7,linux/arm64
TARGETOS ?= linux
@ -64,11 +65,12 @@ lint: golangci-lint
.PHONY: generate
generate:
$(GO) generate $(GENERATE)
$(GO) generate $(PACKAGES)
$(GO) run $(MOCKERY_PACKAGE)
.PHONY: test
test:
$(GO) test -v -coverprofile coverage.out $(PACKAGES)
$(GO) run $(GOTESTSUM_PACKAGE) --no-color=false -- -coverprofile=coverage.out $(PACKAGES)
.PHONY: build
build: $(DIST)/$(EXECUTABLE)
@ -99,3 +101,4 @@ deps:
$(GO) install $(GOFUMPT_PACKAGE)
$(GO) install $(GOLANGCI_LINT_PACKAGE)
$(GO) install $(XGO_PACKAGE)
$(GO) install $(GOTESTSUM_PACKAGE)

View File

@ -1,94 +0,0 @@
---
properties:
- name: endpoint
description: Endpoint for the s3 connection.
type: string
required: false
- name: access-key
description: S3 access key.
type: string
required: false
- name: secret-key
description: S3 secret key.
type: string
required: false
- name: path-style
description: Enable path style for bucket paths.
type: bool
required: false
- name: bucket
description: Name of the bucket.
type: string
required: true
- name: region
description: S3 region.
defaultValue: us-east-1
type: string
required: false
- name: source
description: Upload source path.
defaultValue: .
type: string
required: false
- name: target
description: Upload target path.
defaultValue: /
type: string
required: false
- name: delete
description: Delete locally removed files from the target.
type: bool
required: false
- name: acl
description: Access control list.
type: map
required: false
- name: content-type
description: Content-type settings for uploads.
type: map
required: false
- name: content-encoding
description: Content-encoding settings for uploads.
type: map
required: false
- name: cache_control
description: Cache-control settings for uploads.
type: map
required: false
- name: metadata
description: Additional metadata for uploads.
type: map
required: false
- name: redirects
description: Redirects to create.
type: map
required: false
- name: cloudfront-distribution
description: ID of cloudfront distribution to invalidate.
type: string
required: false
- name: dry_run
description: Dry run disables API calls.
type: bool
required: false
- name: max_concurrency
description: Customize number of concurrent files to process.
defaultValue: 100
type: int

24
aws/api.go Normal file
View 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
View 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
View 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
View 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)
})
}
}

View 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
}

View 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
View 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
View 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)
})
}
}

View File

@ -1,148 +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.
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,
},
}
}

View File

@ -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()
}

View File

@ -21,15 +21,12 @@ Woodpecker CI plugin to perform S3 actions.
## Usage
```YAML
kind: pipeline
name: default
steps:
- name: sync
image: thegeeklab/wp-s3-action
image: quay.io/thegeeklab/wp-s3-action
settings:
access_key: a50d28f4dd477bc184fbd10b376de753
secret_key: bc5785d3ece6a9cdefa42eb99b58986f9095ff1c
access_key: randomstring
secret_key: random-secret
region: us-east-1
bucket: my-bucket.s3-website-us-east-1.amazonaws.com
source: folder/to/archive
@ -49,15 +46,12 @@ steps:
**Customize `acl`, `content_type`, `content_encoding` or `cache_control`:**
```YAML
kind: pipeline
name: default
steps:
- name: sync
image: thegeeklab/wp-s3-action
image: quay.io/thegeeklab/wp-s3-action
settings:
access_key: a50d28f4dd477bc184fbd10b376de753
secret_key: bc5785d3ece6a9cdefa42eb99b58986f9095ff1c
access_key: randomstring
secret_key: random-secret
region: us-east-1
bucket: my-bucket.s3-website-us-east-1.amazonaws.com
source: folder/to/archive
@ -85,16 +79,13 @@ All `map` parameters can be specified as `map` for a subset of files or as `stri
To use [Minio S3](https://docs.min.io/) its required to set `path_style: true`.
```YAML
kind: pipeline
name: default
steps:
- name: sync
image: thegeeklab/wp-s3-action
image: quay.io/thegeeklab/wp-s3-action
settings:
endpoint: https://minio.example.com
access_key: a50d28f4dd477bc184fbd10b376de753
secret_key: bc5785d3ece6a9cdefa42eb99b58986f9095ff1c
access_key: randomstring
secret_key: random-secret
bucket: my-bucket
source: folder/to/archive
target: /target/location
@ -120,8 +111,8 @@ docker build --file Containerfile.multiarch --tag thegeeklab/wp-s3-action .
```Shell
docker run --rm \
-e PLUGIN_BUCKET=my_bucket \
-e AWS_ACCESS_KEY_ID=abc123 \
-e AWS_SECRET_ACCESS_KEY=xyc789 \
-e AWS_ACCESS_KEY_ID=randomstring \
-e AWS_SECRET_ACCESS_KEY=random-secret \
-v $(pwd):/build:z \
-w /build \
thegeeklab/wp-s3-action

123
docs/data/data.yaml Normal file
View File

@ -0,0 +1,123 @@
---
properties:
- name: access_key
description: |
S3 access key.
type: string
required: true
- name: acl
description: |
Access control list.
type: generic
required: false
- name: bucket
description: |
Name of the bucket.
type: string
required: true
- name: cache_control
description: |
Cache-control settings for uploads.
type: generic
required: false
- name: cloudfront_distribution
description: |
ID of cloudfront distribution to invalidate.
type: string
required: false
- name: content_encoding
description: |
Content-encoding settings for uploads.
type: generic
required: false
- name: content_type
description: |
Content-type settings for uploads.
type: generic
required: false
- name: delete
description: |
Delete locally removed files from the target.
type: bool
defaultValue: false
required: false
- name: endpoint
description: |
Endpoint for the s3 connection.
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.
type: integer
defaultValue: 100
required: false
- name: metadata
description: |
Additional metadata for uploads.
type: generic
required: false
- name: path_style
description: |
Enable path style for bucket paths.
type: bool
defaultValue: false
required: false
- name: redirects
description: |
Redirects to create.
type: generic
required: false
- name: region
description: |
S3 region.
type: string
defaultValue: "us-east-1"
required: false
- name: secret_key
description: |
S3 secret key.
type: string
required: true
- name: source
description: |
Upload source path.
type: string
defaultValue: "."
required: false
- name: target
description: |
Upload target path.
type: string
defaultValue: "/"
required: false

56
go.mod
View File

@ -1,24 +1,56 @@
module github.com/thegeeklab/wp-s3-action
go 1.21
go 1.22
require (
github.com/aws/aws-sdk-go v1.44.328
github.com/rs/zerolog v1.30.0
github.com/ryanuber/go-glob v1.0.0
github.com/thegeeklab/wp-plugin-go v0.5.0
github.com/urfave/cli/v2 v2.25.7
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/cpuguy83/go-md2man/v2 v2.0.2 // indirect
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/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
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/joho/godotenv v1.5.1 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
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/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
golang.org/x/net v0.14.0 // indirect
golang.org/x/sys v0.11.0 // indirect
github.com/shopspring/decimal v1.2.0 // indirect
github.com/spf13/cast v1.3.1 // 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
)

129
go.sum
View File

@ -1,74 +1,143 @@
github.com/aws/aws-sdk-go v1.44.328 h1:WBwlf8ym9SDQ/GTIBO9eXyvwappKJyOetWJKl4mT7ZU=
github.com/aws/aws-sdk-go v1.44.328/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI=
github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
github.com/Masterminds/semver/v3 v3.2.0/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ=
github.com/Masterminds/semver/v3 v3.2.1 h1:RN9w6+7QoMeJVGyfmbcgs28Br8cvmnucEXnY0rYXWg0=
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-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=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/huandu/xstrings v1.3.3 h1:/Gcsuc1x8JVbJ9/rlye4xZnVAbEkGauT8lbebqcQws4=
github.com/huandu/xstrings v1.3.3/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/imdario/mergo v0.3.11 h1:3tnifQM4i+fbajXKBHXWEH+KvNHqojZ778UH75j3bGA=
github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40=
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mitchellh/copystructure v1.0.0 h1:Laisrj+bAB6b/yJwB5Bt3ITZhGJdqmxquMKeZ+mmkFQ=
github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw=
github.com/mitchellh/reflectwalk v1.0.0 h1:9D+8oIskB4VJBN5SFlmc27fSlIBZaov1Wpk/IfikLNY=
github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
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.30.0 h1:SymVODrcRsaRaSInD9yQtKbtWqwsfoPcRff/oRXLj4c=
github.com/rs/zerolog v1.30.0/go.mod h1:/tk+P47gFdPXq4QYjvCmT5/Gsug2nagsFWBWhAiSi1w=
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/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=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
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/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.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.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco=
golang.org/x/net v0.14.0 h1:BONx9s002vGdD9umnlX1Po8vOZmrgH34qlHcD1MfK14=
golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI=
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
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=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
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.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.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
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.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc=
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
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.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
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=
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

42
internal/doc/main.go Normal file
View 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)
}
}

View File

@ -1,445 +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
}

View File

@ -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
}
@ -83,7 +100,9 @@ func (p *Plugin) createSyncJobs() error {
localPath = strings.TrimPrefix(path, p.Settings.Source)
localPath = strings.TrimPrefix(localPath, "/")
}
local = append(local, localPath)
p.Settings.Jobs = append(p.Settings.Jobs, Job{
local: filepath.Join(p.Settings.Source, localPath),
remote: filepath.Join(p.Settings.Target, localPath),
@ -132,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))
@ -149,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:
@ -173,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)
}

View File

@ -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,
},
}
}