Skip to content

Commit

Permalink
fix: remove validation here to be moved into prism-client
Browse files Browse the repository at this point in the history
  • Loading branch information
faiq committed Jan 8, 2024
1 parent cf34f59 commit cf8bea5
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 112 deletions.
38 changes: 2 additions & 36 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import (
"context"
"encoding/json"
"fmt"
"net"
"net/url"
"os"
"path/filepath"

Expand Down Expand Up @@ -68,11 +66,9 @@ func (n *NutanixClientHelper) GetClientFromEnvironment(ctx context.Context, nuta
// If PrismCentral is set, add the required env provider
prismCentralInfo := nutanixCluster.Spec.PrismCentral
if prismCentralInfo != nil {
address, err := validateAndSanitizePrismCentralInfoAddress(prismCentralInfo.Address)
if err != nil {
return nil, err
if prismCentralInfo.Address == "" {
return nil, ErrPrismAddressNotSet
}
prismCentralInfo.Address = address
if prismCentralInfo.Port == 0 {
return nil, ErrPrismPortNotSet
}
Expand Down Expand Up @@ -215,33 +211,3 @@ func GetCredentialRefForCluster(nutanixCluster *infrav1.NutanixCluster) (*creden

return prismCentralInfo.CredentialRef, nil
}

func validateAndSanitizePrismCentralInfoAddress(address string) (string, error) {
if address == "" {
return "", ErrPrismAddressNotSet
}
u, urlParseErr := url.Parse(address)
if urlParseErr != nil {
ipHost, ipErr := parseIP(address)
if ipErr != nil {
return "", fmt.Errorf("failed to resolve %s as url or ip addr %w", address, ipErr)
}
return ipHost, nil
}
if u.Scheme != "" || u.Port() != "" {
return u.Hostname(), nil
}
return address, nil
}

func parseIP(s string) (string, error) {
ipStr, _, err := net.SplitHostPort(s)
if err == nil {
return ipStr, nil
}
ip := net.ParseIP(s)
if ip == nil {
return "", fmt.Errorf("invalid IP %s", ip)
}
return ip.String(), nil
}
76 changes: 0 additions & 76 deletions pkg/client/client_test.go

This file was deleted.

0 comments on commit cf8bea5

Please sign in to comment.