Commit 8db76f83 authored by Alain Takoudjou's avatar Alain Takoudjou

slapos_hypermedia: migrate bt to new format

parent 673cba0a
from zExceptions import Unauthorized
from AccessControl import getSecurityManager
if REQUEST is None:
raise Unauthorized
response = REQUEST.RESPONSE
mime_type = 'application/hal+json'
if REQUEST.other['method'] != "GET":
response.setStatus(405)
return ""
elif mime_type != context.Base_handleAcceptHeader([mime_type]):
response.setStatus(406)
return ""
import json
result_dict = json.loads(context.ERP5Document_getHateoas(REQUEST))
portal = context.getPortalObject()
person = portal.ERP5Site_getAuthenticatedMemberPersonValue()
if person is not None:
result_dict['_links']['me'] = {
"href": "urn:jio:get:%s" % person.getRelativeUrl(),
}
else:
user = str(portal.portal_membership.getAuthenticatedMember())
if user != "Anonymous User":
user_document = context.ERP5Site_getUserDocument(user)
result_dict['_links']['me'] = {
'href': 'urn:jio:get:%s' % user_document.getRelativeUrl(),
}
response.setHeader('Content-Type', mime_type)
return json.dumps(result_dict, indent=2)
...@@ -48,47 +48,6 @@ ...@@ -48,47 +48,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_body</string> </key>
<value> <string>from zExceptions import Unauthorized\n
from AccessControl import getSecurityManager\n
\n
if REQUEST is None:\n
raise Unauthorized\n
\n
response = REQUEST.RESPONSE\n
mime_type = \'application/hal+json\'\n
\n
if REQUEST.other[\'method\'] != "GET":\n
response.setStatus(405)\n
return ""\n
elif mime_type != context.Base_handleAcceptHeader([mime_type]):\n
response.setStatus(406)\n
return ""\n
\n
import json\n
result_dict = json.loads(context.ERP5Document_getHateoas(REQUEST))\n
\n
portal = context.getPortalObject()\n
\n
person = portal.ERP5Site_getAuthenticatedMemberPersonValue()\n
if person is not None:\n
result_dict[\'_links\'][\'me\'] = {\n
"href": "urn:jio:get:%s" % person.getRelativeUrl(),\n
}\n
\n
else:\n
user = str(portal.portal_membership.getAuthenticatedMember())\n
if user != "Anonymous User":\n
user_document = context.ERP5Site_getUserDocument(user)\n
result_dict[\'_links\'][\'me\'] = {\n
\'href\': \'urn:jio:get:%s\' % user_document.getRelativeUrl(),\n
}\n
\n
response.setHeader(\'Content-Type\', mime_type)\n
return json.dumps(result_dict, indent=2)\n
</string> </value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>REQUEST=None</string> </value> <value> <string>REQUEST=None</string> </value>
......
from zExceptions import Unauthorized
from AccessControl import getSecurityManager
if REQUEST is None:
raise Unauthorized
response = REQUEST.RESPONSE
mime_type = 'application/hal+json'
if REQUEST.other['method'] != "GET":
response.setStatus(405)
return ""
elif mime_type != context.Base_handleAcceptHeader([mime_type]):
response.setStatus(406)
return ""
elif context.getPortalType() != "Computer":
response.setStatus(403)
return ""
import json
result_dict = {
'_links': {
"self": { "href": context.Base_getRequestUrl() },
"index": {
"href": "urn:jio:get:%s" % context.getRelativeUrl(),
"title": "Computer"
},
"content": [],
},
}
for sql_obj in context.getPortalObject().portal_catalog(
portal_type='Software Installation',
default_aggregate_uid=context.getUid(),
validation_state='validated',
):
obj = sql_obj.getObject()
result_dict['_links']['content'].append({
'href': '%s/ERP5Document_getHateoas' % obj.absolute_url(),
'title': obj.getUrlString()
})
response.setHeader('Content-Type', mime_type)
return json.dumps(result_dict, indent=2)
...@@ -48,53 +48,6 @@ ...@@ -48,53 +48,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_body</string> </key>
<value> <string>from zExceptions import Unauthorized\n
from AccessControl import getSecurityManager\n
if REQUEST is None:\n
raise Unauthorized\n
\n
response = REQUEST.RESPONSE\n
mime_type = \'application/hal+json\'\n
\n
if REQUEST.other[\'method\'] != "GET":\n
response.setStatus(405)\n
return ""\n
elif mime_type != context.Base_handleAcceptHeader([mime_type]):\n
response.setStatus(406)\n
return ""\n
elif context.getPortalType() != "Computer":\n
response.setStatus(403)\n
return ""\n
\n
import json\n
result_dict = {\n
\'_links\': {\n
"self": { "href": context.Base_getRequestUrl() },\n
"index": {\n
"href": "urn:jio:get:%s" % context.getRelativeUrl(),\n
"title": "Computer"\n
},\n
"content": [],\n
},\n
}\n
\n
for sql_obj in context.getPortalObject().portal_catalog(\n
portal_type=\'Software Installation\',\n
default_aggregate_uid=context.getUid(),\n
validation_state=\'validated\',\n
):\n
obj = sql_obj.getObject()\n
result_dict[\'_links\'][\'content\'].append({\n
\'href\': \'%s/ERP5Document_getHateoas\' % obj.absolute_url(),\n
\'title\': obj.getUrlString()\n
})\n
\n
response.setHeader(\'Content-Type\', mime_type)\n
return json.dumps(result_dict, indent=2)\n
</string> </value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>REQUEST=None</string> </value> <value> <string>REQUEST=None</string> </value>
......
from zExceptions import Unauthorized
from AccessControl import getSecurityManager
if REQUEST is None:
raise Unauthorized
response = REQUEST.RESPONSE
mime_type = 'application/hal+json'
if REQUEST.other['method'] != "GET":
response.setStatus(405)
return ""
elif mime_type != context.Base_handleAcceptHeader([mime_type]):
response.setStatus(406)
return ""
elif context.getPortalType() != "Hosting Subscription":
response.setStatus(403)
return ""
import json
result_dict = {
'_links': {
"self": { "href": context.Base_getRequestUrl() },
"content": [],
"index": {
"href": "urn:jio:get:%s" % context.getRelativeUrl(),
"title": "Hosting Subscription"
},
},
}
for sql_obj in context.getPortalObject().portal_catalog(
portal_type=['Software Instance', 'Slave Instance'],
default_specialise_uid=context.getUid(),
):
obj = sql_obj.getObject()
result_dict['_links']['content'].append({
'href': '%s/ERP5Document_getHateoas' % obj.absolute_url(),
'title': obj.getTitle()
})
response.setHeader('Content-Type', mime_type)
return json.dumps(result_dict, indent=2)
...@@ -48,52 +48,6 @@ ...@@ -48,52 +48,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_body</string> </key>
<value> <string>from zExceptions import Unauthorized\n
from AccessControl import getSecurityManager\n
if REQUEST is None:\n
raise Unauthorized\n
\n
response = REQUEST.RESPONSE\n
mime_type = \'application/hal+json\'\n
\n
if REQUEST.other[\'method\'] != "GET":\n
response.setStatus(405)\n
return ""\n
elif mime_type != context.Base_handleAcceptHeader([mime_type]):\n
response.setStatus(406)\n
return ""\n
elif context.getPortalType() != "Hosting Subscription":\n
response.setStatus(403)\n
return ""\n
\n
import json\n
result_dict = {\n
\'_links\': {\n
"self": { "href": context.Base_getRequestUrl() },\n
"content": [],\n
"index": {\n
"href": "urn:jio:get:%s" % context.getRelativeUrl(),\n
"title": "Hosting Subscription"\n
},\n
},\n
}\n
\n
for sql_obj in context.getPortalObject().portal_catalog(\n
portal_type=[\'Software Instance\', \'Slave Instance\'],\n
default_specialise_uid=context.getUid(),\n
):\n
obj = sql_obj.getObject()\n
result_dict[\'_links\'][\'content\'].append({\n
\'href\': \'%s/ERP5Document_getHateoas\' % obj.absolute_url(),\n
\'title\': obj.getTitle()\n
})\n
\n
response.setHeader(\'Content-Type\', mime_type)\n
return json.dumps(result_dict, indent=2)\n
</string> </value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>REQUEST=None</string> </value> <value> <string>REQUEST=None</string> </value>
......
from zExceptions import Unauthorized
from AccessControl import getSecurityManager
if REQUEST is None:
raise Unauthorized
response = REQUEST.RESPONSE
mime_type = 'application/hal+json'
if REQUEST.other['method'] != "GET":
response.setStatus(405)
return ""
elif mime_type != context.Base_handleAcceptHeader([mime_type]):
response.setStatus(406)
return ""
elif context.getPortalType() != "Hosting Subscription":
response.setStatus(403)
return ""
instance_list = context.getPredecessorValueList()
for instance in instance_list:
if instance.getTitle() == context.getTitle():
root_instance = instance
break
else:
raise Exception('Root instance not found.')
import json
result_dict = {
'_links': {
"self": { "href": context.Base_getRequestUrl() },
"content": [
{'href': '%s/ERP5Document_getHateoas' % root_instance.getAbsoluteUrl()},
],
"index": {
"href": "urn:jio:get:%s" % context.getRelativeUrl(),
"title": "Hosting Subscription"
},
},
}
response.setHeader('Content-Type', mime_type)
return json.dumps(result_dict, indent=2)
...@@ -48,52 +48,6 @@ ...@@ -48,52 +48,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_body</string> </key>
<value> <string>from zExceptions import Unauthorized\n
from AccessControl import getSecurityManager\n
if REQUEST is None:\n
raise Unauthorized\n
\n
response = REQUEST.RESPONSE\n
mime_type = \'application/hal+json\'\n
\n
if REQUEST.other[\'method\'] != "GET":\n
response.setStatus(405)\n
return ""\n
elif mime_type != context.Base_handleAcceptHeader([mime_type]):\n
response.setStatus(406)\n
return ""\n
elif context.getPortalType() != "Hosting Subscription":\n
response.setStatus(403)\n
return ""\n
\n
instance_list = context.getPredecessorValueList()\n
for instance in instance_list:\n
if instance.getTitle() == context.getTitle():\n
root_instance = instance\n
break\n
else:\n
raise Exception(\'Root instance not found.\')\n
\n
import json\n
result_dict = {\n
\'_links\': {\n
"self": { "href": context.Base_getRequestUrl() },\n
"content": [\n
{\'href\': \'%s/ERP5Document_getHateoas\' % root_instance.getAbsoluteUrl()},\n
],\n
"index": {\n
"href": "urn:jio:get:%s" % context.getRelativeUrl(),\n
"title": "Hosting Subscription"\n
},\n
},\n
}\n
\n
response.setHeader(\'Content-Type\', mime_type)\n
return json.dumps(result_dict, indent=2)\n
</string> </value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>REQUEST=None</string> </value> <value> <string>REQUEST=None</string> </value>
......
from zExceptions import Unauthorized
from AccessControl import getSecurityManager
if REQUEST is None:
raise Unauthorized
response = REQUEST.RESPONSE
mime_type = 'application/hal+json'
if REQUEST.other['method'] != "GET":
response.setStatus(405)
return ""
elif mime_type != context.Base_handleAcceptHeader([mime_type]):
response.setStatus(406)
return ""
elif context.getPortalType() not in ["Software Instance", "Slave Instance"]:
response.setStatus(403)
return ""
if context.getSlapState() == "stop_requested":
state = 'stopped'
elif context.getSlapState() == "start_requested":
state = 'started'
else:
state = 'destroyed'
import json
result_dict = {
'title': context.getTitle(),
'slave': context.getPortalType() == 'Slave Instance',
'software_type': context.getSourceReference(),
'parameter_dict': context.getInstanceXmlAsDict(),
'sla_dict': context.getSlaXmlAsDict(),
'connection_dict': context.getConnectionXmlAsDict(),
'requested_state': state,
'instance_guid': context.getId(),
'_links': {
"self": { "href": context.Base_getRequestUrl() },
"index": {
"href": "urn:jio:get:%s" % context.getRelativeUrl(),
"title": "Software Instance",
},
'software_release': {
"href": context.getUrlString(),
}
},
}
response.setHeader('Content-Type', mime_type)
return json.dumps(result_dict, indent=2)
...@@ -48,59 +48,6 @@ ...@@ -48,59 +48,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_body</string> </key>
<value> <string>from zExceptions import Unauthorized\n
from AccessControl import getSecurityManager\n
if REQUEST is None:\n
raise Unauthorized\n
\n
response = REQUEST.RESPONSE\n
mime_type = \'application/hal+json\'\n
\n
if REQUEST.other[\'method\'] != "GET":\n
response.setStatus(405)\n
return ""\n
elif mime_type != context.Base_handleAcceptHeader([mime_type]):\n
response.setStatus(406)\n
return ""\n
elif context.getPortalType() not in ["Software Instance", "Slave Instance"]:\n
response.setStatus(403)\n
return ""\n
\n
if context.getSlapState() == "stop_requested":\n
state = \'stopped\'\n
elif context.getSlapState() == "start_requested":\n
state = \'started\'\n
else:\n
state = \'destroyed\'\n
\n
import json\n
result_dict = {\n
\'title\': context.getTitle(),\n
\'slave\': context.getPortalType() == \'Slave Instance\',\n
\'software_type\': context.getSourceReference(),\n
\'parameter_dict\': context.getInstanceXmlAsDict(),\n
\'sla_dict\': context.getSlaXmlAsDict(),\n
\'connection_dict\': context.getConnectionXmlAsDict(),\n
\'requested_state\': state,\n
\'instance_guid\': context.getId(),\n
\'_links\': {\n
"self": { "href": context.Base_getRequestUrl() },\n
"index": {\n
"href": "urn:jio:get:%s" % context.getRelativeUrl(),\n
"title": "Software Instance",\n
},\n
\'software_release\': {\n
"href": context.getUrlString(),\n
}\n
},\n
}\n
\n
response.setHeader(\'Content-Type\', mime_type)\n
return json.dumps(result_dict, indent=2)\n
</string> </value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>REQUEST=None</string> </value> <value> <string>REQUEST=None</string> </value>
......
from zExceptions import Unauthorized
from AccessControl import getSecurityManager
if REQUEST is None:
raise Unauthorized
response = REQUEST.RESPONSE
mime_type = 'application/hal+json'
if REQUEST.other['method'] != "GET":
response.setStatus(405)
return ""
elif mime_type != context.Base_handleAcceptHeader([mime_type]):
response.setStatus(406)
return ""
elif context.getPortalType() not in ["Software Instance", "Slave Instance"]:
response.setStatus(403)
return ""
import json
memcached_dict = context.getPortalObject().portal_memcached.getMemcachedDict(
key_prefix='slap_tool',
plugin_path='portal_memcached/default_memcached_plugin')
try:
d = memcached_dict[context.getReference()]
except KeyError:
d = {
"user": "SlapOS Master",
"text": "#error no data found for %s" % context.getReference()
}
else:
d = json.loads(d)
result_dict = {
'news': [d],
'_links': {
"self": { "href": context.Base_getRequestUrl() },
# XXX current type
"index": {
"href": "urn:jio:get:%s" % context.getRelativeUrl(),
"title": "Software Instance"
},
},
}
response.setHeader('Content-Type', mime_type)
return json.dumps(result_dict, indent=2)
...@@ -48,57 +48,6 @@ ...@@ -48,57 +48,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_body</string> </key>
<value> <string>from zExceptions import Unauthorized\n
from AccessControl import getSecurityManager\n
if REQUEST is None:\n
raise Unauthorized\n
\n
response = REQUEST.RESPONSE\n
mime_type = \'application/hal+json\'\n
\n
if REQUEST.other[\'method\'] != "GET":\n
response.setStatus(405)\n
return ""\n
elif mime_type != context.Base_handleAcceptHeader([mime_type]):\n
response.setStatus(406)\n
return ""\n
elif context.getPortalType() not in ["Software Instance", "Slave Instance"]:\n
response.setStatus(403)\n
return ""\n
\n
import json\n
\n
memcached_dict = context.getPortalObject().portal_memcached.getMemcachedDict(\n
key_prefix=\'slap_tool\',\n
plugin_path=\'portal_memcached/default_memcached_plugin\')\n
try:\n
d = memcached_dict[context.getReference()]\n
except KeyError:\n
d = {\n
"user": "SlapOS Master",\n
"text": "#error no data found for %s" % context.getReference()\n
}\n
else:\n
d = json.loads(d)\n
\n
result_dict = {\n
\'news\': [d],\n
\'_links\': {\n
"self": { "href": context.Base_getRequestUrl() },\n
# XXX current type\n
"index": {\n
"href": "urn:jio:get:%s" % context.getRelativeUrl(),\n
"title": "Software Instance"\n
},\n
},\n
}\n
\n
response.setHeader(\'Content-Type\', mime_type)\n
return json.dumps(result_dict, indent=2)\n
</string> </value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>REQUEST=None</string> </value> <value> <string>REQUEST=None</string> </value>
......
from zExceptions import Unauthorized
from AccessControl import getSecurityManager
if REQUEST is None:
raise Unauthorized
response = REQUEST.RESPONSE
mime_type = 'application/hal+json'
if REQUEST.other['method'] != "GET":
response.setStatus(405)
return ""
elif mime_type != context.Base_handleAcceptHeader([mime_type]):
response.setStatus(406)
return ""
elif context.getPortalType() not in ["Software Instance", "Slave Instance"]:
response.setStatus(403)
return ""
if context.getSlapState() == "stop_requested":
state = 'stopped'
elif context.getSlapState() == "start_requested":
state = 'started'
else:
state = 'destroyed'
import json
result_dict = {
'_links': {
"self": { "href": context.Base_getRequestUrl() },
"index": {
"href": "urn:jio:get:%s" % context.getRelativeUrl(),
"title": "Software Instance",
},
'action_object_jump': {
"href": "%s/ERP5Document_getHateoas" % context.getSpecialiseValue().getAbsoluteUrl(),
"title": "Hosting Subscription",
}
},
}
response.setHeader('Content-Type', mime_type)
return json.dumps(result_dict, indent=2)
...@@ -48,52 +48,6 @@ ...@@ -48,52 +48,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_body</string> </key>
<value> <string>from zExceptions import Unauthorized\n
from AccessControl import getSecurityManager\n
if REQUEST is None:\n
raise Unauthorized\n
\n
response = REQUEST.RESPONSE\n
mime_type = \'application/hal+json\'\n
\n
if REQUEST.other[\'method\'] != "GET":\n
response.setStatus(405)\n
return ""\n
elif mime_type != context.Base_handleAcceptHeader([mime_type]):\n
response.setStatus(406)\n
return ""\n
elif context.getPortalType() not in ["Software Instance", "Slave Instance"]:\n
response.setStatus(403)\n
return ""\n
\n
if context.getSlapState() == "stop_requested":\n
state = \'stopped\'\n
elif context.getSlapState() == "start_requested":\n
state = \'started\'\n
else:\n
state = \'destroyed\'\n
\n
import json\n
result_dict = {\n
\'_links\': {\n
"self": { "href": context.Base_getRequestUrl() },\n
"index": {\n
"href": "urn:jio:get:%s" % context.getRelativeUrl(),\n
"title": "Software Instance",\n
},\n
\'action_object_jump\': {\n
"href": "%s/ERP5Document_getHateoas" % context.getSpecialiseValue().getAbsoluteUrl(),\n
"title": "Hosting Subscription",\n
}\n
},\n
}\n
\n
response.setHeader(\'Content-Type\', mime_type)\n
return json.dumps(result_dict, indent=2)\n
</string> </value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>REQUEST=None</string> </value> <value> <string>REQUEST=None</string> </value>
......
from zExceptions import Unauthorized
from AccessControl import getSecurityManager
if REQUEST is None:
raise Unauthorized
response = REQUEST.RESPONSE
mime_type = 'application/hal+json'
if REQUEST.other['method'] != "GET":
response.setStatus(405)
return ""
elif mime_type != context.Base_handleAcceptHeader([mime_type]):
response.setStatus(406)
return ""
elif context.getPortalType() != "Person":
response.setStatus(403)
return ""
import json
result_dict = {
'_links': {
"self": { "href": context.Base_getRequestUrl() },
# XXX current type
"index": {
"href": "urn:jio:get:%s" % context.getRelativeUrl(),
"title": "Person"
},
"content": [],
},
}
for sql_obj in context.getPortalObject().portal_catalog(
portal_type="Computer",
default_source_administration_uid=context.getUid(),
):
obj = sql_obj.getObject()
result_dict['_links']['content'].append({
'href': '%s/ERP5Document_getHateoas' % obj.absolute_url(),
'title': obj.getTitle(),
})
response.setHeader('Content-Type', mime_type)
return json.dumps(result_dict, indent=2)
...@@ -48,53 +48,6 @@ ...@@ -48,53 +48,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_body</string> </key>
<value> <string>from zExceptions import Unauthorized\n
from AccessControl import getSecurityManager\n
if REQUEST is None:\n
raise Unauthorized\n
\n
response = REQUEST.RESPONSE\n
mime_type = \'application/hal+json\'\n
\n
if REQUEST.other[\'method\'] != "GET":\n
response.setStatus(405)\n
return ""\n
elif mime_type != context.Base_handleAcceptHeader([mime_type]):\n
response.setStatus(406)\n
return ""\n
elif context.getPortalType() != "Person":\n
response.setStatus(403)\n
return ""\n
\n
import json\n
result_dict = {\n
\'_links\': {\n
"self": { "href": context.Base_getRequestUrl() },\n
# XXX current type\n
"index": {\n
"href": "urn:jio:get:%s" % context.getRelativeUrl(),\n
"title": "Person"\n
},\n
"content": [],\n
},\n
}\n
\n
for sql_obj in context.getPortalObject().portal_catalog(\n
portal_type="Computer",\n
default_source_administration_uid=context.getUid(),\n
):\n
obj = sql_obj.getObject()\n
result_dict[\'_links\'][\'content\'].append({\n
\'href\': \'%s/ERP5Document_getHateoas\' % obj.absolute_url(),\n
\'title\': obj.getTitle(),\n
})\n
\n
response.setHeader(\'Content-Type\', mime_type)\n
return json.dumps(result_dict, indent=2)\n
</string> </value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>REQUEST=None</string> </value> <value> <string>REQUEST=None</string> </value>
......
from zExceptions import Unauthorized
from AccessControl import getSecurityManager
if REQUEST is None:
raise Unauthorized
response = REQUEST.RESPONSE
mime_type = 'application/hal+json'
if REQUEST.other['method'] != "GET":
response.setStatus(405)
return ""
elif mime_type != context.Base_handleAcceptHeader([mime_type]):
response.setStatus(406)
return ""
elif context.getPortalType() != "Person":
response.setStatus(403)
return ""
import json
result_dict = {
'_links': {
"self": { "href": context.Base_getRequestUrl() },
# XXX current type
"index": {
"href": "urn:jio:get:%s" % context.getRelativeUrl(),
"title": "Person"
},
"content": [],
},
}
for sql_obj in context.getPortalObject().portal_catalog(
portal_type="Hosting Subscription",
default_destination_section_uid=context.getUid(),
validation_state="validated"
):
obj = sql_obj.getObject()
result_dict['_links']['content'].append({
'href': '%s/ERP5Document_getHateoas' % obj.absolute_url(),
'title': obj.getTitle()
})
response.setHeader('Content-Type', mime_type)
return json.dumps(result_dict, indent=2)
...@@ -48,54 +48,6 @@ ...@@ -48,54 +48,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_body</string> </key>
<value> <string>from zExceptions import Unauthorized\n
from AccessControl import getSecurityManager\n
if REQUEST is None:\n
raise Unauthorized\n
\n
response = REQUEST.RESPONSE\n
mime_type = \'application/hal+json\'\n
\n
if REQUEST.other[\'method\'] != "GET":\n
response.setStatus(405)\n
return ""\n
elif mime_type != context.Base_handleAcceptHeader([mime_type]):\n
response.setStatus(406)\n
return ""\n
elif context.getPortalType() != "Person":\n
response.setStatus(403)\n
return ""\n
\n
import json\n
result_dict = {\n
\'_links\': {\n
"self": { "href": context.Base_getRequestUrl() },\n
# XXX current type\n
"index": {\n
"href": "urn:jio:get:%s" % context.getRelativeUrl(),\n
"title": "Person"\n
},\n
"content": [],\n
},\n
}\n
\n
for sql_obj in context.getPortalObject().portal_catalog(\n
portal_type="Hosting Subscription",\n
default_destination_section_uid=context.getUid(),\n
validation_state="validated"\n
):\n
obj = sql_obj.getObject()\n
result_dict[\'_links\'][\'content\'].append({\n
\'href\': \'%s/ERP5Document_getHateoas\' % obj.absolute_url(),\n
\'title\': obj.getTitle()\n
})\n
\n
response.setHeader(\'Content-Type\', mime_type)\n
return json.dumps(result_dict, indent=2)\n
</string> </value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>REQUEST=None</string> </value> <value> <string>REQUEST=None</string> </value>
......
from zExceptions import Unauthorized
from AccessControl import getSecurityManager
if REQUEST is None:
raise Unauthorized
response = REQUEST.RESPONSE
mime_type = 'application/json'
if REQUEST.other['method'] != "POST":
response.setStatus(405)
return ""
elif mime_type != context.Base_getRequestHeader('Content-Type'):
response.setStatus(406)
return ""
elif context.getPortalType() != "Person":
response.setStatus(403)
return ""
else:
import json
try:
data_dict = json.loads(context.Base_getRequestBody())
except (TypeError, ValueError):
response.setStatus(400)
return ""
else:
def dictToXml(dict_data):
assert same_type(dict_data, {})
result = "<?xml version='1.0' encoding='utf-8'?><instance>\n"
for key, value in dict_data.items():
result += """ <parameter id="%s">%s</parameter>\n""" % (key.encode("UTF-8"), value.encode("UTF-8"))
result += "</instance>"
return result
try:
parameter_kw = {
'software_release': data_dict['software_release'].encode("UTF-8"),
'software_title': data_dict['title'].encode("UTF-8"),
'software_type': data_dict['software_type'].encode("UTF-8"),
'instance_xml': dictToXml(data_dict['parameter']),
'sla_xml': dictToXml(data_dict['sla']),
'shared': data_dict['slave'],
'state': data_dict['status'].encode("UTF-8"),
}
except KeyError:
response.setStatus(400)
return ""
else:
context.requestSoftwareInstance(**parameter_kw)
# XXX Return hosting subscription link
response.setStatus(201)
return ""
...@@ -48,67 +48,6 @@ ...@@ -48,67 +48,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_body</string> </key>
<value> <string encoding="cdata"><![CDATA[
from zExceptions import Unauthorized\n
from AccessControl import getSecurityManager\n
if REQUEST is None:\n
raise Unauthorized\n
\n
response = REQUEST.RESPONSE\n
mime_type = \'application/json\'\n
\n
if REQUEST.other[\'method\'] != "POST":\n
response.setStatus(405)\n
return ""\n
elif mime_type != context.Base_getRequestHeader(\'Content-Type\'):\n
response.setStatus(406)\n
return ""\n
elif context.getPortalType() != "Person":\n
response.setStatus(403)\n
return ""\n
else:\n
import json\n
try:\n
data_dict = json.loads(context.Base_getRequestBody())\n
except (TypeError, ValueError):\n
response.setStatus(400)\n
return ""\n
else:\n
\n
def dictToXml(dict_data):\n
assert same_type(dict_data, {})\n
result = "<?xml version=\'1.0\' encoding=\'utf-8\'?><instance>\\n"\n
for key, value in dict_data.items():\n
result += """ <parameter id="%s">%s</parameter>\\n""" % (key.encode("UTF-8"), value.encode("UTF-8"))\n
result += "</instance>"\n
return result\n
\n
try:\n
parameter_kw = {\n
\'software_release\': data_dict[\'software_release\'].encode("UTF-8"),\n
\'software_title\': data_dict[\'title\'].encode("UTF-8"),\n
\'software_type\': data_dict[\'software_type\'].encode("UTF-8"),\n
\'instance_xml\': dictToXml(data_dict[\'parameter\']),\n
\'sla_xml\': dictToXml(data_dict[\'sla\']),\n
\'shared\': data_dict[\'slave\'],\n
\'state\': data_dict[\'status\'].encode("UTF-8"),\n
}\n
except KeyError:\n
response.setStatus(400)\n
return ""\n
else:\n
\n
context.requestSoftwareInstance(**parameter_kw)\n
# XXX Return hosting subscription link\n
response.setStatus(201)\n
return ""\n
]]></string> </value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>REQUEST=None</string> </value> <value> <string>REQUEST=None</string> </value>
......
from zExceptions import Unauthorized
from AccessControl import getSecurityManager
if REQUEST is None:
raise Unauthorized
response = REQUEST.RESPONSE
mime_type = 'application/hal+json'
if REQUEST.other['method'] != "GET":
response.setStatus(405)
return ""
elif mime_type != context.Base_handleAcceptHeader([mime_type]):
response.setStatus(406)
return ""
elif context.getPortalType() not in ["Software Installation"]:
response.setStatus(403)
return ""
else:
if context.getSlapState() == "stop_requested":
state = 'stopped'
elif context.getSlapState() == "start_requested":
state = 'started'
else:
state = 'destroyed'
import json
result_dict = {
'title': context.getTitle(),
'status': state,
'_links': {
"self": { "href": context.Base_getRequestUrl() },
"index": {
"href": "urn:jio:get:%s" % context.getRelativeUrl(),
"title": "Software Installation"
},
},
}
url_string = context.getUrlString(None)
if url_string is not None:
result_dict["_links"]["software_release"] = { "href": url_string }
response.setHeader('Content-Type', mime_type)
return json.dumps(result_dict)
...@@ -48,54 +48,6 @@ ...@@ -48,54 +48,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_body</string> </key>
<value> <string>from zExceptions import Unauthorized\n
from AccessControl import getSecurityManager\n
if REQUEST is None:\n
raise Unauthorized\n
\n
response = REQUEST.RESPONSE\n
mime_type = \'application/hal+json\'\n
\n
if REQUEST.other[\'method\'] != "GET":\n
response.setStatus(405)\n
return ""\n
elif mime_type != context.Base_handleAcceptHeader([mime_type]):\n
response.setStatus(406)\n
return ""\n
elif context.getPortalType() not in ["Software Installation"]:\n
response.setStatus(403)\n
return ""\n
else:\n
\n
if context.getSlapState() == "stop_requested":\n
state = \'stopped\'\n
elif context.getSlapState() == "start_requested":\n
state = \'started\'\n
else:\n
state = \'destroyed\'\n
\n
import json\n
result_dict = {\n
\'title\': context.getTitle(),\n
\'status\': state,\n
\'_links\': {\n
"self": { "href": context.Base_getRequestUrl() },\n
"index": {\n
"href": "urn:jio:get:%s" % context.getRelativeUrl(),\n
"title": "Software Installation"\n
},\n
},\n
}\n
url_string = context.getUrlString(None)\n
if url_string is not None:\n
result_dict["_links"]["software_release"] = { "href": url_string }\n
\n
response.setHeader(\'Content-Type\', mime_type)\n
return json.dumps(result_dict)\n
</string> </value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>REQUEST=None</string> </value> <value> <string>REQUEST=None</string> </value>
......
from zExceptions import Unauthorized
from AccessControl import getSecurityManager
if REQUEST is None:
raise Unauthorized
response = REQUEST.RESPONSE
mime_type = 'application/hal+json'
if REQUEST.other['method'] != "GET":
response.setStatus(405)
return ""
elif mime_type != context.Base_handleAcceptHeader([mime_type]):
response.setStatus(406)
return ""
elif context.getPortalType() not in ["Software Installation"]:
raise
response.setStatus(403)
return ""
import json
memcached_dict = context.getPortalObject().portal_memcached.getMemcachedDict(
key_prefix='slap_tool',
plugin_path='portal_memcached/default_memcached_plugin')
try:
d = memcached_dict[context.getReference()]
except KeyError:
d = {
"user": "SlapOS Master",
"text": "#error no data found for %s" % context.getReference()
}
else:
d = json.loads(d)
result_dict = {
'news': [d],
'_links': {
"self": { "href": context.Base_getRequestUrl() },
# XXX current type
"index": {
"href": "urn:jio:get:%s" % context.getRelativeUrl(),
"title": "Software Instance"
},
},
}
response.setHeader('Content-Type', mime_type)
return json.dumps(result_dict, indent=2)
...@@ -48,58 +48,6 @@ ...@@ -48,58 +48,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_body</string> </key>
<value> <string>from zExceptions import Unauthorized\n
from AccessControl import getSecurityManager\n
if REQUEST is None:\n
raise Unauthorized\n
\n
response = REQUEST.RESPONSE\n
mime_type = \'application/hal+json\'\n
\n
if REQUEST.other[\'method\'] != "GET":\n
response.setStatus(405)\n
return ""\n
elif mime_type != context.Base_handleAcceptHeader([mime_type]):\n
response.setStatus(406)\n
return ""\n
elif context.getPortalType() not in ["Software Installation"]:\n
raise\n
response.setStatus(403)\n
return ""\n
\n
import json\n
\n
memcached_dict = context.getPortalObject().portal_memcached.getMemcachedDict(\n
key_prefix=\'slap_tool\',\n
plugin_path=\'portal_memcached/default_memcached_plugin\')\n
try:\n
d = memcached_dict[context.getReference()]\n
except KeyError:\n
d = {\n
"user": "SlapOS Master",\n
"text": "#error no data found for %s" % context.getReference()\n
}\n
else:\n
d = json.loads(d)\n
\n
result_dict = {\n
\'news\': [d],\n
\'_links\': {\n
"self": { "href": context.Base_getRequestUrl() },\n
# XXX current type\n
"index": {\n
"href": "urn:jio:get:%s" % context.getRelativeUrl(),\n
"title": "Software Instance"\n
},\n
},\n
}\n
\n
response.setHeader(\'Content-Type\', mime_type)\n
return json.dumps(result_dict, indent=2)\n
</string> </value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>REQUEST=None</string> </value> <value> <string>REQUEST=None</string> </value>
......
erp5_hal_json_style erp5_hal_json_style
slapos_cloud slapos_cloud
slapos_slap_tool slapos_slap_tool
\ 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