|
|
@ -25,7 +25,6 @@ Visit https://github.com/rudecs/terraform-provider-decort for full source code p
|
|
|
|
package decort
|
|
|
|
package decort
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
|
|
|
|
|
|
|
|
"bytes"
|
|
|
|
"bytes"
|
|
|
|
"crypto/tls"
|
|
|
|
"crypto/tls"
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
@ -34,6 +33,7 @@ import (
|
|
|
|
"net/url"
|
|
|
|
"net/url"
|
|
|
|
"strconv"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
|
|
// "time"
|
|
|
|
// "time"
|
|
|
|
|
|
|
|
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
@ -42,7 +42,6 @@ import (
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
|
|
|
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
|
|
|
// "github.com/hashicorp/terraform-plugin-sdk/terraform"
|
|
|
|
// "github.com/hashicorp/terraform-plugin-sdk/terraform"
|
|
|
|
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// enumerated constants that define authentication modes
|
|
|
|
// enumerated constants that define authentication modes
|
|
|
@ -137,7 +136,7 @@ func ControllerConfigure(d *schema.ResourceData) (*ControllerCfg, error) {
|
|
|
|
|
|
|
|
|
|
|
|
if allow_unverified_ssl {
|
|
|
|
if allow_unverified_ssl {
|
|
|
|
log.Warn("ControllerConfigure: allow_unverified_ssl is set - will not check certificates!")
|
|
|
|
log.Warn("ControllerConfigure: allow_unverified_ssl is set - will not check certificates!")
|
|
|
|
transCfg := &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true},}
|
|
|
|
transCfg := &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}}
|
|
|
|
ret_config.cc_client = &http.Client{
|
|
|
|
ret_config.cc_client = &http.Client{
|
|
|
|
Transport: transCfg,
|
|
|
|
Transport: transCfg,
|
|
|
|
Timeout: Timeout180s,
|
|
|
|
Timeout: Timeout180s,
|
|
|
@ -195,7 +194,7 @@ func ControllerConfigure(d *schema.ResourceData) (*ControllerCfg, error) {
|
|
|
|
return ret_config, nil
|
|
|
|
return ret_config, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (config *ControllerCfg) getDecortUsername() (string) {
|
|
|
|
func (config *ControllerCfg) getDecortUsername() string {
|
|
|
|
return config.decort_username
|
|
|
|
return config.decort_username
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -216,7 +215,7 @@ func (config *ControllerCfg) getOAuth2JWT() (string, error) {
|
|
|
|
params.Add("validity", "3600")
|
|
|
|
params.Add("validity", "3600")
|
|
|
|
params_str := params.Encode()
|
|
|
|
params_str := params.Encode()
|
|
|
|
|
|
|
|
|
|
|
|
req, err := http.NewRequest("POST", config.oauth2_url + "/v1/oauth/access_token", strings.NewReader(params_str))
|
|
|
|
req, err := http.NewRequest("POST", config.oauth2_url+"/v1/oauth/access_token", strings.NewReader(params_str))
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -265,7 +264,7 @@ func (config *ControllerCfg) validateJWT(jwt string) (bool, error) {
|
|
|
|
return false, fmt.Errorf("validateJWT method called, but no OAuth2 URL provided.")
|
|
|
|
return false, fmt.Errorf("validateJWT method called, but no OAuth2 URL provided.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
req, err := http.NewRequest("POST", config.controller_url + "/restmachine/cloudapi/accounts/list", nil)
|
|
|
|
req, err := http.NewRequest("POST", config.controller_url+"/restmachine/cloudapi/accounts/list", nil)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -306,7 +305,7 @@ func (config *ControllerCfg) validateLegacyUser() (bool, error) {
|
|
|
|
params.Add("password", config.legacy_password)
|
|
|
|
params.Add("password", config.legacy_password)
|
|
|
|
params_str := params.Encode()
|
|
|
|
params_str := params.Encode()
|
|
|
|
|
|
|
|
|
|
|
|
req, err := http.NewRequest("POST", config.controller_url + "/restmachine/cloudapi/users/authenticate", strings.NewReader(params_str))
|
|
|
|
req, err := http.NewRequest("POST", config.controller_url+"/restmachine/cloudapi/users/authenticate", strings.NewReader(params_str))
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -367,12 +366,13 @@ func (config *ControllerCfg) decortAPICall(method string, api_name string, url_v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
params_str := url_values.Encode()
|
|
|
|
params_str := url_values.Encode()
|
|
|
|
|
|
|
|
|
|
|
|
req, err := http.NewRequest(method, config.controller_url + api_name, strings.NewReader(params_str))
|
|
|
|
req, err := http.NewRequest(method, config.controller_url+api_name, strings.NewReader(params_str))
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
req.Header.Set("Content-Length", strconv.Itoa(len(params_str)))
|
|
|
|
req.Header.Set("Content-Length", strconv.Itoa(len(params_str)))
|
|
|
|
|
|
|
|
req.Header.Set("Accept", "application/json")
|
|
|
|
|
|
|
|
|
|
|
|
if config.auth_mode_code == MODE_OAUTH2 || config.auth_mode_code == MODE_JWT {
|
|
|
|
if config.auth_mode_code == MODE_OAUTH2 || config.auth_mode_code == MODE_JWT {
|
|
|
|
req.Header.Set("Authorization", fmt.Sprintf("bearer %s", config.jwt))
|
|
|
|
req.Header.Set("Authorization", fmt.Sprintf("bearer %s", config.jwt))
|
|
|
@ -385,13 +385,12 @@ func (config *ControllerCfg) decortAPICall(method string, api_name string, url_v
|
|
|
|
defer resp.Body.Close()
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
|
|
|
|
if resp.StatusCode == http.StatusOK {
|
|
|
|
if resp.StatusCode == http.StatusOK {
|
|
|
|
tmp_body, err := ioutil.ReadAll(resp.Body)
|
|
|
|
body, err := ioutil.ReadAll(resp.Body)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
json_resp := Jo2JSON(string(tmp_body))
|
|
|
|
log.Debugf("decortAPICall: %s %s\n %s", method, api_name, body)
|
|
|
|
log.Debugf("decortAPICall: %s %s\n %s", method, api_name, json_resp)
|
|
|
|
return string(body), nil
|
|
|
|
return json_resp, nil
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
return "", fmt.Errorf("decortAPICall: unexpected status code %d when calling API %q with request Body %q",
|
|
|
|
return "", fmt.Errorf("decortAPICall: unexpected status code %d when calling API %q with request Body %q",
|
|
|
|
resp.StatusCode, req.URL, params_str)
|
|
|
|
resp.StatusCode, req.URL, params_str)
|
|
|
@ -405,4 +404,3 @@ func (config *ControllerCfg) decortAPICall(method string, api_name string, url_v
|
|
|
|
|
|
|
|
|
|
|
|
return "", err
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|