OWASP O2 Platform Blog

Creating an API to be consumed by an O2 Script

After creating a Lamba method and putting it on a CSharp file the usual next step is to create an API that can wrap the functionality that we want.

In this case, I’m creating an API for the OWASP version of  TeamMentor  (which you can get from Git-Hub) so here are the two steps I took to create the API

Step 1: Create a CSharp file called API_TeamMentor.cs and located in C:\O2\_New_O2_Scripts\TeamMentor\API_TeamMentor.cs

// This file is part of the OWASP O2 Platform (<a href="http://www.owasp.org/index.php/OWASP_O2_Platform">http://www.owasp.org/index.php/OWASP_O2_Platform</a>) and is released under the Apache 2.0 License (<a href="http://www.apache.org/licenses/LICENSE-2.0">http://www.apache.org/licenses/LICENSE-2.0</a>)
using System;
using System.Text;
using O2.Kernel;
using O2.Kernel.ExtensionMethods;
using O2.DotNetWrappers.ExtensionMethods;using O2.Extra_O2_Scripts;
//O2File:C:\O2\_New_O2_Scripts\TeamMentor\_Extra_O2_Scripts.cs
namespace O2.XRules.Database.APIs
{
    public class API_TeamMentor
    {      
  public string WorkFolder {get;set;}
  public string DataFolder {get;set;}
  
  public API_TeamMentor()
  {
   WorkFolder = @"C:\O2\_New_O2_Scripts\TeamMentor";
   DataFolder = @"C:\SI\SecurityInnovation-OWASP-TeamMentor-Library-9f0a009";
  }
  
  public API_TeamMentor createAssembliesFromXmlFiles()
  {
   //create the dlls that we need to consume these xml file
   DataFolder.pathCombine("OWASP.xml").createAssemblyFromXml(WorkFolder, "tm_Main");
   DataFolder.pathCombine(@"OWASP\index.xml").createAssemblyFromXml(WorkFolder, "tm_Index");
   DataFolder.pathCombine(@"OWASP\Attack\2b2a09fd-a10d-479f-a3df-8e28870319b6.xml").createAssemblyFromXml(WorkFolder, "tm_Article");   
   return this;
  }
  
    }
}

Step 2: Consume API file from an O2 Script:


var teamMentor = new API_TeamMentor();
teamMentor.createAssembliesFromXmlFiles();

return teamMentor;

return "ok";
//using O2.XRules.Database.APIs
//O2File:C:\O2\_New_O2_Scripts\TeamMentor\API_TeamMentor.cs

Note: the execution of the above code is going to create 3 *.XSD, 3 *.CS and 3 *.DLL files in the C:\O2\_New_O2_Scripts\TeamMentor folder:

February 20, 2011 - Posted by | O2 Internals

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: