Index: remoting/tools/me2me_virtual_host.py |
diff --git a/remoting/tools/me2me_virtual_host.py b/remoting/tools/me2me_virtual_host.py |
index b9d072679bd42a6710f505b1ee0fb9e53e25bd67..5004ce0d59824f7796a336f62e16ceddfb2a4ebd 100755 |
--- a/remoting/tools/me2me_virtual_host.py |
+++ b/remoting/tools/me2me_virtual_host.py |
@@ -129,7 +129,9 @@ class Authentication: |
"""Manage authentication tokens for Chromoting/xmpp""" |
def __init__(self): |
- pass |
+ self.chromoting_auth_token = None |
+ self.login = None |
+ self.xmpp_auth_token = None |
def generate_tokens(self): |
"""Prompt for username/password and use them to generate new authentication |
@@ -150,11 +152,22 @@ class Authentication: |
self.xmpp_auth_token = xmpp_authenticator.authenticate(self.login, |
password) |
+ def has_chromoting_token(self): |
+ return self.chromoting_auth_token != None |
+ |
+ def has_xmpp_token(self): |
+ # XMPP connection can be authenticated using either OAuth or XMPP token. |
+ return self.oauth_refresh_token != None or self.xmpp_auth_token != None |
+ |
def load_config(self, config): |
+ # Only some of the auth tokens may be present in the config. We still |
+ # consider config to be valid in this case. |
Jamie
2012/08/13 23:44:31
I'm not a Python expert--I take it .get doesn't th
Lambros
2012/08/14 01:07:44
That is correct, get(key) returns None if the key
Sergey Ulanov
2012/08/14 18:00:37
Done.
|
+ self.chromoting_auth_token = config.get("chromoting_auth_token") |
+ self.oauth_refresh_token = config.get("oauth_refresh_token") |
+ self.xmpp_auth_token = config.get("xmpp_auth_token") |
+ |
try: |
self.login = config["xmpp_login"] |
- self.chromoting_auth_token = config["chromoting_auth_token"] |
- self.xmpp_auth_token = config["xmpp_auth_token"] |
except KeyError: |
return False |
return True |
@@ -661,6 +674,8 @@ def main(): |
parser.add_option("", "--silent", dest="silent", default=False, |
action="store_true", |
help="Start the host without trying to configure it.") |
+ parser.add_option("", "--reload", dest="reload", default=False, |
+ action="store_true", help="Reload the config.") |
Lambros
2012/08/14 01:07:44
Clarify: "Reload the config of the currently-runni
|
(options, args) = parser.parse_args() |
host_hash = hashlib.md5(socket.gethostname()).hexdigest() |
@@ -679,6 +694,13 @@ def main(): |
os.kill(pid, signal.SIGTERM) |
return 0 |
+ if options.reload: |
+ running, pid = PidFile(pid_filename).check() |
+ if not running: |
+ return 1 |
+ os.kill(pid, signal.SIGUSR1) |
+ return 0 |
+ |
if not options.size: |
options.size = [DEFAULT_SIZE] |
@@ -743,11 +765,15 @@ def main(): |
host_config_loaded = host.load_config(host_config) |
if options.silent: |
+ # Just validate the config when run with --silent. |
if not host_config_loaded or not auth_config_loaded: |
logging.error("Failed to load host configuration.") |
return 1 |
+ if not auth.has_xmpp_token(): |
+ logging.error("Auth tokens are not configured.") |
Jamie
2012/08/13 23:44:31
In a previous comment, you state that we can use e
Lambros
2012/08/14 01:07:44
+1 It's not clear to me what's going on here. The
Sergey Ulanov
2012/08/14 18:00:37
The host needs tokens to authenticate XMPP connect
Sergey Ulanov
2012/08/14 18:00:37
has_xmpp_token() returns true if we have any types
|
+ return 1 |
else: |
- need_auth_tokens = not auth_config_loaded |
+ need_auth_tokens = not auth_config_loaded or not auth.has_chromoting_token() |
need_register_host = not host_config_loaded |
# Outside the loop so user doesn't get asked twice. |
if need_register_host: |