Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleksey Lim <alsroot@sugarlabs.org>2012-08-16 13:29:04 (GMT)
committer Aleksey Lim <alsroot@sugarlabs.org>2012-08-16 13:29:04 (GMT)
commit887a3011a17ee44b94a88c6e15dfc5e0259215ac (patch)
tree23993f47ea59d27db79ab9b72a4f5642f9e48fe5
parent08ca6835ce085f0d34d18a88238da1bee531af60 (diff)
Implement anonymous mode to not depend on sugar user existance
-rwxr-xr-xsugar-network-service11
-rw-r--r--sugar_network/local/__init__.py5
-rw-r--r--sugar_network/node/commands.py3
-rw-r--r--sugar_network/toolkit/http.py7
4 files changed, 19 insertions, 7 deletions
diff --git a/sugar-network-service b/sugar-network-service
index d9d6890..4fe474b 100755
--- a/sugar-network-service
+++ b/sugar-network-service
@@ -149,11 +149,16 @@ class Application(application.Application):
name='start', keep_stdout=True)
def _start(self, minimal=False):
if self.check_for_instance():
- printf.info('%s is not run', self.name)
+ printf.info('%s is already run', self.name)
exit(1)
- # In case if it is new Sugar Shell profile
- toolkit.ensure_dsa_pubkey(sugar.profile_path('owner.key'))
+ if local.anonymous.value:
+ sugar.uid = lambda: 'anonymous'
+ sugar.nickname = lambda: 'anonymous'
+ sugar.color = lambda: '#000000,#000000'
+ else:
+ # In case if it is new Sugar Shell profile
+ toolkit.ensure_dsa_pubkey(sugar.profile_path('owner.key'))
jobs = coroutine.Pool()
diff --git a/sugar_network/local/__init__.py b/sugar_network/local/__init__.py
index 9395689..36ed8df 100644
--- a/sugar_network/local/__init__.py
+++ b/sugar_network/local/__init__.py
@@ -69,6 +69,11 @@ tmpdir = Option(
'if specified, use this directory for temporary files, such files '
'might take hunder of megabytes while node synchronizing')
+anonymous = Option(
+ 'use anonymous user to access to Sugar Network server; '
+ 'only read-only operations are available in this mode',
+ default=False, type_cast=Option.bool_cast, action='store_true')
+
def path(*args):
"""Calculate a path from the root.
diff --git a/sugar_network/node/commands.py b/sugar_network/node/commands.py
index 617ab63..4a34dc7 100644
--- a/sugar_network/node/commands.py
+++ b/sugar_network/node/commands.py
@@ -67,8 +67,7 @@ class NodeCommands(ad.VolumeCommands):
'seqno': self.volume.seqno.value,
}
- @ad.volume_command(method='POST', cmd='subscribe',
- permissions=ad.ACCESS_AUTH)
+ @ad.volume_command(method='POST', cmd='subscribe')
def subscribe(self):
enforce(self._subscriber is not None, 'Subscription is disabled')
return self._subscriber.new_ticket()
diff --git a/sugar_network/toolkit/http.py b/sugar_network/toolkit/http.py
index 1c14cbf..3efee83 100644
--- a/sugar_network/toolkit/http.py
+++ b/sugar_network/toolkit/http.py
@@ -32,6 +32,7 @@ from sweets_recipe import Bundle
from active_toolkit.sockets import decode_multipart, BUFFER_SIZE
from sugar_network.toolkit import sugar
from sugar_network import local
+from active_toolkit import enforce
# Let toolkit.http work in concurrence
# TODO Is it safe for the rest of code?
@@ -134,9 +135,9 @@ def _request(method, path, data=None, headers=None, allowed_response=None,
verify = local.certfile.value
headers = None
- key_path = sugar.profile_path('owner.key')
- if exists(key_path):
+ if not local.anonymous.value:
uid = sugar.uid()
+ key_path = sugar.profile_path('owner.key')
headers = {
'sugar_user': uid,
'sugar_user_signature': _sign(key_path, uid),
@@ -163,6 +164,8 @@ def _request(method, path, data=None, headers=None, allowed_response=None,
if response.status_code != 200:
if response.status_code == 401:
+ enforce(not local.anonymous.value,
+ 'Operation is not available in anonymous mode')
_logger.info('User is not registered on the server, '
'registering')
_register()