Skip to content

Commit

Permalink
refactor: use new stemcell utility
Browse files Browse the repository at this point in the history
  • Loading branch information
crhntr committed Jul 7, 2023
1 parent 0b8a27d commit bc20787
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
14 changes: 3 additions & 11 deletions internal/builder/release_manifest_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/pivotal-cf/kiln/pkg/tile"
"io"
"path/filepath"
"strings"
)

type ReleaseManifest struct {
Expand Down Expand Up @@ -48,16 +47,9 @@ func (r ReleaseManifestReader) Read(releaseTarball string) (Part, error) {
return Part{}, err
}

var (
stemcellOS,
stemcellVersion string
)
if len(inputReleaseManifest.CompiledPackages) > 0 {
var found bool
stemcellOS, stemcellVersion, found = strings.Cut(inputReleaseManifest.CompiledPackages[0].Stemcell, "/")
if !found {
return Part{}, fmt.Errorf("%s/%s has invalid stemcell: %q", inputReleaseManifest.Name, inputReleaseManifest.Version, inputReleaseManifest.CompiledPackages[0].Stemcell)
}
stemcellOS, stemcellVersion, stemcellOK := inputReleaseManifest.Stemcell()
if !stemcellOK && len(inputReleaseManifest.CompiledPackages) > 0 {
return Part{}, fmt.Errorf("%s/%s has invalid stemcell: %q", inputReleaseManifest.Name, inputReleaseManifest.Version, inputReleaseManifest.CompiledPackages[0].Stemcell)
}

outputReleaseManifest := ReleaseManifest{
Expand Down
8 changes: 8 additions & 0 deletions pkg/tile/bosh_release.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"io/fs"
"os"
"path"
"strings"

"golang.org/x/exp/slices"
"gopkg.in/yaml.v2"
Expand Down Expand Up @@ -104,6 +105,13 @@ type BOSHReleaseManifest struct {
Packages []BOSHReleasePackage `yaml:"packages"`
}

func (mf BOSHReleaseManifest) Stemcell() (string, string, bool) {
if len(mf.CompiledPackages) == 0 {
return "", "", false
}
return strings.Cut(mf.CompiledPackages[0].Stemcell, "/")
}

type BOSHReleaseTarball struct {
Manifest BOSHReleaseManifest

Expand Down

0 comments on commit bc20787

Please sign in to comment.