mirror of
https://github.com/goreleaser/goreleaser.git
synced 2024-12-27 01:33:39 +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)
|
||||
|
||||
var headers = map[string]string{}
|
||||
if upload.CustomHeaders != nil {
|
||||
for name, value := range upload.CustomHeaders {
|
||||
headers[name] = value
|
||||
}
|
||||
}
|
||||
if upload.ChecksumHeader != "" {
|
||||
sum, err := artifact.Checksum("sha256")
|
||||
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"}}),
|
||||
},
|
||||
{"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) {
|
||||
|
@ -543,17 +543,18 @@ type Blob struct {
|
||||
|
||||
// Upload configuration.
|
||||
type Upload struct {
|
||||
Name string `yaml:",omitempty"`
|
||||
IDs []string `yaml:"ids,omitempty"`
|
||||
Target string `yaml:",omitempty"`
|
||||
Username string `yaml:",omitempty"`
|
||||
Mode string `yaml:",omitempty"`
|
||||
Method string `yaml:",omitempty"`
|
||||
ChecksumHeader string `yaml:"checksum_header,omitempty"`
|
||||
TrustedCerts string `yaml:"trusted_certificates,omitempty"`
|
||||
Checksum bool `yaml:",omitempty"`
|
||||
Signature bool `yaml:",omitempty"`
|
||||
CustomArtifactName bool `yaml:"custom_artifact_name,omitempty"`
|
||||
Name string `yaml:",omitempty"`
|
||||
IDs []string `yaml:"ids,omitempty"`
|
||||
Target string `yaml:",omitempty"`
|
||||
Username string `yaml:",omitempty"`
|
||||
Mode string `yaml:",omitempty"`
|
||||
Method string `yaml:",omitempty"`
|
||||
ChecksumHeader string `yaml:"checksum_header,omitempty"`
|
||||
TrustedCerts string `yaml:"trusted_certificates,omitempty"`
|
||||
Checksum bool `yaml:",omitempty"`
|
||||
Signature bool `yaml:",omitempty"`
|
||||
CustomArtifactName bool `yaml:"custom_artifact_name,omitempty"`
|
||||
CustomHeaders map[string]string `yaml:"custom_headers,omitempty"`
|
||||
}
|
||||
|
||||
// Publisher configuration.
|
||||
|
@ -161,6 +161,11 @@ uploads:
|
||||
# Default is empty.
|
||||
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)
|
||||
checksum: true
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user