summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2013-01-10 20:10:30 +0000
committerGerrit Code Review <review@openstack.org>2013-01-10 20:10:30 +0000
commit3d04363ba4b5955236c7067f14d9844cbabc248b (patch)
tree48b6152ae53e575057bafac7ccbd6d452d8a123c
parentab4282ebb4affe637187245fb9d01a64359f1233 (diff)
parent5edb40b44227a8a615a95bd565dd92ffbb3165c0 (diff)
downloadpython-swiftclient-3d04363ba4b5955236c7067f14d9844cbabc248b.tar.gz
Merge "Add env[SWIFTCLIENT_INSECURE]"
-rwxr-xr-xbin/swift11
-rw-r--r--swiftclient/utils.py28
-rw-r--r--tests/test_swiftclient.py20
3 files changed, 56 insertions, 3 deletions
diff --git a/bin/swift b/bin/swift
index 772c82e..6850de8 100755
--- a/bin/swift
+++ b/bin/swift
@@ -30,7 +30,7 @@ from time import sleep, time
from traceback import format_exception
from urllib import quote, unquote
-from swiftclient import Connection, ClientException, HTTPException
+from swiftclient import Connection, ClientException, HTTPException, utils
def get_conn(options):
@@ -1155,11 +1155,16 @@ Example:
help='Specify a CA bundle file to use in verifying a '
'TLS (https) server certificate. '
'Defaults to env[OS_CACERT]')
+ default_val = utils.config_true_value(
+ environ.get('SWIFTCLIENT_INSECURE'))
parser.add_option('--insecure',
- action="store_true", dest="insecure", default=False,
+ action="store_true", dest="insecure",
+ default=default_val,
help='Allow swiftclient to access insecure keystone '
'server. The keystone\'s certificate will not '
- 'be verified.')
+ 'be verified. '
+ 'Defaults to env[SWIFTCLIENT_INSECURE] '
+ '(set to \'true\' to enable).')
parser.disable_interspersed_args()
(options, args) = parse_args(parser, argv[1:], enforce_requires=False)
parser.enable_interspersed_args()
diff --git a/swiftclient/utils.py b/swiftclient/utils.py
new file mode 100644
index 0000000..f309d29
--- /dev/null
+++ b/swiftclient/utils.py
@@ -0,0 +1,28 @@
+# Copyright (c) 2010-2012 OpenStack, LLC.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""Miscellaneous utility functions for use with Swift."""
+
+TRUE_VALUES = set(('true', '1', 'yes', 'on', 't', 'y'))
+
+
+def config_true_value(value):
+ """
+ Returns True if the value is either True or a string in TRUE_VALUES.
+ Returns False otherwise.
+ This function come from swift.common.utils.config_true_value()
+ """
+ return value is True or \
+ (isinstance(value, basestring) and value.lower() in TRUE_VALUES)
diff --git a/tests/test_swiftclient.py b/tests/test_swiftclient.py
index 600efb0..8f147f8 100644
--- a/tests/test_swiftclient.py
+++ b/tests/test_swiftclient.py
@@ -23,6 +23,7 @@ from urlparse import urlparse
from utils import fake_http_connect, fake_get_keystoneclient_2_0
from swiftclient import client as c
+from swiftclient import utils as u
class TestClientException(testtools.TestCase):
@@ -93,6 +94,25 @@ class TestJsonImport(testtools.TestCase):
self.assertEquals(loads, c.json_loads)
+class TestConfigTrueValue(testtools.TestCase):
+
+ def test_TRUE_VALUES(self):
+ for v in u.TRUE_VALUES:
+ self.assertEquals(v, v.lower())
+
+ def test_config_true_value(self):
+ orig_trues = u.TRUE_VALUES
+ try:
+ u.TRUE_VALUES = 'hello world'.split()
+ for val in 'hello world HELLO WORLD'.split():
+ self.assertTrue(u.config_true_value(val) is True)
+ self.assertTrue(u.config_true_value(True) is True)
+ self.assertTrue(u.config_true_value('foo') is False)
+ self.assertTrue(u.config_true_value(False) is False)
+ finally:
+ u.TRUE_VALUES = orig_trues
+
+
class MockHttpTest(testtools.TestCase):
def setUp(self):