Skip to content
Open
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
16 changes: 10 additions & 6 deletions pkg/client/group_mgmt_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,16 @@ type Argument struct {
JobId string `json:"job_id,omitempty"`
}

func newGroupMgmtClient(ipAddress, username, password, apiVersion string, waitOnJobs, isTenant bool) *GroupMgmtClient {
func newGroupMgmtClient(ipAddress, username, password, apiVersion string, waitOnJobs, isTenant bool, tlsConfig *tls.Config) *GroupMgmtClient {
if tlsConfig == nil && !isTenant {
tlsConfig = &tls.Config{
InsecureSkipVerify: true,
}
}

// Get new resty()
restyClient := resty.New()
restyClient.SetTLSClientConfig(&tls.Config{
InsecureSkipVerify: true,
})
restyClient.SetTLSClientConfig(tlsConfig)

// Create GroupMgmt Client
groupMgmtClient := &GroupMgmtClient{
Expand All @@ -88,13 +92,13 @@ func newGroupMgmtClient(ipAddress, username, password, apiVersion string, waitOn
}

// NewClient instantiates a new client to communicate with the Nimble group
func NewClient(ipAddress, username, password, apiVersion string, waitOnJobs, isTenant bool) (*GroupMgmtClient, error) {
func NewClient(ipAddress, username, password, apiVersion string, waitOnJobs, isTenant bool, tlsConfig *tls.Config) (*GroupMgmtClient, error) {
if apiVersion != "v1" {
return nil, fmt.Errorf("API version \"%s\" is not recognized", apiVersion)
}

// Get resty client
groupMgmtClient := newGroupMgmtClient(ipAddress, username, password, apiVersion, waitOnJobs, isTenant)
groupMgmtClient := newGroupMgmtClient(ipAddress, username, password, apiVersion, waitOnJobs, isTenant, tlsConfig)

// Get session token
sessionToken, err := groupMgmtClient.login(username, password)
Expand Down
4 changes: 2 additions & 2 deletions pkg/client/group_mgmt_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestNewClient(t *testing.T) {

// Create client
var err error
client, err = NewClient(os.Getenv("SDK_TARGET_HOST"), os.Getenv("SDK_TARGET_USER"), os.Getenv("SDK_TARGET_PASSWORD"), "v1", true, false)
client, err = NewClient(os.Getenv("SDK_TARGET_HOST"), os.Getenv("SDK_TARGET_USER"), os.Getenv("SDK_TARGET_PASSWORD"), "v1", true, false, nil)
if err != nil {
t.Errorf("NewClient(): Unable to create client, err: %v", err.Error())
return
Expand Down Expand Up @@ -99,7 +99,7 @@ func TestListGetOrPost(t *testing.T) {

// Create GMD client
var err error
client, err := NewClient(os.Getenv("SDK_TARGET_HOST"), os.Getenv("SDK_TARGET_USER"), os.Getenv("SDK_TARGET_PASSWORD"), "v1", true, false)
client, err := NewClient(os.Getenv("SDK_TARGET_HOST"), os.Getenv("SDK_TARGET_USER"), os.Getenv("SDK_TARGET_PASSWORD"), "v1", true, false, nil)
if err != nil {
t.Errorf("NewGmdClient(): Unable to create GMD client, err: %v", err.Error())
return
Expand Down
13 changes: 11 additions & 2 deletions pkg/service/group_service_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
package service

import (
"crypto/tls"

"github.com/hpe-storage/nimble-golang-sdk/pkg/client"
"github.com/hpe-storage/nimble-golang-sdk/pkg/client/v1/nimbleos"
"github.com/hpe-storage/nimble-golang-sdk/pkg/param"
Expand Down Expand Up @@ -75,6 +77,7 @@ type GroupServiceOptions struct {
Password string
IsTenant bool
ApiVersion string
TLSConfig *tls.Config
}

type ServiceOption func(*GroupServiceOptions)
Expand Down Expand Up @@ -123,10 +126,16 @@ func WithoutWaitForAsyncJobs() func(*GroupServiceOptions) {
}
}

func WithTLSConfig(tlsConfig *tls.Config) func(*GroupServiceOptions) {
return func(groupService *GroupServiceOptions) {
groupService.TLSConfig = tlsConfig
}
}

// NewNsGroupService - initializes NsGroupService
// This function is deprecated. Call NewNimbleGroupService() to initialize a group service
func NewNsGroupService(ip, username, password, apiVersion string, synchronous bool) (gs *NsGroupService, err error) {
client, err := client.NewClient(ip, username, password, apiVersion, synchronous, false)
client, err := client.NewClient(ip, username, password, apiVersion, synchronous, false, nil)
if err != nil {
return nil, err
}
Expand All @@ -144,7 +153,7 @@ func NewNimbleGroupService(serviceOpts ...ServiceOption) (gs *NsGroupService, er
opt(gso)
}

groupMgmtClient, err := client.NewClient(gso.Host, gso.Username, gso.Password, gso.ApiVersion, gso.WaitOnJob, gso.IsTenant)
groupMgmtClient, err := client.NewClient(gso.Host, gso.Username, gso.Password, gso.ApiVersion, gso.WaitOnJob, gso.IsTenant, gso.TLSConfig)
if err != nil {
return nil, err
}
Expand Down