Merge "Add env[SWIFTCLIENT_INSECURE]"

This commit is contained in:
Jenkins 2013-01-10 20:10:30 +00:00 committed by Gerrit Code Review
commit 3d04363ba4
3 changed files with 56 additions and 3 deletions

@ -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()

28
swiftclient/utils.py Normal file

@ -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)

@ -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):