From 0daf1742051b5fce2e7493d7cab6fec9a54f15f4 Mon Sep 17 00:00:00 2001 From: Josh Branham Date: Thu, 3 Oct 2024 10:15:33 -0600 Subject: [PATCH 1/2] OSD-25868: Adds `aws-hosted-cp` as a valid Platform name This extends the Platform structs to accept `aws-hosted-cp` as a valid value for looking up AWSHCP `ByName()`. This value is used internally still and blocks integrating the updated verifier. --- pkg/data/cloud/platform.go | 14 +++++++------- pkg/data/cloud/platform_test.go | 8 ++++++-- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/pkg/data/cloud/platform.go b/pkg/data/cloud/platform.go index 80aedcb4..d992421d 100644 --- a/pkg/data/cloud/platform.go +++ b/pkg/data/cloud/platform.go @@ -8,25 +8,25 @@ import ( // Platform type represents specific Platform types and how they map to their respective platforms. type Platform struct { - // names holds 2 unique lowercase names of the Platform (e.g., "aws"). We use a fixed- - // size array so that this struct remains comparable. Any of the 2 values can be used to refer + // names holds 3 unique lowercase names of the Platform (e.g., "aws"). We use a fixed- + // size array so that this struct remains comparable. Any of the 3 values can be used to refer // to this specific Platform via Platform.ByName(), but only the first (element // 0) element will be the "preferred name" returned by Platform.String() - names [2]string + names [3]string } var ( AWSClassic = Platform{ - names: [2]string{"aws-classic", "aws"}, + names: [3]string{"aws-classic", "aws"}, } AWSHCP = Platform{ - names: [2]string{"aws-hcp", "hostedcluster"}, + names: [3]string{"aws-hcp", "aws-hosted-cp", "hostedcluster"}, } AWSHCPZeroEgress = Platform{ - names: [2]string{"aws-hcp-zeroegress"}, + names: [3]string{"aws-hcp-zeroegress"}, } GCPClassic = Platform{ - names: [2]string{"gcp-classic", "gcp"}, + names: [3]string{"gcp-classic", "gcp"}, } ) diff --git a/pkg/data/cloud/platform_test.go b/pkg/data/cloud/platform_test.go index 204cd8e5..f60c9048 100644 --- a/pkg/data/cloud/platform_test.go +++ b/pkg/data/cloud/platform_test.go @@ -59,7 +59,7 @@ func TestPlatform_String(t *testing.T) { func TestPlatform_IsValid(t *testing.T) { type fields struct { - names [2]string + names [3]string } tests := []struct { name string @@ -84,7 +84,7 @@ func TestPlatform_IsValid(t *testing.T) { { name: "fake platform", fields: fields{ - names: [2]string{"foo", "bar"}, + names: [3]string{"foo", "bar"}, }, want: false, }, @@ -123,6 +123,10 @@ func TestByName(t *testing.T) { name: "aws-hcp", want: AWSHCP, }, + { + name: "aws-hosted-cp", + want: AWSHCP, + }, { name: "hostedcluster", want: AWSHCP, From 30af6a3f840c37c66d77047fcb000e17d4303988 Mon Sep 17 00:00:00 2001 From: Josh Branham Date: Thu, 3 Oct 2024 10:32:06 -0600 Subject: [PATCH 2/2] Handle empty string lookups as an error --- pkg/data/cloud/platform.go | 5 +++++ pkg/data/cloud/platform_test.go | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/pkg/data/cloud/platform.go b/pkg/data/cloud/platform.go index d992421d..3433460a 100644 --- a/pkg/data/cloud/platform.go +++ b/pkg/data/cloud/platform.go @@ -40,6 +40,11 @@ func (plat Platform) String() string { // platform if the provided name isn't supported func ByName(name string) (Platform, error) { normalizedName := strings.TrimSpace(strings.ToLower(name)) + + if normalizedName == "" { + return Platform{}, fmt.Errorf("attempted to lookup Platform with empty string") + } + if slices.Contains(AWSClassic.names[:], normalizedName) { return AWSClassic, nil } diff --git a/pkg/data/cloud/platform_test.go b/pkg/data/cloud/platform_test.go index f60c9048..9a54c62f 100644 --- a/pkg/data/cloud/platform_test.go +++ b/pkg/data/cloud/platform_test.go @@ -143,6 +143,10 @@ func TestByName(t *testing.T) { name: "invalid name", want: Platform{}, }, + { + name: "", + want: Platform{}, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {