Skip to content

Commit

Permalink
Set buildpack version as header on dcl upload
Browse files Browse the repository at this point in the history
  • Loading branch information
f-blass committed Aug 14, 2024
1 parent c35c640 commit 6291f89
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
8 changes: 8 additions & 0 deletions cmd/supply/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions pkg/common/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package common

var versionNumber = "dev"

func VersionNumber() string {
return versionNumber
}

func SetVersion(version string) {
versionNumber = version
}
2 changes: 2 additions & 0 deletions pkg/uploader/uploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 6291f89

Please sign in to comment.