Commit c2867610 authored by Stavros Sachtouris's avatar Stavros Sachtouris
Browse files

Implemented group, delgroup and copy

In CLI:
    - added store group to retrieve user grouos of account
    - added store delgroup to delete a user group by groupname
    - added store copy to copy an object from container/path to destination container/path

In pithos:
    -added get/del_account_group for group/delgroup operations resp.

In storage:
    - added copy_object in OOS style
parent eb903ba7
......@@ -738,6 +738,14 @@ class store_create(_store_account_command):
self.client.container = container
self.client.create_directory(directory_object)
@command(api='storage')
class store_copy(_store_account_command):
"""Copy an opbject"""
def main(self, source_container, source_path, destination_container, destination_path = False):
super(store_copy, self).main()
self.client.copy_object(source_container, source_path, destination_container, destination_path)
@command(api='storage')
class store_upload(_store_container_command):
"""Upload a file"""
......@@ -927,14 +935,31 @@ class store_setversioning(_store_account_command):
self.client.container = container
self.client.set_container_versioning(versioning)
@command(api='storage')
class store_group(_store_account_command):
"""Get user groups details for account"""
def main(self):
super(store_group, self).main()
reply = self.client.get_account_group()
print_dict(reply)
@command(api='storage')
class store_setgroup(_store_account_command):
"""Create/upodate a new user group on account"""
"""Create/update a new user group on account"""
def main(self, groupname, *users):
super(store_setgroup, self).main()
self.client.set_account_group(groupname, users)
@command(api='storage')
class store_delgroup(_store_account_command):
"""Delete a user group on an account"""
def main(self, groupname):
super(store_delgroup, self).main()
self.client.del_account_group(groupname)
@command(api='astakos')
class astakos_authenticate(object):
"""Authenticate a user"""
......
......@@ -36,7 +36,7 @@ import os
from time import time
from .storage import StorageClient
from .storage import StorageClient, ClientError
from .utils import path4url, params4url, prefix_keys, filter_in, filter_out
......@@ -138,6 +138,12 @@ class PithosClient(StorageClient):
self.set_header('X-Account-Group-'+group, userstr)
self.post(path, success=202)
def del_account_group(self, group):
self.assert_account()
path = path4url(self.account)+params4url({'update':None})
self.set_header('X-Account-Group-'+group, '')
r = self.post(path, success=202)
def get_account_quota(self):
return filter_in(self.get_account_info(), 'X-Account-Policy-Quota', exactMatch = True)
......@@ -147,6 +153,9 @@ class PithosClient(StorageClient):
def get_account_meta(self):
return filter_in(self.get_account_info(), 'X-Account-Meta-')
def get_account_group(self):
return filter_in(self.get_account_info(), 'X-Account-Group-')
def set_account_meta(self, metapairs):
assert(type(metapairs) is dict)
self.assert_account()
......
......@@ -149,6 +149,14 @@ class StorageClient(Client):
size = int(r.headers['content-length'])
return r.raw, size
def copy_object(self, src_container, src_object, dst_container, dst_object=False):
self.assert_account()
dst_object = dst_object or src_object
dst_path = path4url(self.account, dst_container, dst_object)
self.set_header('X-Copy-From', path4url(src_container, src_object))
self.set_header('Content-Length', 0)
self.put(dst_path, success=201)
def delete_object(self, object):
self.assert_container()
path = path4url(self.account, self.container, object)
......@@ -163,7 +171,6 @@ class StorageClient(Client):
r = self.get(path, params=params, success=(200, 204, 404))
if r.status_code == 404:
raise ClientError("Incorrect account (%s) for that container"%self.account, r.status_code)
print(unicode(r.json))
return r.json
def list_objects_in_path(self, path_prefix):
......
......@@ -38,11 +38,13 @@ def filter_out(d, prefix, exactMatch = False):
return {key:d[key] for key in d if not key.lower() == prefix.lower()}
return {key:d[key] for key in d if not key.lower().startswith(prefix.lower())}
def filter_in(d, prefix):
"""@return a dict that contains only the entries of d that are prefixed with prefic
def filter_in(d, prefix, exactMatch = False):
"""@return a dict that contains only the entries of d that are prefixed with prefix
"""
if exactMatch:
return {key:d[key] for key in d if key.lower() == prefix.lower()}
return {key:d[key] for key in d if key.lower().startswith(prefix.lower())}
def prefix_keys(d, prefix):
"""@return a sallow copy of d with all its keys prefixed with prefix
"""
......
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