Skip to content
Browse files

quota limits added to cumulus. First round of tests pass, more tests …

…coming soon
  • Loading branch information...
1 parent b6b71d2 commit db231560bb1dcb7932a1ae0f2ae2a2fe63af444b BuzzTroll committed with timf May 27, 2010
View
2 .idea/workspace.xml
@@ -836,7 +836,7 @@
<servers />
</component>
<component name="ToolWindowManager">
- <frame x="0" y="26" width="1400" height="998" extended-state="1" />
+ <frame x="0" y="26" width="1400" height="998" extended-state="0" />
<editor active="true" />
<layout>
<window_info id="Changes" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
View
4 cumulus/etc/acl.sql
@@ -44,8 +44,8 @@ create table users_canonical(
friendly_name varchar(64) UNIQUE
);
-insert into users_canonical(id, friendly_name) values ('CumulusPublicUser', 'CumulusPublicUser');
-insert into users_canonical(id, friendly_name) values ('CumulusAuthenticatedUser', 'CumulusAuthenticatedUser');
+-- insert into users_canonical(id, friendly_name) values ('CumulusPublicUser', 'CumulusPublicUser');
+-- insert into users_canonical(id, friendly_name) values ('CumulusAuthenticatedUser', 'CumulusAuthenticatedUser');
-- user_alias_types
-- ================
-- vairous types of user identifications mechanisms:
View
11 cumulus/pycb/cbAuthzSecurity.py
@@ -74,6 +74,10 @@ def get_uf(self, bucketName, objectName=None):
uf = UserFile(file, self.user)
return uf
+ def set_quota(self, max):
+ self.user.set_quota(max)
+ self.db_obj.commit()
+
# return the permission string of the given object
def get_perms(self, bucketName, objectName=None):
global authed_user
@@ -161,6 +165,13 @@ def get_info(self, bucketName, objectName=None):
finally:
self.db_obj.commit()
+ def get_remaining_quota(self):
+ quota = self.user.get_quota()
+ if quota == User.UNLIMITED:
+ return User.UNLIMITED
+
+ u = self.user.get_quota_usage()
+ return quota - u
# add a new bucket owned by this user
def put_bucket(self, bucketName):
View
13 cumulus/pycb/cbRequest.py
@@ -18,6 +18,7 @@
from twisted.protocols.basic import FileSender
from twisted.python.log import err
import twisted.web.http
+from pynimbusauthz.user import User
#
@@ -579,6 +580,8 @@ def work(self):
ndx = bperms.find("w")
if ndx < 0:
raise cbException('AccessDenied')
+
+ file_size = 0
if exists:
(perms, data_key) = self.user.get_perms(self.bucketName, self.objectName)
ndx = perms.find("w")
@@ -590,6 +593,16 @@ def work(self):
ndx = perms.find("w")
if ndx < 0:
raise cbException('AccessDenied')
+ (file_size, ctm, md5) = self.user.get_info(self.bucketName, self.objectName)
+
+ # gotta decide quota, if existed should get credit for the
+ # existing size
+ remaining_quota = self.user.get_remaining_quota()
+ if remaining_quota != User.UNLIMITED:
+ new_file_len = int(self.request.getHeader('content-length'))
+ if remaining_quota + file_size < new_file_len:
+ pycb.log(logging.INFO, "user %s did not pass quota. file size %d quota %d" % (self.user, new_file_len, remaining_quota))
+ raise cbException('AccountProblem')
obj = self.request.content
self.recvObject(self.request, obj)
View
5 cumulus/pycb/test_common.py
@@ -55,6 +55,11 @@ def make_user():
return (id, pw)
+def set_user_quota(id, quota):
+ auth = pycb.config.auth
+ u = auth.get_user(id)
+ u.set_quota(quota)
+
def clean_user(id):
auth = pycb.config.auth
u = auth.get_user(id)
View
2 cumulus/pynimbusauthz/user.py
@@ -6,7 +6,7 @@
# a simple wrapper around readonly
class User(object):
- UNLIMITED = -1
+ UNLIMITED = None
def __init__(self, db_obj, uu=None, friendly=None, create=False):
if uu == None or create:

0 comments on commit db23156

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