Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion cache/s3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ s3cache is an abstraction on top of Amazon Web Services (AWS) Simple Storage Ser

```toml
[cache]
type="s3"
type="s3"
bucket="tegola-test-data"
```

Expand All @@ -19,6 +19,8 @@ The s3cache config supports the following properties:
- `max_zoom` (int): [Optional] the max zoom the cache should cache to. After this zoom, Set() calls will return before doing work.
- `endpoint` (string): the endpoint where the S3 compliant backend is located. only necessary for non-AWS deployments. defaults to ''.
- `access_control_list` (string): the S3 access control to set on the file when putting the file. defaults to ''.
- `cache_control` (string): the HTTP cache control header to set on the file when putting the file. defaults to ''.


## Credential chain
If the `aws_access_key_id` and `aws_secret_access_key` are not set, then the [credential provider chain](http://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/configuring-sdk.html) will be used. The provider chain supports multiple methods for passing credentials, one of which is setting environment variables. For example:
Expand Down
16 changes: 16 additions & 0 deletions cache/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const (
ConfigKeyAWSAccessKeyID = "aws_access_key_id"
ConfigKeyAWSSecretKey = "aws_secret_access_key"
ConfigKeyACL = "access_control_list" // defaults to ""
ConfigKeyCacheControl = "cache_control" // defaults to ""
)

const (
Expand Down Expand Up @@ -62,6 +63,7 @@ func init() {
// max_zoom (int): max zoom to use the cache. beyond this zoom cache Set() calls will be ignored
// endpoint (string): the endpoint where the S3 compliant backend is located. only necessary for non-AWS deployments. defaults to ''
// access_control_list (string): the S3 access control to set on the file when putting the file. defaults to ''.
// cache_control (string): the http cache-control header to set on the file when putting the file. defaults to ''.

func New(config dict.Dicter) (cache.Interface, error) {
var err error
Expand Down Expand Up @@ -155,6 +157,14 @@ func New(config dict.Dicter) (cache.Interface, error) {
}
s3cache.ACL = acl

// check for control_access_list env var
cachecontrol := os.Getenv("AWS_CacheControl")
cachecontrol, err = config.String(ConfigKeyCacheControl, &cachecontrol)
if err != nil {
return nil, err
}
s3cache.CacheControl = cachecontrol

// in order to confirm we have the correct permissions on the bucket create a small file
// and test a PUT, GET and DELETE to the bucket
key := cache.Key{
Expand Down Expand Up @@ -220,6 +230,9 @@ type Cache struct {

// ACL is the aws ACL, if the not set it will use the default value for aws.
ACL string

// CacheControl is the http Cache Control header, if the not set it will use the default value for aws.
CacheControl string
}

func (s3c *Cache) Set(key *cache.Key, val []byte) error {
Expand All @@ -241,6 +254,9 @@ func (s3c *Cache) Set(key *cache.Key, val []byte) error {
if s3c.ACL != "" {
input.ACL = aws.String(s3c.ACL)
}
if s3c.CacheControl != "" {
input.CacheControl = aws.String(s3c.CacheControl)
}

_, err = s3c.Client.PutObject(&input)
if err != nil {
Expand Down