Skip to content

Conversation

@poddm
Copy link
Contributor

@poddm poddm commented Mar 9, 2023

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:

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=’’)”.

@mlsorensen
Copy link
Contributor

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

// 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)
Copy link
Member

@rohityadavcloud rohityadavcloud Mar 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor

@mlsorensen mlsorensen Mar 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mlsorensen
Copy link
Contributor

@poddm looks like the change would need to be made in the generate.go in order to stick, since the code changed is generated.

pn("func (cs *CloudStackClient) newRawRequest(api string, post bool, params url.Values) (json.RawMessage, error) {")

@poddm poddm closed this Mar 22, 2023
@poddm poddm reopened this Mar 22, 2023
@poddm
Copy link
Contributor Author

poddm commented Mar 22, 2023

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

@mlsorensen
Copy link
Contributor

@poddm see what you think about #52

@poddm
Copy link
Contributor Author

poddm commented Mar 29, 2023

lgtm -

@shwstppr
Copy link
Contributor

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

@mlsorensen
Copy link
Contributor

mlsorensen commented Mar 30, 2023

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

I don't think so, #52 covers it.

@poddm poddm closed this Mar 30, 2023
@poddm poddm deleted the fixasterisk branch October 31, 2023 18:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants