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
1 change: 1 addition & 0 deletions cache/s3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ The s3cache config supports the following properties:
- `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 ''.
- `content_type` (string): the http MIME-type set on the file when putting the file. defaults to 'application/vnd.mapbox-vector-tile'.


## Credential chain
Expand Down
37 changes: 24 additions & 13 deletions cache/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,17 @@ const (
ConfigKeyAWSAccessKeyID = "aws_access_key_id"
ConfigKeyAWSSecretKey = "aws_secret_access_key"
ConfigKeyACL = "access_control_list" // defaults to ""
ConfigKeyCacheControl = "cache_control" // defaults to ""
ConfigKeyCacheControl = "cache_control" // defaults to ""
ConfigKeyContentType = "content_type" // defaults to "application/vnd.mapbox-vector-tile"
)

const (
DefaultBasepath = ""
DefaultRegion = "us-east-1"
DefaultAccessKey = ""
DefaultSecretKey = ""
)

const (
DefaultEndpoint = ""
DefaultBasepath = ""
DefaultRegion = "us-east-1"
DefaultAccessKey = ""
DefaultSecretKey = ""
DefaultContentType = "application/vnd.mapbox-vector-tile"
DefaultEndpoint = ""
)

func init() {
Expand All @@ -67,6 +66,7 @@ func init() {
// 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 ''.
// content_type (string): the http MIME-type set on the file when putting the file. defaults to 'application/vnd.mapbox-vector-tile'.

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

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

contenttype := DefaultContentType
contenttype, err = config.String(ConfigKeyContentType, &contenttype)
if err != nil {
return nil, err
}
s3cache.ContentType = contenttype

// 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 @@ -236,6 +243,9 @@ type Cache struct {

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

// ContentType is MIME content type of the tile. Default is "application/vnd.mapbox-vector-tile"
ContentType string
}

func (s3c *Cache) Set(key *cache.Key, val []byte) error {
Expand All @@ -250,9 +260,10 @@ func (s3c *Cache) Set(key *cache.Key, val []byte) error {
k := filepath.Join(s3c.Basepath, key.String())

input := s3.PutObjectInput{
Body: aws.ReadSeekCloser(bytes.NewReader(val)),
Bucket: aws.String(s3c.Bucket),
Key: aws.String(k),
Body: aws.ReadSeekCloser(bytes.NewReader(val)),
Bucket: aws.String(s3c.Bucket),
Key: aws.String(k),
ContentType: aws.String(s3c.ContentType),
}
if s3c.ACL != "" {
input.ACL = aws.String(s3c.ACL)
Expand Down