This repository was archived by the owner on Feb 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcurl_interpreter.py
More file actions
329 lines (312 loc) · 14.1 KB
/
Copy pathcurl_interpreter.py
File metadata and controls
329 lines (312 loc) · 14.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "copyright", "credits" or "license()" for more information.
>>>
>>> cmd = ['curl']
>>>
>>> cmd.append('--insecure')
>>> cmd
['curl', '--insecure']
>>> cmd.append('-X', 'PUT')
Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
cmd.append('-X', 'PUT')
TypeError: append() takes exactly one argument (2 given)
>>> cmd.extend(['-X', 'PUT'])
>>> cmd
['curl', '--insecure', '-X', 'PUT']
>>>
>>> cmd= ['curl']
>>> cmd.extend([
'-i',
'-H',
"Content-Type: application/json",
'-d'
})
SyntaxError: invalid syntax
>>> cmd.extend([
'-i',
'-H',
"Content-Type: application/json",
'-d'
])
>>> cmd
['curl', '-i', '-H', 'Content-Type: application/json', '-d']
>>> data = '{ "auth": {
"identity": {
"methods": ["password"],
"password": {
"user": {
"name": "admin",
"domain": { "id": "default" },
"password": "nomoresecrete"
}
}
}
}
}'
SyntaxError: EOL while scanning string literal
>>> data = """
{ "auth": {
"identity": {
"methods": ["password"],
"password": {
"user": {
"name": "admin",
"domain": { "id": "default" },
"password": "nomoresecrete"
}
}
}
}
}
"""
>>> data
'\n{ "auth": {\n "identity": {\n "methods": ["password"],\n "password": {\n "user": {\n "name": "admin",\n "domain": { "id": "default" },\n "password": "nomoresecrete"\n }\n }\n }\n }\n}\n'
>>>
>>>
>>> data = { "auth": {"identity": {"methods": "["password"],
SyntaxError: invalid syntax
>>> data = { "auth": {"identity": {"methods": ["password"],
"password": {
"user": {
"name": "admin",
"domain": {"id": "default"},
"password": "nomoresecrete"
}
}
}
}
}
>>> data
{'auth': {'identity': {'password': {'user': {'domain': {'id': 'default'}, 'password': 'nomoresecrete', 'name': 'admin'}}, 'methods': ['password']}}}
>>>
>>> cmd
['curl', '-i', '-H', 'Content-Type: application/json', '-d']
>>> import json
>>> s=json.dumps(data)
>>> s
'{"auth": {"identity": {"password": {"user": {"domain": {"id": "default"}, "password": "nomoresecrete", "name": "admin"}}, "methods": ["password"]}}}'
>>>
>>> cmd.append(s)
>>> cms
Traceback (most recent call last):
File "<pyshell#46>", line 1, in <module>
cms
NameError: name 'cms' is not defined
>>> cmd
['curl', '-i', '-H', 'Content-Type: application/json', '-d', '{"auth": {"identity": {"password": {"user": {"domain": {"id": "default"}, "password": "nomoresecrete", "name": "admin"}}, "methods": ["password"]}}}']
>>>
>>> url='http://localhost:5000/v3/auth/tokens'
>>> cmd.append(url)
>>>
>>> cmd
['curl', '-i', '-H', 'Content-Type: application/json', '-d', '{"auth": {"identity": {"password": {"user": {"domain": {"id": "default"}, "password": "nomoresecrete", "name": "admin"}}, "methods": ["password"]}}}', 'http://localhost:5000/v3/auth/tokens']
>>>
>>> import subprocess
>>> sub = subprocess.Po
Traceback (most recent call last):
File "<pyshell#55>", line 1, in <module>
sub = subprocess.Po
AttributeError: 'module' object has no attribute 'Po'
>>> sub = subprocess.Popen(cmd, stdout=subprocess.PIPE, stder=subprocess.PIPE)
Traceback (most recent call last):
File "<pyshell#56>", line 1, in <module>
sub = subprocess.Popen(cmd, stdout=subprocess.PIPE, stder=subprocess.PIPE)
TypeError: __init__() got an unexpected keyword argument 'stder'
>>> sub = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
>>> output = sub.communicate()
>>> print output[0]
HTTP/1.1 201 Created
Date: Fri, 04 Sep 2015 03:24:25 GMT
Server: Apache/2.4.7 (Ubuntu)
X-Subject-Token: aa6acadf262944dcb0314b951344fc43
Vary: X-Auth-Token
x-openstack-request-id: req-f86c8c4e-5aa8-4eb6-b500-8873022c68b6
Content-Length: 297
Content-Type: application/json
{"token": {"methods": ["password"], "expires_at": "2015-09-04T04:24:25.347509Z", "extras": {}, "user": {"domain": {"id": "default", "name": "Default"}, "id": "36be4c8e3bc844d785820467aa1ca744", "name": "admin"}, "audit_ids": ["UxjXbn9WRISahQF5n_qo6Q"], "issued_at": "2015-09-04T03:24:25.347557Z"}}
>>> print output[1]
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0100 445 100 297 100 148 2610 1300 --:--:-- --:--:-- --:--:-- 2628
>>> cmd
['curl', '-i', '-H', 'Content-Type: application/json', '-d', '{"auth": {"identity": {"password": {"user": {"domain": {"id": "default"}, "password": "nomoresecrete", "name": "admin"}}, "methods": ["password"]}}}', 'http://localhost:5000/v3/auth/tokens']
>>> cmd1=['curl']
>>> cmd1.append('--insecure')
>>> cmd1.extend([
'-i',
'-H',
'Content-Type:',
'-d',
s,
url
])
>>> cmd
['curl', '-i', '-H', 'Content-Type: application/json', '-d', '{"auth": {"identity": {"password": {"user": {"domain": {"id": "default"}, "password": "nomoresecrete", "name": "admin"}}, "methods": ["password"]}}}', 'http://localhost:5000/v3/auth/tokens']
>>> cmd1
['curl', '--insecure', '-i', '-H', 'Content-Type:', '-d', '{"auth": {"identity": {"password": {"user": {"domain": {"id": "default"}, "password": "nomoresecrete", "name": "admin"}}, "methods": ["password"]}}}', 'http://localhost:5000/v3/auth/tokens']
>>> cm1 == cmd
Traceback (most recent call last):
File "<pyshell#74>", line 1, in <module>
cm1 == cmd
NameError: name 'cm1' is not defined
>>> cmd1 == cmd
False
>>> sub = subprocess.Popen(cmd1, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
>>> output = sub.communicate()
>>> print output[0]
HTTP/1.1 201 Created
Date: Fri, 04 Sep 2015 03:29:40 GMT
Server: Apache/2.4.7 (Ubuntu)
X-Subject-Token: 3b44be9d231e47439f56c3c2bace2760
Vary: X-Auth-Token
x-openstack-request-id: req-6f1676b3-0efe-4414-b3a7-e1f0fa28f2fb
Content-Length: 297
Content-Type: application/json
{"token": {"methods": ["password"], "expires_at": "2015-09-04T04:29:40.206107Z", "extras": {}, "user": {"domain": {"id": "default", "name": "Default"}, "id": "36be4c8e3bc844d785820467aa1ca744", "name": "admin"}, "audit_ids": ["2YwwL3FsS3mJ-tulBm6uDw"], "issued_at": "2015-09-04T03:29:40.206176Z"}}
>>>
>>>
>>> print "%s" % cmd1
['curl', '--insecure', '-i', '-H', 'Content-Type:', '-d', '{"auth": {"identity": {"password": {"user": {"domain": {"id": "default"}, "password": "nomoresecrete", "name": "admin"}}, "methods": ["password"]}}}', 'http://localhost:5000/v3/auth/tokens']
>>>
>>> cmd1=['curl']
>>> cmd1.append('--insecure')
>>> cmd1.extend([
'-i',
'-H',
'-d',
s,
url
])
>>>
>>> sub = subprocess.Popen(cmd1, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
>>> output = sub.communicate()
>>> print output[0]
HTTP/1.1 401 Unauthorized
Date: Fri, 04 Sep 2015 03:33:14 GMT
Server: Apache/2.4.7 (Ubuntu)
Vary: X-Auth-Token
x-openstack-request-id: req-69b7a3ea-7585-4a79-83a0-770803608ddc
WWW-Authenticate: Keystone uri="http://localhost:5000"
Content-Length: 162
Content-Type: application/json
{"error": {"message": "The request you have made requires authentication. (Disable debug mode to suppress these details.)", "code": 401, "title": "Unauthorized"}}
>>> cmd1
['curl', '--insecure', '-i', '-H', '-d', '{"auth": {"identity": {"password": {"user": {"domain": {"id": "default"}, "password": "nomoresecrete", "name": "admin"}}, "methods": ["password"]}}}', 'http://localhost:5000/v3/auth/tokens']
>>> cmd1=['curl']
>>> cmd1.extend([
'-i',
'-H',
'Content-Type',
'-d',
s,
url
])
>>> sub = subprocess.Popen(cmd1, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
>>> output = sub.communicate()
>>> print output[0]
HTTP/1.1 400 Bad Request
Date: Fri, 04 Sep 2015 03:35:14 GMT
Server: Apache/2.4.7 (Ubuntu)
Vary: X-Auth-Token
x-openstack-request-id: req-9a19436e-07e7-414f-af2b-51de195904f9
Content-Length: 258
Connection: close
Content-Type: application/json
{"error": {"message": "Expecting to find application/json in Content-Type header - the server could not comply with the request since it is either malformed or otherwise incorrect. The client is assumed to be in error.", "code": 400, "title": "Bad Request"}}
>>> cmd1
['curl', '-i', '-H', 'Content-Type', '-d', '{"auth": {"identity": {"password": {"user": {"domain": {"id": "default"}, "password": "nomoresecrete", "name": "admin"}}, "methods": ["password"]}}}', 'http://localhost:5000/v3/auth/tokens']
>>> ['curl', '-i', '-H', 'Content-Type: application/json', '-d', '{"auth": {"identity": {"password": {"user": {"domain": {"id": "default"}, "password": "nomoresecrete", "name": "admin"}}, "methods": ["password"]}}}', 'http://localhost:5000/v3/auth/tokens']
['curl', '-i', '-H', 'Content-Type: application/json', '-d', '{"auth": {"identity": {"password": {"user": {"domain": {"id": "default"}, "password": "nomoresecrete", "name": "admin"}}, "methods": ["password"]}}}', 'http://localhost:5000/v3/auth/tokens']
>>>
>>> cmd1=['curl']
>>> cmd1.extend([
'-i',
'-H',
'Content-Type:',
'-d',
s,
url
])
>>> s
'{"auth": {"identity": {"password": {"user": {"domain": {"id": "default"}, "password": "nomoresecrete", "name": "admin"}}, "methods": ["password"]}}}'
>>> url
'http://localhost:5000/v3/auth/tokens'
>>> sub = subprocess.Popen(cmd1, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
>>> o = sub.communicate()
>>> print o[0]
HTTP/1.1 201 Created
Date: Fri, 04 Sep 2015 03:37:26 GMT
Server: Apache/2.4.7 (Ubuntu)
X-Subject-Token: 9abcbb7fcef8400d9177daed2ae52c55
Vary: X-Auth-Token
x-openstack-request-id: req-b9c18dff-9c00-40fd-904a-d98a287c9b19
Content-Length: 297
Content-Type: application/json
{"token": {"methods": ["password"], "expires_at": "2015-09-04T04:37:26.222261Z", "extras": {}, "user": {"domain": {"id": "default", "name": "Default"}, "id": "36be4c8e3bc844d785820467aa1ca744", "name": "admin"}, "audit_ids": ["nOlC3ZgkTfuyPkcNACPnXg"], "issued_at": "2015-09-04T03:37:26.222297Z"}}
>>> cmd1
['curl', '-i', '-H', 'Content-Type:', '-d', '{"auth": {"identity": {"password": {"user": {"domain": {"id": "default"}, "password": "nomoresecrete", "name": "admin"}}, "methods": ["password"]}}}', 'http://localhost:5000/v3/auth/tokens']
>>> cmd = 'curl -i -H Content-Type: -d %s %s' % s, url
Traceback (most recent call last):
File "<pyshell#107>", line 1, in <module>
cmd = 'curl -i -H Content-Type: -d %s %s' % s, url
TypeError: not enough arguments for format string
>>> cmd = 'curl -i -H Content-Type: -d %s %s' % (s, url)
>>> cmd
'curl -i -H Content-Type: -d {"auth": {"identity": {"password": {"user": {"domain": {"id": "default"}, "password": "nomoresecrete", "name": "admin"}}, "methods": ["password"]}}} http://localhost:5000/v3/auth/tokens'
>>> sub = subprocess.Popen(cmd1, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
>>> o = sub.communicate()
>>> o[0]
'HTTP/1.1 201 Created\r\nDate: Fri, 04 Sep 2015 03:48:01 GMT\r\nServer: Apache/2.4.7 (Ubuntu)\r\nX-Subject-Token: 90686608d2954e158e73847f192c1550\r\nVary: X-Auth-Token\r\nx-openstack-request-id: req-daa69744-41d3-44ef-8a07-1099bcce3398\r\nContent-Length: 297\r\nContent-Type: application/json\r\n\r\n{"token": {"methods": ["password"], "expires_at": "2015-09-04T04:48:01.779563Z", "extras": {}, "user": {"domain": {"id": "default", "name": "Default"}, "id": "36be4c8e3bc844d785820467aa1ca744", "name": "admin"}, "audit_ids": ["vsjfLfH7TuSLxBED2VlJwg"], "issued_at": "2015-09-04T03:48:01.779616Z"}}'
>>> print o[0]
HTTP/1.1 201 Created
Date: Fri, 04 Sep 2015 03:48:01 GMT
Server: Apache/2.4.7 (Ubuntu)
X-Subject-Token: 90686608d2954e158e73847f192c1550
Vary: X-Auth-Token
x-openstack-request-id: req-daa69744-41d3-44ef-8a07-1099bcce3398
Content-Length: 297
Content-Type: application/json
{"token": {"methods": ["password"], "expires_at": "2015-09-04T04:48:01.779563Z", "extras": {}, "user": {"domain": {"id": "default", "name": "Default"}, "id": "36be4c8e3bc844d785820467aa1ca744", "name": "admin"}, "audit_ids": ["vsjfLfH7TuSLxBED2VlJwg"], "issued_at": "2015-09-04T03:48:01.779616Z"}}
>>> cmd_str = ("curl -i -H \'Content-Type:\' -d \'%s\' \"%s\"" % (s, url))
>>> cmd_str
'curl -i -H \'Content-Type:\' -d \'{"auth": {"identity": {"password": {"user": {"domain": {"id": "default"}, "password": "nomoresecrete", "name": "admin"}}, "methods": ["password"]}}}\' "http://localhost:5000/v3/auth/tokens"'
>>>
>>> cmd = cmd_str.split()
>>> cmd
['curl', '-i', '-H', "'Content-Type:'", '-d', '\'{"auth":', '{"identity":', '{"password":', '{"user":', '{"domain":', '{"id":', '"default"},', '"password":', '"nomoresecrete",', '"name":', '"admin"}},', '"methods":', '["password"]}}}\'', '"http://localhost:5000/v3/auth/tokens"']
>>>
>>> sub = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
>>> o = sub.communicate()
Traceback (most recent call last):
File "<pyshell#121>", line 1, in <module>
o = sub.communicate()
File "/usr/lib/python2.7/subprocess.py", line 799, in communicate
return self._communicate(input)
File "/usr/lib/python2.7/subprocess.py", line 1401, in _communicate
stdout, stderr = self._communicate_with_poll(input)
File "/usr/lib/python2.7/subprocess.py", line 1455, in _communicate_with_poll
ready = poller.poll()
TypeError: 'int' object is not callable
>>>
>>> cmd_str = ("curl -i -H Content-Type: -d %s %s" % (s, url))
>>> cmd = cmd_str.split()
>>> sub = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
>>> o = sub.communicate()
Traceback (most recent call last):
File "<pyshell#126>", line 1, in <module>
o = sub.communicate()
File "/usr/lib/python2.7/subprocess.py", line 799, in communicate
return self._communicate(input)
File "/usr/lib/python2.7/subprocess.py", line 1401, in _communicate
stdout, stderr = self._communicate_with_poll(input)
File "/usr/lib/python2.7/subprocess.py", line 1455, in _communicate_with_poll
ready = poller.poll()
TypeError: 'int' object is not callable
>>>
>>> cmd
['curl', '-i', '-H', 'Content-Type:', '-d', '{"auth":', '{"identity":', '{"password":', '{"user":', '{"domain":', '{"id":', '"default"},', '"password":', '"nomoresecrete",', '"name":', '"admin"}},', '"methods":', '["password"]}}}', 'http://localhost:5000/v3/auth/tokens']
>>>
>>>