Commit fc56880e authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_cloud&jio: Add Person.requestToken API

  This API aims to handle token generation for person, rather them
  keep ad-hoc API on scripts for specific usage
parent 877b3cb5
person = state_change['object']
portal = person.getPortalObject()
# Get required arguments
kwargs = state_change.kwargs
# Required args
# Raise TypeError if all parameters are not provided
try:
request_url = kwargs['request_url']
except KeyError:
raise TypeError, "Person_requestToken takes exactly 1 argument"
request_method = "POST"
access_token = portal.access_token_module.newContent(
portal_type="One Time Restricted Access Token",
agent_value=person,
url_string=request_url,
url_method=request_method
)
access_token_id = access_token.getId()
access_token.validate()
context.REQUEST.set("token", access_token_id)
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Workflow Script" module="erp5.portal_type"/>
</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>state_change</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>script_Person_requestToken</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Workflow Script</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Person_requestToken</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -16,6 +16,7 @@
<key> <string>categories</string> </key>
<value>
<tuple>
<string>destination/portal_workflow/person_slap_interface_workflow/transition_request_token</string>
<string>destination/portal_workflow/person_slap_interface_workflow/transition_request_compute_node</string>
<string>destination/portal_workflow/person_slap_interface_workflow/transition_request_project</string>
<string>destination/portal_workflow/person_slap_interface_workflow/transition_request_software_instance</string>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Workflow Transition" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>action</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>action_name</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>action_type/workflow</string>
<string>before_script/portal_workflow/person_slap_interface_workflow/script_Person_checkConsistency</string>
<string>after_script/portal_workflow/person_slap_interface_workflow/script_Person_requestToken</string>
</tuple>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>guard_permission</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>icon</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>transition_request_token</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Workflow Transition</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Request Token</string> </value>
</item>
<item>
<key> <string>trigger_type</string> </key>
<value> <int>2</int> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -4,21 +4,15 @@ portal = context.getPortalObject()
person = portal.portal_membership.getAuthenticatedMember().getUserValue()
web_site = context.getWebSiteValue()
request_method = "POST"
slapos_master_web_url = web_site.getLayoutProperty(
"configuration_slapos_master_web_url", web_site.absolute_url())
"configuration_slapos_master_web_url",
default=web_site.absolute_url()
)
request_url = "%s/%s" % (slapos_master_web_url, "Person_requestComputer")
access_token = portal.access_token_module.newContent(
portal_type="One Time Restricted Access Token",
agent_value=person,
url_string=request_url,
url_method=request_method
)
access_token_id = access_token.getId()
access_token.validate()
person.requestToken(request_url=request_url)
access_token_id = context.REQUEST.get("token")
slapos_master_api = web_site.getLayoutProperty(
"configuration_slapos_master_api", "https://slap.vifib.com")
......
......@@ -10,8 +10,6 @@ except ValueError:
pass
web_site = context.getWebSiteValue()
request_method = "POST"
request_url = "%s/%s" % (
web_site.getLayoutProperty(
"configuration_slapos_master_web_url",
......@@ -20,14 +18,8 @@ request_url = "%s/%s" % (
"Person_getCertificate"
)
access_token = portal.access_token_module.newContent(
portal_type="One Time Restricted Access Token",
agent_value=person,
url_string=request_url,
url_method=request_method
)
access_token_id = access_token.getId()
access_token.validate()
person.requestToken(request_url=request_url)
access_token_id = context.REQUEST.get("token")
request = context.REQUEST
response = request.RESPONSE
......
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