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