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

VAULT-28317: Fix issue with lowercasing of HCP resources #38

Merged
merged 1 commit into from
Jul 4, 2024
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
9 changes: 3 additions & 6 deletions connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,7 @@ func (c *HCPConnectCommand) getOrganization() (organizationID string, err error)
for _, org := range organizationsResp.GetPayload().Organizations {
if *org.State == hcprmm.HashicorpCloudResourcemanagerOrganizationOrganizationStateACTIVE {
c.Ui.Info(fmt.Sprintf("Organization name: %s", org.Name))
name := strings.ToLower(org.Name)
orgs[name] = org
orgs[org.Name] = org
}
}
userInput, err := c.Ui.Ask(fmt.Sprintf("\nChoose a organization: "))
Expand Down Expand Up @@ -288,8 +287,7 @@ func (c *HCPConnectCommand) getProject(organizationID string) (projectID string,
for _, proj := range projectResp.GetPayload().Projects {
if *proj.State == hcprmm.HashicorpCloudResourcemanagerProjectProjectStateACTIVE {
c.Ui.Info(fmt.Sprintf("Project name: %s", proj.Name))
name := strings.ToLower(proj.Name)
projs[name] = proj
projs[proj.Name] = proj
}
}
userInput, err := c.Ui.Ask(fmt.Sprintf("\nChoose a project: "))
Expand Down Expand Up @@ -366,8 +364,7 @@ func (c *HCPConnectCommand) listClusters(organizationID string, projectID string
for _, cluster := range clustersResp.GetPayload().Clusters {
if *cluster.State == hcpvsm.HashicorpCloudVault20201125ClusterStateRUNNING {
c.Ui.Info(fmt.Sprintf("Cluster identification: %s", cluster.ID))
id := strings.ToLower(cluster.ID)
clusters[id] = cluster
clusters[cluster.ID] = cluster
}
}
userInput, err := c.Ui.Ask("\nChoose a cluster:")
Expand Down
14 changes: 7 additions & 7 deletions connect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func Test_HCPConnectCommand(t *testing.T) {
Projects: []*models.HashicorpCloudResourcemanagerProject{
{
ID: uuid.New().String(),
Name: "mock-project-1",
Name: "Mock-project-1",
State: models.NewHashicorpCloudResourcemanagerProjectProjectState(
models.HashicorpCloudResourcemanagerProjectProjectStateACTIVE,
),
Expand Down Expand Up @@ -260,7 +260,7 @@ func Test_getOrganization(t *testing.T) {
// Test multiple organizations
// UI interaction required
"multiple organizations": {
userInputOrganizationName: "mock-organization-2\n",
userInputOrganizationName: "MOCK-organization-2\n",
expectedOrganizationID: organizationIDTwo,
organizationServiceListResponse: &hcprmo.OrganizationServiceListOK{
Payload: &models.HashicorpCloudResourcemanagerOrganizationListResponse{
Expand All @@ -272,7 +272,7 @@ func Test_getOrganization(t *testing.T) {
},
{
ID: organizationIDTwo,
Name: "mock-organization-2",
Name: "MOCK-organization-2",
State: models.NewHashicorpCloudResourcemanagerOrganizationOrganizationState(models.HashicorpCloudResourcemanagerOrganizationOrganizationStateACTIVE),
},
{
Expand Down Expand Up @@ -382,7 +382,7 @@ func Test_getProject(t *testing.T) {
// Test multiple projects
// UI interaction required
"multiple projects": {
userInputProjectName: "mock-project-2\n",
userInputProjectName: "MOCK_-project-2\n",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests would fail before the fix, and are valid project names.

expectedProjectID: projectIDTwo,
projectServiceListResponse: &hcprmp.ProjectServiceListOK{
Payload: &models.HashicorpCloudResourcemanagerProjectListResponse{
Expand All @@ -394,7 +394,7 @@ func Test_getProject(t *testing.T) {
},
{
ID: projectIDTwo,
Name: "mock-project-2",
Name: "MOCK_-project-2",
State: models.NewHashicorpCloudResourcemanagerProjectProjectState(models.HashicorpCloudResourcemanagerProjectProjectStateACTIVE),
},
{
Expand Down Expand Up @@ -529,7 +529,7 @@ func Test_getCluster(t *testing.T) {
// UI interaction required
"multiple clusters": {
expectedProxyAddr: "https://hcp-proxy-cluster-2.addr:8200",
userInputCluster: "cluster-2\n",
userInputCluster: "CLUSTER-2\n",
listClustersServiceListResponse: &hcpvs.ListOK{
Payload: &hcpvsm.HashicorpCloudVault20201125ListResponse{
Clusters: []*hcpvsm.HashicorpCloudVault20201125Cluster{
Expand All @@ -544,7 +544,7 @@ func Test_getCluster(t *testing.T) {
},
},
{
ID: "cluster-2",
ID: "CLUSTER-2",
DNSNames: &hcpvsm.HashicorpCloudVault20201125ClusterDNSNames{Proxy: "hcp-proxy-cluster-2.addr:8200"},
State: hcpvsm.NewHashicorpCloudVault20201125ClusterState(hcpvsm.HashicorpCloudVault20201125ClusterStateRUNNING),
Config: &hcpvsm.HashicorpCloudVault20201125ClusterConfig{
Expand Down
Loading