Skip to content

Update requester.py#11

Merged
asfgit merged 1 commit intoapache:masterfrom
phillipkent:fix_urllib_quote_plus
Apr 7, 2016
Merged

Update requester.py#11
asfgit merged 1 commit intoapache:masterfrom
phillipkent:fix_urllib_quote_plus

Conversation

@phillipkent
Copy link
Contributor

urllib.quote_plus() requires the option safe="*" (that is, the * character is not encoded) to be consistent with CloudStack's internal encoder/decoder. Without this, API calls containing the * character will fail API authentication.

urllib.quote_plus() requires the option safe="*" (that is, the * character is not encoded) to be consistent with CloudStack's internal encoder/decoder. Without this, API calls containing the * character will fail API authentication.
@yadvr
Copy link
Member

yadvr commented Jan 8, 2016

@phillipkent can you share examples of API/cloudmonkey commands where we would like to use * in the args?

With this http request without this fix:

list users username=*
2016-01-08 22:41:50,945 - connectionpool.py:387 - [DEBUG] "GET /client/api?username=%2A&signatureversion=3&expires=2016-01-08T17%3A21%3A50%2B0000&sessionkey=mF-XRv0Ixt4rhKqi0O54RIkG84Q&command=listUsers&response=json HTTP/1.1" 200 24

This is the request with the fix:
2016-01-08 22:43:00,099 - connectionpool.py:387 - [DEBUG] "GET /client/api?username=%2A&signatureversion=3&expires=2016-01-08T17%3A23%3A00%2B0000&sessionkey=OinP2NNyTEdstZijxXmRYRjZpoI&command=listUsers&response=json HTTP/1.1" 200 24

In both cases, username gets encoded as %2A which looks alright to me.

@phillipkent
Copy link
Contributor Author

@bhaisaab The commands that I tested were to set or modify the displaytext/displayname for a network or virtual machine, such as " update network id=xxxxx displaytext='test*' " . I need to try your example and check that I understand what is going on. I do accept that * is not a very likely symbol to use in a description, however it should work with breaking anything.

@yadvr
Copy link
Member

yadvr commented Jan 11, 2016

@phillipkent I understand, but looks like it still works without your fix. I was able to update network display test with a * in it:

Update API:

2016-01-11 17:10:09,300 - requester.py:49 - [DEBUG] ======== START Request ========
2016-01-11 17:10:09,300 - requester.py:49 - [DEBUG] Requesting command=updateNetwork, args={u'displaytext': u'test*', u'id': u'7c0453ad-1689-423a-a90f-ce69a317694b'}
2016-01-11 17:10:09,301 - connectionpool.py:203 - [INFO] Starting new HTTP connection (1): localhost
2016-01-11 17:10:09,375 - connectionpool.py:383 - [DEBUG] "GET /client/api?signatureversion=3&apiKey=&expires=2016-01-11T11%3A50%3A09%2B0000&id=7c0453ad-1689-423a-a90f-ce69a317694b&command=updateNetwork&signature=MVIus5218oqK8bL46AyPRyR%2FDBI%3D&displaytext=test%2A&response=json HTTP/1.1" 200 None
2016-01-11 17:10:09,375 - requester.py:49 - [DEBUG] Request sent: http://localhost:8096/client/api?signatureversion=3&apiKey=&expires=2016-01-11T11%3A50%3A09%2B0000&id=7c0453ad-1689-423a-a90f-ce69a317694b&command=updateNetwork&signature=MVIus5218oqK8bL46AyPRyR%2FDBI%3D&displaytext=test%2A&response=json
2016-01-11 17:10:09,375 - requester.py:49 - [DEBUG] Response received: {"updatenetworkresponse":{"jobid":"879eac5b-94d5-474a-8e5e-840fd9e5652e"}}
2016-01-11 17:10:09,375 - requester.py:49 - [DEBUG] ======== END Request ========

List API to verify:

2016-01-11 17:10:24,671 - requester.py:49 - [DEBUG] ======== START Request ========
2016-01-11 17:10:24,671 - requester.py:49 - [DEBUG] Requesting command=listNetworks, args={}
2016-01-11 17:10:24,673 - connectionpool.py:203 - [INFO] Starting new HTTP connection (1): localhost
2016-01-11 17:10:24,693 - connectionpool.py:383 - [DEBUG] "GET /client/api?signatureversion=3&apiKey=&expires=2016-01-11T11%3A50%3A24%2B0000&command=listNetworks&signature=2JxFqItleF3j9ehZqXnLQXYgK6g%3D&response=json HTTP/1.1" 200 None
2016-01-11 17:10:24,693 - requester.py:49 - [DEBUG] Request sent: http://localhost:8096/client/api?signatureversion=3&apiKey=&expires=2016-01-11T11%3A50%3A24%2B0000&command=listNetworks&signature=2JxFqItleF3j9ehZqXnLQXYgK6g%3D&response=json
2016-01-11 17:10:24,693 - requester.py:49 - [DEBUG] Response received: {"listnetworksresponse":{"count":1,"network":[{"id":"7c0453ad-1689-423a-a90f-ce69a317694b","name":"guestNetworkForBasicZone","displaytext":"test*","broadcastdomaintype":"Native","traffictype":"Guest","zoneid":"e8c8546d-27bb-40f2-9a57-e37571449bf9","zonename":"MyBasicZone","networkofferingid":"4d7d1343-18ce-466e-8d92-209d96efdcdf","networkofferingname":"DefaultSharedNetworkOffering","networkofferingdisplaytext":"Offering for Shared networks","networkofferingconservemode":true,"networkofferingavailability":"Optional","issystem":false,"state":"Setup","related":"7c0453ad-1689-423a-a90f-ce69a317694b","broadcasturi":"vlan://untagged","dns1":"8.8.8.8","type":"Shared","vlan":"untagged","acltype":"Domain","subdomainaccess":true,"domainid":"f8133339-ad2c-11e5-be84-00012e4ff7d0","domain":"ROOT","service":[{"name":"Dhcp","capability":[{"name":"DhcpAccrossMultipleSubnets","value":"true","canchooseservicecapability":false}]},{"name":"Dns","capability":[{"name":"AllowDnsSuffixModification","value":"true","canchooseservicecapability":false}]},{"name":"UserData"}],"networkdomain":"cs1cloud.internal","physicalnetworkid":"19ded38f-460a-4344-a60f-df788954ba11","restartrequired":false,"specifyipranges":true,"canusefordeploy":true,"ispersistent":false,"tags":[],"displaynetwork":true,"strechedl2subnet":false}]}}
2016-01-11 17:10:24,694 - requester.py:49 - [DEBUG] ======== END Request ========

@phillipkent
Copy link
Contributor Author

@bhaisaab I tested a clean virtualenv install of Cloudmonkey 5.3.2 (from PyPy) and also a clone of the latest Cloudmonkey from github (Python version is 2.7.6). Both of those give me authentication failure when passing a '*' in the command string. The endpoint I am testing is CloudPlatform 4.3.2 (with customisations). Can it be an issue for v4.3.2 but not in later version? I will investigate further and try to diagnose.

@yadvr
Copy link
Member

yadvr commented Jan 14, 2016

I've tried the update network API with ACS 4.5.2 and 4.7.0 and it works for me, so it could be a 4.3.2 related limitation. In that case, we can have this fix though in the request/response logged it made no difference with/without this fix irrespective of the ACS version (as logged in previous comments).

@yadvr
Copy link
Member

yadvr commented Apr 7, 2016

@phillipkent I hit this issue today, while passing an argument. this worked for me.

@asfgit asfgit merged commit 46b84a6 into apache:master Apr 7, 2016
asfgit pushed a commit that referenced this pull request Apr 7, 2016
Update requester.pyurllib.quote_plus() requires the option safe="*" (that is, the * character is not encoded) to be consistent with CloudStack's internal encoder/decoder. Without this, API calls containing the * character will fail API authentication.

* pr/11:
  Update requester.py

Signed-off-by: Rohit Yadav <[email protected]>
@phillipkent
Copy link
Contributor Author

@bhaisaab : Thanks!

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.

3 participants