Skip to content

Commit

Permalink
implement review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
d047491 committed Aug 19, 2024
1 parent 5e144b7 commit 1aac254
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 23 deletions.
19 changes: 3 additions & 16 deletions pkg/supply/env/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,10 @@ type amsDataDeprecated struct {
}

type VcapApplication struct {
ApplicationID string `json:"application_id"`
ApplicationName string `json:"application_name"`
ApplicationUris []string `json:"application_uris"`
CfAPI string `json:"cf_api"`
Limits struct {
Fds int `json:"fds"`
} `json:"limits"`
Name string `json:"name"`
OrganizationID string `json:"organization_id"`
OrganizationName string `json:"organization_name"`
SpaceID string `json:"space_id"`
SpaceName string `json:"space_name"`
Uris []string `json:"uris"`
Users any `json:"users"`
ApplicationName string `json:"application_name"`
}

func LoadVcapApplication(log *libbuildpack.Logger) (VcapApplication, error) {
func LoadVcapApplication(log *libbuildpack.Logger) VcapApplication {
vcapStr, vcapSet := os.LookupEnv("VCAP_APPLICATION")
var result VcapApplication
if vcapSet {
Expand All @@ -46,7 +33,7 @@ func LoadVcapApplication(log *libbuildpack.Logger) (VcapApplication, error) {
log.Error("error parsing VCAP_APPLICATION value %s : %v", vcapStr, err)
}
}
return result, nil
return result
}

func LoadBuildpackConfig(log *libbuildpack.Logger) (Config, error) {
Expand Down
10 changes: 4 additions & 6 deletions pkg/supply/supply.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,18 +280,16 @@ func (s *Supplier) upload(creds *services.IASCredentials, tlsCfg tlsConfig, root
if err != nil {
return fmt.Errorf("unable to create AMS client: %s", err)
}
vcapApp, err := env.LoadVcapApplication(s.Log)
if err != nil {
return err
}
vcapApp := env.LoadVcapApplication(s.Log)

u := uploader.Uploader{
Log: s.Log,
Root: path.Join(s.Stager.BuildDir(), rootDir),
Client: client,
AMSInstanceID: creds.AmsInstanceID,
ExtraHeaders: map[string]string{
"User-Agent": fmt.Sprintf("cloud-authorization-buildpack/%s", s.BuildpackVersion),
"X-Cf-Appname": vcapApp.ApplicationName,
"User-Agent": fmt.Sprintf("cloud-authorization-buildpack/%s", s.BuildpackVersion),
"X-Appname": vcapApp.ApplicationName,
},
}
return u.Do(context.Background(), creds.AmsServerURL)
Expand Down
2 changes: 1 addition & 1 deletion pkg/supply/supply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ var _ = Describe("Supply", func() {
It("sets the cf app name as upload header", func() {
Expect(supplier.Run()).To(Succeed())
expectedValue := []string{"unit-tests-appname"}
Expect(uploadReqSpy.Header).Should(HaveKeyWithValue("X-Cf-Appname", expectedValue))
Expect(uploadReqSpy.Header).Should(HaveKeyWithValue("X-Appname", expectedValue))
})
It("creates a valid launch.yml", func() {
Expect(supplier.Run()).To(Succeed())
Expand Down

0 comments on commit 1aac254

Please sign in to comment.