summaryrefslogtreecommitdiff
path: root/oslo_policy/_checks.py
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@yahoo-inc.com>2015-09-21 18:27:42 -0700
committerJoshua Harlow <harlowja@yahoo-inc.com>2015-09-22 16:29:00 -0700
commit70675997e1a7669564912250fde5c35ea2c0a0f8 (patch)
tree35a8c4e310000820817efc516d42884e95639fad /oslo_policy/_checks.py
parent4e2004ec037e9989b7a73524fc73cbd04ea0351c (diff)
downloadoslo-policy-70675997e1a7669564912250fde5c35ea2c0a0f8.tar.gz
Use requests in http check instead of urllib
The requests interface is much nicer and easier to use so we might as well use it instead of direct urllib usage. Change-Id: I364ddb5f86900a3e166f4480d9f4889a68de247f
Diffstat (limited to 'oslo_policy/_checks.py')
-rw-r--r--oslo_policy/_checks.py11
1 files changed, 5 insertions, 6 deletions
diff --git a/oslo_policy/_checks.py b/oslo_policy/_checks.py
index b011294..16b665a 100644
--- a/oslo_policy/_checks.py
+++ b/oslo_policy/_checks.py
@@ -14,14 +14,15 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
+
import abc
import ast
+import contextlib
import copy
from oslo_serialization import jsonutils
+import requests
import six
-import six.moves.urllib.parse as urlparse
-import six.moves.urllib.request as urlrequest
registered_checks = {}
@@ -268,12 +269,10 @@ class HttpCheck(Check):
element = target.get(key)
if type(element) is object:
temp_target[key] = {}
-
data = {'target': jsonutils.dumps(temp_target),
'credentials': jsonutils.dumps(creds)}
- post_data = urlparse.urlencode(data)
- f = urlrequest.urlopen(url, post_data)
- return f.read() == 'True'
+ with contextlib.closing(requests.post(url, data=data)) as r:
+ return r.text == 'True'
@register(None)