From 6291f89009a25aca9d1f653573787978a45e0578 Mon Sep 17 00:00:00 2001 From: Felix Blass Date: Wed, 14 Aug 2024 11:54:53 +0200 Subject: [PATCH] Set buildpack version as header on dcl upload --- cmd/supply/main.go | 8 ++++++++ pkg/common/version.go | 11 +++++++++++ pkg/uploader/uploader.go | 2 ++ 3 files changed, 21 insertions(+) create mode 100644 pkg/common/version.go diff --git a/cmd/supply/main.go b/cmd/supply/main.go index 2226673..0e4aa8a 100644 --- a/cmd/supply/main.go +++ b/cmd/supply/main.go @@ -6,6 +6,7 @@ import ( "path/filepath" "time" + "github.com/SAP/cloud-authorization-buildpack/pkg/common" "github.com/SAP/cloud-authorization-buildpack/pkg/supply" "github.com/SAP/cloud-authorization-buildpack/pkg/uploader" @@ -26,6 +27,13 @@ func main() { logger.Error("Unable to load buildpack manifest: %s", err) os.Exit(10) } + version, err := manifest.Version() + if err != nil { + logger.Error("Unable to load buildpack version: %s", err) + os.Exit(20) + } + common.SetVersion(version) + installer := libbuildpack.NewInstaller(manifest) stager := libbuildpack.NewStager(os.Args[1:], logger, manifest) diff --git a/pkg/common/version.go b/pkg/common/version.go new file mode 100644 index 0000000..142851b --- /dev/null +++ b/pkg/common/version.go @@ -0,0 +1,11 @@ +package common + +var versionNumber = "dev" + +func VersionNumber() string { + return versionNumber +} + +func SetVersion(version string) { + versionNumber = version +} diff --git a/pkg/uploader/uploader.go b/pkg/uploader/uploader.go index 429d262..69a9bfa 100644 --- a/pkg/uploader/uploader.go +++ b/pkg/uploader/uploader.go @@ -13,6 +13,7 @@ import ( "github.com/cloudfoundry/libbuildpack" + "github.com/SAP/cloud-authorization-buildpack/pkg/common" "github.com/SAP/cloud-authorization-buildpack/pkg/supply/env" ) @@ -91,6 +92,7 @@ func (up *Uploader) do(ctx context.Context, dstURL string, body []byte) (*http.R return nil, fmt.Errorf("could not create DCL upload request %w", err) } r.Header.Set(env.HeaderInstanceID, up.AMSInstanceID) + r.Header.Set("User-Agent", fmt.Sprintf("cloud-authorization-buildpack/%s", common.VersionNumber())) r.Header.Set("Content-Type", "application/gzip") return up.Client.Do(r) }