Skip to content
Permalink
Browse files
Merge pull request #32 from svanharmelen/dev
Add option to only use HTTP GET calls
  • Loading branch information
Sander van Harmelen committed Jul 15, 2015
2 parents 4d162c3 + b2c02b3 commit 1ea251ac0bc73160ff7c8b4798d42493167ba312
Showing 4 changed files with 56 additions and 28 deletions.
@@ -43,12 +43,13 @@ func (e *CSError) Error() error {
}

type CloudStackClient struct {
client *http.Client // The http client for communicating
baseURL string // The base URL of the API
apiKey string // Api key
secret string // Secret key
async bool // Wait for async calls to finish
timeout int64 // Max waiting timeout in seconds for async jobs to finish; defaults to 60 seconds
client *http.Client // The http client for communicating
baseURL string // The base URL of the API
apiKey string // Api key
secret string // Secret key
httpgetonly bool // If `true` only use HTTP GET calls
async bool // Wait for async calls to finish
timeout int64 // Max waiting timeout in seconds for async jobs to finish; defaults to 60 seconds

APIDiscovery *APIDiscoveryService
Account *AccountService
@@ -217,6 +218,12 @@ func NewAsyncClient(apiurl string, apikey string, secret string, verifyssl bool)
return cs
}

// Some cloud providers offer customized (proxied) access to the CloudStack API allowing only HTTP GET calls. So
// by calling this method with `true`, the CloudStack client will only make GET calls.
func (cs *CloudStackClient) HTTPGETOnly(httpGETOnly bool) {
cs.httpgetonly = httpGETOnly
}

// When using the async client an api call will wait for the async call to finish before returning. The default is to poll for 60
// seconds, to check if the async job is finished.
func (cs *CloudStackClient) AsyncTimeout(timeoutInSeconds int64) {
@@ -278,7 +285,7 @@ func (cs *CloudStackClient) newRequest(api string, params url.Values) (json.RawM

var err error
var resp *http.Response
if api == "deployVirtualMachine" || api == "updateVirtualMachine" {
if !cs.httpgetonly && (api == "deployVirtualMachine" || api == "updateVirtualMachine") {
// The deployVirtualMachine API should be called using a POST call
// so we don't have to worry about the userdata size

@@ -43,12 +43,13 @@ func (e *CSError) Error() error {
}

type CloudStackClient struct {
client *http.Client // The http client for communicating
baseURL string // The base URL of the API
apiKey string // Api key
secret string // Secret key
async bool // Wait for async calls to finish
timeout int64 // Max waiting timeout in seconds for async jobs to finish; defaults to 60 seconds
client *http.Client // The http client for communicating
baseURL string // The base URL of the API
apiKey string // Api key
secret string // Secret key
httpgetonly bool // If `true` only use HTTP GET calls
async bool // Wait for async calls to finish
timeout int64 // Max waiting timeout in seconds for async jobs to finish; defaults to 60 seconds

APIDiscovery *APIDiscoveryService
Account *AccountService
@@ -223,6 +224,12 @@ func NewAsyncClient(apiurl string, apikey string, secret string, verifyssl bool)
return cs
}

// Some cloud providers offer customized (proxied) access to the CloudStack API allowing only HTTP GET calls. So
// by calling this method with `true`, the CloudStack client will only make GET calls.
func (cs *CloudStackClient) HTTPGETOnly(httpGETOnly bool) {
cs.httpgetonly = httpGETOnly
}

// When using the async client an api call will wait for the async call to finish before returning. The default is to poll for 60
// seconds, to check if the async job is finished.
func (cs *CloudStackClient) AsyncTimeout(timeoutInSeconds int64) {
@@ -284,7 +291,7 @@ func (cs *CloudStackClient) newRequest(api string, params url.Values) (json.RawM

var err error
var resp *http.Response
if api == "deployVirtualMachine" || api == "updateVirtualMachine" {
if !cs.httpgetonly && (api == "deployVirtualMachine" || api == "updateVirtualMachine") {
// The deployVirtualMachine API should be called using a POST call
// so we don't have to worry about the userdata size

@@ -43,12 +43,13 @@ func (e *CSError) Error() error {
}

type CloudStackClient struct {
client *http.Client // The http client for communicating
baseURL string // The base URL of the API
apiKey string // Api key
secret string // Secret key
async bool // Wait for async calls to finish
timeout int64 // Max waiting timeout in seconds for async jobs to finish; defaults to 60 seconds
client *http.Client // The http client for communicating
baseURL string // The base URL of the API
apiKey string // Api key
secret string // Secret key
httpgetonly bool // If `true` only use HTTP GET calls
async bool // Wait for async calls to finish
timeout int64 // Max waiting timeout in seconds for async jobs to finish; defaults to 60 seconds

APIDiscovery *APIDiscoveryService
Account *AccountService
@@ -217,6 +218,12 @@ func NewAsyncClient(apiurl string, apikey string, secret string, verifyssl bool)
return cs
}

// Some cloud providers offer customized (proxied) access to the CloudStack API allowing only HTTP GET calls. So
// by calling this method with `true`, the CloudStack client will only make GET calls.
func (cs *CloudStackClient) HTTPGETOnly(httpGETOnly bool) {
cs.httpgetonly = httpGETOnly
}

// When using the async client an api call will wait for the async call to finish before returning. The default is to poll for 60
// seconds, to check if the async job is finished.
func (cs *CloudStackClient) AsyncTimeout(timeoutInSeconds int64) {
@@ -278,7 +285,7 @@ func (cs *CloudStackClient) newRequest(api string, params url.Values) (json.RawM

var err error
var resp *http.Response
if api == "deployVirtualMachine" || api == "updateVirtualMachine" {
if !cs.httpgetonly && (api == "deployVirtualMachine" || api == "updateVirtualMachine") {
// The deployVirtualMachine API should be called using a POST call
// so we don't have to worry about the userdata size

@@ -258,12 +258,13 @@ func (as *allServices) GeneralCode() ([]byte, error) {
pn("}")
pn("")
pn("type CloudStackClient struct {")
pn(" client *http.Client // The http client for communicating")
pn(" baseURL string // The base URL of the API")
pn(" apiKey string // Api key")
pn(" secret string // Secret key")
pn(" async bool // Wait for async calls to finish")
pn(" timeout int64 // Max waiting timeout in seconds for async jobs to finish; defaults to 60 seconds")
pn(" client *http.Client // The http client for communicating")
pn(" baseURL string // The base URL of the API")
pn(" apiKey string // Api key")
pn(" secret string // Secret key")
pn(" httpgetonly bool // If `true` only use HTTP GET calls")
pn(" async bool // Wait for async calls to finish")
pn(" timeout int64 // Max waiting timeout in seconds for async jobs to finish; defaults to 60 seconds")
pn("")
for _, s := range as.services {
pn(" %s *%s", strings.TrimSuffix(s.name, "Service"), s.name)
@@ -308,6 +309,12 @@ func (as *allServices) GeneralCode() ([]byte, error) {
pn(" return cs")
pn("}")
pn("")
pn("// Some cloud providers offer customized (proxied) access to the CloudStack API allowing only HTTP GET calls. So")
pn("// by calling this method with `true`, the CloudStack client will only make GET calls.")
pn("func (cs *CloudStackClient) HTTPGETOnly(httpGETOnly bool) {")
pn(" cs.httpgetonly = httpGETOnly")
pn("}")
pn("")
pn("// When using the async client an api call will wait for the async call to finish before returning. The default is to poll for 60")
pn("// seconds, to check if the async job is finished.")
pn("func (cs *CloudStackClient) AsyncTimeout(timeoutInSeconds int64) {")
@@ -369,7 +376,7 @@ func (as *allServices) GeneralCode() ([]byte, error) {
pn("")
pn(" var err error")
pn(" var resp *http.Response")
pn(" if api == \"deployVirtualMachine\" || api == \"updateVirtualMachine\" {")
pn(" if !cs.httpgetonly && (api == \"deployVirtualMachine\" || api == \"updateVirtualMachine\") {")
pn(" // The deployVirtualMachine API should be called using a POST call")
pn(" // so we don't have to worry about the userdata size")
pn("")

0 comments on commit 1ea251a

Please sign in to comment.