mirror of
https://github.com/thegeeklab/wp-s3-action.git
synced 2024-11-25 00:10:39 +00:00
add support for website redirects
This commit is contained in:
parent
5644941fde
commit
2187920d58
18
DOCS.md
18
DOCS.md
@ -10,6 +10,7 @@ Use the S3 sync plugin to synchronize files and folders with an Amazon S3 bucket
|
||||
* `delete` - deletes files in the target not found in the source
|
||||
* `content_type` - override default mime-types to use this value
|
||||
* `metadata` - set custom metadata
|
||||
* `redirects` - targets that should redirect elsewhere
|
||||
|
||||
The following is a sample S3 configuration in your .drone.yml file:
|
||||
|
||||
@ -87,3 +88,20 @@ publish:
|
||||
"*.html":
|
||||
Cache-Control: "max-age: 1000"
|
||||
```
|
||||
|
||||
Additionally, you can specify redirect targets for files that don't exist by using the `redirects` key:
|
||||
|
||||
```yaml
|
||||
publish:
|
||||
s3_sync:
|
||||
acl: public-read
|
||||
region: "us-east-1"
|
||||
bucket: "my-bucket.s3-website-us-east-1.amazonaws.com"
|
||||
access_key: "970d28f4dd477bc184fbd10b376de753"
|
||||
secret_key: "9c5785d3ece6a9cdefa42eb99b58986f9095ff1c"
|
||||
source: folder/to/archive
|
||||
target: /target/location
|
||||
delete: true
|
||||
redirects:
|
||||
some/missing/file: /somewhere/that/actually/exists
|
||||
```
|
||||
|
18
aws.go
18
aws.go
@ -231,6 +231,24 @@ func (a *AWS) visit(path string, info os.FileInfo, err error) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (a *AWS) AddRedirects(redirects map[string]string) error {
|
||||
for path, location := range redirects {
|
||||
fmt.Printf("Adding redirect from \"%s\" to \"%s\"", path, location)
|
||||
a.local = append(a.local, strings.TrimPrefix(path, "/"))
|
||||
_, err := a.client.PutObject(&s3.PutObjectInput{
|
||||
Bucket: aws.String(a.vargs.Bucket),
|
||||
Key: aws.String(path),
|
||||
WebsiteRedirectLocation: aws.String(location),
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *AWS) List(path string) error {
|
||||
resp, err := a.client.ListObjects(&s3.ListObjectsInput{
|
||||
Bucket: aws.String(a.vargs.Bucket),
|
||||
|
8
main.go
8
main.go
@ -51,6 +51,14 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if len(vargs.Redirects) > 0 {
|
||||
err = client.AddRedirects(vargs.Redirects)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
if vargs.Delete {
|
||||
err = client.Cleanup()
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user