From 97b4970a3d1d326e812b06dff6367e4ebce0e19c Mon Sep 17 00:00:00 2001 From: Bianca Moreira Date: Tue, 5 Dec 2023 15:11:21 +0100 Subject: [PATCH] Treat edge case cluster does not have http proxy enabled --- connect.go | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/connect.go b/connect.go index a95ec89..452e4fe 100644 --- a/connect.go +++ b/connect.go @@ -275,8 +275,12 @@ func (c *HCPConnectCommand) getCluster(organizationID string, projectID string, u := strings.Repeat("-", len(title)) c.Ui.Info(fmt.Sprintf("%s\n%s: %s\n", u, title, cluster.ID)) - proxyAddr = "https://" + cluster.DNSNames.Proxy - return proxyAddr, nil + if cluster.DNSNames.Proxy != "" { + proxyAddr = "https://" + cluster.DNSNames.Proxy + return proxyAddr, nil + } else { + return "", errors.New("cluster does not have HTTP Proxy enabled") + } } } @@ -319,8 +323,14 @@ func (c *HCPConnectCommand) listClusters(organizationID string, projectID string if !ok { return "", errors.New(fmt.Sprintf("invalid cluster: %s", userInput)) } - proxyAddr = "https://" + cluster.DNSNames.Proxy - return proxyAddr, nil + + if cluster.DNSNames.Proxy != "" { + proxyAddr = "https://" + cluster.DNSNames.Proxy + return proxyAddr, nil + } else { + return "", errors.New("cluster does not have HTTP Proxy enabled") + } + default: cluster := clustersResp.GetPayload().Clusters[0] if *cluster.State != hcpvsm.HashicorpCloudVault20201125ClusterStateRUNNING { @@ -329,7 +339,11 @@ func (c *HCPConnectCommand) listClusters(organizationID string, projectID string projectID = cluster.ResourceID c.Ui.Info(fmt.Sprintf("HCP Vault Cluster: %s", cluster.ID)) - proxyAddr = "https://" + cluster.DNSNames.Proxy - return proxyAddr, nil + if cluster.DNSNames.Proxy != "" { + proxyAddr = "https://" + cluster.DNSNames.Proxy + return proxyAddr, nil + } else { + return "", errors.New("cluster does not have HTTP Proxy enabled") + } } }