Commit 2fc1c05d authored by Cédric Le Ninivin's avatar Cédric Le Ninivin

slapos_jio_api_style: Add Hash Document Record to API

parent f0b6d1cd
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ActionInformation" module="Products.CMFCore.ActionInformation"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>action</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>action_type/object_slapos_json_get</string>
</tuple>
</value>
</item>
<item>
<key> <string>category</string> </key>
<value> <string>object_slapos_json_get</string> </value>
</item>
<item>
<key> <string>condition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>icon</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>slapos_jio_api_get_hash_document_record</string> </value>
</item>
<item>
<key> <string>permissions</string> </key>
<value>
<tuple>
<string>View</string>
</tuple>
</value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Action Information</string> </value>
</item>
<item>
<key> <string>priority</string> </key>
<value> <float>1.1</float> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Get Hash Document Record</string> </value>
</item>
<item>
<key> <string>visible</string> </key>
<value> <int>1</int> </value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="Expression" module="Products.CMFCore.Expression"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>text</string> </key>
<value> <string>string:${object_url}/HashDocumentRecord_getFromJSON</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ActionInformation" module="Products.CMFCore.ActionInformation"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>action</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>action_type/object_slapos_json_all_docs</string>
</tuple>
</value>
</item>
<item>
<key> <string>category</string> </key>
<value> <string>object_slapos_json_all_docs</string> </value>
</item>
<item>
<key> <string>condition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>icon</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>slapos_jio_api_search_hash_document_record</string> </value>
</item>
<item>
<key> <string>permissions</string> </key>
<value>
<tuple>
<string>View</string>
</tuple>
</value>
</item>
<item>
<key> <string>priority</string> </key>
<value> <float>1.1</float> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Search Hash Document Record</string> </value>
</item>
<item>
<key> <string>visible</string> </key>
<value> <int>1</int> </value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="Expression" module="Products.CMFCore.Expression"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>text</string> </key>
<value> <string>string:${object_url}/jIOWebSection_searchHashDocumentRecordFromJSON</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="JSON Form" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>after_method_id</string> </key>
<value> <string>Base_asJSONText</string> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>application/json</string> </value>
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>HashDocumentRecord_getFromJSON</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>HashDocumentRecord_getFromJSON</string> </value>
</item>
<item>
<key> <string>output_schema</string> </key>
<value> <string>{\n
"$ref: "%(base_url)s/portal_types/Software%20Instance/getTextContent"\n
}</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>JSON Form</string> </value>
</item>
<item>
<key> <string>text_content</string> </key>
<value> <string>{\n
"$schema": "http://json-schema.org/draft-07/schema#",\n
"title": "Get Hash Document Record ",\n
"description": "Data necessary to get Compute Node",\n
"type": "object",\n
"properties": {\n
"reference": {\n
"title": "Hash Document Record Reference",\n
"type": "string",\n
"description": "The unique reference of the Hash Document Record, example: SOFTINST-1234-121213313134"\n
},\n
"portal_type": {\n
"title": "Portal Type",\n
"const": "Hash Document Record",\n
"type": "string"\n
}\n
},\n
"required": [\n
"reference",\n
"portal_type"\n
]\n
}\n
</string> </value>
</item>
<item>
<key> <string>version</string> </key>
<value> <string>01</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="JSON Form" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>after_method_id</string> </key>
<value> <string>jIOWebSection_searchHashDocumentRecord</string> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>application/json</string> </value>
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>jIOWebSection_searchHashDocumentRecordFromJSON</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>jIOWebSection_searchHashDocumentRecordFromJSON</string> </value>
</item>
<item>
<key> <string>output_schema</string> </key>
<value> <string>{\n
"$schema": "http://json-schema.org/draft-07/schema#",\n
"title": "allDocs: Response Payload",\n
"description": "Payload returned by allDocs method.",\n
"properties": {\n
"result_list": {\n
"title": "Result List",\n
"description": "Contains a representation of the items",\n
"type": "array",\n
"items": {\n
"type": "object",\n
"title": "Hash Document Record",\n
"properties": {\n
"reference": {\n
"title": "Hash Document Record Reference",\n
"description": "Unique identifier of the Hash Document Record",\n
"type": "string"\n
},\n
"timestamp": {\n
"title": "Timestamp",\n
"type": "number",\n
"description": "Timestamp of the time at which the hash table was constructed"\n
},\n
"portal_type": {\n
"title": "Portal Type",\n
"const": "Hash Document Record",\n
"type": "string"\n
}\n
}\n
}\n
}\n
}\n
}</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>JSON Form</string> </value>
</item>
<item>
<key> <string>text_content</string> </key>
<value> <string>{\n
"$schema": "http://json-schema.org/draft-07/schema#",\n
"$id": "hash-document-record-search-base-schema.json",\n
"title": "Search Hash Document Record",\n
"description": "Search Hash Document Record. Will only return the latest document available.",\n
"type": "object",\n
"properties": {\n
"node_id": {\n
"title": "Node ID",\n
"type": "string",\n
"description": "The Id of the compute node hosting the instance, example: COMP-1234 or reference of the Instance hosting"\n
},\n
"portal_type": {\n
"title": "Portal Type",\n
"const": "Hash Document Record",\n
"type": "string"\n
}\n
},\n
"required": ["portal_type"]\n
}\n
</string> </value>
</item>
<item>
<key> <string>version</string> </key>
<value> <string>001</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<property_sheet_list>
<portal_type id="Hash Document Record">
<item>JSONTypeConstraint</item>
<item>Reference</item>
<item>TextDocument</item>
</portal_type>
<portal_type id="Software Instance Certificate Record">
......
......@@ -49,5 +49,11 @@ elif portal_type == "Software Instance Certificate Record":
portal_type="Software Instance Certificate Record",
)
elif portal_type == "Hash Document Record":
if "reference" in data_dict:
return portal.portal_catalog.getResultValue(
portal_type="Hash Document Record",
reference=data_dict["reference"]
)
return None
node_id = data_dict.get("node_id", None)
portal = context.getPortalObject()
search_kw = {
"portal_type": "Hash Document Record",
"select_list": ("reference", "creation_date"),
"sort_on": (("creation_date", "DESC"),),
"limit": 1
}
if node_id:
search_kw["strict_aggregate_reference"] = node_id
hash_document_list = portal.portal_catalog(**search_kw)
result_list = []
for hash_document in hash_document_list:
result_list.append({
"portal_type": "Hash Document Record",
# Hackish
"timestamp": hash_document.reference.split("-")[-1],
"reference": hash_document.reference,
})
import json
return json.dumps({
"$schema": json_form.absolute_url().strip() + "/getOutputJSONSchema",
"result_list": result_list,
}, indent=2)
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>data_dict, json_form</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>jIOWebSection_searchHashDocumentRecord</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -9,8 +9,12 @@ result_list.sort()
portal_type_path = portal.portal_types.restrictedTraverse("Hash Document Record")
base_url = portal.portal_preferences.getPreferredSlaposWebSiteUrl().strip("/")
reference = "%s-%s" % (context.getReference(), timestamp)
data = {
"$schema": "/".join([base_url, portal_type_path.getRelativeUrl(), "getTextContent"]),
"portal_type": "",
"reference": reference,
"node_id":context.getReference(),
# Here it should not be hardcoded
"document_hash_list": result_list,
......@@ -20,7 +24,8 @@ data = {
portal.hash_document_record_module.newContent(
portal_type="Hash Document Record",
aggregate=context.getRelativeUrl(),
title="%s-%s" % (context.getReference(), timestamp),
title=reference,
reference=reference,
text_content=json.dumps(data)
)
......
Compute Node | slapos_jio_api_get_compute_node
Compute Node | slapos_jio_api_put_compute_node
Hash Document Record Module | view
Hash Document Record | slapos_jio_api_get_hash_document_record
Hash Document Record | view
Slave Instance | slapos_jio_api_get_software_instance
Software Installation | slapos_jio_api_get_software_installation
......@@ -12,5 +13,6 @@ jIO Web Section | slapos_jio_api_create_compute_node
jIO Web Section | slapos_jio_api_create_software_installation
jIO Web Section | slapos_jio_api_request_software_instance
jIO Web Section | slapos_jio_api_search_compute_node
jIO Web Section | slapos_jio_api_search_hash_document_record
jIO Web Section | slapos_jio_api_search_instance
jIO Web Section | slapos_jio_api_search_software_installation
\ No newline at end of file
portal_callables/ComputeNode_getFromJSON
portal_callables/ComputeNode_updateFromJSON
portal_callables/HashDocumentRecord_getFromJSON
portal_callables/SoftwareInstallation_getFromJSON
portal_callables/SoftwareInstallation_updateFromJSON
portal_callables/SoftwareInstanceCertificateRecord_getFromJSON
......@@ -9,5 +10,6 @@ portal_callables/jIOWebSection_createComputeNodeFromJSON
portal_callables/jIOWebSection_createSoftwareInstallationFromJSON
portal_callables/jIOWebSection_requestSoftwareInstanceFromJSON
portal_callables/jIOWebSection_searchComputeNodeFromJSON
portal_callables/jIOWebSection_searchHashDocumentRecordFromJSON
portal_callables/jIOWebSection_searchInstanceFromJSON
portal_callables/jIOWebSection_searchSoftwareInstallationFromJSON
\ No newline at end of file
Hash Document Record | JSONTypeConstraint
Hash Document Record | Reference
Hash Document Record | TextDocument
Software Instance Certificate Record | JSONTypeConstraint
\ No newline at end of file
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