Commit bc2aac6d authored by Rafael Monnerat's avatar Rafael Monnerat

Add API for add specific Token

  Include the requestAddToken for include an specific token instead generate one.
  This API is only usable from localhost (like revoke) and it is required for SlapOS integration.

  The new entry --disable-token-by-maill is required to allow token generation and re6st be able to include more members
  without expose token generation publically.
parent 9e862353
......@@ -102,7 +102,8 @@ def main():
" 3=DEBUG, 4=TRACE. Use SIGUSR1 to reopen log.")
_('--min-protocol', default=version.min_protocol, type=int,
help="Reject nodes that are too old. Current is %s." % version.protocol)
_('--disable-token-by-mail', default=False, type=boolen,
help="Disable send new tokens by Mail.")
_ = parser.add_argument_group('routing').add_argument
_('--hello', type=int, default=15,
help="Hello interval in seconds, for both wired and wireless"
......
......@@ -237,7 +237,7 @@ class RegistryServer(object):
def handle_request(self, request, method, kw,
_localhost=('127.0.0.1', '::1')):
m = getattr(self, method)
if method in ('revoke', 'versions', 'topology'):
if method in ('revoke', 'versions', 'topology', 'requestAddToken'):
x_forwarded_for = request.headers.get('X-Forwarded-For')
if request.client_address[0] not in _localhost or \
x_forwarded_for and x_forwarded_for not in _localhost:
......@@ -291,14 +291,15 @@ class RegistryServer(object):
(client_prefix,)).next()[0]
@rpc
def requestToken(self, email):
def requestAddToken(self, email, token):
prefix_len = self.config.prefix_length
if not prefix_len:
raise HTTPError(httplib.FORBIDDEN)
with self.lock:
while True:
# Generating token
token = ''.join(random.sample(string.ascii_lowercase, 8))
if token is None:
token = ''.join(random.sample(string.ascii_lowercase, 8))
args = token, email, prefix_len, int(time.time())
# Updating database
try:
......@@ -308,6 +309,15 @@ class RegistryServer(object):
pass
self.timeout = 1
return token
@rpc
def requestToken(self, email):
if self.config.disable_token_by_mail:
raise HTTPError(httplib.FORBIDDEN)
token = self.requestAddToken(email, None)
# Creating and sending email
msg = MIMEText('Hello, your token to join re6st network is: %s\n'
% token)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment