Skip to content

Commit

Permalink
Split login url to its parts (#355)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hakan Memisoglu authored and mergify[bot] committed Oct 11, 2019
1 parent 2007afa commit 48d9504
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion pkg/blockstorage/vmware/vmware.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package vmware

import (
"context"
"fmt"
"time"

"github.com/pkg/errors"
Expand All @@ -24,6 +25,13 @@ const (
// It should contain the username and the password.
VSphereLoginURLKey = "VSphereLoginURL"

// VSphereEndpointKey represents key for the login endpoint.
VSphereEndpointKey = "VSphereEndpoint"
// VSphereUsernameKey represents key for the username.
VSphereUsernameKey = "VSphereUsername"
// VSpherePasswordKey represents key for the password.
VSpherePasswordKey = "VSpherePasswordKey"

noDescription = ""
defaultWaitTime = 10 * time.Minute
)
Expand All @@ -36,7 +44,19 @@ type fcdProvider struct {
// NewProvider creates new VMWare FCD provider with the config.
// URL taken from config helps to establish connection.
func NewProvider(config map[string]string) (blockstorage.Provider, error) {
u, err := soap.ParseURL(config[VSphereLoginURLKey])
ep, ok := config[VSphereEndpointKey]
if !ok {
return nil, errors.New("Failed to find VSphere endpoint value")
}
username, ok := config[VSphereUsernameKey]
if !ok {
return nil, errors.New("Failed to find VSphere username value")
}
password, ok := config[VSpherePasswordKey]
if !ok {
return nil, errors.New("Failed to find VSphere password value")
}
u, err := soap.ParseURL(constructLoginURL(ep, username, password))
if err != nil {
return nil, errors.Wrap(err, "Failed to get config")
}
Expand Down Expand Up @@ -67,6 +87,10 @@ func NewProvider(config map[string]string) (blockstorage.Provider, error) {
}, nil
}

func constructLoginURL(endpoint, username, password string) string {
return fmt.Sprintf("https://%s:%s@%s/sdk", username, password, endpoint)
}

func (p *fcdProvider) Type() blockstorage.Type {
return blockstorage.TypeFCD
}
Expand Down

0 comments on commit 48d9504

Please sign in to comment.