示例#1
0
文件: containers.py 项目: dais/colony
def acl(request, tenant_id, container_name):

    form, handled = ContainerAcl.maybe_handle(request)
    if handled:
        return handled

    remove_form, handled = ContainerAclRemove.maybe_handle(request)
    if handled:
        return handled

    container = api.swift_get_container(request, container_name)
    read_ref, read_groups, write_ref, write_groups = [], [], [], []
    read_acl, write_acl = '', ''
    for h, v in container.headers:
        if 'x-container-read' == h.lower():
            v = clean_acl('X-Container-Read', v)
            read_ref, read_groups = parse_acl(v)
            read_acl = v
        if 'x-container-write' == h.lower():
            v = clean_acl('X-Container-Write', v)
            write_ref, write_groups = parse_acl(v)
            write_acl = v
    #if container.headers.get('x-container-read'):
    #   ref, groups = utils.parse_acl(container.headers.get('x-container-read'))
    #if container.headers.get('x-container-write'):
    #   ref, groups = utils.parse_acl(container.headers.get('x-container-write'))
    """
    ref, groups = parse_acl('test:test,hoge,.r:*')
    read_ref, read_groups = ref, groups 
    write_ref, write_groups = ref, groups 
    """

    return shortcuts.render_to_response(
        'django_openstack/dash/containers/acl.html', {
            'container_name': container_name,
            'container': container,
            'acl_form': form,
            'remove_form': remove_form,
            'read_acl_ref': read_ref,
            'read_acl_groups': read_groups,
            'write_acl_ref': write_ref,
            'write_acl_groups': write_groups,
            'write_acl': write_acl,
            'read_acl': read_acl
        },
        context_instance=template.RequestContext(request))
示例#2
0
文件: containers.py 项目: dais/colony
def acl(request, tenant_id, container_name):

    form, handled = ContainerAcl.maybe_handle(request)
    if handled:
        return handled

    remove_form, handled = ContainerAclRemove.maybe_handle(request)
    if handled:
        return handled

    container = api.swift_get_container(request, container_name)
    read_ref, read_groups, write_ref, write_groups = [],[],[],[]
    read_acl, write_acl = '', ''
    for h,v in container.headers:
        if 'x-container-read' == h.lower():
            v = clean_acl('X-Container-Read', v)
            read_ref, read_groups = parse_acl(v)
            read_acl = v
        if 'x-container-write' == h.lower():
            v = clean_acl('X-Container-Write', v)
            write_ref, write_groups = parse_acl(v)
            write_acl = v
    #if container.headers.get('x-container-read'):
    #   ref, groups = utils.parse_acl(container.headers.get('x-container-read'))
    #if container.headers.get('x-container-write'):
    #   ref, groups = utils.parse_acl(container.headers.get('x-container-write'))

    """
    ref, groups = parse_acl('test:test,hoge,.r:*')
    read_ref, read_groups = ref, groups 
    write_ref, write_groups = ref, groups 
    """

    return shortcuts.render_to_response(
    'django_openstack/dash/containers/acl.html', {
	'container_name' : container_name,
	'container' : container,
	'acl_form' : form,
        'remove_form' : remove_form,
        'read_acl_ref' : read_ref,
        'read_acl_groups' : read_groups,
        'write_acl_ref' : write_ref,
        'write_acl_groups' : write_groups,
        'write_acl' : write_acl,
        'read_acl' : read_acl
	}, context_instance=template.RequestContext(request))
示例#3
0
class ContainerAcl(forms.SelfHandlingForm):
    ''' Form that handles Swift Container Acl '''
    container_name = forms.CharField(widget=forms.HiddenInput())
    acl_type = forms.ChoiceField(label="ACL Type",
                                 choices=((1, 'ReadAcl'), (0, 'WriteAcl')),
                                 initial=1,
                                 widget=forms.RadioSelect)
    read_acl = forms.CharField(widget=forms.HiddenInput(), required=False)
    write_acl = forms.CharField(widget=forms.HiddenInput(), required=False)
    acl_add = forms.CharField(max_length="255", label="ACL", required=True)

    def __init__(self, *args, **kwargs):
        super(ContainerAcl, self).__init__(*args, **kwargs)

    def handle(self, request, data):

        container_name = data['container_name']
        acl_type = data['acl_type']
        try:
            acl_add = data['acl_add']
            acl_add.encode('ascii')
        except UnicodeEncodeError, e:
            messages.error(
                request, "Container ACL contains non-ASCII \
            character %s" % str(e))
            return shortcuts.redirect(request.build_absolute_uri())

        if acl_type == "1":
            type = 'X-Container-Read'
            acl_value = data.get('read_acl', '')
        elif acl_type == "0":
            type = 'X-Container-Write'
            acl_value = data.get('write_acl', '')

        # clean and parse acl
        try:
            acl = clean_acl(type, acl_add)
            acl_orig = clean_acl(type, acl_value)
            ref_add, group_add = parse_acl(acl)
            ref_orig, group_orig = parse_acl(acl_orig)
        except ValueError, e:
            messages.error(request, 'ACL value is invalid %s' % str(e))
            return None
示例#4
0
文件: containers.py 项目: dais/colony
    def handle(self, request, data):

        container_name = data['container_name']
        acl_type = data['acl_type']

        if acl_type == "1":
            type = 'X-Container-Read'
            acl_value = data.get('read_acl', '')
        elif acl_type == "0":
            type = 'X-Container-Write'
            acl_value = data.get('write_acl', '')

        # clean and parse acl
        try:
            acl = clean_acl(type, data['acl_add'])
            acl_orig = clean_acl(type, acl_value)
            ref_add, group_add = parse_acl(acl)
            ref_orig, group_orig = parse_acl(acl_orig)
        except ValueError, e:
            messages.error(request, 'ACL value is invalid %s' % str(e))
            print str(e)
            return
示例#5
0
文件: containers.py 项目: dais/colony
    def handle(self, request, data):


        container_name = data['container_name']
        acl_type = data['acl_type']

        if acl_type == "1":
           type = 'X-Container-Read'
           acl_value = data.get('read_acl', '')
        elif acl_type == "0":
           type = 'X-Container-Write'
           acl_value = data.get('write_acl', '')


        # clean and parse acl
        try:
            acl = clean_acl(type, data['acl_add'])
            acl_orig = clean_acl(type, acl_value)
            ref_add, group_add = parse_acl(acl)
            ref_orig, group_orig = parse_acl(acl_orig)
        except ValueError, e:
            messages.error(request, 'ACL value is invalid %s' % str(e))
            print str(e)
            return
示例#6
0
    def handle(self, request, data):
        header = data['header_name']
        container_name = data['container_name']
        acl_type = data['acl_type']
        acl_value = data['acl_value']

        if acl_type == "read":
            type = 'X-Container-Read'
        elif acl_type == "write":
            type = 'X-Container-Write'
        else:
            pass
        # clean and parse acl
        try:
            acl = clean_acl(type, acl_value)
            refs, groups = parse_acl(acl)
        except ValueError, e:
            messages.error(request, 'ACL value is invalid %s' % str(e))
            return None
示例#7
0
    def handle(self, request, data):
        header = data['header_name']
        container_name = data['container_name']
        acl_type = data['acl_type']
        acl_value = data['acl_value']

        if acl_type == "read":
            type = 'X-Container-Read'
        elif acl_type == "write":
            type = 'X-Container-Write'
        else:
            pass
        # clean and parse acl
        try:
            acl = clean_acl(type, acl_value)
            refs, groups = parse_acl(acl)
        except ValueError, e:
            messages.error(request, 'ACL value is invalid %s' % str(e))
            return None
示例#8
0
    remove_form, handled = ContainerAclRemove.maybe_handle(request)
    if handled:
        return handled
   
    try: 
        container = api.swift_get_container(request, container_name)
    except ResponseError, e:
        messages.error(request, 'Unable to retrive ACL data. \
                       Perhaps you do not have right permission : %s'  % str(e))
        return shortcuts.redirect('dash_containers', tenant_id)
    read_ref, read_groups, write_ref, write_groups = [],[],[],[]
    read_acl, write_acl = '', ''
    for h,v in container.headers:
        if 'x-container-read' == h.lower():
            v = clean_acl('X-Container-Read', v)
            read_ref, read_groups = parse_acl(v)
            read_acl = v
        if 'x-container-write' == h.lower():
            v = clean_acl('X-Container-Write', v)
            write_ref, write_groups = parse_acl(v)
            write_acl = v
    #if container.headers.get('x-container-read'):
    #   ref, groups = utils.parse_acl(container.headers.get('x-container-read'))
    #if container.headers.get('x-container-write'):
    #   ref, groups = utils.parse_acl(container.headers.get('x-container-write'))

    #ref, groups = parse_acl('test:test,hoge,.r:*')
    #read_ref, read_groups = ref, groups 
    #write_ref, write_groups = ref, groups 

    return shortcuts.render_to_response(
示例#9
0
 def test_parse_acl_ref_2(self):
     acl = '.r:*,bob'
     ref,group = parse_acl(acl)
     self.assertEqual(group, ['bob'])
     self.assertEqual(ref, ['*'])
示例#10
0
 def test_parse_acl_ref(self):
     acl = '.r:*'
     ref,group = parse_acl(acl)
     self.assertEqual(group, [])
     self.assertEqual(ref, ['*'])
示例#11
0
    if handled:
        return handled

    try:
        container = api.swift_get_container(request, container_name)
    except ResponseError, e:
        messages.error(
            request, 'Unable to retrive ACL data. \
                       Perhaps you do not have right permission : %s' % str(e))
        return shortcuts.redirect('dash_containers', tenant_id)
    read_ref, read_groups, write_ref, write_groups = [], [], [], []
    read_acl, write_acl = '', ''
    for h, v in container.headers:
        if 'x-container-read' == h.lower():
            v = clean_acl('X-Container-Read', v)
            read_ref, read_groups = parse_acl(v)
            read_acl = v
        if 'x-container-write' == h.lower():
            v = clean_acl('X-Container-Write', v)
            write_ref, write_groups = parse_acl(v)
            write_acl = v
    #if container.headers.get('x-container-read'):
    #   ref, groups = utils.parse_acl(container.headers.get('x-container-read'))
    #if container.headers.get('x-container-write'):
    #   ref, groups = utils.parse_acl(container.headers.get('x-container-write'))

    #ref, groups = parse_acl('test:test,hoge,.r:*')
    #read_ref, read_groups = ref, groups
    #write_ref, write_groups = ref, groups

    return shortcuts.render_to_response(
示例#12
0
 def test_parse_acl_ref_2(self):
     acl = '.r:*,bob'
     ref, group = parse_acl(acl)
     self.assertEqual(group, ['bob'])
     self.assertEqual(ref, ['*'])
示例#13
0
 def test_parse_acl_ref(self):
     acl = '.r:*'
     ref, group = parse_acl(acl)
     self.assertEqual(group, [])
     self.assertEqual(ref, ['*'])