Skip to content
Browse files

Support authurl per container in secrets.conf

  • Loading branch information...
1 parent a11290e commit b910a289e169272d6fa3db31eca4ec0fcac38310 @reidrac committed Jan 3, 2013
Showing with 25 additions and 12 deletions.
  1. +2 −0 secrets.conf.example
  2. +5 −2 swiftnbd/common.py
  3. +9 −5 swiftnbd/main.py
  4. +9 −5 swiftnbd/setup.py
View
2 secrets.conf.example
@@ -6,4 +6,6 @@
[container_name]
username = user
password = pass
+# optional, otherwise default authurl is used
+# authurl = https://hostname/v1.0
View
7 swiftnbd/common.py
@@ -41,13 +41,16 @@ def getSecrets(container, secrets_file):
log = logging.getLogger(__package__)
log.warning("%s is world readable, please consider changing its permissions to 0600" % secrets_file)
- conf = RawConfigParser(dict(username=None, password=None))
+ conf = RawConfigParser(dict(username=None, password=None, authurl=None))
conf.read(secrets_file)
if not conf.has_section(container):
raise ValueError("%s not found in %s" % (container, secrets_file))
- return (conf.get(container, 'username'), conf.get(container, 'password'))
+ return (conf.get(container, 'username'),
+ conf.get(container, 'password'),
+ conf.get(container, 'authurl'),
+ )
def setLog(debug=False, use_syslog=False, use_file=None):
"""Setup logger"""
View
14 swiftnbd/main.py
@@ -25,6 +25,7 @@
import os
import sys
import signal
+import socket
import tempfile
from argparse import ArgumentParser
@@ -57,7 +58,7 @@ def __init__(self):
parser.add_argument("-a", "--auth-url", dest="authurl",
default=auth_url,
- help="authentication URL (default: %s)" % auth_url)
+ help="default authentication URL (default: %s)" % auth_url)
parser.add_argument("-b", "--bind-address", dest="bind_address",
default="127.0.0.1",
@@ -108,22 +109,25 @@ def __init__(self):
self.log.debug(dict((k, v) for k, v in vars(self.args).iteritems() if k != "password"))
try:
- self.username, self.password = getSecrets(self.args.container, self.args.secrets_file)
+ self.username, self.password, self.authurl = getSecrets(self.args.container, self.args.secrets_file)
except ValueError as ex:
parser.error(ex)
+ if self.authurl is None:
+ self.authurl = self.args.authurl
+
def run(self):
if os.path.isfile(self.args.pidfile):
self.log.error("%s found: is the server already running?" % self.args.pidfile)
return 1
- cli = client.Connection(self.args.authurl, self.username, self.password)
+ cli = client.Connection(self.authurl, self.username, self.password)
try:
headers, _ = cli.get_container(self.args.container)
- except client.ClientException as ex:
- if ex.http_status == 404:
+ except (socket.error, client.ClientException) as ex:
+ if getattr(ex, 'http_status', None) == 404:
self.log.error("%s doesn't exist" % self.args.container)
else:
self.log.error(ex)
View
14 swiftnbd/setup.py
@@ -22,6 +22,7 @@
THE SOFTWARE.
"""
+import socket
from argparse import ArgumentParser
from swiftclient import client
@@ -46,7 +47,7 @@ def __init__(self):
parser.add_argument("-a", "--auth-url", dest="authurl",
default=auth_url,
- help="authentication URL (default: %s)" % auth_url)
+ help="default authentication URL (default: %s)" % auth_url)
parser.add_argument("--object-size", dest="object_size",
default=object_size,
@@ -67,18 +68,21 @@ def __init__(self):
self.log.debug(dict((k, v) for k, v in vars(self.args).iteritems() if k != "password"))
try:
- self.username, self.password = getSecrets(self.args.container, self.args.secrets_file)
+ self.username, self.password, self.authurl = getSecrets(self.args.container, self.args.secrets_file)
except ValueError as ex:
parser.error(ex)
+ if self.authurl is None:
+ self.authurl = self.args.authurl
+
def run(self):
- cli = client.Connection(self.args.authurl, self.username, self.password)
+ cli = client.Connection(self.authurl, self.username, self.password)
try:
headers, _ = cli.get_container(self.args.container)
- except client.ClientException as ex:
- if ex.http_status == 404:
+ except (socket.error, client.ClientException) as ex:
+ if getattr(ex, 'http_status', None) == 404:
self.log.debug("%s doesn't exist, will be created" % self.args.container)
else:
self.log.error(ex)

0 comments on commit b910a28

Please sign in to comment.
Something went wrong with that request. Please try again.