diff options
-rwxr-xr-x | bin/swift | 11 | ||||
-rw-r--r-- | swiftclient/utils.py | 28 | ||||
-rw-r--r-- | tests/test_swiftclient.py | 20 |
3 files changed, 56 insertions, 3 deletions
@@ -29,7 +29,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): @@ -1151,11 +1151,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): |