You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cloudstack.apache.org by "poddm (via GitHub)" <gi...@apache.org> on 2023/03/09 18:57:23 UTC

[GitHub] [cloudstack-go] poddm opened a new pull request, #49: fix asterisk encoding

poddm opened a new pull request, #49:
URL: https://github.com/apache/cloudstack-go/pull/49

   Resolving errors when Configuration values contain an asterisk.
   
   ```
   Error: CloudStack API error 401 (CSExceptionErrorCode: 0): unable to verify user credentials and/or request signature
   ```
   
   Found the following note [here](http://docs.cloudstack.apache.org/projects/archived-cloudstack-getting-started/en/latest/dev.html):
   
   > If you have API calls which contain * (asterisk) characters, you will need to add the option “safe = ‘*’” for the URL encoding. The reason is that Python’s urllib will encode * characters by default, while CloudStack’s internal encoder does not encode them; this results in an authentication failure for your API call. In the above you would replace “urllib.quote_plus(request[k])” with “urllib.quote_plus(request[k], safe=’*’)”.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [cloudstack-go] poddm commented on pull request #49: fix asterisk encoding

Posted by "poddm (via GitHub)" <gi...@apache.org>.
poddm commented on PR #49:
URL: https://github.com/apache/cloudstack-go/pull/49#issuecomment-1489194186

   lgtm -


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [cloudstack-go] poddm closed pull request #49: fix asterisk encoding

Posted by "poddm (via GitHub)" <gi...@apache.org>.
poddm closed pull request #49: fix asterisk encoding
URL: https://github.com/apache/cloudstack-go/pull/49


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [cloudstack-go] mlsorensen commented on a diff in pull request #49: fix asterisk encoding

Posted by "mlsorensen (via GitHub)" <gi...@apache.org>.
mlsorensen commented on code in PR #49:
URL: https://github.com/apache/cloudstack-go/pull/49#discussion_r1145067131


##########
cloudstack/cloudstack.go:
##########
@@ -464,17 +464,24 @@ func (cs *CloudStackClient) newRawRequest(api string, post bool, params url.Valu
 	params.Set("command", api)
 	params.Set("response", "json")
 
-	// Generate signature for API call
+	// encode parameters
 	// * Serialize parameters, URL encoding only values and sort them by key, done by encodeValues
+	// * Replace encoded asterisk (*) back to literal.
+	//    CloudStack’s internal encoder does not encode them; this results in an authentication failure for your API call.
+	//    http://docs.cloudstack.apache.org/projects/archived-cloudstack-getting-started/en/latest/dev.html
+	// 	  Not documented http://docs.cloudstack.apache.org/en/latest/developersguide/dev.html#the-cloudstack-api
+	encodedParams := encodeValues(params)
+	encodedParams = strings.Replace(encodedParams, "%2A", "*", -1)

Review Comment:
   It does, you can't set a value with an asterisk via cloud monkey.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [cloudstack-go] mlsorensen commented on pull request #49: fix asterisk encoding

Posted by "mlsorensen (via GitHub)" <gi...@apache.org>.
mlsorensen commented on PR #49:
URL: https://github.com/apache/cloudstack-go/pull/49#issuecomment-1490627220

   > @poddm @mlsorensen do we need this now as #52 is already merged?
   
   I don't think so.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [cloudstack-go] poddm commented on pull request #49: fix asterisk encoding

Posted by "poddm (via GitHub)" <gi...@apache.org>.
poddm commented on PR #49:
URL: https://github.com/apache/cloudstack-go/pull/49#issuecomment-1479969272

   @mlsorensen, overlooked this.  I'll update the PR.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [cloudstack-go] shwstppr commented on pull request #49: fix asterisk encoding

Posted by "shwstppr (via GitHub)" <gi...@apache.org>.
shwstppr commented on PR #49:
URL: https://github.com/apache/cloudstack-go/pull/49#issuecomment-1489923765

   @poddm @mlsorensen do we need this now as #52 is already merged?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [cloudstack-go] mlsorensen commented on pull request #49: fix asterisk encoding

Posted by "mlsorensen (via GitHub)" <gi...@apache.org>.
mlsorensen commented on PR #49:
URL: https://github.com/apache/cloudstack-go/pull/49#issuecomment-1479810041

   Good catch @poddm - I've run into this as well. My only feedback is that maybe if the implementation were within `encodeValues`instead,  it would be easy to add some tests.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [cloudstack-go] mlsorensen commented on pull request #49: fix asterisk encoding

Posted by "mlsorensen (via GitHub)" <gi...@apache.org>.
mlsorensen commented on PR #49:
URL: https://github.com/apache/cloudstack-go/pull/49#issuecomment-1479871956

   @poddm looks like the change would need to be made in the generate.go in order to stick, since the code changed is generated.
   
   https://github.com/apache/cloudstack-go/blob/0106fc79c6b1031ad6d7c89a157ba8a77f6c8afe/generate/generate.go#L529


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [cloudstack-go] poddm closed pull request #49: fix asterisk encoding

Posted by "poddm (via GitHub)" <gi...@apache.org>.
poddm closed pull request #49: fix asterisk encoding
URL: https://github.com/apache/cloudstack-go/pull/49


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [cloudstack-go] hasan07 commented on pull request #49: fix asterisk encoding

Posted by "hasan07 (via GitHub)" <gi...@apache.org>.
hasan07 commented on PR #49:
URL: https://github.com/apache/cloudstack-go/pull/49#issuecomment-1479812544

   This is needed since there is a requirement for some API values to contain “ * ” such as consoleproxy.url.domain otherwise an exception is thrown. Also CloudMonkey is broked for the same API.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [cloudstack-go] poddm commented on pull request #49: fix asterisk encoding

Posted by "poddm (via GitHub)" <gi...@apache.org>.
poddm commented on PR #49:
URL: https://github.com/apache/cloudstack-go/pull/49#issuecomment-1479968217

   > 0106fc7
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [cloudstack-go] rohityadavcloud commented on a diff in pull request #49: fix asterisk encoding

Posted by "rohityadavcloud (via GitHub)" <gi...@apache.org>.
rohityadavcloud commented on code in PR #49:
URL: https://github.com/apache/cloudstack-go/pull/49#discussion_r1145034272


##########
cloudstack/cloudstack.go:
##########
@@ -464,17 +464,24 @@ func (cs *CloudStackClient) newRawRequest(api string, post bool, params url.Valu
 	params.Set("command", api)
 	params.Set("response", "json")
 
-	// Generate signature for API call
+	// encode parameters
 	// * Serialize parameters, URL encoding only values and sort them by key, done by encodeValues
+	// * Replace encoded asterisk (*) back to literal.
+	//    CloudStack’s internal encoder does not encode them; this results in an authentication failure for your API call.
+	//    http://docs.cloudstack.apache.org/projects/archived-cloudstack-getting-started/en/latest/dev.html
+	// 	  Not documented http://docs.cloudstack.apache.org/en/latest/developersguide/dev.html#the-cloudstack-api
+	encodedParams := encodeValues(params)
+	encodedParams = strings.Replace(encodedParams, "%2A", "*", -1)

Review Comment:
   Would you think this also affects cmk cc @mlsorensen ? The referenced docs are quite old and writtend for Python, the more recent Go implementation in cmk uses this code for network request:
   https://github.com/apache/cloudstack-cloudmonkey/blob/main/cmd/network.go



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [cloudstack-go] rohityadavcloud commented on a diff in pull request #49: fix asterisk encoding

Posted by "rohityadavcloud (via GitHub)" <gi...@apache.org>.
rohityadavcloud commented on code in PR #49:
URL: https://github.com/apache/cloudstack-go/pull/49#discussion_r1145034272


##########
cloudstack/cloudstack.go:
##########
@@ -464,17 +464,24 @@ func (cs *CloudStackClient) newRawRequest(api string, post bool, params url.Valu
 	params.Set("command", api)
 	params.Set("response", "json")
 
-	// Generate signature for API call
+	// encode parameters
 	// * Serialize parameters, URL encoding only values and sort them by key, done by encodeValues
+	// * Replace encoded asterisk (*) back to literal.
+	//    CloudStack’s internal encoder does not encode them; this results in an authentication failure for your API call.
+	//    http://docs.cloudstack.apache.org/projects/archived-cloudstack-getting-started/en/latest/dev.html
+	// 	  Not documented http://docs.cloudstack.apache.org/en/latest/developersguide/dev.html#the-cloudstack-api
+	encodedParams := encodeValues(params)
+	encodedParams = strings.Replace(encodedParams, "%2A", "*", -1)

Review Comment:
   Would you think this also affects cmk cc @mlsorensen ? The referenced docs are quite old and written for Python, the more recent Go implementation in cmk uses this code for network request:
   https://github.com/apache/cloudstack-cloudmonkey/blob/main/cmd/network.go



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [cloudstack-go] mlsorensen commented on a diff in pull request #49: fix asterisk encoding

Posted by "mlsorensen (via GitHub)" <gi...@apache.org>.
mlsorensen commented on code in PR #49:
URL: https://github.com/apache/cloudstack-go/pull/49#discussion_r1145067131


##########
cloudstack/cloudstack.go:
##########
@@ -464,17 +464,24 @@ func (cs *CloudStackClient) newRawRequest(api string, post bool, params url.Valu
 	params.Set("command", api)
 	params.Set("response", "json")
 
-	// Generate signature for API call
+	// encode parameters
 	// * Serialize parameters, URL encoding only values and sort them by key, done by encodeValues
+	// * Replace encoded asterisk (*) back to literal.
+	//    CloudStack’s internal encoder does not encode them; this results in an authentication failure for your API call.
+	//    http://docs.cloudstack.apache.org/projects/archived-cloudstack-getting-started/en/latest/dev.html
+	// 	  Not documented http://docs.cloudstack.apache.org/en/latest/developersguide/dev.html#the-cloudstack-api
+	encodedParams := encodeValues(params)
+	encodedParams = strings.Replace(encodedParams, "%2A", "*", -1)

Review Comment:
   It does, you can't set a value with an asterisk via the Go implementation of cloudmonkey.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [cloudstack-go] mlsorensen commented on pull request #49: fix asterisk encoding

Posted by "mlsorensen (via GitHub)" <gi...@apache.org>.
mlsorensen commented on PR #49:
URL: https://github.com/apache/cloudstack-go/pull/49#issuecomment-1479999758

   @poddm see what you think about #52 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org