Revision 54d26a27

b/snf-cyclades-app/synnefo/plankton/views.py
70 70
UPDATE_FIELDS = ('name', 'disk_format', 'container_format', 'is_public',
71 71
                 'owner', 'properties', 'status')
72 72

  
73
DISK_FORMATS = ('diskdump', 'extdump', 'ntfsdump')
74

  
75
CONTAINER_FORMATS = ('aki', 'ari', 'ami', 'bare', 'ovf')
76

  
77
STORE_TYPES = ('pithos')
78

  
73 79

  
74 80
log = getLogger('synnefo.plankton')
75 81

  
......
81 87
        if key == 'properties':
82 88
            for k, v in image.get('properties', {}).items():
83 89
                name = 'x-image-meta-property-' + k.replace('_', '-')
84
                response[name] = v
90
                response[name] = uenc(v)
85 91
        else:
86 92
            name = 'x-image-meta-' + key.replace('_', '-')
87
            response[name] = image.get(key, '')
93
            response[name] = uenc(image.get(key, ''))
88 94

  
89 95
    return response
90 96

  
......
157 163
    except InvalidLocation:
158 164
        raise faults.BadRequest("Invalid location '%s'" % location)
159 165

  
166
    validate_fields(params)
167

  
160 168
    if location:
161 169
        with image_backend(request.user_uniq) as backend:
162 170
            image = backend.register(name, location, params)
......
376 384
    if not set(meta.keys()).issubset(set(UPDATE_FIELDS)):
377 385
        raise faults.BadRequest("Invalid metadata")
378 386

  
387
    validate_fields(meta)
388

  
379 389
    with image_backend(request.user_uniq) as backend:
380 390
        image = backend.update_metadata(image_id, meta)
381 391
    return _create_image_response(image)
......
404 414
    with image_backend(request.user_uniq) as backend:
405 415
        backend.replace_users(image_id, members)
406 416
    return HttpResponse(status=204)
417

  
418

  
419
def validate_fields(params):
420
    if "id" in params:
421
        raise faults.BadRequest("Setting the image ID is not supported")
422

  
423
    if "store" in params:
424
        if params["store"] not in STORE_TYPES:
425
            raise faults.BadRequest("Invalid store type '%s'" %
426
                                    params["store"])
427

  
428
    if "disk_format" in params:
429
        if params["disk_format"] not in DISK_FORMATS:
430
            raise faults.BadRequest("Invalid disk format '%s'" %
431
                                    params['disk_format'])
432

  
433
    if "container_format" in params:
434
        if params["container_format"] not in CONTAINER_FORMATS:
435
            raise faults.BadRequest("Invalid container format '%s'" %
436
                                    params['container_format'])

Also available in: Unified diff