From 34eb13deed8285c670b2b068f6aafbb8d066ba26 Mon Sep 17 00:00:00 2001 From: Richard Vanderpool <49568690+rvanderp3@users.noreply.github.com> Date: Mon, 16 Aug 2021 17:39:17 -0400 Subject: [PATCH] if network not defined, use default network --- cmd/vsphere-priv-check/vsphere-priv-check.go | 2 +- pkg/util/privileges.go | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/cmd/vsphere-priv-check/vsphere-priv-check.go b/cmd/vsphere-priv-check/vsphere-priv-check.go index e5c0781..ed9bf41 100644 --- a/cmd/vsphere-priv-check/vsphere-priv-check.go +++ b/cmd/vsphere-priv-check/vsphere-priv-check.go @@ -53,7 +53,7 @@ func runRootCmd(cmd *cobra.Command, args []string) { } func main() { - fmt.Printf("OpenShift vSphere Pre-Flight Permissions Validator v1.1\n\n") + fmt.Printf("OpenShift vSphere Pre-Flight Permissions Validator v1.2\n\n") rootCmd := newRootCmd() rootCmd.Execute() } diff --git a/pkg/util/privileges.go b/pkg/util/privileges.go index 4403a90..8b376a5 100644 --- a/pkg/util/privileges.go +++ b/pkg/util/privileges.go @@ -9,6 +9,7 @@ import ( "github.com/vmware/govmomi/find" "github.com/vmware/govmomi/object" "github.com/vmware/govmomi/vim25/types" + "log" "strings" ) @@ -121,10 +122,22 @@ func ValidatePrivileges(ssn *Session, p *pctypes.Platform, folder string) error } if val, ok := permissions.RequiredPermissions["Port group"]; ok { - network, err := finder.Network(ctx, p.Network) - if err != nil { - return err + var network object.NetworkReference + if p.Network == "" { + log.Println("'network' not defined in install-config.yaml. attempting to use default network.") + _network, err := finder.DefaultNetwork(ctx) + if err != nil { + return err + } + network = _network + } else { + _network, err := finder.Network(ctx, p.Network) + if err != nil { + return err + } + network = _network } + res, err := authManager.FetchUserPrivilegeOnEntities(ctx, []types.ManagedObjectReference{network.Reference()}, p.Username) if err != nil { return err