Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

arc: enable password-based authentication #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions arc/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,18 @@ def get_username(self):
value = getpass.getuser()
return value

def get_password(self):
"""
Returns the password to login
"""
if os.environ.has_key('ARC_PASSWORD'):
value = os.environ['ARC_PASSWORD']
elif self.has_option('server', 'password'):
value = self.get('server', 'password')
else:
value = getpass.getpass()
return value


Config = UserLocalConfigParser
CONFIG = None
Expand Down
10 changes: 8 additions & 2 deletions arc/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import arc.proxy
import arc.shared.frontend
import arc.shared.rpc
import base64


__all__ = ['get_default', 'Connection']
Expand Down Expand Up @@ -73,7 +74,7 @@ class BaseConnection(object):
Base RPC connection
"""

def __init__(self, hostname=None, port=None, path=None, username=None):
def __init__(self, hostname=None, port=None, path=None, username=None, password=None):
"""
Initializes a connection to an empty path

Expand All @@ -94,6 +95,10 @@ def __init__(self, hostname=None, port=None, path=None, username=None):
username = arc.config.get_default().get_username()
self.username = username

if password is None:
password = arc.config.get_default().get_password()
self.password = password

self.services = {}
self.service_proxies = {}
self.service_interface_versions = {}
Expand All @@ -111,7 +116,8 @@ def _connect(self, path, username):
:param username: the username to login
"""
rpc_uri = "http://%s:%s/%s" % (self.hostname, self.port, path)
headers = {'AUTHORIZATION': username}
base64string = base64.encodestring('%s:%s' % (self.username, self.password))[:-1]
headers = {'AUTHORIZATION': 'Basic %s' % base64string}
return arc.proxy.Proxy(rpc_uri, headers)

def run(self, service, operation, *args, **data):
Expand Down