func (c *Credentials) Delete(apiVersion, apiEndpoint string, timeout ...int) (interface{}, error) {
	httpTimeout := httpTimeout(timeout)
	apiRequest, err := c.commonAPI("DELETE", apiVersion, apiEndpoint, nil, httpTimeout)
	if err != nil {
		return nil, err
	}
	return apiRequest, nil
}
Delete sends a DELETE request to the provided Rubrik API endpoint and returns the full API response. Supported "apiVersions" are v1, v2, and internal.
The optional timeout value corresponds to the number of seconds to wait to establish a connection to the Rubrik cluster before returning a
timeout error. If no value is provided, a default of 15 seconds will be used.
package rubrikcdm
import (
	"bytes"
	"crypto/tls"
	"encoding/json"
	"errors"
	"fmt"
	"io/ioutil"
	"net"
	"net/http"
	"os"
	"reflect"
	"sort"
	"time"
)
type encoding int
const (
	encodePath encoding = 1 + iota
	encodePathSegment
	encodeQueryComponent
)
type Credentials struct {
	NodeIP   string
	Username string
	Password string
	APIToken string
}
func Connect(nodeIP, username, password string, apiToken ...string) *Credentials {
	client := &Credentials{
		NodeIP:   nodeIP,
		Username: username,
		Password: password,
	}
	return client
}
func ConnectAPIToken(nodeIP, apiToken string) *Credentials {
	client := &Credentials{
		NodeIP:   nodeIP,
		APIToken: apiToken,
	}
	return client
}
func ConnectEnv() (*Credentials, error) {
	nodeIP, ok := os.LookupEnv("rubrik_cdm_node_ip")
	if ok != true {
		return nil, errors.New("The `rubrik_cdm_node_ip` environment variable is not present")
	}
	apiTokenFound := true
	apiToken, ok := os.LookupEnv("rubrik_cdm_token")
	if ok != true {
		apiTokenFound = false
	}
	var client *Credentials
	if apiTokenFound == false {
		username, ok := os.LookupEnv("rubrik_cdm_username")
		if ok != true {
			return nil, errors.New("The `rubrik_cdm_username` or `rubrik_cdm_token` environment variable is not present")
		}
		password, ok := os.LookupEnv("rubrik_cdm_password")
		if ok != true {
			return nil, errors.New("The `rubrik_cdm_password` or `rubrik_cdm_token` environment variable is not present")
		}
		client = &Credentials{
			NodeIP:   nodeIP,
			Username: username,
			Password: password,
		}
	} else {
		client = &Credentials{
			NodeIP:   nodeIP,
			APIToken: apiToken,
		}
	}
	return client, nil
}
func (c *Credentials) commonAPI(callType, apiVersion, apiEndpoint string, config interface{}, timeout int) (interface{}, error) {
	if apiVersionValidation(apiVersion) == false {
		return nil, errors.New("Enter a valid API version")
	}
	if endpointValidation(apiEndpoint) == "errorStart" {
		return nil, errors.New("The API Endpoint should begin with '/' (ex: /cluster/me)")
	} else if endpointValidation(apiEndpoint) == "errorEnd" {
		return nil, errors.New("The API Endpoint should not end with '/' (ex. /cluster/me)")
	}
	tr := &http.Transport{
		TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
	}
	client := &http.Client{
		Transport: tr,
		Timeout:   time.Second * time.Duration(timeout),
	}
	requestURL := fmt.Sprintf("https://%s/api/%s%s", c.NodeIP, apiVersion, apiEndpoint)
	var request *http.Request
	switch callType {
	case "GET":
		request, _ = http.NewRequest(callType, getEscape(requestURL), nil)
	case "POST":
		convertedConfig, _ := json.Marshal(config)
		request, _ = http.NewRequest(callType, requestURL, bytes.NewBuffer(convertedConfig))
	case "PATCH":
		convertedConfig, _ := json.Marshal(config)
		request, _ = http.NewRequest(callType, requestURL, bytes.NewBuffer(convertedConfig))
	case "DELETE":
		request, _ = http.NewRequest(callType, requestURL, nil)
	case "JOB_STATUS":
		requestURL = config.(string)
		request, _ = http.NewRequest("GET", requestURL, nil)
	}
	if len(c.Username) != 0 {
		request.SetBasicAuth(c.Username, c.Password)
	} else {
		request.Header.Add("Authorization", fmt.Sprintf("Bearer %s", c.APIToken))
	}
	request.Header.Set("Content-Type", "application/json")
	request.Header.Set("Accept", "application/json")
	request.Header.Set("User-Agent", "Rubrik Go SDK v1.0.2")
	request.Close = true
	apiRequest, err := client.Do(request)
	if err, ok := err.(net.Error); ok && err.Timeout() {
		return nil, errors.New("Unable to establish a connection to the Rubrik cluster")
	} else if err != nil {
		return nil, err
	}
	defer apiRequest.Body.Close()
	body, err := ioutil.ReadAll(apiRequest.Body)
	apiResponse := []byte(body)
	var convertedAPIResponse interface{}
	if err := json.Unmarshal(apiResponse, &convertedAPIResponse); err != nil {
		if apiRequest.StatusCode == 204 {
			convertedAPIResponse = map[string]interface{}{}
			convertedAPIResponse.(map[string]interface{})["statusCode"] = apiRequest.StatusCode
		} else if apiRequest.StatusCode != 200 {
			return nil, fmt.Errorf("%s", apiRequest.Status)
		}
	}
	if reflect.TypeOf(convertedAPIResponse).Kind() == reflect.Slice {
		return convertedAPIResponse, nil
	}
	if _, ok := convertedAPIResponse.(map[string]interface{})["errorType"]; ok {
		return nil, fmt.Errorf("%s", convertedAPIResponse.(map[string]interface{})["message"])
	}
	if _, ok := convertedAPIResponse.(map[string]interface{})["message"]; ok {
		if _, ok := convertedAPIResponse.(map[string]interface{})["setupEncryptionAtRest"]; ok {
			return convertedAPIResponse, nil
		}
		return nil, fmt.Errorf("%s", convertedAPIResponse.(map[string]interface{})["message"])
	}
	return convertedAPIResponse, nil
}
func apiVersionValidation(apiVersion string) bool {
	validAPIVersions := []string{"v1", "v2", "internal"}
	for _, version := range validAPIVersions {
		if version == apiVersion {
			return true
		}
	}
	return false
}
func endpointValidation(apiEndpoint string) string {
	if string(apiEndpoint[0]) != "/" {
		return "errorStart"
	} else if string(apiEndpoint[len(apiEndpoint)-1]) == "/" {
		if string(apiEndpoint[len(apiEndpoint)-2]) != "=" {  
			return "errorEnd"
		}
	}
	return "success"
}
func httpTimeout(timeout []int) int {
	if len(timeout) == 0 {
		return int(15)  
	}
	return int(timeout[0])  
}
func apiToken(apiToken []string) string {
	if len(apiToken) == 0 {
		return ""  
	}
	return apiToken[0]  
}
func getEscape(s string) string {
	return escape(s, encodePathSegment)
}
func escape(s string, mode encoding) string {
	spaceCount, hexCount := 0, 0
	for i := 0; i < len(s); i++ {
		c := s[i]
		if shouldEscape(c, mode) {
			if c == ' ' && mode == encodeQueryComponent {
				spaceCount++
			} else {
				hexCount++
			}
		}
	}
	if spaceCount == 0 && hexCount == 0 {
		return s
	}
	t := make([]byte, len(s)+2*hexCount)
	j := 0
	for i := 0; i < len(s); i++ {
		switch c := s[i]; {
		case c == ' ' && mode == encodeQueryComponent:
			t[j] = '+'
			j++
		case shouldEscape(c, mode):
			t[j] = '%'
			t[j+1] = "0123456789ABCDEF"[c>>4]
			t[j+2] = "0123456789ABCDEF"[c&15]
			j += 3
		default:
			t[j] = s[i]
			j++
		}
	}
	return string(t)
}
func shouldEscape(c byte, mode encoding) bool {
	if 'A' <= c && c <= 'Z' || 'a' <= c && c <= 'z' || '0' <= c && c <= '9' {
		return false
	}
	switch c {
	case '-', '_', '.', '~':  
		return false
	case '$', '&', '+', ',', '/', ':', ';', '=', '?', '@':  
		return c == ';' || c == ','
	}
	return true
}
func (c *Credentials) Get(apiVersion, apiEndpoint string, timeout ...int) (interface{}, error) {
	httpTimeout := httpTimeout(timeout)
	apiRequest, err := c.commonAPI("GET", apiVersion, apiEndpoint, nil, httpTimeout)
	if err != nil {
		return nil, err
	}
	return apiRequest, nil
}
func (c *Credentials) JobStatus(jobStatusURL string, timeout ...int) (interface{}, error) {
	httpTimeout := httpTimeout(timeout)
	apiVersion := "v1"
	apiEndpoint := "/placeholder"
	for {
		apiRequest, err := c.commonAPI("JOB_STATUS", apiVersion, apiEndpoint, jobStatusURL, httpTimeout)
		if err != nil {
			return nil, err
		}
		jobStatus := apiRequest.(map[string]interface{})["status"].(string)
		switch jobStatus {
		case "SUCCEEDED":
			return apiRequest, nil
		case "QUEUED":
			time.Sleep(10 * time.Second)
		case "RUNNING":
			time.Sleep(10 * time.Second)
		case "FINISHING":
			time.Sleep(10 * time.Second)
		default:
			return apiRequest, errors.New("Job failed")
		}
	}
}
func (c *Credentials) Post(apiVersion, apiEndpoint string, config interface{}, timeout ...int) (interface{}, error) {
	httpTimeout := httpTimeout(timeout)
	apiRequest, err := c.commonAPI("POST", apiVersion, apiEndpoint, config, httpTimeout)
	if err != nil {
		return nil, err
	}
	return apiRequest, nil
}
func (c *Credentials) Patch(apiVersion, apiEndpoint string, config interface{}, timeout ...int) (interface{}, error) {
	httpTimeout := httpTimeout(timeout)
	apiRequest, err := c.commonAPI("PATCH", apiVersion, apiEndpoint, config, httpTimeout)
	if err != nil {
		return nil, err
	}
	return apiRequest, nil
}