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

add BOSH Release tarball reading utilities #410

Merged
merged 7 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion internal/acceptance/workflows/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ package workflows

import (
"context"
"golang.org/x/exp/slices"
"os"
"os/exec"
"path/filepath"
"strings"
"testing"

"golang.org/x/exp/slices"

"github.com/cucumber/godog"

"github.com/pivotal-cf/kiln/internal/acceptance/workflows/scenario"
Expand Down
2 changes: 1 addition & 1 deletion internal/acceptance/workflows/scenario/initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

// scenarioContext is based on *godog.ScenarioContext
type scenarioContext interface {
Step(expr, stepFunc interface{})
Step(expr, stepFunc any)
Before(h godog.BeforeScenarioHook)
After(h godog.AfterScenarioHook)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/acceptance/workflows/scenario/initialize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ var (
tableType = reflect.TypeOf((*godog.Table)(nil))
)

func (fake fakeScenarioContext) Step(expr, stepFunc interface{}) {
func (fake fakeScenarioContext) Step(expr, stepFunc any) {
fn := reflect.ValueOf(stepFunc)
if fn.Kind() != reflect.Func {
fake.t.Errorf("expected stepFunc to be %s got %s", reflect.Func, fn.Kind())
Expand Down
2 changes: 1 addition & 1 deletion internal/acceptance/workflows/scenario/shared_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func runAndLogOnError(ctx context.Context, cmd *exec.Cmd, requireSuccess bool) (
return ctx, nil
}

func runAndParseStdoutAsYAML(ctx context.Context, cmd *exec.Cmd, d interface{}) (context.Context, error) {
func runAndParseStdoutAsYAML(ctx context.Context, cmd *exec.Cmd, d any) (context.Context, error) {
var stdout, stderr bytes.Buffer
fds := ctx.Value(standardFileDescriptorsKey).(standardFileDescriptors)
cmd.Stdout = io.MultiWriter(&stdout, fds[1])
Expand Down
4 changes: 3 additions & 1 deletion internal/acceptance/workflows/scenario/step_funcs_tile.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"os"
"strings"

"github.com/pivotal-cf/kiln/pkg/cargo"

"github.com/cucumber/godog"
"gopkg.in/yaml.v2"

Expand Down Expand Up @@ -78,7 +80,7 @@ func theTileOnlyContainsCompiledReleases(ctx context.Context) error {

for _, release := range metadata.Releases {
helloReleaseTarball := bytes.NewBuffer(nil)
_, err := tile.ReadReleaseFromFile(tilePath, release.Name, release.Version, helloReleaseTarball)
_, err := cargo.ReadBOSHReleaseFromFile(tilePath, release.Name, release.Version, helloReleaseTarball)
if err != nil {
return err
}
Expand Down
12 changes: 6 additions & 6 deletions internal/baking/fakes/logger.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/baking/icon_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ var _ = Describe("IconService", func() {
Expect(encoding).To(Equal("dGhpcyBpcyBzb21lIGRhdGE="))

Expect(logger.PrintlnCallCount()).To(Equal(1))
Expect(logger.PrintlnArgsForCall(0)).To(Equal([]interface{}{"Encoding icon..."}))
Expect(logger.PrintlnArgsForCall(0)).To(Equal([]any{"Encoding icon..."}))
})

Context("when the icon path is empty", func() {
Expand Down
2 changes: 1 addition & 1 deletion internal/baking/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

//counterfeiter:generate -o ./fakes/logger.go --fake-name Logger . logger
type logger interface {
Println(v ...interface{})
Println(v ...any)
}

//counterfeiter:generate -o ./fakes/part_reader.go --fake-name PartReader . partReader
Expand Down
4 changes: 2 additions & 2 deletions internal/baking/releases_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func NewReleasesService(logger logger, reader partReader) ReleasesService {
}
}

func (s ReleasesService) FromDirectories(directories []string) (map[string]interface{}, error) {
func (s ReleasesService) FromDirectories(directories []string) (map[string]any, error) {
s.logger.Println("Reading release manifests...")

var releases []builder.Part
Expand All @@ -33,7 +33,7 @@ func (s ReleasesService) FromDirectories(directories []string) (map[string]inter
releases = append(releases, newReleases...)
}

manifests := map[string]interface{}{}
manifests := map[string]any{}
for _, rel := range releases {
manifests[rel.Name] = rel.Metadata
}
Expand Down
4 changes: 2 additions & 2 deletions internal/baking/releases_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ var _ = Describe("ReleasesService", func() {

releases, err := service.FromDirectories([]string{tempDir})
Expect(err).NotTo(HaveOccurred())
Expect(releases).To(Equal(map[string]interface{}{
Expect(releases).To(Equal(map[string]any{
"some-name": "some-metadata",
"other-name": "other-metadata",
}))

Expect(logger.PrintlnCallCount()).To(Equal(1))
Expect(logger.PrintlnArgsForCall(0)).To(Equal([]interface{}{"Reading release manifests..."}))
Expect(logger.PrintlnArgsForCall(0)).To(Equal([]any{"Reading release manifests..."}))

Expect(reader.ReadCallCount()).To(Equal(2))
Expect(reader.ReadArgsForCall(0)).To(Equal(filepath.Join(tempDir, "other-release.tgz")))
Expand Down
10 changes: 5 additions & 5 deletions internal/baking/stemcell_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func NewStemcellService(logger logger, tarballReader partReader) StemcellService
}
}

func (ss StemcellService) FromDirectories(directories []string) (stemcell map[string]interface{}, err error) {
func (ss StemcellService) FromDirectories(directories []string) (stemcell map[string]any, err error) {
ss.logger.Println("Reading stemcells from directories...")

var tarballs []string
Expand All @@ -47,7 +47,7 @@ func (ss StemcellService) FromDirectories(directories []string) (stemcell map[st
}
}

manifests := map[string]interface{}{}
manifests := map[string]any{}
for _, tarball := range tarballs {
manifest, err := ss.tarballReader.Read(tarball)
if err != nil {
Expand All @@ -66,7 +66,7 @@ func (ss StemcellService) FromDirectories(directories []string) (stemcell map[st
return manifests, nil
}

func (ss StemcellService) FromTarball(path string) (interface{}, error) {
func (ss StemcellService) FromTarball(path string) (any, error) {
if path == "" {
return nil, nil
}
Expand All @@ -81,7 +81,7 @@ func (ss StemcellService) FromTarball(path string) (interface{}, error) {
return stemcell.Metadata, nil
}

func (ss StemcellService) FromKilnfile(kilnfilePath string) (map[string]interface{}, error) {
func (ss StemcellService) FromKilnfile(kilnfilePath string) (map[string]any, error) {
kilnfileLockPath := fmt.Sprintf("%s.lock", kilnfilePath)
kilnfileLockBasename := path.Base(kilnfileLockPath)
ss.logger.Println(fmt.Sprintf("Reading stemcell criteria from %s", kilnfileLockBasename))
Expand Down Expand Up @@ -111,7 +111,7 @@ func (ss StemcellService) FromKilnfile(kilnfilePath string) (map[string]interfac

stemcell := stemcellCriteria.Metadata

stemcellManifest := map[string]interface{}{
stemcellManifest := map[string]any{
stemcell.OperatingSystem: stemcellCriteria.Metadata,
}

Expand Down
4 changes: 2 additions & 2 deletions internal/baking/stemcell_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ var _ = Describe("StemcellService", func() {

stemcell, err := service.FromDirectories([]string{tempDir})
Expect(err).NotTo(HaveOccurred())
Expect(stemcell).To(Equal(map[string]interface{}{
Expect(stemcell).To(Equal(map[string]any{
"some-os": builder.StemcellManifest{
Version: "some-version",
OperatingSystem: "some-os",
Expand Down Expand Up @@ -128,7 +128,7 @@ var _ = Describe("StemcellService", func() {
}))

Expect(logger.PrintlnCallCount()).To(Equal(1))
Expect(logger.PrintlnArgsForCall(0)).To(Equal([]interface{}{"Reading stemcell manifest..."}))
Expect(logger.PrintlnArgsForCall(0)).To(Equal([]any{"Reading stemcell manifest..."}))

Expect(reader.ReadCallCount()).To(Equal(1))
Expect(reader.ReadArgsForCall(0)).To(Equal("some-stemcell-tarball"))
Expand Down
6 changes: 3 additions & 3 deletions internal/baking/template_variables_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ func NewTemplateVariablesService(fs billy.Basic) TemplateVariablesService {
return TemplateVariablesService{filesystem: fs}
}

func (s TemplateVariablesService) FromPathsAndPairs(paths []string, pairs []string) (map[string]interface{}, error) {
variables := map[string]interface{}{}
func (s TemplateVariablesService) FromPathsAndPairs(paths []string, pairs []string) (map[string]any, error) {
variables := map[string]any{}

for _, path := range paths {
err := parseVariablesFromFile(s.filesystem, path, variables)
Expand All @@ -40,7 +40,7 @@ func (s TemplateVariablesService) FromPathsAndPairs(paths []string, pairs []stri
return variables, nil
}

func parseVariablesFromFile(fs billy.Basic, path string, variables map[string]interface{}) error {
func parseVariablesFromFile(fs billy.Basic, path string, variables map[string]any) error {
file, err := fs.Open(path)
if err != nil {
return fmt.Errorf("unable to open file %q: %w", path, err)
Expand Down
8 changes: 4 additions & 4 deletions internal/baking/template_variables_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ key-3: value-3
It("parses template variables from a collection of files", func() {
variables, err := service.FromPathsAndPairs([]string{path}, nil)
Expect(err).NotTo(HaveOccurred())
Expect(variables).To(Equal(map[string]interface{}{
"key-1": map[interface{}]interface{}{
"key-2": []interface{}{
Expect(variables).To(Equal(map[string]any{
"key-1": map[any]any{
"key-2": []any{
"value-1",
"value-2",
},
Expand All @@ -66,7 +66,7 @@ key-3: value-3
"key-2=value-2",
})
Expect(err).NotTo(HaveOccurred())
Expect(variables).To(Equal(map[string]interface{}{
Expect(variables).To(Equal(map[string]any{
"key-1": "value-1",
"key-2": "value-2",
}))
Expand Down
4 changes: 2 additions & 2 deletions internal/builder/fakes/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ type Logger struct {
}
}

func (l *Logger) Printf(format string, v ...interface{}) {
func (l *Logger) Printf(format string, v ...any) {
l.PrintfCall.Receives.LogLines = append(l.PrintfCall.Receives.LogLines, fmt.Sprintf(format, v...))
}

func (l *Logger) Println(v ...interface{}) {
func (l *Logger) Println(v ...any) {
l.PrintlnCall.Receives.LogLines = append(l.PrintlnCall.Receives.LogLines, fmt.Sprintf("%s", v...))
}
6 changes: 3 additions & 3 deletions internal/builder/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package builder
import "io"

type logger interface {
Printf(format string, v ...interface{})
Println(v ...interface{})
Printf(format string, v ...any)
Println(v ...any)
}

type Metadata map[string]interface{}
type Metadata map[string]any

func closeAndIgnoreError(c io.Closer) { _ = c.Close() }
34 changes: 17 additions & 17 deletions internal/builder/interpolator.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ type Interpolator struct{}

type InterpolateInput struct {
Version string
BOSHVariables map[string]interface{}
Variables map[string]interface{}
ReleaseManifests map[string]interface{}
StemcellManifests map[string]interface{}
StemcellManifest interface{}
FormTypes map[string]interface{}
BOSHVariables map[string]any
Variables map[string]any
ReleaseManifests map[string]any
StemcellManifests map[string]any
StemcellManifest any
FormTypes map[string]any
IconImage string
InstanceGroups map[string]interface{}
Jobs map[string]interface{}
PropertyBlueprints map[string]interface{}
RuntimeConfigs map[string]interface{}
InstanceGroups map[string]any
Jobs map[string]any
PropertyBlueprints map[string]any
RuntimeConfigs map[string]any
StubReleases bool
MetadataGitSHA func() (string, error)
}
Expand Down Expand Up @@ -124,7 +124,7 @@ func (i Interpolator) functions(input InterpolateInput) template.FuncMap {

if !ok {
if input.StubReleases {
val = map[string]interface{}{
val = map[string]any{
"name": name,
"version": "UNKNOWN",
"file": fmt.Sprintf("%s-UNKNOWN.tgz", name),
Expand Down Expand Up @@ -221,7 +221,7 @@ func (i Interpolator) functions(input InterpolateInput) template.FuncMap {
return i.interpolateValueIntoYAML(input, name, val)
},
"select": func(field, input string) (string, error) {
object := map[string]interface{}{}
object := map[string]any{}

err := json.Unmarshal([]byte(input), &object)
if err != nil {
Expand Down Expand Up @@ -263,7 +263,7 @@ func (i Interpolator) interpolate(input InterpolateInput, name string, templateY
return buffer.Bytes(), nil
}

func (i Interpolator) interpolateValueIntoYAML(input InterpolateInput, name string, val interface{}) (string, error) {
func (i Interpolator) interpolateValueIntoYAML(input InterpolateInput, name string, val any) (string, error) {
initialYAML, err := yaml.Marshal(val)
if err != nil {
return "", err // should never happen
Expand All @@ -288,7 +288,7 @@ func (i Interpolator) yamlMarshalOneLine(yamlContents []byte) ([]byte, error) {
}

func (i Interpolator) prettyPrint(inputYAML []byte) ([]byte, error) {
var data interface{}
var data any
err := yaml.Unmarshal(inputYAML, &data)
if err != nil {
return []byte{}, err // should never happen
Expand All @@ -297,7 +297,7 @@ func (i Interpolator) prettyPrint(inputYAML []byte) ([]byte, error) {
return yaml.Marshal(data)
}

func PreProcessMetadataWithTileFunction(variables map[string]interface{}, name string, dst io.Writer, in []byte) error {
func PreProcessMetadataWithTileFunction(variables map[string]any, name string, dst io.Writer, in []byte) error {
tileFN := tileFunc(variables)

t, err := template.New(name).
Expand All @@ -313,9 +313,9 @@ func PreProcessMetadataWithTileFunction(variables map[string]interface{}, name s

// tileFunc is used both in pre-processing and is also available
// to Interpolator
func tileFunc(variables map[string]interface{}) func() (string, error) {
func tileFunc(variables map[string]any) func() (string, error) {
if variables == nil {
variables = make(map[string]interface{})
variables = make(map[string]any)
}

return func() (string, error) {
Expand Down
Loading
Loading