2015-06-20 18:25:21 +02:00
|
|
|
package services
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"encoding/json"
|
2016-05-04 17:48:12 +02:00
|
|
|
"errors"
|
2015-06-20 18:25:21 +02:00
|
|
|
"fmt"
|
|
|
|
|
2016-05-04 17:48:12 +02:00
|
|
|
common "github.com/maximilien/softlayer-go/common"
|
2015-06-20 18:25:21 +02:00
|
|
|
datatypes "github.com/maximilien/softlayer-go/data_types"
|
|
|
|
softlayer "github.com/maximilien/softlayer-go/softlayer"
|
|
|
|
)
|
|
|
|
|
|
|
|
type softLayer_Network_Storage_Allowed_Host_Service struct {
|
|
|
|
client softlayer.Client
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewSoftLayer_Network_Storage_Allowed_Host_Service(client softlayer.Client) *softLayer_Network_Storage_Allowed_Host_Service {
|
|
|
|
return &softLayer_Network_Storage_Allowed_Host_Service{
|
|
|
|
client: client,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (slns *softLayer_Network_Storage_Allowed_Host_Service) GetName() string {
|
|
|
|
return "SoftLayer_Network_Storage_Allowed_Host"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (slns *softLayer_Network_Storage_Allowed_Host_Service) GetCredential(allowedHostId int) (datatypes.SoftLayer_Network_Storage_Credential, error) {
|
2016-05-04 17:48:12 +02:00
|
|
|
response, errorCode, err := slns.client.GetHttpClient().DoRawHttpRequest(fmt.Sprintf("%s/%d/getCredential.json", slns.GetName(), allowedHostId), "GET", new(bytes.Buffer))
|
2015-06-20 18:25:21 +02:00
|
|
|
if err != nil {
|
|
|
|
return datatypes.SoftLayer_Network_Storage_Credential{}, err
|
|
|
|
}
|
|
|
|
|
2016-05-04 17:48:12 +02:00
|
|
|
if common.IsHttpErrorCode(errorCode) {
|
|
|
|
errorMessage := fmt.Sprintf("softlayer-go: could not SoftLayer_Network_Storage_Allowed_Host#getCredential, HTTP error code: '%d'", errorCode)
|
|
|
|
return datatypes.SoftLayer_Network_Storage_Credential{}, errors.New(errorMessage)
|
|
|
|
}
|
|
|
|
|
2015-06-20 18:25:21 +02:00
|
|
|
credential := datatypes.SoftLayer_Network_Storage_Credential{}
|
|
|
|
err = json.Unmarshal(response, &credential)
|
|
|
|
if err != nil {
|
|
|
|
return datatypes.SoftLayer_Network_Storage_Credential{}, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return credential, nil
|
|
|
|
}
|