From f3c724b10e91b75bbf1746962ae1a50522b8968e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C5=81ukasz=20Nowak?= <luke@nexedi.com>
Date: Tue, 16 Oct 2012 15:04:08 +0200
Subject: [PATCH] Implement getting/revoking Computer certificate.

---
 .../scripts/Computer_getCertificate.xml       | 78 +++++++++++++++++++
 .../scripts/Computer_revokeCertificate.xml    | 72 +++++++++++++++++
 .../states/draft.xml                          |  2 +
 .../transitions/get_certificate.xml           | 62 +++++++++++++++
 .../transitions/revoke_certificate.xml        | 62 +++++++++++++++
 master/bt5/vifib_slap/bt/revision             |  2 +-
 6 files changed, 277 insertions(+), 1 deletion(-)
 create mode 100644 master/bt5/vifib_slap/WorkflowTemplateItem/portal_workflow/computer_slap_interface_workflow/scripts/Computer_getCertificate.xml
 create mode 100644 master/bt5/vifib_slap/WorkflowTemplateItem/portal_workflow/computer_slap_interface_workflow/scripts/Computer_revokeCertificate.xml
 create mode 100644 master/bt5/vifib_slap/WorkflowTemplateItem/portal_workflow/computer_slap_interface_workflow/transitions/get_certificate.xml
 create mode 100644 master/bt5/vifib_slap/WorkflowTemplateItem/portal_workflow/computer_slap_interface_workflow/transitions/revoke_certificate.xml

diff --git a/master/bt5/vifib_slap/WorkflowTemplateItem/portal_workflow/computer_slap_interface_workflow/scripts/Computer_getCertificate.xml b/master/bt5/vifib_slap/WorkflowTemplateItem/portal_workflow/computer_slap_interface_workflow/scripts/Computer_getCertificate.xml
new file mode 100644
index 000000000..ea8d8568e
--- /dev/null
+++ b/master/bt5/vifib_slap/WorkflowTemplateItem/portal_workflow/computer_slap_interface_workflow/scripts/Computer_getCertificate.xml
@@ -0,0 +1,78 @@
+<?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>_body</string> </key>
+            <value> <string>computer = state_change[\'object\']\n
+\n
+if computer.getDestinationReference() is not None:\n
+  raise ValueError(\'Certificate still active.\')\n
+\n
+ca = context.getPortalObject().portal_certificate_authority\n
+certificate_dict = ca.getNewCertificate(computer.getReference())\n
+\n
+computer.setDestinationReference(certificate_dict["id"])\n
+\n
+context.REQUEST.set("computer_certificate", certificate_dict["certificate"])\n
+context.REQUEST.set("computer_key", certificate_dict["key"])\n
+</string> </value>
+        </item>
+        <item>
+            <key> <string>_params</string> </key>
+            <value> <string>state_change</string> </value>
+        </item>
+        <item>
+            <key> <string>id</string> </key>
+            <value> <string>Computer_getCertificate</string> </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+</ZopeData>
diff --git a/master/bt5/vifib_slap/WorkflowTemplateItem/portal_workflow/computer_slap_interface_workflow/scripts/Computer_revokeCertificate.xml b/master/bt5/vifib_slap/WorkflowTemplateItem/portal_workflow/computer_slap_interface_workflow/scripts/Computer_revokeCertificate.xml
new file mode 100644
index 000000000..9a6b896a0
--- /dev/null
+++ b/master/bt5/vifib_slap/WorkflowTemplateItem/portal_workflow/computer_slap_interface_workflow/scripts/Computer_revokeCertificate.xml
@@ -0,0 +1,72 @@
+<?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>_body</string> </key>
+            <value> <string>computer = state_change[\'object\']\n
+destination_reference = computer.getDestinationReference()\n
+if destination_reference is None:\n
+  raise ValueError(\'No certificate\')\n
+context.getPortalObject().portal_certificate_authority.revokeCertificate(destination_reference)\n
+computer.setDestinationReference(None)\n
+</string> </value>
+        </item>
+        <item>
+            <key> <string>_params</string> </key>
+            <value> <string>state_change</string> </value>
+        </item>
+        <item>
+            <key> <string>id</string> </key>
+            <value> <string>Computer_revokeCertificate</string> </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+</ZopeData>
diff --git a/master/bt5/vifib_slap/WorkflowTemplateItem/portal_workflow/computer_slap_interface_workflow/states/draft.xml b/master/bt5/vifib_slap/WorkflowTemplateItem/portal_workflow/computer_slap_interface_workflow/states/draft.xml
index 8ea0f5931..61878173d 100644
--- a/master/bt5/vifib_slap/WorkflowTemplateItem/portal_workflow/computer_slap_interface_workflow/states/draft.xml
+++ b/master/bt5/vifib_slap/WorkflowTemplateItem/portal_workflow/computer_slap_interface_workflow/states/draft.xml
@@ -24,9 +24,11 @@
               <tuple>
                 <string>approve_computer_registration</string>
                 <string>create_computer_registration</string>
+                <string>get_certificate</string>
                 <string>report_computer_bang</string>
                 <string>request_computer_registration</string>
                 <string>request_software_release</string>
+                <string>revoke_certificate</string>
               </tuple>
             </value>
         </item>
diff --git a/master/bt5/vifib_slap/WorkflowTemplateItem/portal_workflow/computer_slap_interface_workflow/transitions/get_certificate.xml b/master/bt5/vifib_slap/WorkflowTemplateItem/portal_workflow/computer_slap_interface_workflow/transitions/get_certificate.xml
new file mode 100644
index 000000000..fa56e7a4a
--- /dev/null
+++ b/master/bt5/vifib_slap/WorkflowTemplateItem/portal_workflow/computer_slap_interface_workflow/transitions/get_certificate.xml
@@ -0,0 +1,62 @@
+<?xml version="1.0"?>
+<ZopeData>
+  <record id="1" aka="AAAAAAAAAAE=">
+    <pickle>
+      <global name="TransitionDefinition" module="Products.DCWorkflow.Transitions"/>
+    </pickle>
+    <pickle>
+      <dictionary>
+        <item>
+            <key> <string>actbox_category</string> </key>
+            <value> <string>workflow</string> </value>
+        </item>
+        <item>
+            <key> <string>actbox_icon</string> </key>
+            <value> <string></string> </value>
+        </item>
+        <item>
+            <key> <string>actbox_name</string> </key>
+            <value> <string></string> </value>
+        </item>
+        <item>
+            <key> <string>actbox_url</string> </key>
+            <value> <string></string> </value>
+        </item>
+        <item>
+            <key> <string>after_script_name</string> </key>
+            <value> <string>Computer_getCertificate</string> </value>
+        </item>
+        <item>
+            <key> <string>description</string> </key>
+            <value> <string></string> </value>
+        </item>
+        <item>
+            <key> <string>guard</string> </key>
+            <value>
+              <none/>
+            </value>
+        </item>
+        <item>
+            <key> <string>id</string> </key>
+            <value> <string>get_certificate</string> </value>
+        </item>
+        <item>
+            <key> <string>new_state_id</string> </key>
+            <value> <string></string> </value>
+        </item>
+        <item>
+            <key> <string>script_name</string> </key>
+            <value> <string></string> </value>
+        </item>
+        <item>
+            <key> <string>title</string> </key>
+            <value> <string></string> </value>
+        </item>
+        <item>
+            <key> <string>trigger_type</string> </key>
+            <value> <int>2</int> </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+</ZopeData>
diff --git a/master/bt5/vifib_slap/WorkflowTemplateItem/portal_workflow/computer_slap_interface_workflow/transitions/revoke_certificate.xml b/master/bt5/vifib_slap/WorkflowTemplateItem/portal_workflow/computer_slap_interface_workflow/transitions/revoke_certificate.xml
new file mode 100644
index 000000000..05539dd7e
--- /dev/null
+++ b/master/bt5/vifib_slap/WorkflowTemplateItem/portal_workflow/computer_slap_interface_workflow/transitions/revoke_certificate.xml
@@ -0,0 +1,62 @@
+<?xml version="1.0"?>
+<ZopeData>
+  <record id="1" aka="AAAAAAAAAAE=">
+    <pickle>
+      <global name="TransitionDefinition" module="Products.DCWorkflow.Transitions"/>
+    </pickle>
+    <pickle>
+      <dictionary>
+        <item>
+            <key> <string>actbox_category</string> </key>
+            <value> <string>workflow</string> </value>
+        </item>
+        <item>
+            <key> <string>actbox_icon</string> </key>
+            <value> <string></string> </value>
+        </item>
+        <item>
+            <key> <string>actbox_name</string> </key>
+            <value> <string></string> </value>
+        </item>
+        <item>
+            <key> <string>actbox_url</string> </key>
+            <value> <string></string> </value>
+        </item>
+        <item>
+            <key> <string>after_script_name</string> </key>
+            <value> <string>Computer_revokeCertificate</string> </value>
+        </item>
+        <item>
+            <key> <string>description</string> </key>
+            <value> <string></string> </value>
+        </item>
+        <item>
+            <key> <string>guard</string> </key>
+            <value>
+              <none/>
+            </value>
+        </item>
+        <item>
+            <key> <string>id</string> </key>
+            <value> <string>revoke_certificate</string> </value>
+        </item>
+        <item>
+            <key> <string>new_state_id</string> </key>
+            <value> <string></string> </value>
+        </item>
+        <item>
+            <key> <string>script_name</string> </key>
+            <value> <string></string> </value>
+        </item>
+        <item>
+            <key> <string>title</string> </key>
+            <value> <string></string> </value>
+        </item>
+        <item>
+            <key> <string>trigger_type</string> </key>
+            <value> <int>2</int> </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+</ZopeData>
diff --git a/master/bt5/vifib_slap/bt/revision b/master/bt5/vifib_slap/bt/revision
index 7edd58a8b..f08bce7b1 100644
--- a/master/bt5/vifib_slap/bt/revision
+++ b/master/bt5/vifib_slap/bt/revision
@@ -1 +1 @@
-840
\ No newline at end of file
+841
\ No newline at end of file
-- 
2.30.9