Skip to content

Commit

Permalink
feat: add Stemcell method on BOSHReleaseManifest
Browse files Browse the repository at this point in the history
  • Loading branch information
crhntr committed Jul 5, 2023
1 parent ee11778 commit fb54765
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
17 changes: 5 additions & 12 deletions internal/builder/release_manifest_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ package builder
import (
"crypto/sha1"
"fmt"
"io"
"path/filepath"
"strings"

"github.com/go-git/go-billy/v5"
"github.com/go-git/go-billy/v5/osfs"
"github.com/pivotal-cf/kiln/pkg/tile"
"io"
"path/filepath"
)

type ReleaseManifest struct {
Expand Down Expand Up @@ -49,14 +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, stemcelOK := inputReleaseManifest.Stemcell()
if !stemcelOK && 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 fb54765

Please sign in to comment.