mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-04-25 12:24:44 +02:00
feat(http): support custom headers in http upload (#2002)
Signed-off-by: Sune Keller <absukl@almbrand.dk>
This commit is contained in:
parent
2edebf0029
commit
f934314be3
@ -240,6 +240,11 @@ func uploadAsset(ctx *context.Context, upload *config.Upload, artifact *artifact
|
|||||||
log.Debugf("generated target url: %s", targetURL)
|
log.Debugf("generated target url: %s", targetURL)
|
||||||
|
|
||||||
var headers = map[string]string{}
|
var headers = map[string]string{}
|
||||||
|
if upload.CustomHeaders != nil {
|
||||||
|
for name, value := range upload.CustomHeaders {
|
||||||
|
headers[name] = value
|
||||||
|
}
|
||||||
|
}
|
||||||
if upload.ChecksumHeader != "" {
|
if upload.ChecksumHeader != "" {
|
||||||
sum, err := artifact.Checksum("sha256")
|
sum, err := artifact.Checksum("sha256")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -469,6 +469,21 @@ func TestUpload(t *testing.T) {
|
|||||||
},
|
},
|
||||||
checks(check{"/blah/2.1.0/a.ubi", "u2", "x", content, map[string]string{"-x-sha256": "5e2bf57d3f40c4b6df69daf1936cb766f832374b4fc0259a7cbff06e2f70f269"}}),
|
checks(check{"/blah/2.1.0/a.ubi", "u2", "x", content, map[string]string{"-x-sha256": "5e2bf57d3f40c4b6df69daf1936cb766f832374b4fc0259a7cbff06e2f70f269"}}),
|
||||||
},
|
},
|
||||||
|
{"custom-headers", true, true, false, false,
|
||||||
|
func(s *httptest.Server) (*context.Context, config.Upload) {
|
||||||
|
return ctx, config.Upload{
|
||||||
|
Mode: ModeBinary,
|
||||||
|
Name: "a",
|
||||||
|
Target: s.URL + "/{{.ProjectName}}/{{.Version}}/",
|
||||||
|
Username: "u2",
|
||||||
|
CustomHeaders: map[string]string{
|
||||||
|
"x-custom-header-name": "custom-header-value",
|
||||||
|
},
|
||||||
|
TrustedCerts: cert(s),
|
||||||
|
}
|
||||||
|
},
|
||||||
|
checks(check{"/blah/2.1.0/a.ubi", "u2", "x", content, map[string]string{"x-custom-header-name": "custom-header-value"}}),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
uploadAndCheck := func(t *testing.T, setup func(*httptest.Server) (*context.Context, config.Upload), wantErrPlain, wantErrTLS bool, check func(r []*h.Request) error, srv *httptest.Server) {
|
uploadAndCheck := func(t *testing.T, setup func(*httptest.Server) (*context.Context, config.Upload), wantErrPlain, wantErrTLS bool, check func(r []*h.Request) error, srv *httptest.Server) {
|
||||||
|
@ -554,6 +554,7 @@ type Upload struct {
|
|||||||
Checksum bool `yaml:",omitempty"`
|
Checksum bool `yaml:",omitempty"`
|
||||||
Signature bool `yaml:",omitempty"`
|
Signature bool `yaml:",omitempty"`
|
||||||
CustomArtifactName bool `yaml:"custom_artifact_name,omitempty"`
|
CustomArtifactName bool `yaml:"custom_artifact_name,omitempty"`
|
||||||
|
CustomHeaders map[string]string `yaml:"custom_headers,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Publisher configuration.
|
// Publisher configuration.
|
||||||
|
@ -161,6 +161,11 @@ uploads:
|
|||||||
# Default is empty.
|
# Default is empty.
|
||||||
checksum_header: -X-SHA256-Sum
|
checksum_header: -X-SHA256-Sum
|
||||||
|
|
||||||
|
# A map of custom headers e.g. to support required content types or auth schemes.
|
||||||
|
# Default is empty.
|
||||||
|
custom_headers:
|
||||||
|
JOB-TOKEN: {{ .Env.CI_JOB_TOKEN }}
|
||||||
|
|
||||||
# Upload checksums (defaults to false)
|
# Upload checksums (defaults to false)
|
||||||
checksum: true
|
checksum: true
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user