Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set buildpack version as header on dcl upload #93

Merged
merged 4 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions cmd/supply/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ 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)
}

installer := libbuildpack.NewInstaller(manifest)

stager := libbuildpack.NewStager(os.Args[1:], logger, manifest)
Expand Down Expand Up @@ -74,6 +80,7 @@ func main() {
BuildpackDir: buildpackDir,
GetClient: uploader.GetClient,
CertCopierSourceDir: path.Join(buildpackDir, "bin"),
BuildpackVersion: version,
}

err = s.Run()
Expand Down
2 changes: 2 additions & 0 deletions pkg/supply/supply.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type Supplier struct {
BuildpackDir string
GetClient func(cert, key []byte) (uploader.AMSClient, error)
CertCopierSourceDir string
BuildpackVersion string
}

type Cloudfoundry struct {
Expand Down Expand Up @@ -284,6 +285,7 @@ func (s *Supplier) upload(creds *services.IASCredentials, tlsCfg tlsConfig, root
Root: path.Join(s.Stager.BuildDir(), rootDir),
Client: client,
AMSInstanceID: creds.AmsInstanceID,
UserAgent: fmt.Sprintf("cloud-authorization-buildpack/%s", s.BuildpackVersion),
}
return u.Do(context.Background(), creds.AmsServerURL)
}
2 changes: 2 additions & 0 deletions pkg/uploader/uploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Uploader struct {
Root string
Client AMSClient
AMSInstanceID string
UserAgent string
}

//go:generate mockgen --build_flags=--mod=mod --destination=../supply/client_mock_test.go --package=supply_test github.com/SAP/cloud-authorization-buildpack/pkg/uploader AMSClient
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", up.UserAgent)
r.Header.Set("Content-Type", "application/gzip")
return up.Client.Do(r)
}
Expand Down
Loading