Refactor SWIFT_HASH_PATH_SUFFIX to be in a config file

This commit is contained in:
David Goetz 2010-10-14 15:58:44 -07:00
parent 2a0f3f8c4b
commit c99c976881
3 changed files with 21 additions and 2 deletions

View File

@ -199,6 +199,12 @@ virtual machine will emulate running a four node Swift cluster.
[filter:cache] [filter:cache]
use = egg:swift#memcache 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`:: #. Create `/etc/swift/account-server/1.conf`::
[DEFAULT] [DEFAULT]

3
etc/swift.conf-sample Normal file
View File

@ -0,0 +1,3 @@
[swift-hash]
swift_hash_path_suffix = changeme

View File

@ -31,7 +31,7 @@ import ctypes
import ctypes.util import ctypes.util
import fcntl import fcntl
import struct import struct
from ConfigParser import ConfigParser from ConfigParser import ConfigParser, NoSectionError, NoOptionError
from tempfile import mkstemp from tempfile import mkstemp
import cPickle as pickle 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 # 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 # paths. It simply appends this value to all paths; guessing the hash a path
# will end up with would also require knowing this suffix. # 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 # Used when reading config values
TRUE_VALUES = set(('true', '1', 'yes', 'True', 'Yes', 'on', 'On')) TRUE_VALUES = set(('true', '1', 'yes', 'True', 'Yes', 'on', 'On'))