def create_raw_object(bucket: str, archiveid: str, content: str) -> http_utils.APIResponse: if not bucket: raise ValueError( "Cannot create document to object store without bucket") if not archiveid: raise ValueError( "Cannot create document to object store without archiveid") if not content: raise ValueError( "Cannot create document to object store without content") create_document_resp = http_utils.http_post_bytes( ["objects", "raw", bucket, archiveid], content, config=catalog_api_conf) if create_document_resp.code != 200: raise http_utils.RequestFailedError( create_document_resp.url, create_document_resp.code, create_document_resp.body, ) return create_document_resp
def test_list_manifests( self, syft_json_name: str, dockerfile_name: str, module_path: str, begin_import: APIResponse, ): operation_uuid = begin_import.body["uuid"] syft_json = imports.load_file(module_path, syft_json_name) manifest = imports.extract_syft_metadata(syft_json)["manifest"] result: APIResponse = http_post_bytes( ["imports", "images", operation_uuid, "manifest"], payload=manifest) assert result.code == 200 list_response = http_get( ["imports", "images", operation_uuid, "manifest"]) assert list_response.code == 200 assert list_response.body[0]["digest"] == result.body["digest"]
def test_upload_image_config( self, syft_json_name: str, dockerfile_name: str, module_path: str, begin_import: APIResponse, ): """ Note copied from test script `scripts/tests/image_import/test_import.py`: Load from the file as bytes arrays instead of json objects to ensure that the digest computation matches and isn't impacted by any python re-ordering of keys or adding/removing whitespace. This should enable the output of `sha256sum <file>` to match the digests returned during this test """ syft_json = imports.load_file(module_path, syft_json_name) image_config = imports.extract_syft_metadata(syft_json)["image_config"] result: APIResponse = http_post_bytes( ["imports", "images", begin_import.body["uuid"], "image_config"], payload=image_config, ) assert result.code == 200
def test_full_upload( self, syft_json_name: str, dockerfile_name: str, module_path: str, begin_import: APIResponse, ): operation_uuid = begin_import.body["uuid"] syft_json = imports.load_file(module_path, syft_json_name) dockerfile = imports.load_file(module_path, dockerfile_name) metadata = imports.extract_syft_metadata(syft_json) # upload dockerfile upload_dockerfile_response: APIResponse = http_post( ["imports", "images", operation_uuid, "dockerfile"], payload=dockerfile, ) assert upload_dockerfile_response.code == 200 dockerfile_digest = upload_dockerfile_response.body["digest"] # upload packages packages = json.loads(syft_json) upload_packages_response: APIResponse = http_post( ["imports", "images", operation_uuid, "packages"], payload=packages) assert upload_packages_response.code == 200 packages_digest = upload_packages_response.body["digest"] # upload manifest upload_manifest_response: APIResponse = http_post_bytes( ["imports", "images", operation_uuid, "manifest"], payload=metadata["manifest"], ) assert upload_manifest_response.code == 200 manifest_digest = upload_manifest_response.body["digest"] # upload image config upload_config_response: APIResponse = http_post_bytes( ["imports", "images", operation_uuid, "image_config"], payload=metadata["image_config"], ) assert upload_config_response.code == 200 image_config_digest = upload_config_response.body["digest"] # upload image payload = { "source": { "import": { "digest": metadata["digest"], "local_image_id": metadata["local_image_id"], "contents": { "packages": packages_digest, "dockerfile": dockerfile_digest, "manifest": manifest_digest, "image_config": image_config_digest, }, "tags": metadata["tags"], "operation_uuid": operation_uuid, } }, "annotations": { "testkey1": "testvalue1", "testkey2": "testvalue2" }, } image_upload_response = http_post(["images"], payload=payload) assert image_upload_response.code == 200 # check image uploaded image_list_response = http_get(["images", metadata["digest"]]) assert image_list_response.code == 200