You've already forked goreleaser
mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-07-15 01:34:21 +02:00
feat(blob): content disposition
Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
@ -29,6 +29,9 @@ func (Pipe) Default(ctx *context.Context) error {
|
||||
if blob.Folder == "" {
|
||||
blob.Folder = "{{ .ProjectName }}/{{ .Tag }}"
|
||||
}
|
||||
if blob.ContentDisposition == "" {
|
||||
blob.ContentDisposition = "attachment;filename={{.Filename}}"
|
||||
}
|
||||
if blob.OldDisableSSL {
|
||||
deprecate.Notice(ctx, "blobs.disableSSL")
|
||||
blob.DisableSSL = true
|
||||
|
@ -86,12 +86,13 @@ func TestMinioUpload(t *testing.T) {
|
||||
ProjectName: "testupload",
|
||||
Blobs: []config.Blob{
|
||||
{
|
||||
Provider: "s3",
|
||||
Bucket: name,
|
||||
Region: "us-east",
|
||||
Endpoint: "http://" + listen,
|
||||
IDs: []string{"foo", "bar"},
|
||||
CacheControl: []string{"max-age=9999"},
|
||||
Provider: "s3",
|
||||
Bucket: name,
|
||||
Region: "us-east",
|
||||
Endpoint: "http://" + listen,
|
||||
IDs: []string{"foo", "bar"},
|
||||
CacheControl: []string{"max-age=9999"},
|
||||
ContentDisposition: "inline",
|
||||
ExtraFiles: []config.ExtraFile{
|
||||
{
|
||||
Glob: "./testdata/*.golden",
|
||||
|
@ -69,28 +69,48 @@ func TestDefaults(t *testing.T) {
|
||||
ctx := testctx.NewWithCfg(config.Project{
|
||||
Blobs: []config.Blob{
|
||||
{
|
||||
Bucket: "foo",
|
||||
Provider: "azblob",
|
||||
IDs: []string{"foo", "bar"},
|
||||
Bucket: "foo",
|
||||
Provider: "azblob",
|
||||
IDs: []string{"foo", "bar"},
|
||||
ContentDisposition: "inline",
|
||||
},
|
||||
{
|
||||
Bucket: "foobar",
|
||||
Provider: "gcs",
|
||||
},
|
||||
{
|
||||
Bucket: "deprecated",
|
||||
Provider: "s3",
|
||||
Folder: "static",
|
||||
OldDisableSSL: true,
|
||||
OldKMSKey: "fake",
|
||||
},
|
||||
},
|
||||
})
|
||||
require.NoError(t, Pipe{}.Default(ctx))
|
||||
require.Equal(t, []config.Blob{
|
||||
{
|
||||
Bucket: "foo",
|
||||
Provider: "azblob",
|
||||
Folder: "{{ .ProjectName }}/{{ .Tag }}",
|
||||
IDs: []string{"foo", "bar"},
|
||||
Bucket: "foo",
|
||||
Provider: "azblob",
|
||||
Folder: "{{ .ProjectName }}/{{ .Tag }}",
|
||||
IDs: []string{"foo", "bar"},
|
||||
ContentDisposition: "inline",
|
||||
},
|
||||
{
|
||||
Bucket: "foobar",
|
||||
Provider: "gcs",
|
||||
Folder: "{{ .ProjectName }}/{{ .Tag }}",
|
||||
Bucket: "foobar",
|
||||
Provider: "gcs",
|
||||
Folder: "{{ .ProjectName }}/{{ .Tag }}",
|
||||
ContentDisposition: "attachment;filename={{.Filename}}",
|
||||
},
|
||||
{
|
||||
Bucket: "deprecated",
|
||||
Provider: "s3",
|
||||
Folder: "static",
|
||||
OldDisableSSL: true,
|
||||
DisableSSL: true,
|
||||
OldKMSKey: "fake",
|
||||
KMSKey: "fake",
|
||||
ContentDisposition: "attachment;filename={{.Filename}}",
|
||||
},
|
||||
}, ctx.Config.Blobs)
|
||||
}
|
||||
|
@ -111,7 +111,8 @@ func doUpload(ctx *context.Context, conf config.Blob) error {
|
||||
}
|
||||
|
||||
up := &productionUploader{
|
||||
cacheControl: conf.CacheControl,
|
||||
cacheControl: conf.CacheControl,
|
||||
contentDisposition: conf.ContentDisposition,
|
||||
}
|
||||
if conf.Provider == "s3" && conf.ACL != "" {
|
||||
up.beforeWrite = func(asFunc func(interface{}) bool) error {
|
||||
@ -229,9 +230,10 @@ type uploader interface {
|
||||
|
||||
// productionUploader actually do upload to.
|
||||
type productionUploader struct {
|
||||
bucket *blob.Bucket
|
||||
beforeWrite func(asFunc func(interface{}) bool) error
|
||||
cacheControl []string
|
||||
bucket *blob.Bucket
|
||||
beforeWrite func(asFunc func(interface{}) bool) error
|
||||
cacheControl []string
|
||||
contentDisposition string
|
||||
}
|
||||
|
||||
func (u *productionUploader) Close() error {
|
||||
@ -255,8 +257,15 @@ func (u *productionUploader) Open(ctx *context.Context, bucket string) error {
|
||||
func (u *productionUploader) Upload(ctx *context.Context, filepath string, data []byte) error {
|
||||
log.WithField("path", filepath).Info("uploading")
|
||||
|
||||
disp, err := tmpl.New(ctx).WithExtraFields(tmpl.Fields{
|
||||
"Filename": path.Base(filepath),
|
||||
}).Apply(u.contentDisposition)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
opts := &blob.WriterOptions{
|
||||
ContentDisposition: "attachment; filename=" + path.Base(filepath),
|
||||
ContentDisposition: disp,
|
||||
BeforeWrite: u.beforeWrite,
|
||||
CacheControl: strings.Join(u.cacheControl, ", "),
|
||||
}
|
||||
|
@ -1093,19 +1093,20 @@ type Before struct {
|
||||
|
||||
// Blob contains config for GO CDK blob.
|
||||
type Blob struct {
|
||||
Bucket string `yaml:"bucket,omitempty" json:"bucket,omitempty"`
|
||||
Provider string `yaml:"provider,omitempty" json:"provider,omitempty"`
|
||||
Region string `yaml:"region,omitempty" json:"region,omitempty"`
|
||||
DisableSSL bool `yaml:"disable_ssl,omitempty" json:"disable_ssl,omitempty"`
|
||||
Folder string `yaml:"folder,omitempty" json:"folder,omitempty"`
|
||||
KMSKey string `yaml:"kms_key,omitempty" json:"kms_key,omitempty"`
|
||||
IDs []string `yaml:"ids,omitempty" json:"ids,omitempty"`
|
||||
Endpoint string `yaml:"endpoint,omitempty" json:"endpoint,omitempty"` // used for minio for example
|
||||
ExtraFiles []ExtraFile `yaml:"extra_files,omitempty" json:"extra_files,omitempty"`
|
||||
Disable string `yaml:"disable,omitempty" json:"disable,omitempty" jsonschema:"oneof_type=string;boolean"`
|
||||
S3ForcePathStyle *bool `yaml:"s3_force_path_style,omitempty" json:"s3_force_path_style,omitempty"`
|
||||
ACL string `yaml:"acl,omitempty" json:"acl,omitempty"`
|
||||
CacheControl []string `yaml:"cache_control,omitempty" json:"cache_control,omitempty"`
|
||||
Bucket string `yaml:"bucket,omitempty" json:"bucket,omitempty"`
|
||||
Provider string `yaml:"provider,omitempty" json:"provider,omitempty"`
|
||||
Region string `yaml:"region,omitempty" json:"region,omitempty"`
|
||||
DisableSSL bool `yaml:"disable_ssl,omitempty" json:"disable_ssl,omitempty"`
|
||||
Folder string `yaml:"folder,omitempty" json:"folder,omitempty"`
|
||||
KMSKey string `yaml:"kms_key,omitempty" json:"kms_key,omitempty"`
|
||||
IDs []string `yaml:"ids,omitempty" json:"ids,omitempty"`
|
||||
Endpoint string `yaml:"endpoint,omitempty" json:"endpoint,omitempty"` // used for minio for example
|
||||
ExtraFiles []ExtraFile `yaml:"extra_files,omitempty" json:"extra_files,omitempty"`
|
||||
Disable string `yaml:"disable,omitempty" json:"disable,omitempty" jsonschema:"oneof_type=string;boolean"`
|
||||
S3ForcePathStyle *bool `yaml:"s3_force_path_style,omitempty" json:"s3_force_path_style,omitempty"`
|
||||
ACL string `yaml:"acl,omitempty" json:"acl,omitempty"`
|
||||
CacheControl []string `yaml:"cache_control,omitempty" json:"cache_control,omitempty"`
|
||||
ContentDisposition string `yaml:"content_disposition,omitempty" json:"content_disposition,omitempty"`
|
||||
|
||||
// Deprecated: use disable_ssl instead
|
||||
OldDisableSSL bool `yaml:"disableSSL,omitempty" json:"disableSSL,omitempty" jsonschema:"deprecated=true,description=use disable_ssl instead"` // nolint:tagliatelle
|
||||
|
@ -105,6 +105,13 @@ blobs:
|
||||
- max-age=9999
|
||||
- public
|
||||
|
||||
# Allows to set the content disposition of the file.
|
||||
#
|
||||
# Default: attachment;filename={{.Filename}}
|
||||
# Templates: allowed
|
||||
# Since: v1.24
|
||||
content_disposition: "inline"
|
||||
|
||||
- provider: gs
|
||||
bucket: goreleaser-bucket
|
||||
folder: "foo/bar/{{.Version}}"
|
||||
|
Reference in New Issue
Block a user