Skip to content

Commit

Permalink
refactor: rename public BOSH Release identifiers
Browse files Browse the repository at this point in the history
add Tarball and make it clear we are working with BOSH releases
  • Loading branch information
crhntr committed Jun 28, 2023
1 parent f0f1656 commit 7977710
Show file tree
Hide file tree
Showing 14 changed files with 51 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func theLockSpecifiesVersionForRelease(ctx context.Context, releaseVersion, rele
if err != nil {
return err
}
releaseLock, err := lock.FindReleaseWithName(releaseName)
releaseLock, err := lock.FindBOSHReleaseWithName(releaseName)
if err != nil {
return err
}
Expand Down Expand Up @@ -225,7 +225,7 @@ func theKilnfileVersionForReleaseIs(ctx context.Context, releaseName, releaseVer
if err != nil {
return err
}
releaseLock, err := kf.ComponentSpec(releaseName)
releaseLock, err := kf.BOSHReleaseTarballSpecification(releaseName)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/commands/find_release_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (cmd *FindReleaseVersion) Execute(args []string) error {
}
releaseSource := cmd.mrsProvider(kilnfile, false)

spec, err := kilnfile.ComponentSpec(cmd.Options.Release)
spec, err := kilnfile.BOSHReleaseTarballSpecification(cmd.Options.Release)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/commands/glaze.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (cmd *Glaze) Usage() jhanda.Usage {
func pinVersions(kf cargo.Kilnfile, kl cargo.KilnfileLock) (cargo.Kilnfile, error) {
kf.Stemcell.Version = kl.Stemcell.Version
for releaseIndex, release := range kf.Releases {
l, err := kl.FindReleaseWithName(release.Name)
l, err := kl.FindBOSHReleaseWithName(release.Name)
if err != nil {
return cargo.Kilnfile{}, fmt.Errorf("release with name %q not found in Kilnfile.lock: %w", release.Name, err)
}
Expand Down
6 changes: 3 additions & 3 deletions internal/commands/update_release.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ func (u UpdateRelease) Execute(args []string) error {
return fmt.Errorf("error loading Kilnfiles: %w", err)
}

releaseLock, err := kilnfileLock.FindReleaseWithName(u.Options.Name)
releaseLock, err := kilnfileLock.FindBOSHReleaseWithName(u.Options.Name)
if err != nil {
return fmt.Errorf(
"no release named %q exists in your Kilnfile.lock - try removing the -release, -boshrelease, or -bosh-release suffix if present",
u.Options.Name,
)
}
releaseSpec, err := kilnfile.ComponentSpec(u.Options.Name)
releaseSpec, err := kilnfile.BOSHReleaseTarballSpecification(u.Options.Name)
if err != nil {
return err
}
Expand Down Expand Up @@ -127,7 +127,7 @@ func (u UpdateRelease) Execute(args []string) error {
releaseLock.RemoteSource = newSourceID
releaseLock.RemotePath = newRemotePath

_ = kilnfileLock.UpdateReleaseLockWithName(u.Options.Name, releaseLock)
_ = kilnfileLock.UpdateBOSHReleaseTarballLockWithName(u.Options.Name, releaseLock)

err = u.Options.Standard.SaveKilnfileLock(u.filesystem, kilnfileLock)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/commands/update_stemcell.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (update UpdateStemcell) Execute(args []string) error {
for i, rel := range kilnfileLock.Releases {
update.Logger.Printf("Updating release %q with stemcell %s %s...", rel.Name, kilnfileLock.Stemcell.OS, trimmedInputVersion)

spec, err := kilnfile.ComponentSpec(rel.Name)
spec, err := kilnfile.BOSHReleaseTarballSpecification(rel.Name)
if err != nil {
return err
}
Expand Down
10 changes: 5 additions & 5 deletions internal/component/release_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,16 @@ const (

// TODO: use the constants from "cargo" everywhere
const (
ReleaseSourceTypeBOSHIO = cargo.ReleaseSourceTypeBOSHIO
ReleaseSourceTypeS3 = cargo.ReleaseSourceTypeS3
ReleaseSourceTypeGithub = cargo.ReleaseSourceTypeGithub
ReleaseSourceTypeArtifactory = cargo.ReleaseSourceTypeArtifactory
ReleaseSourceTypeBOSHIO = cargo.BOSHReleaseTarballSourceTypeBOSHIO
ReleaseSourceTypeS3 = cargo.BOSHReleaseTarballSourceTypeS3
ReleaseSourceTypeGithub = cargo.BOSHReleaseTarballSourceTypeGithub
ReleaseSourceTypeArtifactory = cargo.BOSHReleaseTarballSourceTypeArtifactory
)

// ReleaseSourceFactory returns a configured ReleaseSource based on the Type field on the
// cargo.ReleaseSourceConfig structure.
func ReleaseSourceFactory(releaseConfig cargo.ReleaseSourceConfig, outLogger *log.Logger) ReleaseSource {
releaseConfig.ID = cargo.ReleaseSourceID(releaseConfig)
releaseConfig.ID = cargo.BOSHReleaseTarballSourceID(releaseConfig)
switch releaseConfig.Type {
case ReleaseSourceTypeBOSHIO:
return NewBOSHIOReleaseSource(releaseConfig, "", outLogger)
Expand Down
2 changes: 1 addition & 1 deletion pkg/cargo/bump.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func fetchReleasesFromRepo(ctx context.Context, repoService RepositoryReleaseLis
}

func fetchReleasesForBump(ctx context.Context, repoService RepositoryReleaseLister, kf Kilnfile, bump Bump) Bump {
spec, err := kf.ComponentSpec(bump.Name)
spec, err := kf.BOSHReleaseTarballSpecification(bump.Name)
if err != nil {
return bump
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/cargo/kilnfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type Kilnfile struct {
Stemcell Stemcell `yaml:"stemcell_criteria,omitempty"`
}

func (kf Kilnfile) ComponentSpec(name string) (BOSHReleaseTarballSpecification, error) {
func (kf Kilnfile) BOSHReleaseTarballSpecification(name string) (BOSHReleaseTarballSpecification, error) {
for _, s := range kf.Releases {
if s.Name == name {
return s, nil
Expand All @@ -32,7 +32,7 @@ type KilnfileLock struct {
Stemcell Stemcell `yaml:"stemcell_criteria"`
}

func (k KilnfileLock) FindReleaseWithName(name string) (BOSHReleaseTarballLock, error) {
func (k KilnfileLock) FindBOSHReleaseWithName(name string) (BOSHReleaseTarballLock, error) {
for _, r := range k.Releases {
if r.Name == name {
return r, nil
Expand All @@ -41,7 +41,7 @@ func (k KilnfileLock) FindReleaseWithName(name string) (BOSHReleaseTarballLock,
return BOSHReleaseTarballLock{}, errors.New("not found")
}

func (k KilnfileLock) UpdateReleaseLockWithName(name string, lock BOSHReleaseTarballLock) error {
func (k KilnfileLock) UpdateBOSHReleaseTarballLockWithName(name string, lock BOSHReleaseTarballLock) error {
for i, r := range k.Releases {
if r.Name == name {
k.Releases[i] = lock
Expand Down
4 changes: 2 additions & 2 deletions pkg/cargo/kilnfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ remote_path: fake/path/to/fake-component-name
damnit.Expect(string(cl)).To(Equal(validComponentLockYaml))
}

func TestKilnfileLock_UpdateReleaseLockWithName(t *testing.T) {
func TestKilnfileLock_UpdateBOSHReleaseTarballLockWithName(t *testing.T) {
type args struct {
name string
lock BOSHReleaseTarballLock
Expand Down Expand Up @@ -63,7 +63,7 @@ func TestKilnfileLock_UpdateReleaseLockWithName(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := tt.KilnfileLock.UpdateReleaseLockWithName(tt.args.name, tt.args.lock); tt.wantErr {
if err := tt.KilnfileLock.UpdateBOSHReleaseTarballLockWithName(tt.args.name, tt.args.lock); tt.wantErr {
assert.Error(t, err)
} else {
assert.NoError(t, err)
Expand Down
30 changes: 15 additions & 15 deletions pkg/cargo/release_source.go
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
package cargo

const (
// ReleaseSourceTypeBOSHIO is the value of the Type field on cargo.ReleaseSourceConfig
// BOSHReleaseTarballSourceTypeBOSHIO is the value of the Type field on cargo.ReleaseSourceConfig
// for fetching https://bosh.io releases.
ReleaseSourceTypeBOSHIO = "bosh.io"
BOSHReleaseTarballSourceTypeBOSHIO = "bosh.io"

// ReleaseSourceTypeS3 is the value for the Type field on cargo.ReleaseSourceConfig
// BOSHReleaseTarballSourceTypeS3 is the value for the Type field on cargo.ReleaseSourceConfig
// for releases stored on
ReleaseSourceTypeS3 = "s3"
BOSHReleaseTarballSourceTypeS3 = "s3"

// ReleaseSourceTypeGithub is the value for the Type field on cargo.ReleaseSourceConfig
// BOSHReleaseTarballSourceTypeGithub is the value for the Type field on cargo.ReleaseSourceConfig
// for releases stored on GitHub.
ReleaseSourceTypeGithub = "github"
BOSHReleaseTarballSourceTypeGithub = "github"

// ReleaseSourceTypeArtifactory is the value for the Type field on cargo.ReleaseSourceConfig
// BOSHReleaseTarballSourceTypeArtifactory is the value for the Type field on cargo.ReleaseSourceConfig
// for releases stored on Artifactory.
ReleaseSourceTypeArtifactory = "artifactory"
BOSHReleaseTarballSourceTypeArtifactory = "artifactory"
)

func ReleaseSourceID(releaseConfig ReleaseSourceConfig) string {
func BOSHReleaseTarballSourceID(releaseConfig ReleaseSourceConfig) string {
if releaseConfig.ID != "" {
return releaseConfig.ID
}
switch releaseConfig.Type {
case ReleaseSourceTypeBOSHIO:
return ReleaseSourceTypeBOSHIO
case ReleaseSourceTypeS3:
case BOSHReleaseTarballSourceTypeBOSHIO:
return BOSHReleaseTarballSourceTypeBOSHIO
case BOSHReleaseTarballSourceTypeS3:
return releaseConfig.Bucket
case ReleaseSourceTypeGithub:
case BOSHReleaseTarballSourceTypeGithub:
return releaseConfig.Org
case ReleaseSourceTypeArtifactory:
return ReleaseSourceTypeArtifactory
case BOSHReleaseTarballSourceTypeArtifactory:
return BOSHReleaseTarballSourceTypeArtifactory
default:
return ""
}
Expand Down
18 changes: 9 additions & 9 deletions pkg/cargo/release_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ func TestReleaseSourceID(t *testing.T) {
{Name: "zero value", ExpectedID: "", Configuration: ReleaseSourceConfig{}},
{Name: "unknown type", ExpectedID: "", Configuration: ReleaseSourceConfig{Type: "banana"}},

{Name: ReleaseSourceTypeArtifactory + " with ID set", ExpectedID: "identifier", Configuration: ReleaseSourceConfig{ID: "identifier", Type: ReleaseSourceTypeArtifactory}},
{Name: ReleaseSourceTypeBOSHIO + " with ID set", ExpectedID: "identifier", Configuration: ReleaseSourceConfig{ID: "identifier", Type: ReleaseSourceTypeBOSHIO}},
{Name: ReleaseSourceTypeGithub + " with ID set", ExpectedID: "identifier", Configuration: ReleaseSourceConfig{ID: "identifier", Type: ReleaseSourceTypeGithub}},
{Name: ReleaseSourceTypeS3 + " with ID set", ExpectedID: "identifier", Configuration: ReleaseSourceConfig{ID: "identifier", Type: ReleaseSourceTypeS3}},
{Name: BOSHReleaseTarballSourceTypeArtifactory + " with ID set", ExpectedID: "identifier", Configuration: ReleaseSourceConfig{ID: "identifier", Type: BOSHReleaseTarballSourceTypeArtifactory}},
{Name: BOSHReleaseTarballSourceTypeBOSHIO + " with ID set", ExpectedID: "identifier", Configuration: ReleaseSourceConfig{ID: "identifier", Type: BOSHReleaseTarballSourceTypeBOSHIO}},
{Name: BOSHReleaseTarballSourceTypeGithub + " with ID set", ExpectedID: "identifier", Configuration: ReleaseSourceConfig{ID: "identifier", Type: BOSHReleaseTarballSourceTypeGithub}},
{Name: BOSHReleaseTarballSourceTypeS3 + " with ID set", ExpectedID: "identifier", Configuration: ReleaseSourceConfig{ID: "identifier", Type: BOSHReleaseTarballSourceTypeS3}},

{Name: ReleaseSourceTypeArtifactory + " default", ExpectedID: ReleaseSourceTypeArtifactory, Configuration: ReleaseSourceConfig{ID: "", Type: ReleaseSourceTypeArtifactory}},
{Name: ReleaseSourceTypeBOSHIO + " default", ExpectedID: ReleaseSourceTypeBOSHIO, Configuration: ReleaseSourceConfig{ID: "", Type: ReleaseSourceTypeBOSHIO}},
{Name: ReleaseSourceTypeGithub + " default", ExpectedID: "identifier", Configuration: ReleaseSourceConfig{ID: "", Type: ReleaseSourceTypeGithub, Org: "identifier"}},
{Name: ReleaseSourceTypeS3 + " default", ExpectedID: "identifier", Configuration: ReleaseSourceConfig{ID: "", Type: ReleaseSourceTypeS3, Bucket: "identifier"}},
{Name: BOSHReleaseTarballSourceTypeArtifactory + " default", ExpectedID: BOSHReleaseTarballSourceTypeArtifactory, Configuration: ReleaseSourceConfig{ID: "", Type: BOSHReleaseTarballSourceTypeArtifactory}},
{Name: BOSHReleaseTarballSourceTypeBOSHIO + " default", ExpectedID: BOSHReleaseTarballSourceTypeBOSHIO, Configuration: ReleaseSourceConfig{ID: "", Type: BOSHReleaseTarballSourceTypeBOSHIO}},
{Name: BOSHReleaseTarballSourceTypeGithub + " default", ExpectedID: "identifier", Configuration: ReleaseSourceConfig{ID: "", Type: BOSHReleaseTarballSourceTypeGithub, Org: "identifier"}},
{Name: BOSHReleaseTarballSourceTypeS3 + " default", ExpectedID: "identifier", Configuration: ReleaseSourceConfig{ID: "", Type: BOSHReleaseTarballSourceTypeS3, Bucket: "identifier"}},
} {
t.Run(tt.Name, func(t *testing.T) {
assert.Equal(t, tt.ExpectedID, ReleaseSourceID(tt.Configuration))
assert.Equal(t, tt.ExpectedID, BOSHReleaseTarballSourceID(tt.Configuration))
})
}
}
4 changes: 2 additions & 2 deletions pkg/cargo/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func Validate(spec Kilnfile, lock KilnfileLock) []error {
continue
}

componentLock, err := lock.FindReleaseWithName(componentSpec.Name)
componentLock, err := lock.FindBOSHReleaseWithName(componentSpec.Name)
if err != nil {
result = append(result,
fmt.Errorf("component spec for release %q not found in lock", componentSpec.Name))
Expand All @@ -41,7 +41,7 @@ func ensureRemoteSourceExistsForEachReleaseLock(spec Kilnfile, lock KilnfileLock
var result []error
for _, release := range lock.Releases {
if releaseSourceIndex := slices.IndexFunc(spec.ReleaseSources, func(config ReleaseSourceConfig) bool {
return ReleaseSourceID(config) == release.RemoteSource
return BOSHReleaseTarballSourceID(config) == release.RemoteSource
}); releaseSourceIndex < 0 {
result = append(result,
fmt.Errorf("release source %q for release lock %q not found in Kilnfile", release.RemoteSource, release.Name))
Expand Down
10 changes: 5 additions & 5 deletions pkg/cargo/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,14 @@ func TestValidate_release_sources(t *testing.T) {
please := NewWithT(t)
results := Validate(Kilnfile{
ReleaseSources: []ReleaseSourceConfig{
{Type: ReleaseSourceTypeBOSHIO},
{Type: BOSHReleaseTarballSourceTypeBOSHIO},
},
Releases: []BOSHReleaseTarballSpecification{
{Name: "orange"},
},
}, KilnfileLock{
Releases: []BOSHReleaseTarballLock{
{Name: "orange", Version: "1.2.3", RemoteSource: ReleaseSourceTypeBOSHIO},
{Name: "orange", Version: "1.2.3", RemoteSource: BOSHReleaseTarballSourceTypeBOSHIO},
},
})
please.Expect(results).To(BeEmpty())
Expand All @@ -152,14 +152,14 @@ func TestValidate_release_sources(t *testing.T) {
please := NewWithT(t)
results := Validate(Kilnfile{
ReleaseSources: []ReleaseSourceConfig{
{ID: "open source", Type: ReleaseSourceTypeBOSHIO},
{ID: "open source", Type: BOSHReleaseTarballSourceTypeBOSHIO},
},
Releases: []BOSHReleaseTarballSpecification{
{Name: "orange"},
},
}, KilnfileLock{
Releases: []BOSHReleaseTarballLock{
{Name: "orange", Version: "1.2.3", RemoteSource: ReleaseSourceTypeBOSHIO},
{Name: "orange", Version: "1.2.3", RemoteSource: BOSHReleaseTarballSourceTypeBOSHIO},
},
})
please.Expect(results).To(HaveLen(1))
Expand All @@ -168,7 +168,7 @@ func TestValidate_release_sources(t *testing.T) {
please := NewWithT(t)
results := Validate(Kilnfile{
ReleaseSources: []ReleaseSourceConfig{
{Org: "crhntr", Type: ReleaseSourceTypeGithub},
{Org: "crhntr", Type: BOSHReleaseTarballSourceTypeGithub},
},
Releases: []BOSHReleaseTarballSpecification{
{Name: "hello-tile", GitHubRepository: "https://github.com/crhntr/hello-tile"},
Expand Down
2 changes: 1 addition & 1 deletion pkg/notes/notes_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ func setEmptyComponentGitHubRepositoryFromOtherKilnfile(k1, k2 cargo.Kilnfile) c
if r.GitHubRepository != "" {
continue
}
spec, err := k2.ComponentSpec(r.Name)
spec, err := k2.BOSHReleaseTarballSpecification(r.Name)
if err != nil {
continue
}
Expand Down

0 comments on commit 7977710

Please sign in to comment.