From c99c976881b8e41c4333dfbf2bbae8d5608b38e6 Mon Sep 17 00:00:00 2001 From: David Goetz Date: Thu, 14 Oct 2010 15:58:44 -0700 Subject: [PATCH] Refactor SWIFT_HASH_PATH_SUFFIX to be in a config file --- doc/source/development_saio.rst | 6 ++++++ etc/swift.conf-sample | 3 +++ swift/common/utils.py | 14 ++++++++++++-- 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 etc/swift.conf-sample diff --git a/doc/source/development_saio.rst b/doc/source/development_saio.rst index 17a443d692..bdb3a1daf1 100644 --- a/doc/source/development_saio.rst +++ b/doc/source/development_saio.rst @@ -199,6 +199,12 @@ virtual machine will emulate running a four node Swift cluster. [filter:cache] use = egg:swift#memcache + #. Create `/etc/swift/swift.conf`:: + + [swift-hash] + # random unique string that can never change (DO NOT LOSE) + swift_hash_path_suffix = changeme + #. Create `/etc/swift/account-server/1.conf`:: [DEFAULT] diff --git a/etc/swift.conf-sample b/etc/swift.conf-sample new file mode 100644 index 0000000000..7e1c31d26c --- /dev/null +++ b/etc/swift.conf-sample @@ -0,0 +1,3 @@ +[swift-hash] +swift_hash_path_suffix = changeme + diff --git a/swift/common/utils.py b/swift/common/utils.py index f8feb73968..f87a0d55d2 100644 --- a/swift/common/utils.py +++ b/swift/common/utils.py @@ -31,7 +31,7 @@ import ctypes import ctypes.util import fcntl import struct -from ConfigParser import ConfigParser +from ConfigParser import ConfigParser, NoSectionError, NoOptionError from tempfile import mkstemp import cPickle as pickle @@ -56,7 +56,17 @@ _posix_fadvise = None # Used by hash_path to offer a bit more security when generating hashes for # paths. It simply appends this value to all paths; guessing the hash a path # will end up with would also require knowing this suffix. -HASH_PATH_SUFFIX = os.environ.get('SWIFT_HASH_PATH_SUFFIX', 'endcap') +hash_conf = ConfigParser() +HASH_PATH_SUFFIX = None +if hash_conf.read('/etc/swift/swift.conf'): + try: + HASH_PATH_SUFFIX = hash_conf.get('swift-hash', + 'swift_hash_path_suffix') + except (NoSectionError, NoOptionError): + pass +if HASH_PATH_SUFFIX is None: + sys.exit("Error: [swift-hash]: swift_hash_path_suffix missing " + "from /etc/swift/swift.conf") # Used when reading config values TRUE_VALUES = set(('true', '1', 'yes', 'True', 'Yes', 'on', 'On'))