def test_change_acl(self): with self.app.app_context(): public_grants = { 'CanonicalUser': '******', 'Group': 'READ' } private_grants = {'CanonicalUser': '******'} bit_store = BitStore('test_pub', 'test_package', body='test') s3 = boto3.client('s3') bucket_name = self.app.config['S3_BUCKET_NAME'] s3.create_bucket(Bucket=bucket_name) metadata_key = bit_store.build_s3_key('datapackage.json') bit_store.save_metadata() res = s3.get_object_acl(Bucket=bucket_name, Key=metadata_key) owner_id = res['Owner']['ID'] aws_all_user_group_url = 'http://acs.amazonaws.com/groups/global/AllUsers' full_control = filter(lambda grant: grant['Permission'] == 'FULL_CONTROL', res['Grants']) self.assertEqual(len(full_control), 1) self.assertEqual(full_control[0].get('Grantee')['ID'], owner_id) read_control = filter(lambda grant: grant['Permission'] == 'READ', res['Grants']) self.assertEqual(len(read_control), 1) self.assertEqual(read_control[0].get('Grantee')['URI'], aws_all_user_group_url) bit_store.change_acl("private") res = s3.get_object_acl(Bucket=bucket_name, Key=metadata_key) full_control = filter(lambda grant: grant['Permission'] == 'FULL_CONTROL', res['Grants']) self.assertEqual(len(full_control), 1) self.assertEqual(full_control[0].get('Grantee')['ID'], owner_id) read_control = filter(lambda grant: grant['Permission'] == 'READ', res['Grants']) self.assertEqual(len(read_control), 0)
def finalize_publish(cls, user_id, datapackage_url): ''' Gets the datapackage.json and README from S3 and imports into database. Returns status "queued" if ok, else - None ''' publisher, package, version = BitStore.extract_information_from_s3_url( datapackage_url) if Package.exists(publisher, package): status = check_is_authorized('Package::Update', publisher, package, user_id) else: status = check_is_authorized('Package::Create', publisher, package, user_id) if not status: raise InvalidUsage('Not authorized to upload data', 400) bit_store = BitStore(publisher, package) b = bit_store.get_metadata_body() body = json.loads(b) bit_store.change_acl('public-read') readme = bit_store.get_s3_object(bit_store.get_readme_object_key()) Package.create_or_update(name=package, publisher_name=publisher, descriptor=body, readme=readme) return "queued"
def undelete_data_package(publisher, package): """ DPR data package un-delete operation. This API is responsible for un-mark the mark for delete of data package --- tags: - package parameters: - in: path name: publisher type: string required: true description: publisher name - in: path name: package type: string required: true description: package name - in: header name: Authorization type: string required: true description: JWT Token responses: 500: description: Internal Server Error 200: description: Success Message schema: id: put_package_success properties: status: type: string default: OK """ bitstore = BitStore(publisher=publisher, package=package) status_db = logic.Package.change_status(publisher, package, models.PackageStateEnum.active) try: status_acl = bitstore.change_acl('public-read') except Exception as e: ## TODO roll back changes in db raise InvalidUsage(e.message, 500) if status_acl and status_db: return jsonify({"status": "OK"}), 200
def delete_data_package(publisher, package): """ DPR Data Package Soft Delete Marks Data Package as private --- tags: - package parameters: - in: path name: publisher type: string required: true description: publisher name - in: path name: package type: string required: true description: package name - in: header name: Authorization type: string required: true description: JWT Token responses: 500: description: Internal Server Error 200: description: Success Message schema: id: put_package_success properties: status: type: string default: OK """ bitstore = BitStore(publisher=publisher, package=package) status_db = logic.Package.change_status(publisher, package, models.PackageStateEnum.deleted) try: status_acl = bitstore.change_acl('private') except Exception as e: ## TODO roll back changes in db raise InvalidUsage(e.message, 500) if status_acl and status_db: return jsonify({"status": "OK"}), 200