You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by mi...@apache.org on 2017/05/24 02:40:06 UTC

[01/14] incubator-trafficcontrol git commit: Applying review comments by mitchell852

Repository: incubator-trafficcontrol
Updated Branches:
  refs/heads/master ef05b19bd -> 95c1f3804


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/b7eb8db4/traffic_ops/app/t/api/1.2/api_capabilities.t
----------------------------------------------------------------------
diff --git a/traffic_ops/app/t/api/1.2/api_capabilities.t b/traffic_ops/app/t/api/1.2/api_capabilities.t
index 71371fe..5581bec 100644
--- a/traffic_ops/app/t/api/1.2/api_capabilities.t
+++ b/traffic_ops/app/t/api/1.2/api_capabilities.t
@@ -152,7 +152,7 @@ $t->post_ok("/api/1.2/api_capabilities" => {Accept => 'application/json'} => jso
 	, 'Does mapping details return?';
 
 #get by cap name
-$t->get_ok("/api/1.2/api_capabilities/capability/$cap_name")->status_is(200)
+$t->get_ok("/api/1.2/api_capabilities?capability=$cap_name")->status_is(200)
 	->json_is( "/response/0/id" => 1 )
 	->json_is( "/response/0/httpMethod" => $http_method )
 	->json_is( "/response/0/route" => $route )


[07/14] incubator-trafficcontrol git commit: Changed parmaeter name from "capName" to "capability". Added "capability" as a query parameter to the api_capabilities API as a filter, and removed the dedicated API Updated the documentation and UT accordingl

Posted by mi...@apache.org.
Changed parmaeter name from "capName" to "capability".
Added "capability" as a query parameter to the api_capabilities API as a filter, and removed the dedicated API
Updated the documentation and UT accordingly.


Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/a9827fdf
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/a9827fdf
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/a9827fdf

Branch: refs/heads/master
Commit: a9827fdf88ad3a8025539c2a92c2e5103f3991ce
Parents: 7fb81cc
Author: naamashoresh <na...@qwilt.com>
Authored: Sun May 21 11:30:32 2017 +0300
Committer: Jeremy Mitchell <mi...@gmail.com>
Committed: Tue May 23 20:39:03 2017 -0600

----------------------------------------------------------------------
 .../traffic_ops_api/v12/api_capability.rst      | 137 ++++++-------------
 .../traffic_ops_api/v12/capability.rst          |  24 ++--
 traffic_ops/app/lib/API/ApiCapability.pm        |  16 +--
 traffic_ops/app/t/api/1.2/api_capabilities.t    |  54 ++++----
 traffic_ops/app/t/api/1.2/capabilities.t        |   4 +-
 5 files changed, 94 insertions(+), 141 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/a9827fdf/docs/source/development/traffic_ops_api/v12/api_capability.rst
----------------------------------------------------------------------
diff --git a/docs/source/development/traffic_ops_api/v12/api_capability.rst b/docs/source/development/traffic_ops_api/v12/api_capability.rst
index d1a3b86..1ec1ed8 100644
--- a/docs/source/development/traffic_ops_api/v12/api_capability.rst
+++ b/docs/source/development/traffic_ops_api/v12/api_capability.rst
@@ -31,6 +31,14 @@ API-Capabilities
 
   Role(s) Required: None
 
+  **Query Parameters**
+
+  +----------------+----------+--------+------------------------------------+
+  |    Name        | Required | Type   |         Description                |
+  +================+==========+========+====================================+
+  | ``capability`` |   no     | string | Capability name.                   |
+  +----------------+----------+--------+------------------------------------+
+
   **Response Properties**
 
   +-------------------+--------+--------------------------------------------------+
@@ -42,7 +50,7 @@ API-Capabilities
   +-------------------+--------+--------------------------------------------------+
   | ``route``         | string | API route.                                       |
   +-------------------+--------+--------------------------------------------------+
-  | ``capName``       | string | Capability name.                                 |
+  | ``capability``    | string | Capability name.                                 |
   +-------------------+--------+--------------------------------------------------+
   | ``lastUpdated``   | string |                                                  |
   +-------------------+--------+--------------------------------------------------+
@@ -55,14 +63,14 @@ API-Capabilities
               "id": "6",
               "httpMethod": "GET",
               "route": "/api/*/asns",
-              "capName": "asn-read",
+              "capability": "asn-read",
               "lastUpdated": "2017-04-02 08:22:43"
            },
            {
               "id": "7",
               "httpMethod": "GET",
               "route": "/api/*/asns/*",
-              "capName": "asn-read",
+              "capability": "asn-read",
               "lastUpdated": "2017-04-02 08:22:43"
            }
         ]
@@ -80,11 +88,11 @@ API-Capabilities
 
   **Request Route Parameters**
 
-  +-------------+----------+---------------------------------------------+
-  |    Name     | Required |                Description                  |
-  +=============+==========+=============================================+
-  |   ``id``    |   yes    | Mapping id.                                 |
-  +-------------+----------+---------------------------------------------+
+  +-------------+----------+-------+-------------------------------------+
+  |    Name     | Required |  Type |         Description                 |
+  +=============+==========+=======+=====================================+
+  |   ``id``    |   yes    | int   | Mapping id.                         |
+  +-------------+----------+-------+-------------------------------------+
 
   **Response Properties**
 
@@ -97,7 +105,7 @@ API-Capabilities
   +-------------------+--------+--------------------------------------------------+
   | ``route``         | string | API route.                                       |
   +-------------------+--------+--------------------------------------------------+
-  | ``capName``       | string | Capability name.                                 |
+  | ``capability``    | string | Capability name.                                 |
   +-------------------+--------+--------------------------------------------------+
   | ``lastUpdated``   | string |                                                  |
   +-------------------+--------+--------------------------------------------------+
@@ -110,62 +118,7 @@ API-Capabilities
               "id": "6",
               "httpMethod": "GET",
               "route": "/api/*/asns",
-              "capName": "asn-read",
-              "lastUpdated": "2017-04-02 08:22:43"
-           }
-        ]
-    }
-
-|
-
-**GET /api/1.2/api_capabilities/capability/:name**
-
-  Get all API-capability mappings by capability name.
-
-  Authentication Required: Yes
-
-  Role(s) Required: None
-
-  **Request Route Parameters**
-
-  +-------------+----------+---------------------------------------------+
-  |    Name     | Required |                Description                  |
-  +=============+==========+=============================================+
-  |   ``name``  |   yes    | Capability name.                            |
-  +-------------+----------+---------------------------------------------+
-
-  **Response Properties**
-
-  +-------------------+--------+--------------------------------------------------+
-  |    Parameter      |  Type  |                   Description                    |
-  +===================+========+==================================================+
-  | ``id``            | int    | Mapping id.                                      |
-  +-------------------+--------+--------------------------------------------------+
-  | ``httpMethod``    | enum   | One of: 'GET', 'POST', 'PUT', 'PATCH', 'DELETE'. |
-  +-------------------+--------+--------------------------------------------------+
-  | ``route``         | string | API route.                                       |
-  +-------------------+--------+--------------------------------------------------+
-  | ``capName``       | string | Capability name                                  |
-  +-------------------+--------+--------------------------------------------------+
-  | ``lastUpdated``   | string |                                                  |
-  +-------------------+--------+--------------------------------------------------+
-
-  **Response Example** ::
-
-    {
-     "response": [
-           {
-              "id": "6",
-              "httpMethod": "GET",
-              "route": "/api/*/asns",
-              "capName": "asn-read",
-              "lastUpdated": "2017-04-02 08:22:43"
-           },
-           {
-              "id": "7",
-              "httpMethod": "GET",
-              "route": "/api/*/asns/*",
-              "capName": "asn-read",
+              "capability": "asn-read",
               "lastUpdated": "2017-04-02 08:22:43"
            }
         ]
@@ -181,24 +134,24 @@ API-Capabilities
 
   Role(s) Required:  admin or oper
 
-  **Request Parameters**
+  **Request Properties**
 
-  +-------------------+--------+--------------------------------------------------+
-  |    Parameter      |  Type  |                   Description                    |
-  +===================+========+==================================================+
-  | ``httpMethod``    | enum   | One of: 'GET', 'POST', 'PUT', 'PATCH', 'DELETE'. |
-  +-------------------+--------+--------------------------------------------------+
-  | ``route``         | string | API route.                                       |
-  +-------------------+--------+--------------------------------------------------+
-  | ``capName``       | string | Capability name                                  |
-  +-------------------+--------+--------------------------------------------------+
+  +----------------+----------+--------+--------------------------------------------------+
+  |    Name        | Required | Type   |                Description                       |
+  +================+==========+========+==================================================+
+  | ``httpMethod`` | yes      | enum   | One of: 'GET', 'POST', 'PUT', 'PATCH', 'DELETE'. |
+  +----------------+----------+--------+--------------------------------------------------+
+  | ``route``      | yes      | string | API route.                                       |
+  +----------------+----------+--------+--------------------------------------------------+
+  | ``capability`` | yes      | string | Capability name                                  |
+  +----------------+----------+--------+--------------------------------------------------+
 
   **Request Example** ::
 
     {
         "httpMethod": "POST",
         "route": "/api/*/cdns",
-        "capName": "cdn-write"
+        "capability": "cdn-write"
     }
 
   **Response Properties**
@@ -214,7 +167,7 @@ API-Capabilities
   +--------------------+--------+--------------------------------------------------+
   | ``>route``         | string | API route.                                       |
   +--------------------+--------+--------------------------------------------------+
-  | ``>capName``       | string | Capability name                                  |
+  | ``>capability``    | string | Capability name                                  |
   +--------------------+--------+--------------------------------------------------+
   | ``>lastUpdated``   | string |                                                  |
   +--------------------+--------+--------------------------------------------------+
@@ -233,7 +186,7 @@ API-Capabilities
               "id": "6",
               "httpMethod": "POST",
               "route": "/api/*/cdns",
-              "capName": "cdn-write",
+              "capability": "cdn-write",
               "lastUpdated": "2017-04-02 08:22:43"
         },
         "alerts":[
@@ -256,11 +209,11 @@ API-Capabilities
 
   **Request Route Parameters**
 
-  +-------------------+----------+------------------------------------------------+
-  | Name              |   Type   |                 Description                    |
-  +===================+==========+================================================+
-  |   ``id``          |   yes    | Mapping id.                                    |
-  +-------------------+----------+------------------------------------------------+
+  +-------------------+----------+--------+---------------------------------------+
+  | Name              | Required | Type   |           Description                 |
+  +===================+==========+========+=======================================+
+  |   ``id``          |   yes    | string | Mapping id.                           |
+  +-------------------+----------+--------+---------------------------------------+
 
   **Request Properties**
 
@@ -271,7 +224,7 @@ API-Capabilities
   +-------------------+--------+--------------------------------------------------+
   | ``route``         | string | API route.                                       |
   +-------------------+--------+--------------------------------------------------+
-  | ``capName``       | string | Capability name                                  |
+  | ``capability``    | string | Capability name                                  |
   +-------------------+--------+--------------------------------------------------+
 
 
@@ -280,7 +233,7 @@ API-Capabilities
     {
         "httpMethod": "GET",
         "route": "/api/*/cdns",
-        "capName": "cdn-read"
+        "capability": "cdn-read"
     }
 
   **Response Properties**
@@ -296,7 +249,7 @@ API-Capabilities
   +--------------------+--------+--------------------------------------------------+
   | ``>route``         | string | API route.                                       |
   +--------------------+--------+--------------------------------------------------+
-  | ``>capName``       | string | Capability name                                  |
+  | ``>capability``    | string | Capability name                                  |
   +--------------------+--------+--------------------------------------------------+
   | ``>lastUpdated``   | string |                                                  |
   +--------------------+--------+--------------------------------------------------+
@@ -314,7 +267,7 @@ API-Capabilities
               "id": "6",
               "httpMethod": "GET",
               "route": "/api/*/cdns",
-              "capName": "cdn-read",
+              "capability": "cdn-read",
               "lastUpdated": "2017-04-02 08:22:43"
         },
         "alerts":[
@@ -337,11 +290,11 @@ API-Capabilities
 
   **Request Route Parameters**
 
-  +-----------------+----------+------------------------------------------------+
-  | Name            | Required | Description                                    |
-  +=================+==========+================================================+
-  |   ``id``          |   yes    | Mapping id.                                  |
-  +-----------------+----------+------------------------------------------------+
+  +-------------------+----------+--------+---------------------------------------+
+  | Name              | Required | Type   |           Description                 |
+  +===================+==========+========+=======================================+
+  |   ``id``          |   yes    | string | Mapping id.                           |
+  +-------------------+----------+--------+---------------------------------------+
 
   **Response Properties**
 

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/a9827fdf/docs/source/development/traffic_ops_api/v12/capability.rst
----------------------------------------------------------------------
diff --git a/docs/source/development/traffic_ops_api/v12/capability.rst b/docs/source/development/traffic_ops_api/v12/capability.rst
index eb3d0f7..e91863e 100644
--- a/docs/source/development/traffic_ops_api/v12/capability.rst
+++ b/docs/source/development/traffic_ops_api/v12/capability.rst
@@ -72,11 +72,11 @@ Capabilities
 
   **Request Route Parameters**
 
-  +-------------+----------+---------------------------------------------+
-  |    Name     | Required |                Description                  |
-  +=============+==========+=============================================+
-  |   ``name``  |   yes    | Capability name.                            |
-  +-------------+----------+---------------------------------------------+
+  +-------------+----------+--------+------------------------------------+
+  |    Name     | Required | Type   |          Description               |
+  +=============+==========+========+====================================+
+  |   ``name``  |   yes    | string | Capability name.                   |
+  +-------------+----------+--------+------------------------------------+
 
   **Response Properties**
 
@@ -114,13 +114,13 @@ Capabilities
 
   **Request Parameters**
 
-  +-------------------+--------+-------------------------------------------------+
-  |    Parameter      |  Type  |                   Description                   |
-  +===================+========+=================================================+
-  | ``name``          | string | Capability name.                                |
-  +-------------------+--------+-------------------------------------------------+
-  | ``description``   | string | Describing the APIs covered by the capability.  |
-  +-------------------+--------+-------------------------------------------------+
+  +-----------------+----------+--------+-------------------------------------------------+
+  |      Name       | Required | Type   |          Description                            |
+  +=================+==========+========+=================================================+
+  |   ``name``      | yes      | string | Capability name.                                |
+  +-----------------+----------+--------+-------------------------------------------------+
+  | ``description`` | yes      | string | Describing the APIs covered by the capability.  |
+  +-----------------+----------+--------+-------------------------------------------------+
 
   **Request Example** ::
 

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/a9827fdf/traffic_ops/app/lib/API/ApiCapability.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/app/lib/API/ApiCapability.pm b/traffic_ops/app/lib/API/ApiCapability.pm
index 2ee71ab..5686d00 100644
--- a/traffic_ops/app/lib/API/ApiCapability.pm
+++ b/traffic_ops/app/lib/API/ApiCapability.pm
@@ -46,7 +46,7 @@ sub index {
 				"id"          	=> $row->id,
 				"httpMethod"	=> $row->http_method,
 				"route" 		=> $row->route,
-				"capName"   	=> $row->capability->name,
+				"capability"   	=> $row->capability->name,
 				"lastUpdated" 	=> $row->last_updated
 			}
 		);
@@ -66,7 +66,7 @@ sub renderResults {
 				"id"          	=> $row->id,
 				"httpMethod"	=> $row->http_method,
 				"route" 		=> $row->route,
-				"capName"   	=> $row->capability->name,
+				"capability"   	=> $row->capability->name,
 				"lastUpdated" 	=> $row->last_updated
 			}
 		);
@@ -147,7 +147,7 @@ sub create {
 
 	my $http_method = $params->{httpMethod} if defined($params->{httpMethod});
 	my $route = $params->{route} if defined($params->{route});
-	my $capability = $params->{capName} if defined($params->{capName});
+	my $capability = $params->{capability} if defined($params->{capability});
 	my $id = undef;
 
 	my ( $is_valid, $errStr ) = $self->is_mapping_valid( $id, $http_method, $route, $capability );
@@ -169,10 +169,10 @@ sub create {
 		$response->{id}				= $rs->id;
 		$response->{httpMethod}		= $rs->http_method;
 		$response->{route}			= $rs->route;
-		$response->{capName}		= $rs->capability->name;
+		$response->{capability}		= $rs->capability->name;
 		$response->{lastUpdated}	= $rs->last_updated;
 
-		&log( $self, "Created API-Capability mapping: '$response->{httpMethod}', '$response->{route}', '$response->{capName}' for id: " . $response->{id}, "APICHANGE" );
+		&log( $self, "Created API-Capability mapping: '$response->{httpMethod}', '$response->{route}', '$response->{capability}' for id: " . $response->{id}, "APICHANGE" );
 
 		return $self->success( $response, "API-Capability mapping was created." );
 	}
@@ -196,7 +196,7 @@ sub update {
 
 	my $http_method = $params->{httpMethod} if defined($params->{httpMethod});
 	my $route = $params->{route} if defined($params->{route});
-	my $capability = $params->{capName} if defined($params->{capName});
+	my $capability = $params->{capability} if defined($params->{capability});
 
 	my $mapping = $self->db->resultset('ApiCapability')->find( { id => $id } );
 	if ( !defined($mapping) ) {
@@ -220,10 +220,10 @@ sub update {
 		$response->{id}				= $rs->id;
 		$response->{httpMethod}		= $rs->http_method;
 		$response->{route}			= $rs->route;
-		$response->{capName}		= $rs->capability->name;
+		$response->{capability}		= $rs->capability->name;
 		$response->{lastUpdated}	= $rs->last_updated;
 
-		&log( $self, "Updated API-Capability mapping: '$response->{httpMethod}', '$response->{route}', '$response->{capName}' for id: " . $response->{id}, "APICHANGE" );
+		&log( $self, "Updated API-Capability mapping: '$response->{httpMethod}', '$response->{route}', '$response->{capability}' for id: " . $response->{id}, "APICHANGE" );
 
 		return $self->success( $response, "API-Capability mapping was updated." );
 	}

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/a9827fdf/traffic_ops/app/t/api/1.2/api_capabilities.t
----------------------------------------------------------------------
diff --git a/traffic_ops/app/t/api/1.2/api_capabilities.t b/traffic_ops/app/t/api/1.2/api_capabilities.t
index 5581bec..5221c03 100644
--- a/traffic_ops/app/t/api/1.2/api_capabilities.t
+++ b/traffic_ops/app/t/api/1.2/api_capabilities.t
@@ -71,12 +71,12 @@ my $http_method = "GET";
 my $route = "sample/route";
 my $cap_name = "basic-read";
 $t->post_ok("/api/1.2/api_capabilities" => {Accept => 'application/json'} => json => {
-			"httpMethod" => $http_method, "route" => $route, "capName" => $cap_name
+			"httpMethod" => $http_method, "route" => $route, "capability" => $cap_name
 		})->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content};} )
 	->json_is( "/response/id" => 1 )
 	->json_is( "/response/httpMethod" => $http_method )
 	->json_is( "/response/route" => $route )
-	->json_is( "/response/capName" => $cap_name )
+	->json_is( "/response/capability" => $cap_name )
 	, 'Does mapping details return?';
 
 #verifying the create worked
@@ -84,7 +84,7 @@ $t->get_ok("/api/1.2/api_capabilities")->status_is(200)
 	->json_is( "/response/0/id" => 1 )
 	->json_is( "/response/0/httpMethod" => $http_method )
 	->json_is( "/response/0/route" => $route )
-	->json_is( "/response/0/capName" => $cap_name )
+	->json_is( "/response/0/capability" => $cap_name )
 	->or( sub { diag $t->tx->res->content->asset->{content}; } );;
 
 #verifying get single
@@ -92,12 +92,12 @@ $t->get_ok("/api/1.2/api_capabilities/1")->status_is(200)
 	->json_is( "/response/0/id" => 1 )
 	->json_is( "/response/0/httpMethod" => $http_method )
 	->json_is( "/response/0/route" => $route )
-	->json_is( "/response/0/capName" => $cap_name )
+	->json_is( "/response/0/capability" => $cap_name )
 	->or( sub { diag $t->tx->res->content->asset->{content}; } );;
 
 #insert the same mapping twice - fails
 $t->post_ok("/api/1.2/api_capabilities" => {Accept => 'application/json'} => json => {
-		"httpMethod" => $http_method, "route" => $route, "capName" => $cap_name
+		"httpMethod" => $http_method, "route" => $route, "capability" => $cap_name
 	})->status_is(400)->or( sub { diag $t->tx->res->content->asset->{content};} )
 	->json_is( "/alerts/0/text" => "HTTP method \'$http_method\', route \'$route\' are already mapped to capability: $cap_name" )
 	, 'Is same entry twice?';
@@ -105,12 +105,12 @@ $t->post_ok("/api/1.2/api_capabilities" => {Accept => 'application/json'} => jso
 #edit a mapping
 my $cap_name_updated = "cdn-write";
 $t->put_ok("/api/1.2/api_capabilities/1" => {Accept => 'application/json'} => json => {
-		"httpMethod" => $http_method, "route" => $route, "capName" => $cap_name_updated
+		"httpMethod" => $http_method, "route" => $route, "capability" => $cap_name_updated
 	})->status_is(200)
 	->json_is( "/response/id" => 1 )
 	->json_is( "/response/httpMethod" => $http_method )
 	->json_is( "/response/route" => $route )
-	->json_is( "/response/capName" => $cap_name_updated )
+	->json_is( "/response/capability" => $cap_name_updated )
 	, 'Did update succeed?';
 
 #get after update
@@ -118,17 +118,17 @@ $t->get_ok("/api/1.2/api_capabilities/1" => {Accept => 'application/json'} )->st
 	->json_is( "/response/0/id" => 1 )
 	->json_is( "/response/0/httpMethod" => $http_method )
 	->json_is( "/response/0/route" => $route )
-	->json_is( "/response/0/capName" => $cap_name_updated )
+	->json_is( "/response/0/capability" => $cap_name_updated )
 	, 'Did get after update succeed?';
 
 #edit the mapping back
 $t->put_ok("/api/1.2/api_capabilities/1" => {Accept => 'application/json'} => json => {
-		"httpMethod" => $http_method, "route" => $route, "capName" => $cap_name
+		"httpMethod" => $http_method, "route" => $route, "capability" => $cap_name
 	})->status_is(200)
 	->json_is( "/response/id" => 1 )
 	->json_is( "/response/httpMethod" => $http_method )
 	->json_is( "/response/route" => $route )
-	->json_is( "/response/capName" => $cap_name )
+	->json_is( "/response/capability" => $cap_name )
 	, 'Did update succeed?';
 
 #get after update
@@ -136,19 +136,19 @@ $t->get_ok("/api/1.2/api_capabilities/1" => {Accept => 'application/json'} )->st
 	->json_is( "/response/0/id" => 1 )
 	->json_is( "/response/0/httpMethod" => $http_method )
 	->json_is( "/response/0/route" => $route )
-	->json_is( "/response/0/capName" => $cap_name )
+	->json_is( "/response/0/capability" => $cap_name )
 	, 'Did get after update back succeed?';
 
 #insert another mapping
 my $http_method_post = "POST";
 my $route_sample2 = "sample/route2";
 $t->post_ok("/api/1.2/api_capabilities" => {Accept => 'application/json'} => json => {
-		"httpMethod" => $http_method_post, "route" => $route_sample2, "capName" => $cap_name
+		"httpMethod" => $http_method_post, "route" => $route_sample2, "capability" => $cap_name
 	})->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content};} )
 	->json_is( "/response/id" => 2 )
 	->json_is( "/response/httpMethod" => $http_method_post )
 	->json_is( "/response/route" => $route_sample2 )
-	->json_is( "/response/capName" => $cap_name )
+	->json_is( "/response/capability" => $cap_name )
 	, 'Does mapping details return?';
 
 #get by cap name
@@ -156,11 +156,11 @@ $t->get_ok("/api/1.2/api_capabilities?capability=$cap_name")->status_is(200)
 	->json_is( "/response/0/id" => 1 )
 	->json_is( "/response/0/httpMethod" => $http_method )
 	->json_is( "/response/0/route" => $route )
-	->json_is( "/response/0/capName" => $cap_name )
+	->json_is( "/response/0/capability" => $cap_name )
 	->json_is( "/response/1/id" => 2 )
 	->json_is( "/response/1/httpMethod" => $http_method_post )
 	->json_is( "/response/1/route" => $route_sample2 )
-	->json_is( "/response/1/capName" => $cap_name )
+	->json_is( "/response/1/capability" => $cap_name )
 	->or( sub { diag $t->tx->res->content->asset->{content}; } );;
 
 #test delete
@@ -175,54 +175,54 @@ $t->get_ok("/api/1.2/api_capabilities/2")->status_is(200)->json_is( "/response",
 
 # adding invalid entry - no httpMethod
 $t->post_ok("/api/1.2/api_capabilities" => {Accept => 'application/json'} => json => {
-		"route" => $route, "capName" => $cap_name
+		"route" => $route, "capability" => $cap_name
 	})->status_is(400)->or( sub { diag $t->tx->res->content->asset->{content};} )
 	->json_is( "/alerts/0/text" => "HTTP method is required." )
 	, 'Was invalid insert (no httpMethod) reject correctly?';
 
 # adding invalid entry - no route
 $t->post_ok("/api/1.2/api_capabilities" => {Accept => 'application/json'} => json => {
-		"httpMethod" => $http_method, "capName" => $cap_name
+		"httpMethod" => $http_method, "capability" => $cap_name
 	})->status_is(400)->or( sub { diag $t->tx->res->content->asset->{content};} )
 	->json_is( "/alerts/0/text" => "Route is required." )
 	, 'Was invalid insert (no route) reject correctly?';
 
 # adding invalid entry - empty route
 $t->post_ok("/api/1.2/api_capabilities" => {Accept => 'application/json'} => json => {
-		"httpMethod" => $http_method, "capName" => $cap_name, "route" => ""
+		"httpMethod" => $http_method, "capability" => $cap_name, "route" => ""
 	})->status_is(400)->or( sub { diag $t->tx->res->content->asset->{content};} )
 	->json_is( "/alerts/0/text" => "Route is required." )
 	, 'Was invalid insert (no route) reject correctly?';
 
-# adding invalid entry - no capName
+# adding invalid entry - no capability
 $t->post_ok("/api/1.2/api_capabilities" => {Accept => 'application/json'} => json => {
 		"httpMethod" => $http_method, "route" => $route
 	})->status_is(400)->or( sub { diag $t->tx->res->content->asset->{content};} )
 	->json_is( "/alerts/0/text" => "Capability name is required." )
-	, 'Was invalid insert (no capName) reject correctly?';
+	, 'Was invalid insert (no capability) reject correctly?';
 
-# adding invalid entry - empty capName
+# adding invalid entry - empty capability
 $t->post_ok("/api/1.2/api_capabilities" => {Accept => 'application/json'} => json => {
-		"httpMethod" => $http_method, "route" => $route, "capName" => ""
+		"httpMethod" => $http_method, "route" => $route, "capability" => ""
 	})->status_is(400)->or( sub { diag $t->tx->res->content->asset->{content};} )
 	->json_is( "/alerts/0/text" => "Capability name is required." )
-	, 'Was invalid insert (no capName) reject correctly?';
+	, 'Was invalid insert (no capability) reject correctly?';
 
 # adding invalid entry - invalid httpMethod
 my $invalid_http_method = 'BAD';
 $t->post_ok("/api/1.2/api_capabilities" => {Accept => 'application/json'} => json => {
-		"httpMethod" => $invalid_http_method, "route" => $route, "capName" => $cap_name
+		"httpMethod" => $invalid_http_method, "route" => $route, "capability" => $cap_name
 	})->status_is(400)->or( sub { diag $t->tx->res->content->asset->{content};} )
 	->json_is( "/alerts/0/text" => "HTTP method \'$invalid_http_method\' is invalid. Valid values are: DELETE, GET, PATCH, POST, PUT" )
-	, 'Was invalid insert (no capName) reject correctly?';
+	, 'Was invalid insert (no capability) reject correctly?';
 
 # adding invalid entry - non-existing capability
 my $non_existing_cap = "non-existing";
 $t->post_ok("/api/1.2/api_capabilities" => {Accept => 'application/json'} => json => {
-		"httpMethod" => $http_method, "route" => $route, "capName" => $non_existing_cap
+		"httpMethod" => $http_method, "route" => $route, "capability" => $non_existing_cap
 	})->status_is(400)->or( sub { diag $t->tx->res->content->asset->{content};} )
 	->json_is( "/alerts/0/text" => "Capability \'$non_existing_cap\' does not exist." )
-	, 'Was invalid insert (no capName) reject correctly?';
+	, 'Was invalid insert (no capability) reject correctly?';
 
 
 ok $t->get_ok('/logout')->status_is(302)->or( sub { diag $t->tx->res->content->asset->{content}; } );

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/a9827fdf/traffic_ops/app/t/api/1.2/capabilities.t
----------------------------------------------------------------------
diff --git a/traffic_ops/app/t/api/1.2/capabilities.t b/traffic_ops/app/t/api/1.2/capabilities.t
index b1031ef..3219b38 100644
--- a/traffic_ops/app/t/api/1.2/capabilities.t
+++ b/traffic_ops/app/t/api/1.2/capabilities.t
@@ -162,12 +162,12 @@ $t->post_ok("/api/1.2/capabilities" => {Accept => 'application/json'} => json =>
 my $http_method = "GET";
 my $route = "sample/route";
 $t->post_ok("/api/1.2/api_capabilities" => {Accept => 'application/json'} => json => {
-		"httpMethod" => $http_method, "route" => $route, "capName" => $cap_name
+		"httpMethod" => $http_method, "route" => $route, "capability" => $cap_name
 	})->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content};} )
 	->json_is( "/response/id" => 1 )
 	->json_is( "/response/httpMethod" => $http_method )
 	->json_is( "/response/route" => $route )
-	->json_is( "/response/capName" => $cap_name )
+	->json_is( "/response/capability" => $cap_name )
 	, 'Does mapping details return?';
 
 #test delete -  should fail


[05/14] incubator-trafficcontrol git commit: Documentation for new capabilities & api_capabilities APIs.

Posted by mi...@apache.org.
Documentation for new capabilities & api_capabilities APIs.

(cherry picked from commit d79f76c2deb11ffbd3f237d4833bac03d87ca61b)


Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/c324141d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/c324141d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/c324141d

Branch: refs/heads/master
Commit: c324141da978eea4883412c0cabe3436ae3c66e7
Parents: 7a5ce13
Author: naamashoresh <na...@qwilt.com>
Authored: Thu May 4 10:30:12 2017 +0300
Committer: Jeremy Mitchell <mi...@gmail.com>
Committed: Tue May 23 20:39:02 2017 -0600

----------------------------------------------------------------------
 docs/source/development/traffic_ops.rst         |   2 +
 .../traffic_ops_api/v12/api_capability.rst      | 367 +++++++++++++++++++
 .../traffic_ops_api/v12/capability.rst          | 271 ++++++++++++++
 3 files changed, 640 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/c324141d/docs/source/development/traffic_ops.rst
----------------------------------------------------------------------
diff --git a/docs/source/development/traffic_ops.rst b/docs/source/development/traffic_ops.rst
index ed287b5..d068d26 100644
--- a/docs/source/development/traffic_ops.rst
+++ b/docs/source/development/traffic_ops.rst
@@ -603,10 +603,12 @@ API 1.2 Reference
 .. toctree:: 
   :maxdepth: 1
 
+  traffic_ops_api/v12/api_capability
   traffic_ops_api/v12/asn
   traffic_ops_api/v12/cachegroup
   traffic_ops_api/v12/cachegroup_parameter
   traffic_ops_api/v12/cache_stats
+  traffic_ops_api/v12/capability
   traffic_ops_api/v12/cdn
   traffic_ops_api/v12/changelog
   traffic_ops_api/v12/deliveryservice

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/c324141d/docs/source/development/traffic_ops_api/v12/api_capability.rst
----------------------------------------------------------------------
diff --git a/docs/source/development/traffic_ops_api/v12/api_capability.rst b/docs/source/development/traffic_ops_api/v12/api_capability.rst
new file mode 100644
index 0000000..d1a3b86
--- /dev/null
+++ b/docs/source/development/traffic_ops_api/v12/api_capability.rst
@@ -0,0 +1,367 @@
+..
+..
+.. Licensed under the Apache License, Version 2.0 (the "License");
+.. you may not use this file except in compliance with the License.
+.. You may obtain a copy of the License at
+..
+..     http://www.apache.org/licenses/LICENSE-2.0
+..
+.. Unless required by applicable law or agreed to in writing, software
+.. distributed under the License is distributed on an "AS IS" BASIS,
+.. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+.. See the License for the specific language governing permissions and
+.. limitations under the License.
+..
+
+.. _to-api-v12-api_capability:
+
+API-Capabilities
+============
+
+.. _to-api-v12-api-capability-route:
+
+/api/1.2/api_capabilities
++++++++++++++
+
+**GET /api/1.2/api_capabilities**
+
+  Get all API-capability mappings.
+
+  Authentication Required: Yes
+
+  Role(s) Required: None
+
+  **Response Properties**
+
+  +-------------------+--------+--------------------------------------------------+
+  |    Parameter      |  Type  |                   Description                    |
+  +===================+========+==================================================+
+  | ``id``            | int    | Mapping id.                                      |
+  +-------------------+--------+--------------------------------------------------+
+  | ``httpMethod``    | enum   | One of: 'GET', 'POST', 'PUT', 'PATCH', 'DELETE'. |
+  +-------------------+--------+--------------------------------------------------+
+  | ``route``         | string | API route.                                       |
+  +-------------------+--------+--------------------------------------------------+
+  | ``capName``       | string | Capability name.                                 |
+  +-------------------+--------+--------------------------------------------------+
+  | ``lastUpdated``   | string |                                                  |
+  +-------------------+--------+--------------------------------------------------+
+
+  **Response Example** ::
+
+    {
+     "response": [
+           {
+              "id": "6",
+              "httpMethod": "GET",
+              "route": "/api/*/asns",
+              "capName": "asn-read",
+              "lastUpdated": "2017-04-02 08:22:43"
+           },
+           {
+              "id": "7",
+              "httpMethod": "GET",
+              "route": "/api/*/asns/*",
+              "capName": "asn-read",
+              "lastUpdated": "2017-04-02 08:22:43"
+           }
+        ]
+    }
+
+|
+
+**GET /api/1.2/api_capabilities/:id**
+
+  Get an API-capability mapping by id.
+
+  Authentication Required: Yes
+
+  Role(s) Required: None
+
+  **Request Route Parameters**
+
+  +-------------+----------+---------------------------------------------+
+  |    Name     | Required |                Description                  |
+  +=============+==========+=============================================+
+  |   ``id``    |   yes    | Mapping id.                                 |
+  +-------------+----------+---------------------------------------------+
+
+  **Response Properties**
+
+  +-------------------+--------+--------------------------------------------------+
+  |    Parameter      |  Type  |                   Description                    |
+  +===================+========+==================================================+
+  | ``id``            | int    | Mapping id.                                      |
+  +-------------------+--------+--------------------------------------------------+
+  | ``httpMethod``    | enum   | One of: 'GET', 'POST', 'PUT', 'PATCH', 'DELETE'. |
+  +-------------------+--------+--------------------------------------------------+
+  | ``route``         | string | API route.                                       |
+  +-------------------+--------+--------------------------------------------------+
+  | ``capName``       | string | Capability name.                                 |
+  +-------------------+--------+--------------------------------------------------+
+  | ``lastUpdated``   | string |                                                  |
+  +-------------------+--------+--------------------------------------------------+
+
+  **Response Example** ::
+
+    {
+     "response": [
+           {
+              "id": "6",
+              "httpMethod": "GET",
+              "route": "/api/*/asns",
+              "capName": "asn-read",
+              "lastUpdated": "2017-04-02 08:22:43"
+           }
+        ]
+    }
+
+|
+
+**GET /api/1.2/api_capabilities/capability/:name**
+
+  Get all API-capability mappings by capability name.
+
+  Authentication Required: Yes
+
+  Role(s) Required: None
+
+  **Request Route Parameters**
+
+  +-------------+----------+---------------------------------------------+
+  |    Name     | Required |                Description                  |
+  +=============+==========+=============================================+
+  |   ``name``  |   yes    | Capability name.                            |
+  +-------------+----------+---------------------------------------------+
+
+  **Response Properties**
+
+  +-------------------+--------+--------------------------------------------------+
+  |    Parameter      |  Type  |                   Description                    |
+  +===================+========+==================================================+
+  | ``id``            | int    | Mapping id.                                      |
+  +-------------------+--------+--------------------------------------------------+
+  | ``httpMethod``    | enum   | One of: 'GET', 'POST', 'PUT', 'PATCH', 'DELETE'. |
+  +-------------------+--------+--------------------------------------------------+
+  | ``route``         | string | API route.                                       |
+  +-------------------+--------+--------------------------------------------------+
+  | ``capName``       | string | Capability name                                  |
+  +-------------------+--------+--------------------------------------------------+
+  | ``lastUpdated``   | string |                                                  |
+  +-------------------+--------+--------------------------------------------------+
+
+  **Response Example** ::
+
+    {
+     "response": [
+           {
+              "id": "6",
+              "httpMethod": "GET",
+              "route": "/api/*/asns",
+              "capName": "asn-read",
+              "lastUpdated": "2017-04-02 08:22:43"
+           },
+           {
+              "id": "7",
+              "httpMethod": "GET",
+              "route": "/api/*/asns/*",
+              "capName": "asn-read",
+              "lastUpdated": "2017-04-02 08:22:43"
+           }
+        ]
+    }
+
+|
+
+**POST /api/1.2/api_capabilities**
+
+  Create an API-capability mapping.
+
+  Authentication Required: Yes
+
+  Role(s) Required:  admin or oper
+
+  **Request Parameters**
+
+  +-------------------+--------+--------------------------------------------------+
+  |    Parameter      |  Type  |                   Description                    |
+  +===================+========+==================================================+
+  | ``httpMethod``    | enum   | One of: 'GET', 'POST', 'PUT', 'PATCH', 'DELETE'. |
+  +-------------------+--------+--------------------------------------------------+
+  | ``route``         | string | API route.                                       |
+  +-------------------+--------+--------------------------------------------------+
+  | ``capName``       | string | Capability name                                  |
+  +-------------------+--------+--------------------------------------------------+
+
+  **Request Example** ::
+
+    {
+        "httpMethod": "POST",
+        "route": "/api/*/cdns",
+        "capName": "cdn-write"
+    }
+
+  **Response Properties**
+
+  +--------------------+--------+--------------------------------------------------+
+  |    Parameter       |  Type  |                   Description                    |
+  +====================+========+==================================================+
+  | ``response``       |  hash  | The details of the creation, if success.         |
+  +--------------------+--------+--------------------------------------------------+
+  | ``>id``            | int    | Mapping id.                                      |
+  +--------------------+--------+--------------------------------------------------+
+  | ``>httpMethod``    | enum   | One of: 'GET', 'POST', 'PUT', 'PATCH', 'DELETE'. |
+  +--------------------+--------+--------------------------------------------------+
+  | ``>route``         | string | API route.                                       |
+  +--------------------+--------+--------------------------------------------------+
+  | ``>capName``       | string | Capability name                                  |
+  +--------------------+--------+--------------------------------------------------+
+  | ``>lastUpdated``   | string |                                                  |
+  +--------------------+--------+--------------------------------------------------+
+  | ``alerts``         | array  | A collection of alert messages.                  |
+  +--------------------+--------+--------------------------------------------------+
+  | ``>level``         | string | Success, info, warning or error.                 |
+  +--------------------+--------+--------------------------------------------------+
+  | ``>text``          | string | Alert message.                                   |
+  +--------------------+--------+--------------------------------------------------+
+
+
+  **Response Example** ::
+
+    {
+        "response":{
+              "id": "6",
+              "httpMethod": "POST",
+              "route": "/api/*/cdns",
+              "capName": "cdn-write",
+              "lastUpdated": "2017-04-02 08:22:43"
+        },
+        "alerts":[
+            {
+                "level": "success",
+                "text": "API-capability mapping was created."
+            }
+        ]
+    }
+
+|
+
+**PUT /api/1.2/api_capabilities/{:id}**
+
+  Edit an API-capability mapping.
+
+  Authentication Required: Yes
+
+  Role(s) Required:  admin or oper
+
+  **Request Route Parameters**
+
+  +-------------------+----------+------------------------------------------------+
+  | Name              |   Type   |                 Description                    |
+  +===================+==========+================================================+
+  |   ``id``          |   yes    | Mapping id.                                    |
+  +-------------------+----------+------------------------------------------------+
+
+  **Request Properties**
+
+  +-------------------+--------+--------------------------------------------------+
+  |    Parameter      |  Type  |                   Description                    |
+  +===================+========+==================================================+
+  | ``httpMethod``    | enum   | One of: 'GET', 'POST', 'PUT', 'PATCH', 'DELETE'. |
+  +-------------------+--------+--------------------------------------------------+
+  | ``route``         | string | API route.                                       |
+  +-------------------+--------+--------------------------------------------------+
+  | ``capName``       | string | Capability name                                  |
+  +-------------------+--------+--------------------------------------------------+
+
+
+  **Request Example** ::
+
+    {
+        "httpMethod": "GET",
+        "route": "/api/*/cdns",
+        "capName": "cdn-read"
+    }
+
+  **Response Properties**
+
+  +--------------------+--------+--------------------------------------------------+
+  |    Parameter       |  Type  |                   Description                    |
+  +====================+========+==================================================+
+  | ``response``       |  hash  | The details of the creation, if success.         |
+  +--------------------+--------+--------------------------------------------------+
+  | ``>id``            | int    | Mapping id.                                      |
+  +--------------------+--------+--------------------------------------------------+
+  | ``>httpMethod``    | enum   | One of: 'GET', 'POST', 'PUT', 'PATCH', 'DELETE'. |
+  +--------------------+--------+--------------------------------------------------+
+  | ``>route``         | string | API route.                                       |
+  +--------------------+--------+--------------------------------------------------+
+  | ``>capName``       | string | Capability name                                  |
+  +--------------------+--------+--------------------------------------------------+
+  | ``>lastUpdated``   | string |                                                  |
+  +--------------------+--------+--------------------------------------------------+
+  | ``alerts``         | array  | A collection of alert messages.                  |
+  +--------------------+--------+--------------------------------------------------+
+  | ``>level``         | string | Success, info, warning or error.                 |
+  +--------------------+--------+--------------------------------------------------+
+  | ``>text``          | string | Alert message.                                   |
+  +--------------------+--------+--------------------------------------------------+
+
+  **Response Example** ::
+
+    {
+        "response":{
+              "id": "6",
+              "httpMethod": "GET",
+              "route": "/api/*/cdns",
+              "capName": "cdn-read",
+              "lastUpdated": "2017-04-02 08:22:43"
+        },
+        "alerts":[
+            {
+                "level": "success",
+                "text": "API-capability mapping was updated."
+            }
+        ]
+    }
+
+|
+
+**DELETE /api/1.2/api_capabilities/{:id}**
+
+  Delete a capability.
+
+  Authentication Required: Yes
+
+  Role(s) Required:  admin or oper
+
+  **Request Route Parameters**
+
+  +-----------------+----------+------------------------------------------------+
+  | Name            | Required | Description                                    |
+  +=================+==========+================================================+
+  |   ``id``          |   yes    | Mapping id.                                  |
+  +-----------------+----------+------------------------------------------------+
+
+  **Response Properties**
+
+  +-----------------+----------+------------------------------------------------+
+  |  Parameter      |  Type    |           Description                          |
+  +=================+==========+================================================+
+  |  ``alerts``     |  array   |  A collection of alert messages.               |
+  +-----------------+----------+------------------------------------------------+
+  |  ``>level``     |  string  |  success, info, warning or error.              |
+  +-----------------+----------+------------------------------------------------+
+  |  ``>text``      |  string  |  Alert message.                                |
+  +-----------------+----------+------------------------------------------------+
+
+  **Response Example** ::
+
+    {
+          "alerts": [
+                    {
+                            "level": "success",
+                            "text": "API-capability mapping deleted."
+                    }
+            ],
+    }

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/c324141d/docs/source/development/traffic_ops_api/v12/capability.rst
----------------------------------------------------------------------
diff --git a/docs/source/development/traffic_ops_api/v12/capability.rst b/docs/source/development/traffic_ops_api/v12/capability.rst
new file mode 100644
index 0000000..eb3d0f7
--- /dev/null
+++ b/docs/source/development/traffic_ops_api/v12/capability.rst
@@ -0,0 +1,271 @@
+..
+..
+.. Licensed under the Apache License, Version 2.0 (the "License");
+.. you may not use this file except in compliance with the License.
+.. You may obtain a copy of the License at
+..
+..     http://www.apache.org/licenses/LICENSE-2.0
+..
+.. Unless required by applicable law or agreed to in writing, software
+.. distributed under the License is distributed on an "AS IS" BASIS,
+.. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+.. See the License for the specific language governing permissions and
+.. limitations under the License.
+..
+
+.. _to-api-v12-capability:
+
+Capabilities
+============
+
+.. _to-api-v12-capability-route:
+
+/api/1.2/capabilities
++++++++++++++
+
+**GET /api/1.2/capabilities**
+
+  Get all capabilities.
+
+  Authentication Required: Yes
+
+  Role(s) Required: None
+
+  **Response Properties**
+
+  +-------------------+--------+-------------------------------------------------+
+  |    Parameter      |  Type  |                   Description                   |
+  +===================+========+=================================================+
+  | ``name``          | string | Capability name.                                |
+  +-------------------+--------+-------------------------------------------------+
+  | ``description``   | string | Describing the APIs covered by the capability.  |
+  +-------------------+--------+-------------------------------------------------+
+  | ``lastUpdated``   | string |                                                 |
+  +-------------------+--------+-------------------------------------------------+
+
+  **Response Example** ::
+
+    {
+     "response": [
+           {
+              "name": "cdn-read",
+              "description": "View CDN configuration",
+              "lastUpdated": "2017-04-02 08:22:43"
+           },
+           {
+              "name": "cdn-write",
+              "description": "Create, edit or delete CDN configuration",
+              "lastUpdated": "2017-04-02 08:22:43"
+           }
+        ]
+    }
+
+|
+
+**GET /api/1.2/capabilities/:name**
+
+  Get a capability by name.
+
+  Authentication Required: Yes
+
+  Role(s) Required: None
+
+  **Request Route Parameters**
+
+  +-------------+----------+---------------------------------------------+
+  |    Name     | Required |                Description                  |
+  +=============+==========+=============================================+
+  |   ``name``  |   yes    | Capability name.                            |
+  +-------------+----------+---------------------------------------------+
+
+  **Response Properties**
+
+  +-------------------+--------+-------------------------------------------------+
+  |    Parameter      |  Type  |                   Description                   |
+  +===================+========+=================================================+
+  | ``name``          | string | Capability name.                                |
+  +-------------------+--------+-------------------------------------------------+
+  | ``description``   | string | Describing the APIs covered by the capability.  |
+  +-------------------+--------+-------------------------------------------------+
+  | ``lastUpdated``   | string |                                                 |
+  +-------------------+--------+-------------------------------------------------+
+
+  **Response Example** ::
+
+    {
+     "response": [
+           {
+              "name": "cdn-read",
+              "description": "View CDN configuration",
+              "lastUpdated": "2017-04-02 08:22:43"
+           }
+        ]
+    }
+
+|
+
+**POST /api/1.2/capabilities**
+
+  Create a capability.
+
+  Authentication Required: Yes
+
+  Role(s) Required:  admin or oper
+
+  **Request Parameters**
+
+  +-------------------+--------+-------------------------------------------------+
+  |    Parameter      |  Type  |                   Description                   |
+  +===================+========+=================================================+
+  | ``name``          | string | Capability name.                                |
+  +-------------------+--------+-------------------------------------------------+
+  | ``description``   | string | Describing the APIs covered by the capability.  |
+  +-------------------+--------+-------------------------------------------------+
+
+  **Request Example** ::
+
+    {
+        "name": "cdn-write",
+        "description": "Create, edit or delete CDN configuration"
+    }
+
+  **Response Properties**
+
+  +--------------------+--------+-------------------------------------------------+
+  |    Parameter       |  Type  |                   Description                   |
+  +====================+========+=================================================+
+  | ``response``       |  hash  | The details of the creation, if success.        |
+  +--------------------+--------+-------------------------------------------------+
+  | ``>name``          | string | Capability name.                                |
+  +--------------------+--------+-------------------------------------------------+
+  | ``>description``   | string | Describing the APIs covered by the capability.  |
+  +--------------------+--------+-------------------------------------------------+
+  | ``alerts``         | array  | A collection of alert messages.                 |
+  +--------------------+--------+-------------------------------------------------+
+  | ``>level``         | string | Success, info, warning or error.                |
+  +--------------------+--------+-------------------------------------------------+
+  | ``>text``          | string | Alert message.                                  |
+  +--------------------+--------+-------------------------------------------------+
+
+
+  **Response Example** ::
+
+    {
+        "response":{
+            "name": "cdn-write",
+            "description": "Create, edit or delete CDN configuration"
+        },
+        "alerts":[
+            {
+                "level": "success",
+                "text": "Capability was created."
+            }
+        ]
+    }
+
+|
+
+**PUT /api/1.2/capabilities/{:name}**
+
+  Edit a capability.
+
+  Authentication Required: Yes
+
+  Role(s) Required:  admin or oper
+
+  **Request Route Parameters**
+
+  +-------------------+----------+------------------------------------------------+
+  | Name              |   Type   |                 Description                    |
+  +===================+==========+================================================+
+  | ``name``          | int      | Capability name.                               |
+  +-------------------+----------+------------------------------------------------+
+
+  **Request Properties**
+
+  +-------------------+--------+-------------------------------------------------+
+  |    Parameter      |  Type  |                   Description                   |
+  +===================+========+=================================================+
+  | ``description``   | string | Describing the APIs covered by the capability.  |
+  +-------------------+--------+-------------------------------------------------+
+
+
+  **Request Example** ::
+
+    {
+        "description": "View CDN configuration"
+    }
+
+  **Response Properties**
+
+  +--------------------+--------+-------------------------------------------------+
+  |    Parameter       |  Type  |                   Description                   |
+  +====================+========+=================================================+
+  | ``response``       |  hash  | The details of the update, if success.          |
+  +--------------------+--------+-------------------------------------------------+
+  | ``>name``          | string | Capability name.                                |
+  +--------------------+--------+-------------------------------------------------+
+  | ``>description``   |  int   | Describing the APIs covered by the capability.  |
+  +--------------------+--------+-------------------------------------------------+
+  | ``alerts``         | array  | A collection of alert messages.                 |
+  +--------------------+--------+-------------------------------------------------+
+  | ``>level``         | string | Success, info, warning or error.                |
+  +--------------------+--------+-------------------------------------------------+
+  | ``>text``          | string | Alert message.                                  |
+  +--------------------+--------+-------------------------------------------------+
+
+  **Response Example** ::
+
+    {
+        "response":{
+            "name": "cdn-read",
+            "description": "View CDN configuration"
+        },
+        "alerts":[
+            {
+                "level": "success",
+                "text": "Capability was updated."
+            }
+        ]
+    }
+
+|
+
+**DELETE /api/1.2/capabilities/{:name}**
+
+  Delete a capability.
+
+  Authentication Required: Yes
+
+  Role(s) Required:  admin or oper
+
+  **Request Route Parameters**
+
+  +-----------------+----------+------------------------------------------------+
+  | Name            | Required | Description                                    |
+  +=================+==========+================================================+
+  | ``name``        | yes      | Capability name.                               |
+  +-----------------+----------+------------------------------------------------+
+
+  **Response Properties**
+
+  +-----------------+----------+------------------------------------------------+
+  |  Parameter      |  Type    |           Description                          |
+  +=================+==========+================================================+
+  |  ``alerts``     |  array   |  A collection of alert messages.               |
+  +-----------------+----------+------------------------------------------------+
+  |  ``>level``     |  string  |  success, info, warning or error.              |
+  +-----------------+----------+------------------------------------------------+
+  |  ``>text``      |  string  |  Alert message.                                |
+  +-----------------+----------+------------------------------------------------+
+
+  **Response Example** ::
+
+    {
+          "alerts": [
+                    {
+                            "level": "success",
+                            "text": "Capability deleted."
+                    }
+            ],
+    }


[03/14] incubator-trafficcontrol git commit: Adding capabilities & api_capalities APIs

Posted by mi...@apache.org.
Adding capabilities & api_capalities APIs

(cherry picked from commit db31205f6cdae581f072a34347f057441721b31c)


Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/9546e8ad
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/9546e8ad
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/9546e8ad

Branch: refs/heads/master
Commit: 9546e8ad26fac8a221880867a5e62f00cf9cbbf2
Parents: 5392f50
Author: naamashoresh <na...@qwilt.com>
Authored: Thu May 4 10:28:18 2017 +0300
Committer: Jeremy Mitchell <mi...@gmail.com>
Committed: Tue May 23 20:39:02 2017 -0600

----------------------------------------------------------------------
 traffic_ops/app/lib/API/ApiCapability.pm | 258 ++++++++++++++++++++++++++
 traffic_ops/app/lib/API/Capability.pm    | 185 ++++++++++++++++++
 traffic_ops/app/lib/TrafficOpsRoutes.pm  |  17 ++
 3 files changed, 460 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/9546e8ad/traffic_ops/app/lib/API/ApiCapability.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/app/lib/API/ApiCapability.pm b/traffic_ops/app/lib/API/ApiCapability.pm
new file mode 100644
index 0000000..2e2ca73
--- /dev/null
+++ b/traffic_ops/app/lib/API/ApiCapability.pm
@@ -0,0 +1,258 @@
+package API::ApiCapability;
+#
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+#
+#
+
+use UI::Utils;
+
+use Mojo::Base 'Mojolicious::Controller';
+use Data::Dumper;
+
+
+
+my $finfo = __FILE__ . ":";
+
+my %valid_http_methods = map { $_ => 1 } ('GET', 'POST', 'PUT', 'PATCH', 'DELETE');
+
+sub all {
+	my $self = shift;
+	my @data;
+	my $orderby = "capability";
+	$orderby = $self->param('orderby') if ( defined $self->param('orderby') );
+
+	my $rs_data = $self->db->resultset("ApiCapability")->search( undef, { order_by => $orderby } );
+	while ( my $row = $rs_data->next ) {
+		push(
+			@data, {
+				"id"          	=> $row->id,
+				"httpMethod"	=> $row->http_method,
+				"route" 		=> $row->route,
+				"capName"   	=> $row->capability->name,
+				"lastUpdated" 	=> $row->last_updated
+			}
+		);
+	}
+	$self->success( \@data );
+}
+
+
+sub renderResults {
+	my $self = shift;
+	my $rs_data = shift;
+
+	my @data = ();
+	while ( my $row = $rs_data->next ) {
+		push(
+			@data, {
+				"id"          	=> $row->id,
+				"httpMethod"	=> $row->http_method,
+				"route" 		=> $row->route,
+				"capName"   	=> $row->capability->name,
+				"lastUpdated" 	=> $row->last_updated
+			}
+		);
+	}
+	$self->success( \@data );
+}
+
+sub capName {
+	my $self = shift;
+	my $capability = $self->param('name');
+
+	my $rs_data = $self->db->resultset("ApiCapability")->search( 'me.capability' => $capability );
+	$self->renderResults( $rs_data ) ;
+}
+
+sub index {
+	my $self = shift;
+	my $id = $self->param('id');
+
+	my $rs_data = $self->db->resultset("ApiCapability")->search( 'me.id' => $id );
+	$self->renderResults( $rs_data ) ;
+}
+
+sub is_mapping_valid {
+	my $self = shift;
+	my $id = shift;
+	my $http_method = shift;
+	my $route = shift;
+	my $capability = shift;
+
+	if ( !defined($http_method) ) {
+		return ( undef, "HTTP method is required." );
+	}
+
+	if ( !exists( $valid_http_methods{ $http_method } ) ) {
+		return ( undef, "HTTP method \'$http_method\' is invalid. Valid values are: " . join(", ", sort keys %valid_http_methods ) );
+	}
+
+	if ( !defined($route) or $route eq "" ) {
+		return ( undef, "Route is required." );
+	}
+
+	if ( !defined($capability) or $capability eq "" ) {
+		return (undef, "Capability name is required." );
+	}
+	# check if capability exists
+	my $rs_data = $self->db->resultset("Capability")->search( { 'name' => { 'like', $capability } } )->single();
+	if (!defined($rs_data)) {
+		return (undef, "Capability '$capability' does not exist." );
+	}
+
+	# search a mapping for the same http_method & route
+	$rs_data = $self->db->resultset("ApiCapability")->search( { 'route' => { 'like', $route } } )->search( {
+		'http_method' => { '=', $http_method } } )->single();
+	# if adding a new entry, make sure it is unique
+	if ( !defined( $id ) ) {
+		if (defined($rs_data)) {
+			my $allocated_capability = $rs_data->capability->name;
+			return (undef, "HTTP method '$http_method', route '$route' are already mapped to capability: $allocated_capability" );
+		}
+	}
+	else {
+		if (defined($rs_data)) {
+			my $lid = $rs_data->id;
+			if ($lid ne $id) {
+				my $allocated_capability = $rs_data->capability->name;
+				return (undef, "HTTP method '$http_method', route '$route' are already mapped to capability: $allocated_capability" );
+			}
+		}
+	}
+
+	return ( 1, undef );
+}
+
+sub create {
+	my $self = shift;
+	my $params = $self->req->json;
+
+	if ( !&is_oper($self) ) {
+		return $self->forbidden();
+	}
+
+	if ( !defined($params) ) {
+		return $self->alert("Parameters must be in JSON format.");
+	}
+
+	my $http_method = $params->{httpMethod} if defined($params->{httpMethod});
+	my $route = $params->{route} if defined($params->{route});
+	my $capability = $params->{capName} if defined($params->{capName});
+	my $id = undef;
+
+	my ( $is_valid, $errStr ) = $self->is_mapping_valid( $id, $http_method, $route, $capability );
+	if ( !$is_valid ) {
+		return $self->alert( $errStr );
+	}
+
+	my $values = {
+		id 			=> $self->db->resultset('ApiCapability')->get_column('id')->max() + 1,
+		http_method	=> $http_method,
+		route		=> $route,
+		capability	=> $capability
+	};
+
+	my $insert = $self->db->resultset('ApiCapability')->create($values);
+	my $rs = $insert->insert();
+	if ($rs) {
+		my $response;
+		$response->{id}				= $rs->id;
+		$response->{httpMethod}		= $rs->http_method;
+		$response->{route}			= $rs->route;
+		$response->{capName}		= $rs->capability->name;
+		$response->{lastUpdated}	= $rs->last_updated;
+
+		&log( $self, "Created API-Capability mapping: '$response->{httpMethod}', '$response->{route}', '$response->{capName}' for id: " . $response->{id}, "APICHANGE" );
+
+		return $self->success( $response, "API-Capability mapping was created." );
+	}
+	else {
+		return $self->alert( "API-Capability mapping creation failed." );
+	}
+}
+
+sub update {
+	my $self = shift;
+	my $id = $self->param('id');
+	my $params = $self->req->json;
+
+	if ( !&is_oper($self) ) {
+		return $self->forbidden();
+	}
+
+	if ( !defined($params) ) {
+		return $self->alert("Parameters must be in JSON format.");
+	}
+
+	my $http_method = $params->{httpMethod} if defined($params->{httpMethod});
+	my $route = $params->{route} if defined($params->{route});
+	my $capability = $params->{capName} if defined($params->{capName});
+
+	my $mapping = $self->db->resultset('ApiCapability')->find( { id => $id } );
+	if ( !defined($mapping) ) {
+		return $self->not_found();
+	}
+
+	my ( $is_valid, $errStr ) = $self->is_mapping_valid( $id, $http_method, $route, $capability );
+	if ( !$is_valid ) {
+		return $self->alert( $errStr );
+	}
+
+	my $values = {
+		http_method	=> $http_method,
+		route		=> $route,
+		capability	=> $capability
+	};
+
+	my $rs = $mapping->update($values);
+	if ($rs) {
+		my $response;
+		$response->{id}				= $rs->id;
+		$response->{httpMethod}		= $rs->http_method;
+		$response->{route}			= $rs->route;
+		$response->{capName}		= $rs->capability->name;
+		$response->{lastUpdated}	= $rs->last_updated;
+
+		&log( $self, "Updated API-Capability mapping: '$response->{httpMethod}', '$response->{route}', '$response->{capName}' for id: " . $response->{id}, "APICHANGE" );
+
+		return $self->success( $response, "API-Capability mapping was updated." );
+	}
+	else {
+		return $self->alert( "API-Capability mapping update failed." );
+	}
+}
+
+sub delete {
+	my $self = shift;
+	my $id     = $self->param('id');
+
+	if ( !&is_oper($self) ) {
+		return $self->forbidden();
+	}
+
+	my $mapping = $self->db->resultset('ApiCapability')->find( { id => $id } );
+	if ( !defined($mapping) ) {
+		return $self->not_found();
+	}
+
+	my $rs = $mapping->delete();
+	if ($rs) {
+		return $self->success_message("API-capability mapping deleted.");
+	} else {
+		return $self->alert( "API-capability mapping deletion failed." );
+	}
+}
+
+1;

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/9546e8ad/traffic_ops/app/lib/API/Capability.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/app/lib/API/Capability.pm b/traffic_ops/app/lib/API/Capability.pm
new file mode 100644
index 0000000..695434b
--- /dev/null
+++ b/traffic_ops/app/lib/API/Capability.pm
@@ -0,0 +1,185 @@
+package API::Capability;
+#
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+#
+#
+
+use UI::Utils;
+
+use Mojo::Base 'Mojolicious::Controller';
+use Data::Dumper;
+
+my $finfo = __FILE__ . ":";
+
+sub all {
+	my $self = shift;
+	my @data;
+	my $orderby = "name";
+	$orderby = $self->param('orderby') if ( defined $self->param('orderby') );
+
+	my $rs_data = $self->db->resultset("Capability")->search( undef, { order_by => $orderby } );
+	while ( my $row = $rs_data->next ) {
+		push(
+			@data, {
+				"name"          => $row->name,
+				"description"	=> $row->description,
+				"lastUpdated" 	=> $row->last_updated
+			}
+		);
+	}
+	$self->success( \@data );
+}
+
+sub name {
+	my $self = shift;
+	my $name = $self->param('name');
+
+	my $rs_data = $self->db->resultset("Capability")->search( 'me.name' => $name  );
+	my @data = ();
+	while ( my $row = $rs_data->next ) {
+		push(
+			@data, {
+				"name"          => $row->name,
+				"description"	=> $row->description,
+				"lastUpdated" 	=> $row->last_updated
+			}
+		);
+	}
+	$self->success( \@data );
+}
+
+sub create {
+	my $self = shift;
+	my $params = $self->req->json;
+
+	if ( !&is_oper($self) ) {
+		return $self->forbidden();
+	}
+
+	if ( !defined($params) ) {
+		return $self->alert("Parameters must be in JSON format.");
+	}
+
+	my $name = $params->{name} if defined($params->{name});
+	my $description = $params->{description} if defined($params->{description});
+
+	if ( !defined($name) or $name eq "" ) {
+		return $self->alert( "Name is required." );
+	}
+
+	if ( !defined($description) or $description eq "" ) {
+		return $self->alert( "Description is required." );
+	}
+
+	# check if capability exists
+	my $rs_data = $self->db->resultset("Capability")->search( { 'name' => { 'like', $name } } )->single();
+	if (defined($rs_data)) {
+		return $self->alert( "Capability '$name' already exists." );
+	}
+
+	my $values = {
+		name		=> $name,
+		description	=> $description
+	};
+
+	my $insert = $self->db->resultset('Capability')->create($values);
+	my $rs = $insert->insert();
+	if ($rs) {
+		my $response;
+		$response->{name}			= $rs->name;
+		$response->{description}	= $rs->description;
+
+		&log( $self, "Created Capability: '$response->{name}', '$response->{description}'", "APICHANGE" );
+
+		return $self->success( $response, "Capability was created." );
+	}
+	else {
+		return $self->alert( "Capability creation failed." );
+	}
+}
+
+sub update {
+	my $self = shift;
+	my $name = $self->param('name');
+	my $params = $self->req->json;
+
+	if ( !&is_oper($self) ) {
+		return $self->forbidden();
+	}
+
+	if ( !defined($params) ) {
+		return $self->alert("Parameters must be in JSON format.");
+	}
+
+	my $description = $params->{description} if defined($params->{description});
+
+	my $capability = $self->db->resultset('Capability')->find( { name => $name } );
+	if ( !defined($capability) or $capability eq "" ) {
+		return $self->not_found();
+	}
+
+	if ( !defined($description) or $description eq "" ) {
+		return $self->alert( "Description is required." );
+	}
+
+	my $values = {
+		description => $description
+	};
+
+	my $rs = $capability->update($values);
+	if ($rs) {
+		my $response;
+		$response->{name}			= $rs->name;
+		$response->{description}	= $rs->description;
+		$response->{lastUpdated}	= $rs->last_updated;
+
+		&log( $self, "Updated Capability: '$response->{name}', '$response->{description}'", "APICHANGE" );
+
+		return $self->success( $response, "Capability was updated." );
+	}
+	else {
+		return $self->alert( "Capability update failed." );
+	}
+}
+
+sub delete {
+	my $self = shift;
+	my $name = $self->param('name');
+
+	if ( !&is_oper($self) ) {
+		return $self->forbidden();
+	}
+
+	my $capability = $self->db->resultset('Capability')->find( { name => $name } );
+	if ( !defined($capability) ) {
+		return $self->not_found();
+	}
+
+	# make sure no api_capability refers to this capability
+	my $rs_data = $self->db->resultset("ApiCapability")->find( {'me.capability' => $name} );
+	if (defined($rs_data)) {
+		my $reference_id = $rs_data->id;
+		return $self->alert( "Capability \'$name\' is refered by an api_capability mapping: $reference_id. Deletion failed." );
+	}
+
+	my $rs = $capability->delete();
+	if ($rs) {
+		return $self->success_message("Capability deleted.");
+	} else {
+		return $self->alert( "Capability deletion failed." );
+	}
+}
+
+1;

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/9546e8ad/traffic_ops/app/lib/TrafficOpsRoutes.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/app/lib/TrafficOpsRoutes.pm b/traffic_ops/app/lib/TrafficOpsRoutes.pm
index ab6e5a7..e808b29 100644
--- a/traffic_ops/app/lib/TrafficOpsRoutes.pm
+++ b/traffic_ops/app/lib/TrafficOpsRoutes.pm
@@ -681,6 +681,23 @@ sub api_routes {
 	# Supports ?orderby=key
 	$r->get("/api/$version/roles")->over( authenticated => 1 )->to( 'Role#index', namespace => $namespace );
 
+	# -- CAPABILITIES
+	# Supports ?orderby=key
+	$r->get("/api/$version/capabilities")->over( authenticated => 1 )->to( 'Capability#all', namespace => $namespace );
+	$r->get("/api/$version/capabilities/:name")->over( authenticated => 1 )->to( 'Capability#name', namespace => $namespace );
+	$r->put("/api/$version/capabilities/:name")->over( authenticated => 1 )->to( 'Capability#update', namespace => $namespace );
+	$r->post("/api/$version/capabilities")->over( authenticated => 1 )->to( 'Capability#create', namespace => $namespace );
+	$r->delete("/api/$version/capabilities/:name")->over( authenticated => 1 )->to( 'Capability#delete', namespace => $namespace );
+
+	# -- API-CAPABILITIES
+	# Supports ?orderby=key
+	$r->get("/api/$version/api_capabilities")->over( authenticated => 1 )->to( 'ApiCapability#all', namespace => $namespace );
+	$r->get("/api/$version/api_capabilities/:id")->over( authenticated => 1 )->to( 'ApiCapability#index', namespace => $namespace );
+	$r->get("/api/$version/api_capabilities/capability/:name")->over( authenticated => 1 )->to( 'ApiCapability#capName', namespace => $namespace );
+	$r->put("/api/$version/api_capabilities/:id")->over( authenticated => 1 )->to( 'ApiCapability#update', namespace => $namespace );
+	$r->post("/api/$version/api_capabilities")->over( authenticated => 1 )->to( 'ApiCapability#create', namespace => $namespace );
+	$r->delete("/api/$version/api_capabilities/:id")->over( authenticated => 1 )->to( 'ApiCapability#delete', namespace => $namespace );
+
 	# -- SERVERS
 	# -- SERVERS: CRUD
 	$r->get("/api/$version/servers")->over( authenticated => 1 )->to( 'Server#index', namespace => $namespace );


[09/14] incubator-trafficcontrol git commit: Schema changes which are part of the previous commit.

Posted by mi...@apache.org.
Schema changes which are part of the previous commit.


Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/7fb81cc7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/7fb81cc7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/7fb81cc7

Branch: refs/heads/master
Commit: 7fb81cc7839380152f5ee79842d5e0d9c9423843
Parents: b7eb8db
Author: naamashoresh <na...@qwilt.com>
Authored: Sun May 21 11:29:05 2017 +0300
Committer: Jeremy Mitchell <mi...@gmail.com>
Committed: Tue May 23 20:39:03 2017 -0600

----------------------------------------------------------------------
 .../app/lib/Schema/Result/ApiCapability.pm      | 25 ++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/7fb81cc7/traffic_ops/app/lib/Schema/Result/ApiCapability.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/app/lib/Schema/Result/ApiCapability.pm b/traffic_ops/app/lib/Schema/Result/ApiCapability.pm
index 2c7e89c..f5ec12b 100644
--- a/traffic_ops/app/lib/Schema/Result/ApiCapability.pm
+++ b/traffic_ops/app/lib/Schema/Result/ApiCapability.pm
@@ -98,6 +98,27 @@ __PACKAGE__->add_columns(
 
 __PACKAGE__->set_primary_key("id");
 
+=head1 UNIQUE CONSTRAINTS
+
+=head2 C<api_capability_http_method_route_capability_key>
+
+=over 4
+
+=item * L</http_method>
+
+=item * L</route>
+
+=item * L</capability>
+
+=back
+
+=cut
+
+__PACKAGE__->add_unique_constraint(
+  "api_capability_http_method_route_capability_key",
+  ["http_method", "route", "capability"],
+);
+
 =head1 RELATIONS
 
 =head2 capability
@@ -116,8 +137,8 @@ __PACKAGE__->belongs_to(
 );
 
 
-# Created by DBIx::Class::Schema::Loader v0.07046 @ 2017-04-01 22:22:35
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:vYfANFCOS9i3LpGHRzMv3w
+# Created by DBIx::Class::Schema::Loader v0.07046 @ 2017-05-21 10:15:00
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:b1CNpOv08i47l8nNcqxLoA
 
 
 # You can replace this text with custom code or comments, and it will be preserved on regeneration


[14/14] incubator-trafficcontrol git commit: This closes #544

Posted by mi...@apache.org.
This closes #544


Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/95c1f380
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/95c1f380
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/95c1f380

Branch: refs/heads/master
Commit: 95c1f3804fa32dc5017c41f37e815789a932fb08
Parents: ee23727
Author: Jeremy Mitchell <mi...@gmail.com>
Authored: Tue May 23 20:39:54 2017 -0600
Committer: Jeremy Mitchell <mi...@gmail.com>
Committed: Tue May 23 20:39:54 2017 -0600

----------------------------------------------------------------------

----------------------------------------------------------------------



[13/14] incubator-trafficcontrol git commit: Removed redundant true & false variables

Posted by mi...@apache.org.
Removed redundant true & false variables


Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/ee23727c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/ee23727c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/ee23727c

Branch: refs/heads/master
Commit: ee23727c81d06fd786fbd58ea797af0de095dad0
Parents: dfb7fcb
Author: naamashoresh <na...@qwilt.com>
Authored: Sun May 21 13:53:42 2017 +0300
Committer: Jeremy Mitchell <mi...@gmail.com>
Committed: Tue May 23 20:39:03 2017 -0600

----------------------------------------------------------------------
 traffic_ops/app/t/api/1.2/api_capabilities.t | 3 ---
 traffic_ops/app/t/api/1.2/capabilities.t     | 3 ---
 2 files changed, 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/ee23727c/traffic_ops/app/t/api/1.2/api_capabilities.t
----------------------------------------------------------------------
diff --git a/traffic_ops/app/t/api/1.2/api_capabilities.t b/traffic_ops/app/t/api/1.2/api_capabilities.t
index 5221c03..ef672d3 100644
--- a/traffic_ops/app/t/api/1.2/api_capabilities.t
+++ b/traffic_ops/app/t/api/1.2/api_capabilities.t
@@ -32,9 +32,6 @@ my $schema = Schema->connect_to_database;
 my $dbh    = Schema->database_handle;
 my $t      = Test::Mojo->new('TrafficOps');
 
-my $false = 0;
-my $true = 1;
-
 Test::TestHelper->unload_core_data($schema);
 Test::TestHelper->load_core_data($schema);
 

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/ee23727c/traffic_ops/app/t/api/1.2/capabilities.t
----------------------------------------------------------------------
diff --git a/traffic_ops/app/t/api/1.2/capabilities.t b/traffic_ops/app/t/api/1.2/capabilities.t
index 3219b38..6686a87 100644
--- a/traffic_ops/app/t/api/1.2/capabilities.t
+++ b/traffic_ops/app/t/api/1.2/capabilities.t
@@ -32,9 +32,6 @@ my $schema = Schema->connect_to_database;
 my $dbh    = Schema->database_handle;
 my $t      = Test::Mojo->new('TrafficOps');
 
-my $false = 0;
-my $true = 1;
-
 Test::TestHelper->unload_core_data($schema);
 Test::TestHelper->load_core_data($schema);
 


[12/14] incubator-trafficcontrol git commit: added "not_found" for non-existent capability

Posted by mi...@apache.org.
added "not_found" for non-existent capability


Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/7df2da0f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/7df2da0f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/7df2da0f

Branch: refs/heads/master
Commit: 7df2da0f5549f9acf69a29cb15a0b0f37681ebcc
Parents: e782bc6
Author: naamashoresh <na...@qwilt.com>
Authored: Sun May 21 13:40:02 2017 +0300
Committer: Jeremy Mitchell <mi...@gmail.com>
Committed: Tue May 23 20:39:03 2017 -0600

----------------------------------------------------------------------
 traffic_ops/app/lib/API/Capability.pm | 3 +++
 1 file changed, 3 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/7df2da0f/traffic_ops/app/lib/API/Capability.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/app/lib/API/Capability.pm b/traffic_ops/app/lib/API/Capability.pm
index 6a3212a..23e1dc7 100644
--- a/traffic_ops/app/lib/API/Capability.pm
+++ b/traffic_ops/app/lib/API/Capability.pm
@@ -47,6 +47,9 @@ sub name {
 	my $name = $self->param('name');
 
 	my $rs_data = $self->db->resultset("Capability")->search( 'me.name' => $name );
+	if ( !defined($rs_data) ) {
+		return $self->not_found();
+	}
 	my @data = ();
 	while ( my $row = $rs_data->next ) {
 		push(


[08/14] incubator-trafficcontrol git commit: Removed redundant check for empty string

Posted by mi...@apache.org.
Removed redundant check for empty string


Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/dfb7fcbb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/dfb7fcbb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/dfb7fcbb

Branch: refs/heads/master
Commit: dfb7fcbbf47087ba601313c29809769eccfea775
Parents: 7df2da0
Author: naamashoresh <na...@qwilt.com>
Authored: Sun May 21 13:47:00 2017 +0300
Committer: Jeremy Mitchell <mi...@gmail.com>
Committed: Tue May 23 20:39:03 2017 -0600

----------------------------------------------------------------------
 traffic_ops/app/lib/API/Capability.pm | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/dfb7fcbb/traffic_ops/app/lib/API/Capability.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/app/lib/API/Capability.pm b/traffic_ops/app/lib/API/Capability.pm
index 23e1dc7..53d9b47 100644
--- a/traffic_ops/app/lib/API/Capability.pm
+++ b/traffic_ops/app/lib/API/Capability.pm
@@ -129,7 +129,7 @@ sub update {
 	my $description = $params->{description} if defined( $params->{description} );
 
 	my $capability = $self->db->resultset('Capability')->find( { name => $name } );
-	if ( !defined($capability) or $capability eq "" ) {
+	if ( !defined($capability) ) {
 		return $self->not_found();
 	}
 


[11/14] incubator-trafficcontrol git commit: removed hardcoding row index perltidy

Posted by mi...@apache.org.
removed hardcoding row index
perltidy


Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/e782bc62
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/e782bc62
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/e782bc62

Branch: refs/heads/master
Commit: e782bc621e5964a3f51470a9b5980d0572e5acf2
Parents: 8d6ddc7
Author: naamashoresh <na...@qwilt.com>
Authored: Sun May 21 13:30:46 2017 +0300
Committer: Jeremy Mitchell <mi...@gmail.com>
Committed: Tue May 23 20:39:03 2017 -0600

----------------------------------------------------------------------
 traffic_ops/app/lib/API/ApiCapability.pm | 151 ++++++++++++++------------
 1 file changed, 80 insertions(+), 71 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/e782bc62/traffic_ops/app/lib/API/ApiCapability.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/app/lib/API/ApiCapability.pm b/traffic_ops/app/lib/API/ApiCapability.pm
index 5686d00..e143b1c 100644
--- a/traffic_ops/app/lib/API/ApiCapability.pm
+++ b/traffic_ops/app/lib/API/ApiCapability.pm
@@ -21,11 +21,9 @@ use UI::Utils;
 use Mojo::Base 'Mojolicious::Controller';
 use Data::Dumper;
 
-
-
 my $finfo = __FILE__ . ":";
 
-my %valid_http_methods = map { $_ => 1 } ('GET', 'POST', 'PUT', 'PATCH', 'DELETE');
+my %valid_http_methods = map { $_ => 1 } ( 'GET', 'POST', 'PUT', 'PATCH', 'DELETE' );
 
 sub index {
 	my $self       = shift;
@@ -43,31 +41,30 @@ sub index {
 	while ( my $row = $rs_data->next ) {
 		push(
 			@data, {
-				"id"          	=> $row->id,
-				"httpMethod"	=> $row->http_method,
-				"route" 		=> $row->route,
-				"capability"   	=> $row->capability->name,
-				"lastUpdated" 	=> $row->last_updated
+				"id"          => $row->id,
+				"httpMethod"  => $row->http_method,
+				"route"       => $row->route,
+				"capability"  => $row->capability->name,
+				"lastUpdated" => $row->last_updated
 			}
 		);
 	}
 	$self->success( \@data );
 }
 
-
 sub renderResults {
-	my $self = shift;
+	my $self    = shift;
 	my $rs_data = shift;
 
 	my @data = ();
 	while ( my $row = $rs_data->next ) {
 		push(
 			@data, {
-				"id"          	=> $row->id,
-				"httpMethod"	=> $row->http_method,
-				"route" 		=> $row->route,
-				"capability"   	=> $row->capability->name,
-				"lastUpdated" 	=> $row->last_updated
+				"id"          => $row->id,
+				"httpMethod"  => $row->http_method,
+				"route"       => $row->route,
+				"capability"  => $row->capability->name,
+				"lastUpdated" => $row->last_updated
 			}
 		);
 	}
@@ -76,25 +73,28 @@ sub renderResults {
 
 sub show {
 	my $self = shift;
-	my $id = $self->param('id');
+	my $id   = $self->param('id');
 
 	my $rs_data = $self->db->resultset("ApiCapability")->search( 'me.id' => $id );
-	$self->renderResults( $rs_data ) ;
+	if ( !defined($rs_data) ) {
+		return $self->not_found();
+	}
+	$self->renderResults($rs_data);
 }
 
 sub is_mapping_valid {
-	my $self = shift;
-	my $id = shift;
+	my $self        = shift;
+	my $id          = shift;
 	my $http_method = shift;
-	my $route = shift;
-	my $capability = shift;
+	my $route       = shift;
+	my $capability  = shift;
 
 	if ( !defined($http_method) ) {
 		return ( undef, "HTTP method is required." );
 	}
 
-	if ( !exists( $valid_http_methods{ $http_method } ) ) {
-		return ( undef, "HTTP method \'$http_method\' is invalid. Valid values are: " . join(", ", sort keys %valid_http_methods ) );
+	if ( !exists( $valid_http_methods{$http_method} ) ) {
+		return ( undef, "HTTP method \'$http_method\' is invalid. Valid values are: " . join( ", ", sort keys %valid_http_methods ) );
 	}
 
 	if ( !defined($route) or $route eq "" ) {
@@ -102,30 +102,35 @@ sub is_mapping_valid {
 	}
 
 	if ( !defined($capability) or $capability eq "" ) {
-		return (undef, "Capability name is required." );
+		return ( undef, "Capability name is required." );
 	}
+
 	# check if capability exists
 	my $rs_data = $self->db->resultset("Capability")->search( { 'name' => { 'like', $capability } } )->single();
-	if (!defined($rs_data)) {
-		return (undef, "Capability '$capability' does not exist." );
+	if ( !defined($rs_data) ) {
+		return ( undef, "Capability '$capability' does not exist." );
 	}
 
 	# search a mapping for the same http_method & route
-	$rs_data = $self->db->resultset("ApiCapability")->search( { 'route' => { 'like', $route } } )->search( {
-		'http_method' => { '=', $http_method } } )->single();
+	$rs_data = $self->db->resultset("ApiCapability")->search( { 'route' => { 'like', $route } } )->search(
+		{
+			'http_method' => { '=', $http_method }
+		}
+	)->single();
+
 	# if adding a new entry, make sure it is unique
-	if ( !defined( $id ) ) {
-		if (defined($rs_data)) {
+	if ( !defined($id) ) {
+		if ( defined($rs_data) ) {
 			my $allocated_capability = $rs_data->capability->name;
-			return (undef, "HTTP method '$http_method', route '$route' are already mapped to capability: $allocated_capability" );
+			return ( undef, "HTTP method '$http_method', route '$route' are already mapped to capability: $allocated_capability" );
 		}
 	}
 	else {
-		if (defined($rs_data)) {
+		if ( defined($rs_data) ) {
 			my $lid = $rs_data->id;
-			if ($lid ne $id) {
+			if ( $lid ne $id ) {
 				my $allocated_capability = $rs_data->capability->name;
-				return (undef, "HTTP method '$http_method', route '$route' are already mapped to capability: $allocated_capability" );
+				return ( undef, "HTTP method '$http_method', route '$route' are already mapped to capability: $allocated_capability" );
 			}
 		}
 	}
@@ -134,7 +139,7 @@ sub is_mapping_valid {
 }
 
 sub create {
-	my $self = shift;
+	my $self   = shift;
 	my $params = $self->req->json;
 
 	if ( !&is_oper($self) ) {
@@ -145,45 +150,46 @@ sub create {
 		return $self->alert("Parameters must be in JSON format.");
 	}
 
-	my $http_method = $params->{httpMethod} if defined($params->{httpMethod});
-	my $route = $params->{route} if defined($params->{route});
-	my $capability = $params->{capability} if defined($params->{capability});
-	my $id = undef;
+	my $http_method = $params->{httpMethod} if defined( $params->{httpMethod} );
+	my $route       = $params->{route}      if defined( $params->{route} );
+	my $capability  = $params->{capability} if defined( $params->{capability} );
+	my $id          = undef;
 
 	my ( $is_valid, $errStr ) = $self->is_mapping_valid( $id, $http_method, $route, $capability );
 	if ( !$is_valid ) {
-		return $self->alert( $errStr );
+		return $self->alert($errStr);
 	}
 
 	my $values = {
-		id 			=> $self->db->resultset('ApiCapability')->get_column('id')->max() + 1,
-		http_method	=> $http_method,
-		route		=> $route,
-		capability	=> $capability
+		http_method => $http_method,
+		route       => $route,
+		capability  => $capability
 	};
 
 	my $insert = $self->db->resultset('ApiCapability')->create($values);
-	my $rs = $insert->insert();
+	my $rs     = $insert->insert();
 	if ($rs) {
 		my $response;
-		$response->{id}				= $rs->id;
-		$response->{httpMethod}		= $rs->http_method;
-		$response->{route}			= $rs->route;
-		$response->{capability}		= $rs->capability->name;
-		$response->{lastUpdated}	= $rs->last_updated;
+		$response->{id}          = $rs->id;
+		$response->{httpMethod}  = $rs->http_method;
+		$response->{route}       = $rs->route;
+		$response->{capability}  = $rs->capability->name;
+		$response->{lastUpdated} = $rs->last_updated;
 
-		&log( $self, "Created API-Capability mapping: '$response->{httpMethod}', '$response->{route}', '$response->{capability}' for id: " . $response->{id}, "APICHANGE" );
+		&log( $self,
+			"Created API-Capability mapping: '$response->{httpMethod}', '$response->{route}', '$response->{capability}' for id: " . $response->{id},
+			"APICHANGE" );
 
 		return $self->success( $response, "API-Capability mapping was created." );
 	}
 	else {
-		return $self->alert( "API-Capability mapping creation failed." );
+		return $self->alert("API-Capability mapping creation failed.");
 	}
 }
 
 sub update {
-	my $self = shift;
-	my $id = $self->param('id');
+	my $self   = shift;
+	my $id     = $self->param('id');
 	my $params = $self->req->json;
 
 	if ( !&is_oper($self) ) {
@@ -194,9 +200,9 @@ sub update {
 		return $self->alert("Parameters must be in JSON format.");
 	}
 
-	my $http_method = $params->{httpMethod} if defined($params->{httpMethod});
-	my $route = $params->{route} if defined($params->{route});
-	my $capability = $params->{capability} if defined($params->{capability});
+	my $http_method = $params->{httpMethod} if defined( $params->{httpMethod} );
+	my $route       = $params->{route}      if defined( $params->{route} );
+	my $capability  = $params->{capability} if defined( $params->{capability} );
 
 	my $mapping = $self->db->resultset('ApiCapability')->find( { id => $id } );
 	if ( !defined($mapping) ) {
@@ -205,36 +211,38 @@ sub update {
 
 	my ( $is_valid, $errStr ) = $self->is_mapping_valid( $id, $http_method, $route, $capability );
 	if ( !$is_valid ) {
-		return $self->alert( $errStr );
+		return $self->alert($errStr);
 	}
 
 	my $values = {
-		http_method	=> $http_method,
-		route		=> $route,
-		capability	=> $capability
+		http_method => $http_method,
+		route       => $route,
+		capability  => $capability
 	};
 
 	my $rs = $mapping->update($values);
 	if ($rs) {
 		my $response;
-		$response->{id}				= $rs->id;
-		$response->{httpMethod}		= $rs->http_method;
-		$response->{route}			= $rs->route;
-		$response->{capability}		= $rs->capability->name;
-		$response->{lastUpdated}	= $rs->last_updated;
+		$response->{id}          = $rs->id;
+		$response->{httpMethod}  = $rs->http_method;
+		$response->{route}       = $rs->route;
+		$response->{capability}  = $rs->capability->name;
+		$response->{lastUpdated} = $rs->last_updated;
 
-		&log( $self, "Updated API-Capability mapping: '$response->{httpMethod}', '$response->{route}', '$response->{capability}' for id: " . $response->{id}, "APICHANGE" );
+		&log( $self,
+			"Updated API-Capability mapping: '$response->{httpMethod}', '$response->{route}', '$response->{capability}' for id: " . $response->{id},
+			"APICHANGE" );
 
 		return $self->success( $response, "API-Capability mapping was updated." );
 	}
 	else {
-		return $self->alert( "API-Capability mapping update failed." );
+		return $self->alert("API-Capability mapping update failed.");
 	}
 }
 
 sub delete {
 	my $self = shift;
-	my $id     = $self->param('id');
+	my $id   = $self->param('id');
 
 	if ( !&is_oper($self) ) {
 		return $self->forbidden();
@@ -248,8 +256,9 @@ sub delete {
 	my $rs = $mapping->delete();
 	if ($rs) {
 		return $self->success_message("API-capability mapping deleted.");
-	} else {
-		return $self->alert( "API-capability mapping deletion failed." );
+	}
+	else {
+		return $self->alert("API-capability mapping deletion failed.");
 	}
 }
 


[04/14] incubator-trafficcontrol git commit: Authorization model - Adding tables: capability (list of available capabilities), api_capability mapping, role_capability mapping & user_role. Seeding capability & api_capability tables. Also seeding root role

Posted by mi...@apache.org.
Authorization model -
Adding tables: capability (list of available capabilities), api_capability mapping, role_capability mapping & user_role.
Seeding capability & api_capability tables. Also seeding root role.

(cherry picked from commit 4879a2c1138a37786df2fe8652edae3592a4bd12)


Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/5392f500
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/5392f500
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/5392f500

Branch: refs/heads/master
Commit: 5392f5004b7ac6b028c417c2ec1bdb306c5607ab
Parents: ef05b19
Author: naamashoresh <na...@qwilt.com>
Authored: Thu May 4 10:26:17 2017 +0300
Committer: Jeremy Mitchell <mi...@gmail.com>
Committed: Tue May 23 20:39:02 2017 -0600

----------------------------------------------------------------------
 ...0406000001_create_capabilities_and_roles.sql |  89 +++++++
 traffic_ops/app/db/seeds.sql                    | 252 ++++++++++++++++++-
 .../app/lib/Schema/Result/ApiCapability.pm      | 124 +++++++++
 traffic_ops/app/lib/Schema/Result/Capability.pm | 109 ++++++++
 .../app/lib/Schema/Result/RoleCapability.pm     |  99 ++++++++
 traffic_ops/app/lib/Schema/Result/UserRole.pm   |  99 ++++++++
 6 files changed, 771 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/5392f500/traffic_ops/app/db/migrations/20170406000001_create_capabilities_and_roles.sql
----------------------------------------------------------------------
diff --git a/traffic_ops/app/db/migrations/20170406000001_create_capabilities_and_roles.sql b/traffic_ops/app/db/migrations/20170406000001_create_capabilities_and_roles.sql
new file mode 100644
index 0000000..23b730b
--- /dev/null
+++ b/traffic_ops/app/db/migrations/20170406000001_create_capabilities_and_roles.sql
@@ -0,0 +1,89 @@
+/*
+
+    Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+        http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+*/
+
+-- +goose Up
+-- SQL in section 'Up' is executed when this migration is applied
+
+
+-- capability
+CREATE TABLE capability (
+    name text primary key UNIQUE NOT NULL,
+    description text,
+    last_updated timestamp with time zone DEFAULT now()
+);
+
+CREATE TRIGGER on_update_current_timestamp BEFORE UPDATE ON capability FOR EACH ROW EXECUTE PROCEDURE on_update_current_timestamp_last_updated();
+
+-- http_method_t (enum)
+CREATE TYPE http_method_t as ENUM ('GET', 'POST', 'PUT', 'PATCH', 'DELETE');
+
+-- api_capability
+
+CREATE TABLE api_capability (
+    id BIGSERIAL primary key NOT NULL,
+    http_method http_method_t NOT NULL,
+    route text NOT NULL,
+    capability text NOT NULL,
+    CONSTRAINT fk_capability FOREIGN KEY (capability) REFERENCES capability(name) ON DELETE RESTRICT,
+    last_updated timestamp with time zone DEFAULT now()
+);
+
+CREATE TRIGGER on_update_current_timestamp BEFORE UPDATE ON api_capability FOR EACH ROW EXECUTE PROCEDURE on_update_current_timestamp_last_updated();
+
+-- role_capability
+CREATE TABLE role_capability (
+    role_id bigint NOT NULL,
+    CONSTRAINT fk_role_id FOREIGN KEY (role_id) REFERENCES role(id) ON DELETE CASCADE,  
+    cap_name text NOT NULL,
+    CONSTRAINT fk_cap_name FOREIGN KEY (cap_name) REFERENCES capability(name) ON DELETE RESTRICT,
+    last_updated timestamp with time zone DEFAULT now()
+);
+
+CREATE TRIGGER on_update_current_timestamp BEFORE UPDATE ON role_capability FOR EACH ROW EXECUTE PROCEDURE on_update_current_timestamp_last_updated();
+
+-- user_role
+CREATE TABLE user_role (
+    user_id bigint NOT NULL,
+    CONSTRAINT fk_user_id FOREIGN KEY (user_id) REFERENCES tm_user(id) ON DELETE CASCADE,
+    role_id bigint NOT NULL,
+    CONSTRAINT fk_role_id FOREIGN KEY (role_id) REFERENCES role(id) ON DELETE RESTRICT,
+    last_updated timestamp with time zone DEFAULT now()
+);
+
+CREATE TRIGGER on_update_current_timestamp BEFORE UPDATE ON user_role FOR EACH ROW EXECUTE PROCEDURE on_update_current_timestamp_last_updated();
+
+
+-- +goose Down
+-- SQL section 'Down' is executed when this migration is rolled back
+
+
+DROP TRIGGER on_update_current_timestamp ON user_role;
+
+DROP TABLE user_role;
+
+DROP TRIGGER on_update_current_timestamp ON role_capability;
+
+DROP TABLE role_capability;
+
+DROP TRIGGER on_update_current_timestamp ON api_capability;
+
+DROP TABLE api_capability;
+
+DROP TRIGGER on_update_current_timestamp ON capability;
+
+DROP TABLE capability;
+
+
+

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/5392f500/traffic_ops/app/db/seeds.sql
----------------------------------------------------------------------
diff --git a/traffic_ops/app/db/seeds.sql b/traffic_ops/app/db/seeds.sql
index 8e725a1..f372c20 100644
--- a/traffic_ops/app/db/seeds.sql
+++ b/traffic_ops/app/db/seeds.sql
@@ -1,4 +1,4 @@
-/*
+-- -- -- -- -- -- -- /*
 
 	Licensed under the Apache License, Version 2.0 (the "License");
 	you may not use this file except in compliance with the License.
@@ -69,10 +69,260 @@ insert into role (name, description, priv_level) values ('steering', 'Role for S
 insert into role (name, description, priv_level) values ('read-only user', 'Read-Only user', 10) ON CONFLICT (name) DO NOTHING;
 insert into role (name, description, priv_level) values ('portal', 'Portal User', 2) ON CONFLICT (name) DO NOTHING;
 insert into role (name, description, priv_level) values ('disallowed', 'Block all access', 0) ON CONFLICT (name) DO NOTHING;
+insert into role (name, description, priv_level) values ('root', 'Role for full capabilities - super-user ', 30) ON CONFLICT DO NOTHING;
 
 -- tenants
 insert into tenant (name, active, parent_id) values ('root', true, null) ON CONFLICT DO NOTHING;
 
+-- capabilities
+insert into capability (name, description) values ('all-read', 'Full read access') ON CONFLICT DO NOTHING;
+insert into capability (name, description) values ('all-write', 'Full write access') ON CONFLICT DO NOTHING;
+insert into capability (name, description) values ('asn-read', 'View ASN configuration') ON CONFLICT DO NOTHING;
+insert into capability (name, description) values ('asn-write', 'Create, edit or delete ASN configuration') ON CONFLICT DO NOTHING;
+insert into capability (name, description) values ('basic-read', 'Basic read operations. Every user should have this capability') ON CONFLICT DO NOTHING;
+insert into capability (name, description) values ('basic-write', 'Basic write operations. Every user should have this capability') ON CONFLICT DO NOTHING;
+insert into capability (name, description) values ('cache-config-files-read', 'View the generated cache configuration files') ON CONFLICT DO NOTHING;
+insert into capability (name, description) values ('cache-group-read', 'View cache-group configuration') ON CONFLICT DO NOTHING;
+insert into capability (name, description) values ('cache-group-write', 'Create, edit or delete cache-group configuration') ON CONFLICT DO NOTHING;
+insert into capability (name, description) values ('cache-stats-read', 'View Cache statistics read access') ON CONFLICT DO NOTHING;
+insert into capability (name, description) values ('cdn-config-snapshot-read', 'View config snapshot at CDN level') ON CONFLICT DO NOTHING;
+insert into capability (name, description) values ('cdn-config-snapshot-write', 'Config snapshot write access at CDN level') ON CONFLICT DO NOTHING;
+insert into capability (name, description) values ('cdn-health-read', 'View CDN health') ON CONFLICT DO NOTHING;
+insert into capability (name, description) values ('cdn-read', 'View CDN configuration') ON CONFLICT DO NOTHING;
+insert into capability (name, description) values ('cdn-write', 'Create, edit or delete CDN configuration') ON CONFLICT DO NOTHING;
+insert into capability (name, description) values ('cdn-security-keys-read', 'View CDN DNSSEC keys') ON CONFLICT DO NOTHING;
+insert into capability (name, description) values ('cdn-security-keys-write', 'Create, edit or delete CDN DNSSEC keys') ON CONFLICT DO NOTHING;
+insert into capability (name, description) values ('cdn-stats-read', 'View CDN statistics') ON CONFLICT DO NOTHING;
+insert into capability (name, description) values ('cdn-stats-write', 'Create, edit or delete CDN statistics') ON CONFLICT DO NOTHING;
+insert into capability (name, description) values ('change-log-read', 'View change-log') ON CONFLICT DO NOTHING;
+insert into capability (name, description) values ('change-log-write', 'Create change-log entries') ON CONFLICT DO NOTHING;
+insert into capability (name, description) values ('division-read', 'View division configuration') ON CONFLICT DO NOTHING;
+insert into capability (name, description) values ('division-write', 'Create, edit or delete division configuration') ON CONFLICT DO NOTHING;
+insert into capability (name, description) values ('ds-cache-read', 'View delivery-service cache assignment') ON CONFLICT DO NOTHING;
+insert into capability (name, description) values ('ds-cache-read', 'Create, edit or delete delivery-service cache assignment') ON CONFLICT DO NOTHING;
+insert into capability (name, description) values ('ds-health-read', 'View delivery-service health') ON CONFLICT DO NOTHING;
+insert into capability (name, description) values ('ds-read', 'View delivery-service configuration') ON CONFLICT DO NOTHING;
+insert into capability (name, description) values ('ds-write', 'Create, edit or delete delivery-service configuration') ON CONFLICT DO NOTHING;
+insert into capability (name, description) values ('ds-security-keys-read', 'View delivery-service security keys') ON CONFLICT DO NOTHING;
+insert into capability (name, description) values ('ds-security-keys-write', 'Create, edit or delete delivery-service security keys') ON CONFLICT DO NOTHING;
+insert into capability (name, description) values ('ds-stats-read', 'View delivery-service statistics') ON CONFLICT DO NOTHING;
+insert into capability (name, description) values ('ds-steering-read', 'View delivery-service steering configuration') ON CONFLICT DO NOTHING;
+insert into capability (name, description) values ('ds-steering-write', 'Create, edit or delete delivery-service steering configuration') ON CONFLICT DO NOTHING;
+insert into capability (name, description) values ('federation-routing-read', 'View federation routing') ON CONFLICT DO NOTHING;
+insert into capability (name, description) values ('federation-routing-write', 'Create, edit or delete federation routing') ON CONFLICT DO NOTHING;
+insert into capability (name, description) values ('job-read', 'View jobs') ON CONFLICT DO NOTHING;
+insert into capability (name, description) values ('job-write', 'Create, edit or delete jobs') ON CONFLICT DO NOTHING;
+insert into capability (name, description) values ('params-read', 'View parameters') ON CONFLICT DO NOTHING;
+insert into capability (name, description) values ('params-write', 'Create, edit or delete parameters') ON CONFLICT DO NOTHING;
+insert into capability (name, description) values ('phys-location-read', 'View physical location configuration') ON CONFLICT DO NOTHING;
+insert into capability (name, description) values ('phys-location-write', 'Create, edit or delete physical location configuration') ON CONFLICT DO NOTHING;
+insert into capability (name, description) values ('profile-read', 'View profiles') ON CONFLICT DO NOTHING;
+insert into capability (name, description) values ('profile-write', 'Create, edit or delete profiles') ON CONFLICT DO NOTHING;
+insert into capability (name, description) values ('queue-updates-write', 'Queue updates to caches') ON CONFLICT DO NOTHING;
+insert into capability (name, description) values ('region-read', 'View region configuration') ON CONFLICT DO NOTHING;
+insert into capability (name, description) values ('region-write', 'Create, edit or delete region configuration') ON CONFLICT DO NOTHING;
+insert into capability (name, description) values ('role-read', 'View role configuration') ON CONFLICT DO NOTHING;
+insert into capability (name, description) values ('role-write', 'Create, edit or delete role configuration') ON CONFLICT DO NOTHING;
+insert into capability (name, description) values ('security-keys-read', 'View security keys') ON CONFLICT DO NOTHING;
+insert into capability (name, description) values ('security-keys-write', 'Create, edit or delete security keys') ON CONFLICT DO NOTHING;
+insert into capability (name, description) values ('server-pull-updates-read', 'Read server update indication') ON CONFLICT DO NOTHING;
+insert into capability (name, description) values ('server-pull-updates-write', 'Write server update indication') ON CONFLICT DO NOTHING;
+insert into capability (name, description) values ('server-read', 'View server configuration') ON CONFLICT DO NOTHING;
+insert into capability (name, description) values ('server-write', 'Create, edit or delete server configuration') ON CONFLICT DO NOTHING;
+insert into capability (name, description) values ('static-dns-read', 'View static DNS configuration') ON CONFLICT DO NOTHING;
+insert into capability (name, description) values ('static-dns-write', 'Create, edit or delete static DNS configuration') ON CONFLICT DO NOTHING;
+insert into capability (name, description) values ('status-read', 'View the list of defined statuses') ON CONFLICT DO NOTHING;
+insert into capability (name, description) values ('to-extension-read', 'View Traffic Ops extensions') ON CONFLICT DO NOTHING;
+insert into capability (name, description) values ('to-extension-write', 'Create, edit or delete Traffic Ops extensions') ON CONFLICT DO NOTHING;
+insert into capability (name, description) values ('type-read', 'View types configuration') ON CONFLICT DO NOTHING;
+insert into capability (name, description) values ('type-write', 'Create, edit or delete type configuration') ON CONFLICT DO NOTHING;
+insert into capability (name, description) values ('user-read', 'View user configuration') ON CONFLICT DO NOTHING;
+insert into capability (name, description) values ('user-write', 'Create, edit or delete user configuration') ON CONFLICT DO NOTHING;
+
+-- roles_capabilities
+insert into role_capability (role_id, cap_name) values (10, 'all-read') ON CONFLICT DO NOTHING;
+insert into role_capability (role_id, cap_name) values (10, 'all-write') ON CONFLICT DO NOTHING;
+
+-- api_capabilities
+insert into api_capability (http_method, route, capability) values ('GET', '/', 'all-read') ON CONFLICT DO NOTHING;
+insert into api_capability (http_method, route, capability) values ('POST', '/', 'all-write') ON CONFLICT DO NOTHING;
+insert into api_capability (http_method, route, capability) values ('PUT', '/', 'all-write') ON CONFLICT DO NOTHING;
+insert into api_capability (http_method, route, capability) values ('PATCH', '/', 'all-write') ON CONFLICT DO NOTHING;
+insert into api_capability (http_method, route, capability) values ('DELETE', '/', 'all-write') ON CONFLICT DO NOTHING;
+
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/asns', 'asn-read') ON CONFLICT DO NOTHING; -- 4
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/asns/*', 'asn-read') ON CONFLICT DO NOTHING; -- 5
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/asns', 'asn-write') ON CONFLICT DO NOTHING; -- 6
+insert into api_capability (http_method, route, capability) values ('PUT', '/api/*/asns/*', 'asn-write') ON CONFLICT DO NOTHING; -- 7
+insert into api_capability (http_method, route, capability) values ('DELETE', '/api/*/asns/*', 'asn-write') ON CONFLICT DO NOTHING; -- 8
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cache_stats', 'cache-stats-read') ON CONFLICT DO NOTHING; -- 11
+insert into api_capability (http_method, route, capability) values ('GET', '/internal/api/*/daily_summary', 'cache-stats-read') ON CONFLICT DO NOTHING; -- 12
+insert into api_capability (http_method, route, capability) values ('GET', '/internal/api/*/current_stats', 'cache-stats-read') ON CONFLICT DO NOTHING; -- 13
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cachegroups', 'cache-group-read') ON CONFLICT DO NOTHING; -- 16
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cachegroups/list', 'cache-group-read') ON CONFLICT DO NOTHING; -- 17
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cachegroups/trimmed', 'cache-group-read') ON CONFLICT DO NOTHING; -- 18
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cachegroups/*', 'cache-group-read') ON CONFLICT DO NOTHING; -- 19
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/cachegroups', 'cache-group-write') ON CONFLICT DO NOTHING; -- 20
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/cachegroups/create', 'cache-group-write') ON CONFLICT DO NOTHING; -- 21
+insert into api_capability (http_method, route, capability) values ('PUT', '/api/*/cachegroups/*', 'cache-group-write') ON CONFLICT DO NOTHING; -- 22
+insert into api_capability (http_method, route, capability) values ('PUT', '/api/*/cachegroups/*/update', 'cache-group-write') ON CONFLICT DO NOTHING; -- 23
+insert into api_capability (http_method, route, capability) values ('DELETE', '/api/*/cachegroups/*', 'cache-group-write') ON CONFLICT DO NOTHING; -- 24
+insert into api_capability (http_method, route, capability) values ('DELETE', '/api/*/cachegroups/*/delete', 'cache-group-write') ON CONFLICT DO NOTHING; -- 25
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/cachegroups/*/queue_update', 'queue-updates-write') ON CONFLICT DO NOTHING; -- 26
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/cachegroups/*/queue_update', 'queue-updates-write') ON CONFLICT DO NOTHING; -- 27
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cachegroups/*/parameters', 'params-read') ON CONFLICT DO NOTHING; -- 28
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cdns', 'cdn-read') ON CONFLICT DO NOTHING; -- 31
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cdns/*', 'cdn-read') ON CONFLICT DO NOTHING; -- 32
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cdns/name/*', 'cdn-read') ON CONFLICT DO NOTHING; -- 33
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/cdns', 'cdn-write') ON CONFLICT DO NOTHING; -- 34
+insert into api_capability (http_method, route, capability) values ('PUT', '/api/*/cdns/*', 'cdn-write') ON CONFLICT DO NOTHING; -- 35
+insert into api_capability (http_method, route, capability) values ('DELETE', '/api/*/cdns/*', 'cdn-write') ON CONFLICT DO NOTHING; -- 36
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/cdns/*/queue_update', 'queue-updates-write') ON CONFLICT DO NOTHING; -- 37
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/cdns/*/queue_update', 'queue-updates-write') ON CONFLICT DO NOTHING; -- 38
+insert into api_capability (http_method, route, capability) values ('PUT', '/api/*/cdns/*/snapshot', 'cdn-config-snapshot-write') ON CONFLICT DO NOTHING; -- 40
+insert into api_capability (http_method, route, capability) values ('PUT', '/api/*/snapshot/*', 'cdn-config-snapshot-write') ON CONFLICT DO NOTHING; -- 41
+insert into api_capability (http_method, route, capability) values ('PUT', '/api/*/snapshot/*', 'cdn-config-snapshot-write') ON CONFLICT DO NOTHING; -- 42
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cdns/configs', 'cdn-read') ON CONFLICT DO NOTHING; -- 44
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cdns/*/configs/routing', 'cdn-read') ON CONFLICT DO NOTHING; -- 45
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cdns/*/configs/monitoring', 'cdn-read') ON CONFLICT DO NOTHING; -- 46
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cdns/domains', 'cdn-read') ON CONFLICT DO NOTHING; -- 47
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cdns/health', 'cdn-health-read') ON CONFLICT DO NOTHING; -- 48
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cdns/*/health', 'cdn-health-read') ON CONFLICT DO NOTHING; -- 49
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cdns/capacity', 'cdn-health-read') ON CONFLICT DO NOTHING; -- 50
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cdns/routing', 'cdn-read') ON CONFLICT DO NOTHING; -- 51
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cdns/name/*/sslkeys', 'cdn-security-keys-read') ON CONFLICT DO NOTHING; -- 52
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cdns/usage/overview', 'cdn-stats-read') ON CONFLICT DO NOTHING; -- 54
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/logs', 'change-log-read') ON CONFLICT DO NOTHING; -- 57
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/logs/*/days', 'change-log-read') ON CONFLICT DO NOTHING; -- 58
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/logs/newcount', 'change-log-read') ON CONFLICT DO NOTHING; -- 60
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/deliveryservices', 'ds-read') ON CONFLICT DO NOTHING; -- 69
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/deliveryservices/list', 'ds-read') ON CONFLICT DO NOTHING; -- 70
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/deliveryservices/*', 'ds-read') ON CONFLICT DO NOTHING; -- 71
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/deliveryservices/*/get', 'ds-read') ON CONFLICT DO NOTHING; -- 72
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/deliveryservices', 'ds-write') ON CONFLICT DO NOTHING; -- 73
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/*/deliveryservices/create', 'ds-write') ON CONFLICT DO NOTHING; -- 74
+insert into api_capability (http_method, route, capability) values ('PUT', '/api/*/deliveryservices/*', 'ds-write') ON CONFLICT DO NOTHING; -- 75
+insert into api_capability (http_method, route, capability) values ('PUT', '/api/*/*/deliveryservices/*/update', 'ds-write') ON CONFLICT DO NOTHING; -- 76
+insert into api_capability (http_method, route, capability) values ('DELETE', '/api/*/deliveryservices/*', 'ds-write') ON CONFLICT DO NOTHING; -- 77
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/deliveryservices/*/health', 'ds-health-read') ON CONFLICT DO NOTHING; -- 78
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/deliveryservices/*/capacity', 'ds-health-read') ON CONFLICT DO NOTHING; -- 79
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/deliveryservices/*/routing', 'ds-read') ON CONFLICT DO NOTHING; -- 80
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/deliveryservices/*/state', 'ds-read') ON CONFLICT DO NOTHING; -- 81
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/deliveryservice_stats', 'ds-stats-read') ON CONFLICT DO NOTHING; -- 82
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/deliveryservices/request', 'ds-read') ON CONFLICT DO NOTHING; -- 83
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/deliveryservices/xmlId/*/sslkeys', 'ds-security-keys-read') ON CONFLICT DO NOTHING; -- 84
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/deliveryservices/hostname/#hostname/sslkeys', 'ds-security-keys-read') ON CONFLICT DO NOTHING; -- 85
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/deliveryservices/sslkeys/generate', 'ds-security-keys-write') ON CONFLICT DO NOTHING; -- 86
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/deliveryservices/sslkeys/add', 'ds-security-keys-write') ON CONFLICT DO NOTHING; -- 87
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/deliveryservices/xmlId/*/sslkeys/delete', 'ds-security-keys-write') ON CONFLICT DO NOTHING; -- 88
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/deliveryservices/xmlId/*/urlkeys', 'ds-security-keys-read') ON CONFLICT DO NOTHING; -- 89
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/deliveryservices/xmlId/*/urlkeys/generate', 'ds-security-keys-write') ON CONFLICT DO NOTHING; -- 90
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/deliveryservices/*/regexes', 'ds-read') ON CONFLICT DO NOTHING; -- 91
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/deliveryservice_matches', 'ds-read') ON CONFLICT DO NOTHING; -- 92
+insert into api_capability (http_method, route, capability) values ('GET', '/internal/api/*/steering', 'ds-steering-read') ON CONFLICT DO NOTHING; -- 96
+insert into api_capability (http_method, route, capability) values ('GET', '/internal/api/*/steering/*', 'ds-steering-read') ON CONFLICT DO NOTHING; -- 97
+insert into api_capability (http_method, route, capability) values ('POST', '/internal/api/*/steering', 'ds-steering-write') ON CONFLICT DO NOTHING; -- 98
+insert into api_capability (http_method, route, capability) values ('PUT', '/internal/api/*/steering/*', 'ds-steering-write') ON CONFLICT DO NOTHING; -- 99
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/deliveryserviceserver', 'ds-cache-read') ON CONFLICT DO NOTHING; -- 103
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/deliveryservices/*/servers', 'ds-cache-write') ON CONFLICT DO NOTHING; -- 106
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/deliveryservices_regexes', 'ds-read') ON CONFLICT DO NOTHING; -- 109
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/deliveryservices/*/regexes', 'ds-read') ON CONFLICT DO NOTHING; -- 110
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/deliveryservices/*/regexes/*', 'ds-read') ON CONFLICT DO NOTHING; -- 111
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/deliveryservices/*/regexes', 'ds-write') ON CONFLICT DO NOTHING; -- 112
+insert into api_capability (http_method, route, capability) values ('PUT', '/api/*/deliveryservices/*/regexes/*', 'ds-write') ON CONFLICT DO NOTHING; -- 113
+insert into api_capability (http_method, route, capability) values ('DELETE', '/api/*/deliveryservices/*/regexes/*', 'ds-write') ON CONFLICT DO NOTHING; -- 114
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/divisions', 'division-read') ON CONFLICT DO NOTHING; -- 120
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/divisions/*', 'division-read') ON CONFLICT DO NOTHING; -- 121
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/divisions', 'division-write') ON CONFLICT DO NOTHING; -- 122
+insert into api_capability (http_method, route, capability) values ('PUT', '/api/*/divisions/*', 'division-write') ON CONFLICT DO NOTHING; -- 123
+insert into api_capability (http_method, route, capability) values ('DELETE', '/api/*/divisions/*', 'division-write') ON CONFLICT DO NOTHING; -- 124
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cdns/name/*/dnsseckeys', 'cdn-security-keys-read') ON CONFLICT DO NOTHING; -- 127
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/cdns/dnsseckeys/generate', 'cdn-security-keys-write') ON CONFLICT DO NOTHING; -- 128
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cdns/name/*/dnsseckeys/delete', 'cdn-security-keys-write') ON CONFLICT DO NOTHING; -- 129
+insert into api_capability (http_method, route, capability) values ('GET', '/internal/api/*/cdns/dnsseckeys/refresh', 'cdn-security-keys-read') ON CONFLICT DO NOTHING; -- 130
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/to_extensions', 'to-extension-read') ON CONFLICT DO NOTHING; -- 134
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/to_extensions', 'to-extension-write') ON CONFLICT DO NOTHING; -- 135
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/to_extensions/*/delete', 'to-extension-write') ON CONFLICT DO NOTHING; -- 136
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/federations', 'federation-routing-read') ON CONFLICT DO NOTHING; -- 139
+insert into api_capability (http_method, route, capability) values ('GET', '/internal/api/*/federations', 'federation-routing-read') ON CONFLICT DO NOTHING; -- 140
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/federations', 'federation-routing-write') ON CONFLICT DO NOTHING; -- 141
+insert into api_capability (http_method, route, capability) values ('PUT', '/api/*/federations', 'federation-routing-write') ON CONFLICT DO NOTHING; -- 142
+insert into api_capability (http_method, route, capability) values ('DELETE', '/api/*/federations', 'federation-routing-write') ON CONFLICT DO NOTHING; -- 143
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/hwinfo', 'all-read') ON CONFLICT DO NOTHING; -- 148
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/parameters', 'params-read') ON CONFLICT DO NOTHING; -- 164
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/parameters/*', 'params-read') ON CONFLICT DO NOTHING; -- 168
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/parameters', 'params-write') ON CONFLICT DO NOTHING; -- 169
+insert into api_capability (http_method, route, capability) values ('PUT', '/api/*/parameters/*', 'params-write') ON CONFLICT DO NOTHING; -- 170
+insert into api_capability (http_method, route, capability) values ('DELETE', '/api/*/parameters/*', 'params-write') ON CONFLICT DO NOTHING; -- 171
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/parameters/*/validate', 'params-write') ON CONFLICT DO NOTHING; -- 172
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/profiles/*/parameters', 'params-read') ON CONFLICT DO NOTHING; -- 173
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/profiles/name/*/parameters', 'params-read') ON CONFLICT DO NOTHING; -- 174a
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/parameters/profile', 'params-read') ON CONFLICT DO NOTHING; -- 174b
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/profiles/name/*/parameters', 'params-write') ON CONFLICT DO NOTHING; -- 175
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/profiles/*/parameters', 'params-write') ON CONFLICT DO NOTHING; -- 176
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/profileparameters', 'params-read') ON CONFLICT DO NOTHING; -- 181
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/profileparameters', 'params-write') ON CONFLICT DO NOTHING; -- 182
+insert into api_capability (http_method, route, capability) values ('DELETE', '/api/*/profileparameters/*/*', 'params-write') ON CONFLICT DO NOTHING; -- 183
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cachegroupparameters', 'params-read') ON CONFLICT DO NOTHING; -- 186
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/phys_locations', 'phys-location-read') ON CONFLICT DO NOTHING; -- 191
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/phys_locations/trimmed', 'phys-location-read') ON CONFLICT DO NOTHING; -- 192
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/phys_locations/*', 'phys-location-read') ON CONFLICT DO NOTHING; -- 193
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/phys_locations', 'phys-location-write') ON CONFLICT DO NOTHING; -- 194
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/regions/*/phys_locations', 'phys-location-write') ON CONFLICT DO NOTHING; -- 195
+insert into api_capability (http_method, route, capability) values ('PUT', '/api/*/phys_locations/*', 'phys-location-write') ON CONFLICT DO NOTHING; -- 196
+insert into api_capability (http_method, route, capability) values ('DELETE', '/api/*/phys_locations/*', 'phys-location-write') ON CONFLICT DO NOTHING; -- 197
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/profiles', 'profile-read') ON CONFLICT DO NOTHING; -- 200
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/profiles/trimmed', 'profile-read') ON CONFLICT DO NOTHING; -- 201
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/profiles/*', 'profile-read') ON CONFLICT DO NOTHING; -- 202
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/profiles', 'profile-write') ON CONFLICT DO NOTHING; -- 203
+insert into api_capability (http_method, route, capability) values ('PUT', '/api/*/profiles/*', 'profile-write') ON CONFLICT DO NOTHING; -- 204
+insert into api_capability (http_method, route, capability) values ('DELETE', '/api/*/profiles/*', 'profile-write') ON CONFLICT DO NOTHING; -- 205
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/profiles/name/*/copy/*', 'profile-write') ON CONFLICT DO NOTHING; -- 206
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/regions', 'region-read') ON CONFLICT DO NOTHING; -- 213
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/regions/*', 'region-read') ON CONFLICT DO NOTHING; -- 214
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/regions', 'region-write') ON CONFLICT DO NOTHING; -- 215
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/divisions/*/regions', 'region-write') ON CONFLICT DO NOTHING; -- 216
+insert into api_capability (http_method, route, capability) values ('PUT', '/api/*/regions/*', 'region-write') ON CONFLICT DO NOTHING; -- 217
+insert into api_capability (http_method, route, capability) values ('DELETE', '/api/*/regions/*', 'region-write') ON CONFLICT DO NOTHING; -- 218
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/riak/ping', 'cdn-security-keys-write') ON CONFLICT DO NOTHING; -- 221
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/keys/ping', 'security-keys-write') ON CONFLICT DO NOTHING; -- 222
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/riak/bucket/#bucket/key/#key/values', 'security-keys-read') ON CONFLICT DO NOTHING; -- 223
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/riak/stats', 'security-keys-read') ON CONFLICT DO NOTHING; -- 224
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/roles', 'role-read') ON CONFLICT DO NOTHING; -- 227
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/servers', 'server-read') ON CONFLICT DO NOTHING; -- 230
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/servers?dsId=*', 'server-read') ON CONFLICT DO NOTHING; -- 231
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/servers?type=*', 'server-read') ON CONFLICT DO NOTHING; -- 232
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/servers?status=*', 'server-read') ON CONFLICT DO NOTHING; -- 233
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/servers?profileId=*', 'server-read') ON CONFLICT DO NOTHING; -- 234
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/servers/*', 'server-read') ON CONFLICT DO NOTHING; -- 235
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/servers', 'server-write') ON CONFLICT DO NOTHING; -- 237
+insert into api_capability (http_method, route, capability) values ('PUT', '/api/*/servers/*', 'server-write') ON CONFLICT DO NOTHING; -- 238
+insert into api_capability (http_method, route, capability) values ('DELETE', '/api/*/servers/*', 'server-write') ON CONFLICT DO NOTHING; -- 239
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/servers/details', 'server-read') ON CONFLICT DO NOTHING; -- 247
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/servers/totals', 'server-read') ON CONFLICT DO NOTHING; -- 249
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/servers/checks', 'server-read') ON CONFLICT DO NOTHING; -- 250a
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/servercheck/aadata', 'server-read') ON CONFLICT DO NOTHING; -- 250b
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/servercheck', 'server-write') ON CONFLICT DO NOTHING; -- 251
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/servers/*/queue_update', 'queue-updates-write') ON CONFLICT DO NOTHING; -- 252
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/servers/*/queue_update', 'queue-updates-write') ON CONFLICT DO NOTHING; -- 253
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/*/stats_summary', 'cdn-stats-read') ON CONFLICT DO NOTHING; -- 258
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/*/stats_summary?lastSummaryDate=true', 'cdn-stats-read') ON CONFLICT DO NOTHING; -- 259
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/*/stats_summary/create', 'cdn-stats-write') ON CONFLICT DO NOTHING; -- 260
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/statuses', 'status-read') ON CONFLICT DO NOTHING; -- 263
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/statuses/*', 'status-read') ON CONFLICT DO NOTHING; -- 264
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/staticdnsentries', 'static-dns-read') ON CONFLICT DO NOTHING; -- 270
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/system/info', 'basic-read') ON CONFLICT DO NOTHING; -- 275
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/types', 'type-read') ON CONFLICT DO NOTHING; -- 278
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/types/trimmed', 'type-read') ON CONFLICT DO NOTHING; -- 279
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/types/*', 'type-read') ON CONFLICT DO NOTHING; -- 280
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/types', 'type-write') ON CONFLICT DO NOTHING; -- 281
+insert into api_capability (http_method, route, capability) values ('PUT', '/api/*/types/*', 'type-write') ON CONFLICT DO NOTHING; -- 282
+insert into api_capability (http_method, route, capability) values ('DELETE', '/api/*/types/*', 'type-write') ON CONFLICT DO NOTHING; -- 283
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/users', 'user-read') ON CONFLICT DO NOTHING; -- 289
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/users/*', 'user-read') ON CONFLICT DO NOTHING; -- 290
+insert into api_capability (http_method, route, capability) values ('PUT', '/api/*/users/*', 'user-write') ON CONFLICT DO NOTHING; -- 292
+
+
 -- types
 -- delivery service types
 insert into type (name, description, use_in_table) values ('HTTP', 'HTTP Content Routing', 'deliveryservice') ON CONFLICT (name) DO NOTHING;

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/5392f500/traffic_ops/app/lib/Schema/Result/ApiCapability.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/app/lib/Schema/Result/ApiCapability.pm b/traffic_ops/app/lib/Schema/Result/ApiCapability.pm
new file mode 100644
index 0000000..2c7e89c
--- /dev/null
+++ b/traffic_ops/app/lib/Schema/Result/ApiCapability.pm
@@ -0,0 +1,124 @@
+use utf8;
+package Schema::Result::ApiCapability;
+
+# Created by DBIx::Class::Schema::Loader
+# DO NOT MODIFY THE FIRST PART OF THIS FILE
+
+=head1 NAME
+
+Schema::Result::ApiCapability
+
+=cut
+
+use strict;
+use warnings;
+
+use base 'DBIx::Class::Core';
+
+=head1 TABLE: C<api_capability>
+
+=cut
+
+__PACKAGE__->table("api_capability");
+
+=head1 ACCESSORS
+
+=head2 id
+
+  data_type: 'bigint'
+  is_auto_increment: 1
+  is_nullable: 0
+  sequence: 'api_capability_id_seq'
+
+=head2 http_method
+
+  data_type: 'enum'
+  extra: {custom_type_name => "http_method_t",list => ["GET","POST","PUT","PATCH","DELETE"]}
+  is_nullable: 0
+
+=head2 route
+
+  data_type: 'text'
+  is_nullable: 0
+
+=head2 capability
+
+  data_type: 'text'
+  is_foreign_key: 1
+  is_nullable: 0
+
+=head2 last_updated
+
+  data_type: 'timestamp with time zone'
+  default_value: current_timestamp
+  is_nullable: 1
+  original: {default_value => \"now()"}
+
+=cut
+
+__PACKAGE__->add_columns(
+  "id",
+  {
+    data_type         => "bigint",
+    is_auto_increment => 1,
+    is_nullable       => 0,
+    sequence          => "api_capability_id_seq",
+  },
+  "http_method",
+  {
+    data_type => "enum",
+    extra => {
+      custom_type_name => "http_method_t",
+      list => ["GET", "POST", "PUT", "PATCH", "DELETE"],
+    },
+    is_nullable => 0,
+  },
+  "route",
+  { data_type => "text", is_nullable => 0 },
+  "capability",
+  { data_type => "text", is_foreign_key => 1, is_nullable => 0 },
+  "last_updated",
+  {
+    data_type     => "timestamp with time zone",
+    default_value => \"current_timestamp",
+    is_nullable   => 1,
+    original      => { default_value => \"now()" },
+  },
+);
+
+=head1 PRIMARY KEY
+
+=over 4
+
+=item * L</id>
+
+=back
+
+=cut
+
+__PACKAGE__->set_primary_key("id");
+
+=head1 RELATIONS
+
+=head2 capability
+
+Type: belongs_to
+
+Related object: L<Schema::Result::Capability>
+
+=cut
+
+__PACKAGE__->belongs_to(
+  "capability",
+  "Schema::Result::Capability",
+  { name => "capability" },
+  { is_deferrable => 0, on_delete => "RESTRICT", on_update => "NO ACTION" },
+);
+
+
+# Created by DBIx::Class::Schema::Loader v0.07046 @ 2017-04-01 22:22:35
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:vYfANFCOS9i3LpGHRzMv3w
+
+
+# You can replace this text with custom code or comments, and it will be preserved on regeneration
+1;

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/5392f500/traffic_ops/app/lib/Schema/Result/Capability.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/app/lib/Schema/Result/Capability.pm b/traffic_ops/app/lib/Schema/Result/Capability.pm
new file mode 100644
index 0000000..d636726
--- /dev/null
+++ b/traffic_ops/app/lib/Schema/Result/Capability.pm
@@ -0,0 +1,109 @@
+use utf8;
+package Schema::Result::Capability;
+
+# Created by DBIx::Class::Schema::Loader
+# DO NOT MODIFY THE FIRST PART OF THIS FILE
+
+=head1 NAME
+
+Schema::Result::Capability
+
+=cut
+
+use strict;
+use warnings;
+
+use base 'DBIx::Class::Core';
+
+=head1 TABLE: C<capability>
+
+=cut
+
+__PACKAGE__->table("capability");
+
+=head1 ACCESSORS
+
+=head2 name
+
+  data_type: 'text'
+  is_nullable: 0
+
+=head2 description
+
+  data_type: 'text'
+  is_nullable: 1
+
+=head2 last_updated
+
+  data_type: 'timestamp with time zone'
+  default_value: current_timestamp
+  is_nullable: 1
+  original: {default_value => \"now()"}
+
+=cut
+
+__PACKAGE__->add_columns(
+  "name",
+  { data_type => "text", is_nullable => 0 },
+  "description",
+  { data_type => "text", is_nullable => 1 },
+  "last_updated",
+  {
+    data_type     => "timestamp with time zone",
+    default_value => \"current_timestamp",
+    is_nullable   => 1,
+    original      => { default_value => \"now()" },
+  },
+);
+
+=head1 PRIMARY KEY
+
+=over 4
+
+=item * L</name>
+
+=back
+
+=cut
+
+__PACKAGE__->set_primary_key("name");
+
+=head1 RELATIONS
+
+=head2 api_capabilities
+
+Type: has_many
+
+Related object: L<Schema::Result::ApiCapability>
+
+=cut
+
+__PACKAGE__->has_many(
+  "api_capabilities",
+  "Schema::Result::ApiCapability",
+  { "foreign.capability" => "self.name" },
+  { cascade_copy => 0, cascade_delete => 0 },
+);
+
+=head2 role_capabilities
+
+Type: has_many
+
+Related object: L<Schema::Result::RoleCapability>
+
+=cut
+
+__PACKAGE__->has_many(
+  "role_capabilities",
+  "Schema::Result::RoleCapability",
+  { "foreign.cap_name" => "self.name" },
+  { cascade_copy => 0, cascade_delete => 0 },
+);
+
+
+# Created by DBIx::Class::Schema::Loader v0.07046 @ 2017-04-01 22:22:35
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:34+RZwrrOVdouhv+bD2V/Q
+
+
+# You can replace this text with custom code or comments, and it will be preserved on regeneration
+1;

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/5392f500/traffic_ops/app/lib/Schema/Result/RoleCapability.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/app/lib/Schema/Result/RoleCapability.pm b/traffic_ops/app/lib/Schema/Result/RoleCapability.pm
new file mode 100644
index 0000000..6154ebd
--- /dev/null
+++ b/traffic_ops/app/lib/Schema/Result/RoleCapability.pm
@@ -0,0 +1,99 @@
+use utf8;
+package Schema::Result::RoleCapability;
+
+# Created by DBIx::Class::Schema::Loader
+# DO NOT MODIFY THE FIRST PART OF THIS FILE
+
+=head1 NAME
+
+Schema::Result::RoleCapability
+
+=cut
+
+use strict;
+use warnings;
+
+use base 'DBIx::Class::Core';
+
+=head1 TABLE: C<role_capability>
+
+=cut
+
+__PACKAGE__->table("role_capability");
+
+=head1 ACCESSORS
+
+=head2 role_id
+
+  data_type: 'bigint'
+  is_foreign_key: 1
+  is_nullable: 0
+
+=head2 cap_name
+
+  data_type: 'text'
+  is_foreign_key: 1
+  is_nullable: 0
+
+=head2 last_updated
+
+  data_type: 'timestamp with time zone'
+  default_value: current_timestamp
+  is_nullable: 1
+  original: {default_value => \"now()"}
+
+=cut
+
+__PACKAGE__->add_columns(
+  "role_id",
+  { data_type => "bigint", is_foreign_key => 1, is_nullable => 0 },
+  "cap_name",
+  { data_type => "text", is_foreign_key => 1, is_nullable => 0 },
+  "last_updated",
+  {
+    data_type     => "timestamp with time zone",
+    default_value => \"current_timestamp",
+    is_nullable   => 1,
+    original      => { default_value => \"now()" },
+  },
+);
+
+=head1 RELATIONS
+
+=head2 cap_name
+
+Type: belongs_to
+
+Related object: L<Schema::Result::Capability>
+
+=cut
+
+__PACKAGE__->belongs_to(
+  "cap_name",
+  "Schema::Result::Capability",
+  { name => "cap_name" },
+  { is_deferrable => 0, on_delete => "RESTRICT", on_update => "NO ACTION" },
+);
+
+=head2 role
+
+Type: belongs_to
+
+Related object: L<Schema::Result::Role>
+
+=cut
+
+__PACKAGE__->belongs_to(
+  "role",
+  "Schema::Result::Role",
+  { id => "role_id" },
+  { is_deferrable => 0, on_delete => "CASCADE", on_update => "NO ACTION" },
+);
+
+
+# Created by DBIx::Class::Schema::Loader v0.07046 @ 2017-03-27 14:22:23
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:QKteDmebV7GN1Oc5uwNo7A
+
+
+# You can replace this text with custom code or comments, and it will be preserved on regeneration
+1;

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/5392f500/traffic_ops/app/lib/Schema/Result/UserRole.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/app/lib/Schema/Result/UserRole.pm b/traffic_ops/app/lib/Schema/Result/UserRole.pm
new file mode 100644
index 0000000..38a694e
--- /dev/null
+++ b/traffic_ops/app/lib/Schema/Result/UserRole.pm
@@ -0,0 +1,99 @@
+use utf8;
+package Schema::Result::UserRole;
+
+# Created by DBIx::Class::Schema::Loader
+# DO NOT MODIFY THE FIRST PART OF THIS FILE
+
+=head1 NAME
+
+Schema::Result::UserRole
+
+=cut
+
+use strict;
+use warnings;
+
+use base 'DBIx::Class::Core';
+
+=head1 TABLE: C<user_role>
+
+=cut
+
+__PACKAGE__->table("user_role");
+
+=head1 ACCESSORS
+
+=head2 user_id
+
+  data_type: 'bigint'
+  is_foreign_key: 1
+  is_nullable: 0
+
+=head2 role_id
+
+  data_type: 'bigint'
+  is_foreign_key: 1
+  is_nullable: 0
+
+=head2 last_updated
+
+  data_type: 'timestamp with time zone'
+  default_value: current_timestamp
+  is_nullable: 1
+  original: {default_value => \"now()"}
+
+=cut
+
+__PACKAGE__->add_columns(
+  "user_id",
+  { data_type => "bigint", is_foreign_key => 1, is_nullable => 0 },
+  "role_id",
+  { data_type => "bigint", is_foreign_key => 1, is_nullable => 0 },
+  "last_updated",
+  {
+    data_type     => "timestamp with time zone",
+    default_value => \"current_timestamp",
+    is_nullable   => 1,
+    original      => { default_value => \"now()" },
+  },
+);
+
+=head1 RELATIONS
+
+=head2 role
+
+Type: belongs_to
+
+Related object: L<Schema::Result::Role>
+
+=cut
+
+__PACKAGE__->belongs_to(
+  "role",
+  "Schema::Result::Role",
+  { id => "role_id" },
+  { is_deferrable => 0, on_delete => "RESTRICT", on_update => "NO ACTION" },
+);
+
+=head2 user
+
+Type: belongs_to
+
+Related object: L<Schema::Result::TmUser>
+
+=cut
+
+__PACKAGE__->belongs_to(
+  "user",
+  "Schema::Result::TmUser",
+  { id => "user_id" },
+  { is_deferrable => 0, on_delete => "CASCADE", on_update => "NO ACTION" },
+);
+
+
+# Created by DBIx::Class::Schema::Loader v0.07046 @ 2017-03-27 10:20:36
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:jniOIr+9VEUCu1dZp9snNg
+
+
+# You can replace this text with custom code or comments, and it will be preserved on regeneration
+1;


[10/14] incubator-trafficcontrol git commit: Cancelled "root" role, using the existing "admin" role instead.

Posted by mi...@apache.org.
Cancelled "root" role, using the existing "admin" role instead.


Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/8d6ddc7b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/8d6ddc7b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/8d6ddc7b

Branch: refs/heads/master
Commit: 8d6ddc7b356d3690f0e8252beb151035fc567c34
Parents: a9827fd
Author: naamashoresh <na...@qwilt.com>
Authored: Sun May 21 11:34:10 2017 +0300
Committer: Jeremy Mitchell <mi...@gmail.com>
Committed: Tue May 23 20:39:03 2017 -0600

----------------------------------------------------------------------
 traffic_ops/app/db/seeds.sql | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/8d6ddc7b/traffic_ops/app/db/seeds.sql
----------------------------------------------------------------------
diff --git a/traffic_ops/app/db/seeds.sql b/traffic_ops/app/db/seeds.sql
index f6071b8..b5fa70a 100644
--- a/traffic_ops/app/db/seeds.sql
+++ b/traffic_ops/app/db/seeds.sql
@@ -69,7 +69,6 @@ insert into role (name, description, priv_level) values ('steering', 'Role for S
 insert into role (name, description, priv_level) values ('read-only user', 'Read-Only user', 10) ON CONFLICT (name) DO NOTHING;
 insert into role (name, description, priv_level) values ('portal', 'Portal User', 2) ON CONFLICT (name) DO NOTHING;
 insert into role (name, description, priv_level) values ('disallowed', 'Block all access', 0) ON CONFLICT (name) DO NOTHING;
-insert into role (name, description, priv_level) values ('root', 'Role for full capabilities - super-user ', 30) ON CONFLICT DO NOTHING;
 
 -- tenants
 insert into tenant (name, active, parent_id) values ('root', true, null) ON CONFLICT DO NOTHING;
@@ -140,8 +139,8 @@ insert into capability (name, description) values ('user-read', 'View user confi
 insert into capability (name, description) values ('user-write', 'Create, edit or delete user configuration') ON CONFLICT (name) DO NOTHING;
 
 -- roles_capabilities
-insert into role_capability (role_id, cap_name) values ((select id from role where name='root'), 'all-read') ON CONFLICT (role_id, cap_name) DO NOTHING;
-insert into role_capability (role_id, cap_name) values ((select id from role where name='root'), 'all-write') ON CONFLICT (role_id, cap_name) DO NOTHING;
+insert into role_capability (role_id, cap_name) values ((select id from role where name='admin'), 'all-read') ON CONFLICT (role_id, cap_name) DO NOTHING;
+insert into role_capability (role_id, cap_name) values ((select id from role where name='admin'), 'all-write') ON CONFLICT (role_id, cap_name) DO NOTHING;
 
 -- api_capabilities
 insert into api_capability (http_method, route, capability) values ('GET', '/', 'all-read') ON CONFLICT (http_method, route, capability) DO NOTHING;


[06/14] incubator-trafficcontrol git commit: Unit tests for new capabilities & api_capabilities APIs

Posted by mi...@apache.org.
Unit tests for new capabilities & api_capabilities APIs

(cherry picked from commit 78f2f846074d61171a88aa78fccccd07ec994686)


Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/7a5ce13e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/7a5ce13e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/7a5ce13e

Branch: refs/heads/master
Commit: 7a5ce13e7d7249883450bcaac25676691c7e3ae8
Parents: 9546e8a
Author: naamashoresh <na...@qwilt.com>
Authored: Thu May 4 10:29:00 2017 +0300
Committer: Jeremy Mitchell <mi...@gmail.com>
Committed: Tue May 23 20:39:02 2017 -0600

----------------------------------------------------------------------
 traffic_ops/app/t/api/1.2/api_capabilities.t | 232 ++++++++++++++++++++++
 traffic_ops/app/t/api/1.2/capabilities.t     | 183 +++++++++++++++++
 2 files changed, 415 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/7a5ce13e/traffic_ops/app/t/api/1.2/api_capabilities.t
----------------------------------------------------------------------
diff --git a/traffic_ops/app/t/api/1.2/api_capabilities.t b/traffic_ops/app/t/api/1.2/api_capabilities.t
new file mode 100644
index 0000000..71371fe
--- /dev/null
+++ b/traffic_ops/app/t/api/1.2/api_capabilities.t
@@ -0,0 +1,232 @@
+package main;
+#
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+use Mojo::Base -strict;
+use Test::More;
+use Test::Mojo;
+use DBI;
+use strict;
+use warnings;
+no warnings 'once';
+use warnings 'all';
+use Test::TestHelper;
+
+#no_transactions=>1 ==> keep fixtures after every execution, beware of duplicate data!
+#no_transactions=>0 ==> delete fixtures after every execution
+
+BEGIN { $ENV{MOJO_MODE} = "test" }
+
+my $schema = Schema->connect_to_database;
+my $dbh    = Schema->database_handle;
+my $t      = Test::Mojo->new('TrafficOps');
+
+my $false = 0;
+my $true = 1;
+
+Test::TestHelper->unload_core_data($schema);
+Test::TestHelper->load_core_data($schema);
+
+ok $t->post_ok( '/login', => form => { u => Test::TestHelper::ADMIN_USER, p => Test::TestHelper::ADMIN_USER_PASSWORD } )->status_is(302)
+	->or( sub { diag $t->tx->res->content->asset->{content}; } ), 'Should login?';
+
+#clear the tables
+my $th = $dbh->prepare("TRUNCATE TABLE capability CASCADE");
+$th->execute();
+
+#add capabilities required for the tests (basic-read & cdn-write)
+my $description = "Basic read operations";
+my $cap_name = "basic-read";
+$t->post_ok("/api/1.2/capabilities" => {Accept => 'application/json'} => json => {
+		"name" => $cap_name, "description" => $description
+	})->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content};} )
+	->json_is( "/response/description" => $description )
+	->json_is( "/response/name" => $cap_name )
+	, 'Does capability details return?';
+
+$description = "CDN write operations";
+$cap_name = "cdn-write";
+$t->post_ok("/api/1.2/capabilities" => {Accept => 'application/json'} => json => {
+		"name" => $cap_name, "description" => $description
+	})->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content};} )
+	->json_is( "/response/description" => $description )
+	->json_is( "/response/name" => $cap_name )
+	, 'Does capability details return?';
+
+$t->get_ok("/api/1.2/api_capabilities")->status_is(200)->json_is( "/response", [] )->or( sub { diag $t->tx->res->content->asset->{content}; } );;
+
+# adding valid entry
+my $http_method = "GET";
+my $route = "sample/route";
+my $cap_name = "basic-read";
+$t->post_ok("/api/1.2/api_capabilities" => {Accept => 'application/json'} => json => {
+			"httpMethod" => $http_method, "route" => $route, "capName" => $cap_name
+		})->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content};} )
+	->json_is( "/response/id" => 1 )
+	->json_is( "/response/httpMethod" => $http_method )
+	->json_is( "/response/route" => $route )
+	->json_is( "/response/capName" => $cap_name )
+	, 'Does mapping details return?';
+
+#verifying the create worked
+$t->get_ok("/api/1.2/api_capabilities")->status_is(200)
+	->json_is( "/response/0/id" => 1 )
+	->json_is( "/response/0/httpMethod" => $http_method )
+	->json_is( "/response/0/route" => $route )
+	->json_is( "/response/0/capName" => $cap_name )
+	->or( sub { diag $t->tx->res->content->asset->{content}; } );;
+
+#verifying get single
+$t->get_ok("/api/1.2/api_capabilities/1")->status_is(200)
+	->json_is( "/response/0/id" => 1 )
+	->json_is( "/response/0/httpMethod" => $http_method )
+	->json_is( "/response/0/route" => $route )
+	->json_is( "/response/0/capName" => $cap_name )
+	->or( sub { diag $t->tx->res->content->asset->{content}; } );;
+
+#insert the same mapping twice - fails
+$t->post_ok("/api/1.2/api_capabilities" => {Accept => 'application/json'} => json => {
+		"httpMethod" => $http_method, "route" => $route, "capName" => $cap_name
+	})->status_is(400)->or( sub { diag $t->tx->res->content->asset->{content};} )
+	->json_is( "/alerts/0/text" => "HTTP method \'$http_method\', route \'$route\' are already mapped to capability: $cap_name" )
+	, 'Is same entry twice?';
+
+#edit a mapping
+my $cap_name_updated = "cdn-write";
+$t->put_ok("/api/1.2/api_capabilities/1" => {Accept => 'application/json'} => json => {
+		"httpMethod" => $http_method, "route" => $route, "capName" => $cap_name_updated
+	})->status_is(200)
+	->json_is( "/response/id" => 1 )
+	->json_is( "/response/httpMethod" => $http_method )
+	->json_is( "/response/route" => $route )
+	->json_is( "/response/capName" => $cap_name_updated )
+	, 'Did update succeed?';
+
+#get after update
+$t->get_ok("/api/1.2/api_capabilities/1" => {Accept => 'application/json'} )->status_is(200)
+	->json_is( "/response/0/id" => 1 )
+	->json_is( "/response/0/httpMethod" => $http_method )
+	->json_is( "/response/0/route" => $route )
+	->json_is( "/response/0/capName" => $cap_name_updated )
+	, 'Did get after update succeed?';
+
+#edit the mapping back
+$t->put_ok("/api/1.2/api_capabilities/1" => {Accept => 'application/json'} => json => {
+		"httpMethod" => $http_method, "route" => $route, "capName" => $cap_name
+	})->status_is(200)
+	->json_is( "/response/id" => 1 )
+	->json_is( "/response/httpMethod" => $http_method )
+	->json_is( "/response/route" => $route )
+	->json_is( "/response/capName" => $cap_name )
+	, 'Did update succeed?';
+
+#get after update
+$t->get_ok("/api/1.2/api_capabilities/1" => {Accept => 'application/json'} )->status_is(200)
+	->json_is( "/response/0/id" => 1 )
+	->json_is( "/response/0/httpMethod" => $http_method )
+	->json_is( "/response/0/route" => $route )
+	->json_is( "/response/0/capName" => $cap_name )
+	, 'Did get after update back succeed?';
+
+#insert another mapping
+my $http_method_post = "POST";
+my $route_sample2 = "sample/route2";
+$t->post_ok("/api/1.2/api_capabilities" => {Accept => 'application/json'} => json => {
+		"httpMethod" => $http_method_post, "route" => $route_sample2, "capName" => $cap_name
+	})->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content};} )
+	->json_is( "/response/id" => 2 )
+	->json_is( "/response/httpMethod" => $http_method_post )
+	->json_is( "/response/route" => $route_sample2 )
+	->json_is( "/response/capName" => $cap_name )
+	, 'Does mapping details return?';
+
+#get by cap name
+$t->get_ok("/api/1.2/api_capabilities/capability/$cap_name")->status_is(200)
+	->json_is( "/response/0/id" => 1 )
+	->json_is( "/response/0/httpMethod" => $http_method )
+	->json_is( "/response/0/route" => $route )
+	->json_is( "/response/0/capName" => $cap_name )
+	->json_is( "/response/1/id" => 2 )
+	->json_is( "/response/1/httpMethod" => $http_method_post )
+	->json_is( "/response/1/route" => $route_sample2 )
+	->json_is( "/response/1/capName" => $cap_name )
+	->or( sub { diag $t->tx->res->content->asset->{content}; } );;
+
+#test delete
+$t->delete_ok("/api/1.2/api_capabilities/2")->status_is(200)
+	->json_is( "/alerts/0/text" => "API-capability mapping deleted." )
+	, 'Did delete succeed?';
+
+#make sure mapping was deleted
+$t->get_ok("/api/1.2/api_capabilities/2")->status_is(200)->json_is( "/response", [] )->or( sub { diag $t->tx->res->content->asset->{content}; } );;
+
+#negative tests
+
+# adding invalid entry - no httpMethod
+$t->post_ok("/api/1.2/api_capabilities" => {Accept => 'application/json'} => json => {
+		"route" => $route, "capName" => $cap_name
+	})->status_is(400)->or( sub { diag $t->tx->res->content->asset->{content};} )
+	->json_is( "/alerts/0/text" => "HTTP method is required." )
+	, 'Was invalid insert (no httpMethod) reject correctly?';
+
+# adding invalid entry - no route
+$t->post_ok("/api/1.2/api_capabilities" => {Accept => 'application/json'} => json => {
+		"httpMethod" => $http_method, "capName" => $cap_name
+	})->status_is(400)->or( sub { diag $t->tx->res->content->asset->{content};} )
+	->json_is( "/alerts/0/text" => "Route is required." )
+	, 'Was invalid insert (no route) reject correctly?';
+
+# adding invalid entry - empty route
+$t->post_ok("/api/1.2/api_capabilities" => {Accept => 'application/json'} => json => {
+		"httpMethod" => $http_method, "capName" => $cap_name, "route" => ""
+	})->status_is(400)->or( sub { diag $t->tx->res->content->asset->{content};} )
+	->json_is( "/alerts/0/text" => "Route is required." )
+	, 'Was invalid insert (no route) reject correctly?';
+
+# adding invalid entry - no capName
+$t->post_ok("/api/1.2/api_capabilities" => {Accept => 'application/json'} => json => {
+		"httpMethod" => $http_method, "route" => $route
+	})->status_is(400)->or( sub { diag $t->tx->res->content->asset->{content};} )
+	->json_is( "/alerts/0/text" => "Capability name is required." )
+	, 'Was invalid insert (no capName) reject correctly?';
+
+# adding invalid entry - empty capName
+$t->post_ok("/api/1.2/api_capabilities" => {Accept => 'application/json'} => json => {
+		"httpMethod" => $http_method, "route" => $route, "capName" => ""
+	})->status_is(400)->or( sub { diag $t->tx->res->content->asset->{content};} )
+	->json_is( "/alerts/0/text" => "Capability name is required." )
+	, 'Was invalid insert (no capName) reject correctly?';
+
+# adding invalid entry - invalid httpMethod
+my $invalid_http_method = 'BAD';
+$t->post_ok("/api/1.2/api_capabilities" => {Accept => 'application/json'} => json => {
+		"httpMethod" => $invalid_http_method, "route" => $route, "capName" => $cap_name
+	})->status_is(400)->or( sub { diag $t->tx->res->content->asset->{content};} )
+	->json_is( "/alerts/0/text" => "HTTP method \'$invalid_http_method\' is invalid. Valid values are: DELETE, GET, PATCH, POST, PUT" )
+	, 'Was invalid insert (no capName) reject correctly?';
+
+# adding invalid entry - non-existing capability
+my $non_existing_cap = "non-existing";
+$t->post_ok("/api/1.2/api_capabilities" => {Accept => 'application/json'} => json => {
+		"httpMethod" => $http_method, "route" => $route, "capName" => $non_existing_cap
+	})->status_is(400)->or( sub { diag $t->tx->res->content->asset->{content};} )
+	->json_is( "/alerts/0/text" => "Capability \'$non_existing_cap\' does not exist." )
+	, 'Was invalid insert (no capName) reject correctly?';
+
+
+ok $t->get_ok('/logout')->status_is(302)->or( sub { diag $t->tx->res->content->asset->{content}; } );
+
+$dbh->disconnect();
+done_testing();
+

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/7a5ce13e/traffic_ops/app/t/api/1.2/capabilities.t
----------------------------------------------------------------------
diff --git a/traffic_ops/app/t/api/1.2/capabilities.t b/traffic_ops/app/t/api/1.2/capabilities.t
new file mode 100644
index 0000000..b1031ef
--- /dev/null
+++ b/traffic_ops/app/t/api/1.2/capabilities.t
@@ -0,0 +1,183 @@
+package main;
+#
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+use Mojo::Base -strict;
+use Test::More;
+use Test::Mojo;
+use DBI;
+use strict;
+use warnings;
+no warnings 'once';
+use warnings 'all';
+use Test::TestHelper;
+
+#no_transactions=>1 ==> keep fixtures after every execution, beware of duplicate data!
+#no_transactions=>0 ==> delete fixtures after every execution
+
+BEGIN { $ENV{MOJO_MODE} = "test" }
+
+my $schema = Schema->connect_to_database;
+my $dbh    = Schema->database_handle;
+my $t      = Test::Mojo->new('TrafficOps');
+
+my $false = 0;
+my $true = 1;
+
+Test::TestHelper->unload_core_data($schema);
+Test::TestHelper->load_core_data($schema);
+
+ok $t->post_ok( '/login', => form => { u => Test::TestHelper::ADMIN_USER, p => Test::TestHelper::ADMIN_USER_PASSWORD } )->status_is(302)
+	->or( sub { diag $t->tx->res->content->asset->{content}; } ), 'Should login?';
+
+#clear the table
+my $th = $dbh->prepare("TRUNCATE TABLE capability CASCADE");
+$th->execute();
+
+$t->get_ok("/api/1.2/capabilities")->status_is(200)->json_is( "/response", [] )->or( sub { diag $t->tx->res->content->asset->{content}; } );;
+
+# adding valid entry
+my $description = "Basic read operations";
+my $cap_name = "basic-read";
+$t->post_ok("/api/1.2/capabilities" => {Accept => 'application/json'} => json => {
+			"name" => $cap_name, "description" => $description
+		})->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content};} )
+	->json_is( "/response/description" => $description )
+	->json_is( "/response/name" => $cap_name )
+	, 'Does capability details return?';
+
+#verifying the create worked
+$t->get_ok("/api/1.2/capabilities")->status_is(200)
+	->json_is( "/response/0/name" => $cap_name )
+	->json_is( "/response/0/description" => $description )
+	->or( sub { diag $t->tx->res->content->asset->{content}; } );;
+
+#verifying get by capapbility
+$t->get_ok("/api/1.2/capabilities/$cap_name")->status_is(200)
+	->json_is( "/response/0/name" => $cap_name )
+	->json_is( "/response/0/description" => $description )
+	->or( sub { diag $t->tx->res->content->asset->{content}; } );;
+
+#insert the same capability twice - fails
+$t->post_ok("/api/1.2/capabilities" => {Accept => 'application/json'} => json => {
+		"name" => $cap_name, "description" => $description
+	})->status_is(400)->or( sub { diag $t->tx->res->content->asset->{content};} )
+	->json_is( "/alerts/0/text" => "Capability \'$cap_name\' already exists." )
+	, 'Is same entry twice?';
+
+#edit a capability
+my $description_updated = "edited desctiption";
+$t->put_ok("/api/1.2/capabilities/$cap_name" => {Accept => 'application/json'} => json => {
+		"description" => $description_updated
+	})->status_is(200)
+	->json_is( "/response/name" => $cap_name )
+	->json_is( "/response/description" => $description_updated )
+	, 'Did update succeed?';
+
+#get after update
+$t->get_ok("/api/1.2/capabilities/$cap_name" => {Accept => 'application/json'} )->status_is(200)
+	->json_is( "/response/0/name" => $cap_name )
+	->json_is( "/response/0/description" => $description_updated )
+	, 'Did get after update succeed?';
+
+#edit the mapping back
+$t->put_ok("/api/1.2/capabilities/$cap_name" => {Accept => 'application/json'} => json => {
+		"name" => $cap_name, "description" => $description
+	})->status_is(200)
+	->json_is( "/response/name" => $cap_name )
+	->json_is( "/response/description" => $description )
+	, 'Did update succeed?';
+
+#get after update
+$t->get_ok("/api/1.2/capabilities/$cap_name" => {Accept => 'application/json'} )->status_is(200)
+	->json_is( "/response/0/name" => $cap_name )
+	->json_is( "/response/0/description" => $description )
+	, 'Did get after update back succeed?';
+
+#insert another capability
+my $cap_name_basic_write = "basic-write";
+my $description_basic_write = "Basic write operations";
+$t->post_ok("/api/1.2/capabilities" => {Accept => 'application/json'} => json => {
+		"name" => $cap_name_basic_write, "description" => $description_basic_write
+	})->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content};} )
+	->json_is( "/response/name" => $cap_name_basic_write )
+	->json_is( "/response/description" => $description_basic_write )
+	, 'Does capability details return?';
+
+#get by cap name
+$t->get_ok("/api/1.2/capabilities/$cap_name_basic_write")->status_is(200)
+	->json_is( "/response/0/name" => $cap_name_basic_write )
+	->json_is( "/response/0/description" => $description_basic_write )
+	->or( sub { diag $t->tx->res->content->asset->{content}; } );;
+
+#test delete
+$t->delete_ok("/api/1.2/capabilities/$cap_name_basic_write")->status_is(200)
+	->json_is( "/alerts/0/text" => "Capability deleted." )
+	, 'Did delete succeed?';
+
+#make sure mapping was deleted
+$t->get_ok("/api/1.2/capabilities/$cap_name_basic_write")->status_is(200)->json_is( "/response", [] )->or( sub { diag $t->tx->res->content->asset->{content}; } );;
+
+#negative tests
+# adding invalid entry - no description
+$t->post_ok("/api/1.2/capabilities" => {Accept => 'application/json'} => json => {
+		"name" => $cap_name
+	})->status_is(400)->or( sub { diag $t->tx->res->content->asset->{content};} )
+	->json_is( "/alerts/0/text" => "Description is required." )
+	, 'Was invalid insert (no description) reject correctly?';
+
+# adding invalid entry - empty description
+$t->post_ok("/api/1.2/capabilities" => {Accept => 'application/json'} => json => {
+		"name" => $cap_name, "description" => ""
+	})->status_is(400)->or( sub { diag $t->tx->res->content->asset->{content};} )
+	->json_is( "/alerts/0/text" => "Description is required." )
+	, 'Was invalid insert (no description) reject correctly?';
+
+# adding invalid entry - no name
+$t->post_ok("/api/1.2/capabilities" => {Accept => 'application/json'} => json => {
+		"description" => $description
+	})->status_is(400)->or( sub { diag $t->tx->res->content->asset->{content};} )
+	->json_is( "/alerts/0/text" => "Name is required." )
+	, 'Was invalid insert (no route) reject correctly?';
+
+# adding invalid entry - empty name
+$t->post_ok("/api/1.2/capabilities" => {Accept => 'application/json'} => json => {
+		"description" => $description, "name" => ""
+	})->status_is(400)->or( sub { diag $t->tx->res->content->asset->{content};} )
+	->json_is( "/alerts/0/text" => "Name is required." )
+	, 'Was invalid insert (no route) reject correctly?';
+
+# trying to delete a referenced capability. first add a mapping to it.
+my $http_method = "GET";
+my $route = "sample/route";
+$t->post_ok("/api/1.2/api_capabilities" => {Accept => 'application/json'} => json => {
+		"httpMethod" => $http_method, "route" => $route, "capName" => $cap_name
+	})->status_is(200)->or( sub { diag $t->tx->res->content->asset->{content};} )
+	->json_is( "/response/id" => 1 )
+	->json_is( "/response/httpMethod" => $http_method )
+	->json_is( "/response/route" => $route )
+	->json_is( "/response/capName" => $cap_name )
+	, 'Does mapping details return?';
+
+#test delete -  should fail
+$t->delete_ok("/api/1.2/capabilities/$cap_name")->status_is(400)
+	->json_is( "/alerts/0/text" => "Capability \'$cap_name\' is refered by an api_capability mapping: 1. Deletion failed." )
+	, 'Did delete succeed?';
+
+
+ok $t->get_ok('/logout')->status_is(302)->or( sub { diag $t->tx->res->content->asset->{content}; } );
+
+$dbh->disconnect();
+done_testing();
+


[02/14] incubator-trafficcontrol git commit: Applying review comments by mitchell852

Posted by mi...@apache.org.
Applying review comments by mitchell852

(cherry picked from commit 0dcee94a32d78da1561038407710662783bed327)


Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/b7eb8db4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/b7eb8db4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/b7eb8db4

Branch: refs/heads/master
Commit: b7eb8db4ea053fee085496bd59d80c95ce6c8fb5
Parents: c324141
Author: naamashoresh <na...@qwilt.com>
Authored: Thu May 4 14:47:10 2017 +0300
Committer: Jeremy Mitchell <mi...@gmail.com>
Committed: Tue May 23 20:39:02 2017 -0600

----------------------------------------------------------------------
 ...0406000001_create_capabilities_and_roles.sql |   2 +
 traffic_ops/app/db/seeds.sql                    | 484 +++++++++----------
 traffic_ops/app/lib/API/ApiCapability.pm        |  22 +-
 traffic_ops/app/lib/API/Capability.pm           |  73 ++-
 traffic_ops/app/lib/TrafficOpsRoutes.pm         |   7 +-
 traffic_ops/app/t/api/1.2/api_capabilities.t    |   2 +-
 6 files changed, 294 insertions(+), 296 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/b7eb8db4/traffic_ops/app/db/migrations/20170406000001_create_capabilities_and_roles.sql
----------------------------------------------------------------------
diff --git a/traffic_ops/app/db/migrations/20170406000001_create_capabilities_and_roles.sql b/traffic_ops/app/db/migrations/20170406000001_create_capabilities_and_roles.sql
index 23b730b..fbedbed 100644
--- a/traffic_ops/app/db/migrations/20170406000001_create_capabilities_and_roles.sql
+++ b/traffic_ops/app/db/migrations/20170406000001_create_capabilities_and_roles.sql
@@ -37,6 +37,7 @@ CREATE TABLE api_capability (
     route text NOT NULL,
     capability text NOT NULL,
     CONSTRAINT fk_capability FOREIGN KEY (capability) REFERENCES capability(name) ON DELETE RESTRICT,
+    UNIQUE (http_method, route, capability),
     last_updated timestamp with time zone DEFAULT now()
 );
 
@@ -48,6 +49,7 @@ CREATE TABLE role_capability (
     CONSTRAINT fk_role_id FOREIGN KEY (role_id) REFERENCES role(id) ON DELETE CASCADE,  
     cap_name text NOT NULL,
     CONSTRAINT fk_cap_name FOREIGN KEY (cap_name) REFERENCES capability(name) ON DELETE RESTRICT,
+    UNIQUE (role_id, cap_name),
     last_updated timestamp with time zone DEFAULT now()
 );
 

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/b7eb8db4/traffic_ops/app/db/seeds.sql
----------------------------------------------------------------------
diff --git a/traffic_ops/app/db/seeds.sql b/traffic_ops/app/db/seeds.sql
index f372c20..f6071b8 100644
--- a/traffic_ops/app/db/seeds.sql
+++ b/traffic_ops/app/db/seeds.sql
@@ -75,252 +75,252 @@ insert into role (name, description, priv_level) values ('root', 'Role for full
 insert into tenant (name, active, parent_id) values ('root', true, null) ON CONFLICT DO NOTHING;
 
 -- capabilities
-insert into capability (name, description) values ('all-read', 'Full read access') ON CONFLICT DO NOTHING;
-insert into capability (name, description) values ('all-write', 'Full write access') ON CONFLICT DO NOTHING;
-insert into capability (name, description) values ('asn-read', 'View ASN configuration') ON CONFLICT DO NOTHING;
-insert into capability (name, description) values ('asn-write', 'Create, edit or delete ASN configuration') ON CONFLICT DO NOTHING;
-insert into capability (name, description) values ('basic-read', 'Basic read operations. Every user should have this capability') ON CONFLICT DO NOTHING;
-insert into capability (name, description) values ('basic-write', 'Basic write operations. Every user should have this capability') ON CONFLICT DO NOTHING;
-insert into capability (name, description) values ('cache-config-files-read', 'View the generated cache configuration files') ON CONFLICT DO NOTHING;
-insert into capability (name, description) values ('cache-group-read', 'View cache-group configuration') ON CONFLICT DO NOTHING;
-insert into capability (name, description) values ('cache-group-write', 'Create, edit or delete cache-group configuration') ON CONFLICT DO NOTHING;
-insert into capability (name, description) values ('cache-stats-read', 'View Cache statistics read access') ON CONFLICT DO NOTHING;
-insert into capability (name, description) values ('cdn-config-snapshot-read', 'View config snapshot at CDN level') ON CONFLICT DO NOTHING;
-insert into capability (name, description) values ('cdn-config-snapshot-write', 'Config snapshot write access at CDN level') ON CONFLICT DO NOTHING;
-insert into capability (name, description) values ('cdn-health-read', 'View CDN health') ON CONFLICT DO NOTHING;
-insert into capability (name, description) values ('cdn-read', 'View CDN configuration') ON CONFLICT DO NOTHING;
-insert into capability (name, description) values ('cdn-write', 'Create, edit or delete CDN configuration') ON CONFLICT DO NOTHING;
-insert into capability (name, description) values ('cdn-security-keys-read', 'View CDN DNSSEC keys') ON CONFLICT DO NOTHING;
-insert into capability (name, description) values ('cdn-security-keys-write', 'Create, edit or delete CDN DNSSEC keys') ON CONFLICT DO NOTHING;
-insert into capability (name, description) values ('cdn-stats-read', 'View CDN statistics') ON CONFLICT DO NOTHING;
-insert into capability (name, description) values ('cdn-stats-write', 'Create, edit or delete CDN statistics') ON CONFLICT DO NOTHING;
-insert into capability (name, description) values ('change-log-read', 'View change-log') ON CONFLICT DO NOTHING;
-insert into capability (name, description) values ('change-log-write', 'Create change-log entries') ON CONFLICT DO NOTHING;
-insert into capability (name, description) values ('division-read', 'View division configuration') ON CONFLICT DO NOTHING;
-insert into capability (name, description) values ('division-write', 'Create, edit or delete division configuration') ON CONFLICT DO NOTHING;
-insert into capability (name, description) values ('ds-cache-read', 'View delivery-service cache assignment') ON CONFLICT DO NOTHING;
-insert into capability (name, description) values ('ds-cache-read', 'Create, edit or delete delivery-service cache assignment') ON CONFLICT DO NOTHING;
-insert into capability (name, description) values ('ds-health-read', 'View delivery-service health') ON CONFLICT DO NOTHING;
-insert into capability (name, description) values ('ds-read', 'View delivery-service configuration') ON CONFLICT DO NOTHING;
-insert into capability (name, description) values ('ds-write', 'Create, edit or delete delivery-service configuration') ON CONFLICT DO NOTHING;
-insert into capability (name, description) values ('ds-security-keys-read', 'View delivery-service security keys') ON CONFLICT DO NOTHING;
-insert into capability (name, description) values ('ds-security-keys-write', 'Create, edit or delete delivery-service security keys') ON CONFLICT DO NOTHING;
-insert into capability (name, description) values ('ds-stats-read', 'View delivery-service statistics') ON CONFLICT DO NOTHING;
-insert into capability (name, description) values ('ds-steering-read', 'View delivery-service steering configuration') ON CONFLICT DO NOTHING;
-insert into capability (name, description) values ('ds-steering-write', 'Create, edit or delete delivery-service steering configuration') ON CONFLICT DO NOTHING;
-insert into capability (name, description) values ('federation-routing-read', 'View federation routing') ON CONFLICT DO NOTHING;
-insert into capability (name, description) values ('federation-routing-write', 'Create, edit or delete federation routing') ON CONFLICT DO NOTHING;
-insert into capability (name, description) values ('job-read', 'View jobs') ON CONFLICT DO NOTHING;
-insert into capability (name, description) values ('job-write', 'Create, edit or delete jobs') ON CONFLICT DO NOTHING;
-insert into capability (name, description) values ('params-read', 'View parameters') ON CONFLICT DO NOTHING;
-insert into capability (name, description) values ('params-write', 'Create, edit or delete parameters') ON CONFLICT DO NOTHING;
-insert into capability (name, description) values ('phys-location-read', 'View physical location configuration') ON CONFLICT DO NOTHING;
-insert into capability (name, description) values ('phys-location-write', 'Create, edit or delete physical location configuration') ON CONFLICT DO NOTHING;
-insert into capability (name, description) values ('profile-read', 'View profiles') ON CONFLICT DO NOTHING;
-insert into capability (name, description) values ('profile-write', 'Create, edit or delete profiles') ON CONFLICT DO NOTHING;
-insert into capability (name, description) values ('queue-updates-write', 'Queue updates to caches') ON CONFLICT DO NOTHING;
-insert into capability (name, description) values ('region-read', 'View region configuration') ON CONFLICT DO NOTHING;
-insert into capability (name, description) values ('region-write', 'Create, edit or delete region configuration') ON CONFLICT DO NOTHING;
-insert into capability (name, description) values ('role-read', 'View role configuration') ON CONFLICT DO NOTHING;
-insert into capability (name, description) values ('role-write', 'Create, edit or delete role configuration') ON CONFLICT DO NOTHING;
-insert into capability (name, description) values ('security-keys-read', 'View security keys') ON CONFLICT DO NOTHING;
-insert into capability (name, description) values ('security-keys-write', 'Create, edit or delete security keys') ON CONFLICT DO NOTHING;
-insert into capability (name, description) values ('server-pull-updates-read', 'Read server update indication') ON CONFLICT DO NOTHING;
-insert into capability (name, description) values ('server-pull-updates-write', 'Write server update indication') ON CONFLICT DO NOTHING;
-insert into capability (name, description) values ('server-read', 'View server configuration') ON CONFLICT DO NOTHING;
-insert into capability (name, description) values ('server-write', 'Create, edit or delete server configuration') ON CONFLICT DO NOTHING;
-insert into capability (name, description) values ('static-dns-read', 'View static DNS configuration') ON CONFLICT DO NOTHING;
-insert into capability (name, description) values ('static-dns-write', 'Create, edit or delete static DNS configuration') ON CONFLICT DO NOTHING;
-insert into capability (name, description) values ('status-read', 'View the list of defined statuses') ON CONFLICT DO NOTHING;
-insert into capability (name, description) values ('to-extension-read', 'View Traffic Ops extensions') ON CONFLICT DO NOTHING;
-insert into capability (name, description) values ('to-extension-write', 'Create, edit or delete Traffic Ops extensions') ON CONFLICT DO NOTHING;
-insert into capability (name, description) values ('type-read', 'View types configuration') ON CONFLICT DO NOTHING;
-insert into capability (name, description) values ('type-write', 'Create, edit or delete type configuration') ON CONFLICT DO NOTHING;
-insert into capability (name, description) values ('user-read', 'View user configuration') ON CONFLICT DO NOTHING;
-insert into capability (name, description) values ('user-write', 'Create, edit or delete user configuration') ON CONFLICT DO NOTHING;
+insert into capability (name, description) values ('all-read', 'Full read access') ON CONFLICT (name) DO NOTHING;
+insert into capability (name, description) values ('all-write', 'Full write access') ON CONFLICT (name) DO NOTHING;
+insert into capability (name, description) values ('asn-read', 'View ASN configuration') ON CONFLICT (name) DO NOTHING;
+insert into capability (name, description) values ('asn-write', 'Create, edit or delete ASN configuration') ON CONFLICT (name) DO NOTHING;
+insert into capability (name, description) values ('basic-read', 'Basic read operations. Every user should have this capability') ON CONFLICT (name) DO NOTHING;
+insert into capability (name, description) values ('basic-write', 'Basic write operations. Every user should have this capability') ON CONFLICT (name) DO NOTHING;
+insert into capability (name, description) values ('cache-config-files-read', 'View the generated cache configuration files') ON CONFLICT (name) DO NOTHING;
+insert into capability (name, description) values ('cache-group-read', 'View cache-group configuration') ON CONFLICT (name) DO NOTHING;
+insert into capability (name, description) values ('cache-group-write', 'Create, edit or delete cache-group configuration') ON CONFLICT (name) DO NOTHING;
+insert into capability (name, description) values ('cache-stats-read', 'View Cache statistics read access') ON CONFLICT (name) DO NOTHING;
+insert into capability (name, description) values ('cdn-config-snapshot-read', 'View config snapshot at CDN level') ON CONFLICT (name) DO NOTHING;
+insert into capability (name, description) values ('cdn-config-snapshot-write', 'Config snapshot write access at CDN level') ON CONFLICT (name) DO NOTHING;
+insert into capability (name, description) values ('cdn-health-read', 'View CDN health') ON CONFLICT (name) DO NOTHING;
+insert into capability (name, description) values ('cdn-read', 'View CDN configuration') ON CONFLICT (name) DO NOTHING;
+insert into capability (name, description) values ('cdn-write', 'Create, edit or delete CDN configuration') ON CONFLICT (name) DO NOTHING;
+insert into capability (name, description) values ('cdn-security-keys-read', 'View CDN DNSSEC keys') ON CONFLICT (name) DO NOTHING;
+insert into capability (name, description) values ('cdn-security-keys-write', 'Create, edit or delete CDN DNSSEC keys') ON CONFLICT (name) DO NOTHING;
+insert into capability (name, description) values ('cdn-stats-read', 'View CDN statistics') ON CONFLICT (name) DO NOTHING;
+insert into capability (name, description) values ('cdn-stats-write', 'Create, edit or delete CDN statistics') ON CONFLICT (name) DO NOTHING;
+insert into capability (name, description) values ('change-log-read', 'View change-log') ON CONFLICT (name) DO NOTHING;
+insert into capability (name, description) values ('change-log-write', 'Create change-log entries') ON CONFLICT (name) DO NOTHING;
+insert into capability (name, description) values ('division-read', 'View division configuration') ON CONFLICT (name) DO NOTHING;
+insert into capability (name, description) values ('division-write', 'Create, edit or delete division configuration') ON CONFLICT (name) DO NOTHING;
+insert into capability (name, description) values ('ds-cache-read', 'View delivery-service cache assignment') ON CONFLICT (name) DO NOTHING;
+insert into capability (name, description) values ('ds-cache-read', 'Create, edit or delete delivery-service cache assignment') ON CONFLICT (name) DO NOTHING;
+insert into capability (name, description) values ('ds-health-read', 'View delivery-service health') ON CONFLICT (name) DO NOTHING;
+insert into capability (name, description) values ('ds-read', 'View delivery-service configuration') ON CONFLICT (name) DO NOTHING;
+insert into capability (name, description) values ('ds-write', 'Create, edit or delete delivery-service configuration') ON CONFLICT (name) DO NOTHING;
+insert into capability (name, description) values ('ds-security-keys-read', 'View delivery-service security keys') ON CONFLICT (name) DO NOTHING;
+insert into capability (name, description) values ('ds-security-keys-write', 'Create, edit or delete delivery-service security keys') ON CONFLICT (name) DO NOTHING;
+insert into capability (name, description) values ('ds-stats-read', 'View delivery-service statistics') ON CONFLICT (name) DO NOTHING;
+insert into capability (name, description) values ('ds-steering-read', 'View delivery-service steering configuration') ON CONFLICT (name) DO NOTHING;
+insert into capability (name, description) values ('ds-steering-write', 'Create, edit or delete delivery-service steering configuration') ON CONFLICT (name) DO NOTHING;
+insert into capability (name, description) values ('federation-routing-read', 'View federation routing') ON CONFLICT (name) DO NOTHING;
+insert into capability (name, description) values ('federation-routing-write', 'Create, edit or delete federation routing') ON CONFLICT (name) DO NOTHING;
+insert into capability (name, description) values ('job-read', 'View jobs') ON CONFLICT (name) DO NOTHING;
+insert into capability (name, description) values ('job-write', 'Create, edit or delete jobs') ON CONFLICT (name) DO NOTHING;
+insert into capability (name, description) values ('params-read', 'View parameters') ON CONFLICT (name) DO NOTHING;
+insert into capability (name, description) values ('params-write', 'Create, edit or delete parameters') ON CONFLICT (name) DO NOTHING;
+insert into capability (name, description) values ('phys-location-read', 'View physical location configuration') ON CONFLICT (name) DO NOTHING;
+insert into capability (name, description) values ('phys-location-write', 'Create, edit or delete physical location configuration') ON CONFLICT (name) DO NOTHING;
+insert into capability (name, description) values ('profile-read', 'View profiles') ON CONFLICT (name) DO NOTHING;
+insert into capability (name, description) values ('profile-write', 'Create, edit or delete profiles') ON CONFLICT (name) DO NOTHING;
+insert into capability (name, description) values ('queue-updates-write', 'Queue updates to caches') ON CONFLICT (name) DO NOTHING;
+insert into capability (name, description) values ('region-read', 'View region configuration') ON CONFLICT (name) DO NOTHING;
+insert into capability (name, description) values ('region-write', 'Create, edit or delete region configuration') ON CONFLICT (name) DO NOTHING;
+insert into capability (name, description) values ('role-read', 'View role configuration') ON CONFLICT (name) DO NOTHING;
+insert into capability (name, description) values ('role-write', 'Create, edit or delete role configuration') ON CONFLICT (name) DO NOTHING;
+insert into capability (name, description) values ('security-keys-read', 'View security keys') ON CONFLICT (name) DO NOTHING;
+insert into capability (name, description) values ('security-keys-write', 'Create, edit or delete security keys') ON CONFLICT (name) DO NOTHING;
+insert into capability (name, description) values ('server-pull-updates-read', 'Read server update indication') ON CONFLICT (name) DO NOTHING;
+insert into capability (name, description) values ('server-pull-updates-write', 'Write server update indication') ON CONFLICT (name) DO NOTHING;
+insert into capability (name, description) values ('server-read', 'View server configuration') ON CONFLICT (name) DO NOTHING;
+insert into capability (name, description) values ('server-write', 'Create, edit or delete server configuration') ON CONFLICT (name) DO NOTHING;
+insert into capability (name, description) values ('static-dns-read', 'View static DNS configuration') ON CONFLICT (name) DO NOTHING;
+insert into capability (name, description) values ('static-dns-write', 'Create, edit or delete static DNS configuration') ON CONFLICT (name) DO NOTHING;
+insert into capability (name, description) values ('status-read', 'View the list of defined statuses') ON CONFLICT (name) DO NOTHING;
+insert into capability (name, description) values ('to-extension-read', 'View Traffic Ops extensions') ON CONFLICT (name) DO NOTHING;
+insert into capability (name, description) values ('to-extension-write', 'Create, edit or delete Traffic Ops extensions') ON CONFLICT (name) DO NOTHING;
+insert into capability (name, description) values ('type-read', 'View types configuration') ON CONFLICT (name) DO NOTHING;
+insert into capability (name, description) values ('type-write', 'Create, edit or delete type configuration') ON CONFLICT (name) DO NOTHING;
+insert into capability (name, description) values ('user-read', 'View user configuration') ON CONFLICT (name) DO NOTHING;
+insert into capability (name, description) values ('user-write', 'Create, edit or delete user configuration') ON CONFLICT (name) DO NOTHING;
 
 -- roles_capabilities
-insert into role_capability (role_id, cap_name) values (10, 'all-read') ON CONFLICT DO NOTHING;
-insert into role_capability (role_id, cap_name) values (10, 'all-write') ON CONFLICT DO NOTHING;
+insert into role_capability (role_id, cap_name) values ((select id from role where name='root'), 'all-read') ON CONFLICT (role_id, cap_name) DO NOTHING;
+insert into role_capability (role_id, cap_name) values ((select id from role where name='root'), 'all-write') ON CONFLICT (role_id, cap_name) DO NOTHING;
 
 -- api_capabilities
-insert into api_capability (http_method, route, capability) values ('GET', '/', 'all-read') ON CONFLICT DO NOTHING;
-insert into api_capability (http_method, route, capability) values ('POST', '/', 'all-write') ON CONFLICT DO NOTHING;
-insert into api_capability (http_method, route, capability) values ('PUT', '/', 'all-write') ON CONFLICT DO NOTHING;
-insert into api_capability (http_method, route, capability) values ('PATCH', '/', 'all-write') ON CONFLICT DO NOTHING;
-insert into api_capability (http_method, route, capability) values ('DELETE', '/', 'all-write') ON CONFLICT DO NOTHING;
-
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/asns', 'asn-read') ON CONFLICT DO NOTHING; -- 4
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/asns/*', 'asn-read') ON CONFLICT DO NOTHING; -- 5
-insert into api_capability (http_method, route, capability) values ('POST', '/api/*/asns', 'asn-write') ON CONFLICT DO NOTHING; -- 6
-insert into api_capability (http_method, route, capability) values ('PUT', '/api/*/asns/*', 'asn-write') ON CONFLICT DO NOTHING; -- 7
-insert into api_capability (http_method, route, capability) values ('DELETE', '/api/*/asns/*', 'asn-write') ON CONFLICT DO NOTHING; -- 8
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cache_stats', 'cache-stats-read') ON CONFLICT DO NOTHING; -- 11
-insert into api_capability (http_method, route, capability) values ('GET', '/internal/api/*/daily_summary', 'cache-stats-read') ON CONFLICT DO NOTHING; -- 12
-insert into api_capability (http_method, route, capability) values ('GET', '/internal/api/*/current_stats', 'cache-stats-read') ON CONFLICT DO NOTHING; -- 13
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cachegroups', 'cache-group-read') ON CONFLICT DO NOTHING; -- 16
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cachegroups/list', 'cache-group-read') ON CONFLICT DO NOTHING; -- 17
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cachegroups/trimmed', 'cache-group-read') ON CONFLICT DO NOTHING; -- 18
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cachegroups/*', 'cache-group-read') ON CONFLICT DO NOTHING; -- 19
-insert into api_capability (http_method, route, capability) values ('POST', '/api/*/cachegroups', 'cache-group-write') ON CONFLICT DO NOTHING; -- 20
-insert into api_capability (http_method, route, capability) values ('POST', '/api/*/cachegroups/create', 'cache-group-write') ON CONFLICT DO NOTHING; -- 21
-insert into api_capability (http_method, route, capability) values ('PUT', '/api/*/cachegroups/*', 'cache-group-write') ON CONFLICT DO NOTHING; -- 22
-insert into api_capability (http_method, route, capability) values ('PUT', '/api/*/cachegroups/*/update', 'cache-group-write') ON CONFLICT DO NOTHING; -- 23
-insert into api_capability (http_method, route, capability) values ('DELETE', '/api/*/cachegroups/*', 'cache-group-write') ON CONFLICT DO NOTHING; -- 24
-insert into api_capability (http_method, route, capability) values ('DELETE', '/api/*/cachegroups/*/delete', 'cache-group-write') ON CONFLICT DO NOTHING; -- 25
-insert into api_capability (http_method, route, capability) values ('POST', '/api/*/cachegroups/*/queue_update', 'queue-updates-write') ON CONFLICT DO NOTHING; -- 26
-insert into api_capability (http_method, route, capability) values ('POST', '/api/*/cachegroups/*/queue_update', 'queue-updates-write') ON CONFLICT DO NOTHING; -- 27
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cachegroups/*/parameters', 'params-read') ON CONFLICT DO NOTHING; -- 28
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cdns', 'cdn-read') ON CONFLICT DO NOTHING; -- 31
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cdns/*', 'cdn-read') ON CONFLICT DO NOTHING; -- 32
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cdns/name/*', 'cdn-read') ON CONFLICT DO NOTHING; -- 33
-insert into api_capability (http_method, route, capability) values ('POST', '/api/*/cdns', 'cdn-write') ON CONFLICT DO NOTHING; -- 34
-insert into api_capability (http_method, route, capability) values ('PUT', '/api/*/cdns/*', 'cdn-write') ON CONFLICT DO NOTHING; -- 35
-insert into api_capability (http_method, route, capability) values ('DELETE', '/api/*/cdns/*', 'cdn-write') ON CONFLICT DO NOTHING; -- 36
-insert into api_capability (http_method, route, capability) values ('POST', '/api/*/cdns/*/queue_update', 'queue-updates-write') ON CONFLICT DO NOTHING; -- 37
-insert into api_capability (http_method, route, capability) values ('POST', '/api/*/cdns/*/queue_update', 'queue-updates-write') ON CONFLICT DO NOTHING; -- 38
-insert into api_capability (http_method, route, capability) values ('PUT', '/api/*/cdns/*/snapshot', 'cdn-config-snapshot-write') ON CONFLICT DO NOTHING; -- 40
-insert into api_capability (http_method, route, capability) values ('PUT', '/api/*/snapshot/*', 'cdn-config-snapshot-write') ON CONFLICT DO NOTHING; -- 41
-insert into api_capability (http_method, route, capability) values ('PUT', '/api/*/snapshot/*', 'cdn-config-snapshot-write') ON CONFLICT DO NOTHING; -- 42
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cdns/configs', 'cdn-read') ON CONFLICT DO NOTHING; -- 44
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cdns/*/configs/routing', 'cdn-read') ON CONFLICT DO NOTHING; -- 45
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cdns/*/configs/monitoring', 'cdn-read') ON CONFLICT DO NOTHING; -- 46
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cdns/domains', 'cdn-read') ON CONFLICT DO NOTHING; -- 47
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cdns/health', 'cdn-health-read') ON CONFLICT DO NOTHING; -- 48
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cdns/*/health', 'cdn-health-read') ON CONFLICT DO NOTHING; -- 49
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cdns/capacity', 'cdn-health-read') ON CONFLICT DO NOTHING; -- 50
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cdns/routing', 'cdn-read') ON CONFLICT DO NOTHING; -- 51
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cdns/name/*/sslkeys', 'cdn-security-keys-read') ON CONFLICT DO NOTHING; -- 52
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cdns/usage/overview', 'cdn-stats-read') ON CONFLICT DO NOTHING; -- 54
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/logs', 'change-log-read') ON CONFLICT DO NOTHING; -- 57
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/logs/*/days', 'change-log-read') ON CONFLICT DO NOTHING; -- 58
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/logs/newcount', 'change-log-read') ON CONFLICT DO NOTHING; -- 60
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/deliveryservices', 'ds-read') ON CONFLICT DO NOTHING; -- 69
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/deliveryservices/list', 'ds-read') ON CONFLICT DO NOTHING; -- 70
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/deliveryservices/*', 'ds-read') ON CONFLICT DO NOTHING; -- 71
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/deliveryservices/*/get', 'ds-read') ON CONFLICT DO NOTHING; -- 72
-insert into api_capability (http_method, route, capability) values ('POST', '/api/*/deliveryservices', 'ds-write') ON CONFLICT DO NOTHING; -- 73
-insert into api_capability (http_method, route, capability) values ('POST', '/api/*/*/deliveryservices/create', 'ds-write') ON CONFLICT DO NOTHING; -- 74
-insert into api_capability (http_method, route, capability) values ('PUT', '/api/*/deliveryservices/*', 'ds-write') ON CONFLICT DO NOTHING; -- 75
-insert into api_capability (http_method, route, capability) values ('PUT', '/api/*/*/deliveryservices/*/update', 'ds-write') ON CONFLICT DO NOTHING; -- 76
-insert into api_capability (http_method, route, capability) values ('DELETE', '/api/*/deliveryservices/*', 'ds-write') ON CONFLICT DO NOTHING; -- 77
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/deliveryservices/*/health', 'ds-health-read') ON CONFLICT DO NOTHING; -- 78
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/deliveryservices/*/capacity', 'ds-health-read') ON CONFLICT DO NOTHING; -- 79
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/deliveryservices/*/routing', 'ds-read') ON CONFLICT DO NOTHING; -- 80
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/deliveryservices/*/state', 'ds-read') ON CONFLICT DO NOTHING; -- 81
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/deliveryservice_stats', 'ds-stats-read') ON CONFLICT DO NOTHING; -- 82
-insert into api_capability (http_method, route, capability) values ('POST', '/api/*/deliveryservices/request', 'ds-read') ON CONFLICT DO NOTHING; -- 83
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/deliveryservices/xmlId/*/sslkeys', 'ds-security-keys-read') ON CONFLICT DO NOTHING; -- 84
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/deliveryservices/hostname/#hostname/sslkeys', 'ds-security-keys-read') ON CONFLICT DO NOTHING; -- 85
-insert into api_capability (http_method, route, capability) values ('POST', '/api/*/deliveryservices/sslkeys/generate', 'ds-security-keys-write') ON CONFLICT DO NOTHING; -- 86
-insert into api_capability (http_method, route, capability) values ('POST', '/api/*/deliveryservices/sslkeys/add', 'ds-security-keys-write') ON CONFLICT DO NOTHING; -- 87
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/deliveryservices/xmlId/*/sslkeys/delete', 'ds-security-keys-write') ON CONFLICT DO NOTHING; -- 88
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/deliveryservices/xmlId/*/urlkeys', 'ds-security-keys-read') ON CONFLICT DO NOTHING; -- 89
-insert into api_capability (http_method, route, capability) values ('POST', '/api/*/deliveryservices/xmlId/*/urlkeys/generate', 'ds-security-keys-write') ON CONFLICT DO NOTHING; -- 90
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/deliveryservices/*/regexes', 'ds-read') ON CONFLICT DO NOTHING; -- 91
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/deliveryservice_matches', 'ds-read') ON CONFLICT DO NOTHING; -- 92
-insert into api_capability (http_method, route, capability) values ('GET', '/internal/api/*/steering', 'ds-steering-read') ON CONFLICT DO NOTHING; -- 96
-insert into api_capability (http_method, route, capability) values ('GET', '/internal/api/*/steering/*', 'ds-steering-read') ON CONFLICT DO NOTHING; -- 97
-insert into api_capability (http_method, route, capability) values ('POST', '/internal/api/*/steering', 'ds-steering-write') ON CONFLICT DO NOTHING; -- 98
-insert into api_capability (http_method, route, capability) values ('PUT', '/internal/api/*/steering/*', 'ds-steering-write') ON CONFLICT DO NOTHING; -- 99
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/deliveryserviceserver', 'ds-cache-read') ON CONFLICT DO NOTHING; -- 103
-insert into api_capability (http_method, route, capability) values ('POST', '/api/*/deliveryservices/*/servers', 'ds-cache-write') ON CONFLICT DO NOTHING; -- 106
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/deliveryservices_regexes', 'ds-read') ON CONFLICT DO NOTHING; -- 109
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/deliveryservices/*/regexes', 'ds-read') ON CONFLICT DO NOTHING; -- 110
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/deliveryservices/*/regexes/*', 'ds-read') ON CONFLICT DO NOTHING; -- 111
-insert into api_capability (http_method, route, capability) values ('POST', '/api/*/deliveryservices/*/regexes', 'ds-write') ON CONFLICT DO NOTHING; -- 112
-insert into api_capability (http_method, route, capability) values ('PUT', '/api/*/deliveryservices/*/regexes/*', 'ds-write') ON CONFLICT DO NOTHING; -- 113
-insert into api_capability (http_method, route, capability) values ('DELETE', '/api/*/deliveryservices/*/regexes/*', 'ds-write') ON CONFLICT DO NOTHING; -- 114
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/divisions', 'division-read') ON CONFLICT DO NOTHING; -- 120
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/divisions/*', 'division-read') ON CONFLICT DO NOTHING; -- 121
-insert into api_capability (http_method, route, capability) values ('POST', '/api/*/divisions', 'division-write') ON CONFLICT DO NOTHING; -- 122
-insert into api_capability (http_method, route, capability) values ('PUT', '/api/*/divisions/*', 'division-write') ON CONFLICT DO NOTHING; -- 123
-insert into api_capability (http_method, route, capability) values ('DELETE', '/api/*/divisions/*', 'division-write') ON CONFLICT DO NOTHING; -- 124
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cdns/name/*/dnsseckeys', 'cdn-security-keys-read') ON CONFLICT DO NOTHING; -- 127
-insert into api_capability (http_method, route, capability) values ('POST', '/api/*/cdns/dnsseckeys/generate', 'cdn-security-keys-write') ON CONFLICT DO NOTHING; -- 128
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cdns/name/*/dnsseckeys/delete', 'cdn-security-keys-write') ON CONFLICT DO NOTHING; -- 129
-insert into api_capability (http_method, route, capability) values ('GET', '/internal/api/*/cdns/dnsseckeys/refresh', 'cdn-security-keys-read') ON CONFLICT DO NOTHING; -- 130
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/to_extensions', 'to-extension-read') ON CONFLICT DO NOTHING; -- 134
-insert into api_capability (http_method, route, capability) values ('POST', '/api/*/to_extensions', 'to-extension-write') ON CONFLICT DO NOTHING; -- 135
-insert into api_capability (http_method, route, capability) values ('POST', '/api/*/to_extensions/*/delete', 'to-extension-write') ON CONFLICT DO NOTHING; -- 136
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/federations', 'federation-routing-read') ON CONFLICT DO NOTHING; -- 139
-insert into api_capability (http_method, route, capability) values ('GET', '/internal/api/*/federations', 'federation-routing-read') ON CONFLICT DO NOTHING; -- 140
-insert into api_capability (http_method, route, capability) values ('POST', '/api/*/federations', 'federation-routing-write') ON CONFLICT DO NOTHING; -- 141
-insert into api_capability (http_method, route, capability) values ('PUT', '/api/*/federations', 'federation-routing-write') ON CONFLICT DO NOTHING; -- 142
-insert into api_capability (http_method, route, capability) values ('DELETE', '/api/*/federations', 'federation-routing-write') ON CONFLICT DO NOTHING; -- 143
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/hwinfo', 'all-read') ON CONFLICT DO NOTHING; -- 148
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/parameters', 'params-read') ON CONFLICT DO NOTHING; -- 164
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/parameters/*', 'params-read') ON CONFLICT DO NOTHING; -- 168
-insert into api_capability (http_method, route, capability) values ('POST', '/api/*/parameters', 'params-write') ON CONFLICT DO NOTHING; -- 169
-insert into api_capability (http_method, route, capability) values ('PUT', '/api/*/parameters/*', 'params-write') ON CONFLICT DO NOTHING; -- 170
-insert into api_capability (http_method, route, capability) values ('DELETE', '/api/*/parameters/*', 'params-write') ON CONFLICT DO NOTHING; -- 171
-insert into api_capability (http_method, route, capability) values ('POST', '/api/*/parameters/*/validate', 'params-write') ON CONFLICT DO NOTHING; -- 172
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/profiles/*/parameters', 'params-read') ON CONFLICT DO NOTHING; -- 173
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/profiles/name/*/parameters', 'params-read') ON CONFLICT DO NOTHING; -- 174a
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/parameters/profile', 'params-read') ON CONFLICT DO NOTHING; -- 174b
-insert into api_capability (http_method, route, capability) values ('POST', '/api/*/profiles/name/*/parameters', 'params-write') ON CONFLICT DO NOTHING; -- 175
-insert into api_capability (http_method, route, capability) values ('POST', '/api/*/profiles/*/parameters', 'params-write') ON CONFLICT DO NOTHING; -- 176
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/profileparameters', 'params-read') ON CONFLICT DO NOTHING; -- 181
-insert into api_capability (http_method, route, capability) values ('POST', '/api/*/profileparameters', 'params-write') ON CONFLICT DO NOTHING; -- 182
-insert into api_capability (http_method, route, capability) values ('DELETE', '/api/*/profileparameters/*/*', 'params-write') ON CONFLICT DO NOTHING; -- 183
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cachegroupparameters', 'params-read') ON CONFLICT DO NOTHING; -- 186
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/phys_locations', 'phys-location-read') ON CONFLICT DO NOTHING; -- 191
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/phys_locations/trimmed', 'phys-location-read') ON CONFLICT DO NOTHING; -- 192
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/phys_locations/*', 'phys-location-read') ON CONFLICT DO NOTHING; -- 193
-insert into api_capability (http_method, route, capability) values ('POST', '/api/*/phys_locations', 'phys-location-write') ON CONFLICT DO NOTHING; -- 194
-insert into api_capability (http_method, route, capability) values ('POST', '/api/*/regions/*/phys_locations', 'phys-location-write') ON CONFLICT DO NOTHING; -- 195
-insert into api_capability (http_method, route, capability) values ('PUT', '/api/*/phys_locations/*', 'phys-location-write') ON CONFLICT DO NOTHING; -- 196
-insert into api_capability (http_method, route, capability) values ('DELETE', '/api/*/phys_locations/*', 'phys-location-write') ON CONFLICT DO NOTHING; -- 197
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/profiles', 'profile-read') ON CONFLICT DO NOTHING; -- 200
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/profiles/trimmed', 'profile-read') ON CONFLICT DO NOTHING; -- 201
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/profiles/*', 'profile-read') ON CONFLICT DO NOTHING; -- 202
-insert into api_capability (http_method, route, capability) values ('POST', '/api/*/profiles', 'profile-write') ON CONFLICT DO NOTHING; -- 203
-insert into api_capability (http_method, route, capability) values ('PUT', '/api/*/profiles/*', 'profile-write') ON CONFLICT DO NOTHING; -- 204
-insert into api_capability (http_method, route, capability) values ('DELETE', '/api/*/profiles/*', 'profile-write') ON CONFLICT DO NOTHING; -- 205
-insert into api_capability (http_method, route, capability) values ('POST', '/api/*/profiles/name/*/copy/*', 'profile-write') ON CONFLICT DO NOTHING; -- 206
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/regions', 'region-read') ON CONFLICT DO NOTHING; -- 213
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/regions/*', 'region-read') ON CONFLICT DO NOTHING; -- 214
-insert into api_capability (http_method, route, capability) values ('POST', '/api/*/regions', 'region-write') ON CONFLICT DO NOTHING; -- 215
-insert into api_capability (http_method, route, capability) values ('POST', '/api/*/divisions/*/regions', 'region-write') ON CONFLICT DO NOTHING; -- 216
-insert into api_capability (http_method, route, capability) values ('PUT', '/api/*/regions/*', 'region-write') ON CONFLICT DO NOTHING; -- 217
-insert into api_capability (http_method, route, capability) values ('DELETE', '/api/*/regions/*', 'region-write') ON CONFLICT DO NOTHING; -- 218
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/riak/ping', 'cdn-security-keys-write') ON CONFLICT DO NOTHING; -- 221
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/keys/ping', 'security-keys-write') ON CONFLICT DO NOTHING; -- 222
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/riak/bucket/#bucket/key/#key/values', 'security-keys-read') ON CONFLICT DO NOTHING; -- 223
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/riak/stats', 'security-keys-read') ON CONFLICT DO NOTHING; -- 224
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/roles', 'role-read') ON CONFLICT DO NOTHING; -- 227
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/servers', 'server-read') ON CONFLICT DO NOTHING; -- 230
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/servers?dsId=*', 'server-read') ON CONFLICT DO NOTHING; -- 231
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/servers?type=*', 'server-read') ON CONFLICT DO NOTHING; -- 232
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/servers?status=*', 'server-read') ON CONFLICT DO NOTHING; -- 233
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/servers?profileId=*', 'server-read') ON CONFLICT DO NOTHING; -- 234
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/servers/*', 'server-read') ON CONFLICT DO NOTHING; -- 235
-insert into api_capability (http_method, route, capability) values ('POST', '/api/*/servers', 'server-write') ON CONFLICT DO NOTHING; -- 237
-insert into api_capability (http_method, route, capability) values ('PUT', '/api/*/servers/*', 'server-write') ON CONFLICT DO NOTHING; -- 238
-insert into api_capability (http_method, route, capability) values ('DELETE', '/api/*/servers/*', 'server-write') ON CONFLICT DO NOTHING; -- 239
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/servers/details', 'server-read') ON CONFLICT DO NOTHING; -- 247
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/servers/totals', 'server-read') ON CONFLICT DO NOTHING; -- 249
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/servers/checks', 'server-read') ON CONFLICT DO NOTHING; -- 250a
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/servercheck/aadata', 'server-read') ON CONFLICT DO NOTHING; -- 250b
-insert into api_capability (http_method, route, capability) values ('POST', '/api/*/servercheck', 'server-write') ON CONFLICT DO NOTHING; -- 251
-insert into api_capability (http_method, route, capability) values ('POST', '/api/*/servers/*/queue_update', 'queue-updates-write') ON CONFLICT DO NOTHING; -- 252
-insert into api_capability (http_method, route, capability) values ('POST', '/api/*/servers/*/queue_update', 'queue-updates-write') ON CONFLICT DO NOTHING; -- 253
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/*/stats_summary', 'cdn-stats-read') ON CONFLICT DO NOTHING; -- 258
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/*/stats_summary?lastSummaryDate=true', 'cdn-stats-read') ON CONFLICT DO NOTHING; -- 259
-insert into api_capability (http_method, route, capability) values ('POST', '/api/*/*/stats_summary/create', 'cdn-stats-write') ON CONFLICT DO NOTHING; -- 260
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/statuses', 'status-read') ON CONFLICT DO NOTHING; -- 263
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/statuses/*', 'status-read') ON CONFLICT DO NOTHING; -- 264
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/staticdnsentries', 'static-dns-read') ON CONFLICT DO NOTHING; -- 270
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/system/info', 'basic-read') ON CONFLICT DO NOTHING; -- 275
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/types', 'type-read') ON CONFLICT DO NOTHING; -- 278
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/types/trimmed', 'type-read') ON CONFLICT DO NOTHING; -- 279
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/types/*', 'type-read') ON CONFLICT DO NOTHING; -- 280
-insert into api_capability (http_method, route, capability) values ('POST', '/api/*/types', 'type-write') ON CONFLICT DO NOTHING; -- 281
-insert into api_capability (http_method, route, capability) values ('PUT', '/api/*/types/*', 'type-write') ON CONFLICT DO NOTHING; -- 282
-insert into api_capability (http_method, route, capability) values ('DELETE', '/api/*/types/*', 'type-write') ON CONFLICT DO NOTHING; -- 283
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/users', 'user-read') ON CONFLICT DO NOTHING; -- 289
-insert into api_capability (http_method, route, capability) values ('GET', '/api/*/users/*', 'user-read') ON CONFLICT DO NOTHING; -- 290
-insert into api_capability (http_method, route, capability) values ('PUT', '/api/*/users/*', 'user-write') ON CONFLICT DO NOTHING; -- 292
+insert into api_capability (http_method, route, capability) values ('GET', '/', 'all-read') ON CONFLICT (http_method, route, capability) DO NOTHING;
+insert into api_capability (http_method, route, capability) values ('POST', '/', 'all-write') ON CONFLICT (http_method, route, capability) DO NOTHING;
+insert into api_capability (http_method, route, capability) values ('PUT', '/', 'all-write') ON CONFLICT (http_method, route, capability) DO NOTHING;
+insert into api_capability (http_method, route, capability) values ('PATCH', '/', 'all-write') ON CONFLICT (http_method, route, capability) DO NOTHING;
+insert into api_capability (http_method, route, capability) values ('DELETE', '/', 'all-write') ON CONFLICT (http_method, route, capability) DO NOTHING;
+
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/asns', 'asn-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 4
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/asns/*', 'asn-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 5
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/asns', 'asn-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 6
+insert into api_capability (http_method, route, capability) values ('PUT', '/api/*/asns/*', 'asn-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 7
+insert into api_capability (http_method, route, capability) values ('DELETE', '/api/*/asns/*', 'asn-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 8
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cache_stats', 'cache-stats-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 11
+insert into api_capability (http_method, route, capability) values ('GET', '/internal/api/*/daily_summary', 'cache-stats-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 12
+insert into api_capability (http_method, route, capability) values ('GET', '/internal/api/*/current_stats', 'cache-stats-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 13
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cachegroups', 'cache-group-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 16
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cachegroups/list', 'cache-group-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 17
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cachegroups/trimmed', 'cache-group-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 18
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cachegroups/*', 'cache-group-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 19
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/cachegroups', 'cache-group-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 20
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/cachegroups/create', 'cache-group-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 21
+insert into api_capability (http_method, route, capability) values ('PUT', '/api/*/cachegroups/*', 'cache-group-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 22
+insert into api_capability (http_method, route, capability) values ('PUT', '/api/*/cachegroups/*/update', 'cache-group-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 23
+insert into api_capability (http_method, route, capability) values ('DELETE', '/api/*/cachegroups/*', 'cache-group-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 24
+insert into api_capability (http_method, route, capability) values ('DELETE', '/api/*/cachegroups/*/delete', 'cache-group-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 25
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/cachegroups/*/queue_update', 'queue-updates-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 26
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/cachegroups/*/queue_update', 'queue-updates-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 27
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cachegroups/*/parameters', 'params-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 28
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cdns', 'cdn-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 31
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cdns/*', 'cdn-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 32
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cdns/name/*', 'cdn-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 33
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/cdns', 'cdn-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 34
+insert into api_capability (http_method, route, capability) values ('PUT', '/api/*/cdns/*', 'cdn-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 35
+insert into api_capability (http_method, route, capability) values ('DELETE', '/api/*/cdns/*', 'cdn-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 36
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/cdns/*/queue_update', 'queue-updates-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 37
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/cdns/*/queue_update', 'queue-updates-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 38
+insert into api_capability (http_method, route, capability) values ('PUT', '/api/*/cdns/*/snapshot', 'cdn-config-snapshot-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 40
+insert into api_capability (http_method, route, capability) values ('PUT', '/api/*/snapshot/*', 'cdn-config-snapshot-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 41
+insert into api_capability (http_method, route, capability) values ('PUT', '/api/*/snapshot/*', 'cdn-config-snapshot-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 42
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cdns/configs', 'cdn-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 44
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cdns/*/configs/routing', 'cdn-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 45
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cdns/*/configs/monitoring', 'cdn-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 46
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cdns/domains', 'cdn-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 47
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cdns/health', 'cdn-health-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 48
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cdns/*/health', 'cdn-health-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 49
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cdns/capacity', 'cdn-health-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 50
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cdns/routing', 'cdn-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 51
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cdns/name/*/sslkeys', 'cdn-security-keys-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 52
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cdns/usage/overview', 'cdn-stats-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 54
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/logs', 'change-log-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 57
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/logs/*/days', 'change-log-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 58
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/logs/newcount', 'change-log-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 60
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/deliveryservices', 'ds-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 69
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/deliveryservices/list', 'ds-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 70
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/deliveryservices/*', 'ds-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 71
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/deliveryservices/*/get', 'ds-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 72
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/deliveryservices', 'ds-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 73
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/*/deliveryservices/create', 'ds-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 74
+insert into api_capability (http_method, route, capability) values ('PUT', '/api/*/deliveryservices/*', 'ds-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 75
+insert into api_capability (http_method, route, capability) values ('PUT', '/api/*/*/deliveryservices/*/update', 'ds-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 76
+insert into api_capability (http_method, route, capability) values ('DELETE', '/api/*/deliveryservices/*', 'ds-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 77
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/deliveryservices/*/health', 'ds-health-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 78
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/deliveryservices/*/capacity', 'ds-health-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 79
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/deliveryservices/*/routing', 'ds-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 80
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/deliveryservices/*/state', 'ds-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 81
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/deliveryservice_stats', 'ds-stats-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 82
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/deliveryservices/request', 'ds-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 83
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/deliveryservices/xmlId/*/sslkeys', 'ds-security-keys-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 84
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/deliveryservices/hostname/*/sslkeys', 'ds-security-keys-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 85
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/deliveryservices/sslkeys/generate', 'ds-security-keys-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 86
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/deliveryservices/sslkeys/add', 'ds-security-keys-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 87
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/deliveryservices/xmlId/*/sslkeys/delete', 'ds-security-keys-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 88
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/deliveryservices/xmlId/*/urlkeys', 'ds-security-keys-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 89
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/deliveryservices/xmlId/*/urlkeys/generate', 'ds-security-keys-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 90
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/deliveryservices/*/regexes', 'ds-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 91
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/deliveryservice_matches', 'ds-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 92
+insert into api_capability (http_method, route, capability) values ('GET', '/internal/api/*/steering', 'ds-steering-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 96
+insert into api_capability (http_method, route, capability) values ('GET', '/internal/api/*/steering/*', 'ds-steering-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 97
+insert into api_capability (http_method, route, capability) values ('POST', '/internal/api/*/steering', 'ds-steering-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 98
+insert into api_capability (http_method, route, capability) values ('PUT', '/internal/api/*/steering/*', 'ds-steering-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 99
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/deliveryserviceserver', 'ds-cache-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 103
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/deliveryservices/*/servers', 'ds-cache-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 106
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/deliveryservices_regexes', 'ds-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 109
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/deliveryservices/*/regexes', 'ds-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 110
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/deliveryservices/*/regexes/*', 'ds-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 111
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/deliveryservices/*/regexes', 'ds-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 112
+insert into api_capability (http_method, route, capability) values ('PUT', '/api/*/deliveryservices/*/regexes/*', 'ds-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 113
+insert into api_capability (http_method, route, capability) values ('DELETE', '/api/*/deliveryservices/*/regexes/*', 'ds-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 114
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/divisions', 'division-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 120
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/divisions/*', 'division-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 121
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/divisions', 'division-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 122
+insert into api_capability (http_method, route, capability) values ('PUT', '/api/*/divisions/*', 'division-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 123
+insert into api_capability (http_method, route, capability) values ('DELETE', '/api/*/divisions/*', 'division-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 124
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cdns/name/*/dnsseckeys', 'cdn-security-keys-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 127
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/cdns/dnsseckeys/generate', 'cdn-security-keys-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 128
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cdns/name/*/dnsseckeys/delete', 'cdn-security-keys-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 129
+insert into api_capability (http_method, route, capability) values ('GET', '/internal/api/*/cdns/dnsseckeys/refresh', 'cdn-security-keys-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 130
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/to_extensions', 'to-extension-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 134
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/to_extensions', 'to-extension-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 135
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/to_extensions/*/delete', 'to-extension-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 136
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/federations', 'federation-routing-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 139
+insert into api_capability (http_method, route, capability) values ('GET', '/internal/api/*/federations', 'federation-routing-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 140
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/federations', 'federation-routing-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 141
+insert into api_capability (http_method, route, capability) values ('PUT', '/api/*/federations', 'federation-routing-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 142
+insert into api_capability (http_method, route, capability) values ('DELETE', '/api/*/federations', 'federation-routing-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 143
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/hwinfo', 'all-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 148
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/parameters', 'params-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 164
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/parameters/*', 'params-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 168
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/parameters', 'params-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 169
+insert into api_capability (http_method, route, capability) values ('PUT', '/api/*/parameters/*', 'params-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 170
+insert into api_capability (http_method, route, capability) values ('DELETE', '/api/*/parameters/*', 'params-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 171
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/parameters/*/validate', 'params-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 172
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/profiles/*/parameters', 'params-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 173
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/profiles/name/*/parameters', 'params-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 174a
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/parameters/profile', 'params-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 174b
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/profiles/name/*/parameters', 'params-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 175
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/profiles/*/parameters', 'params-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 176
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/profileparameters', 'params-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 181
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/profileparameters', 'params-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 182
+insert into api_capability (http_method, route, capability) values ('DELETE', '/api/*/profileparameters/*/*', 'params-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 183
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/cachegroupparameters', 'params-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 186
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/phys_locations', 'phys-location-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 191
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/phys_locations/trimmed', 'phys-location-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 192
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/phys_locations/*', 'phys-location-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 193
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/phys_locations', 'phys-location-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 194
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/regions/*/phys_locations', 'phys-location-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 195
+insert into api_capability (http_method, route, capability) values ('PUT', '/api/*/phys_locations/*', 'phys-location-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 196
+insert into api_capability (http_method, route, capability) values ('DELETE', '/api/*/phys_locations/*', 'phys-location-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 197
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/profiles', 'profile-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 200
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/profiles/trimmed', 'profile-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 201
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/profiles/*', 'profile-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 202
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/profiles', 'profile-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 203
+insert into api_capability (http_method, route, capability) values ('PUT', '/api/*/profiles/*', 'profile-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 204
+insert into api_capability (http_method, route, capability) values ('DELETE', '/api/*/profiles/*', 'profile-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 205
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/profiles/name/*/copy/*', 'profile-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 206
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/regions', 'region-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 213
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/regions/*', 'region-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 214
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/regions', 'region-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 215
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/divisions/*/regions', 'region-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 216
+insert into api_capability (http_method, route, capability) values ('PUT', '/api/*/regions/*', 'region-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 217
+insert into api_capability (http_method, route, capability) values ('DELETE', '/api/*/regions/*', 'region-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 218
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/riak/ping', 'cdn-security-keys-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 221
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/keys/ping', 'security-keys-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 222
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/riak/bucket/#bucket/key/#key/values', 'security-keys-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 223
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/riak/stats', 'security-keys-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 224
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/roles', 'role-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 227
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/servers', 'server-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 230
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/servers?dsId=*', 'server-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 231
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/servers?type=*', 'server-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 232
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/servers?status=*', 'server-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 233
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/servers?profileId=*', 'server-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 234
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/servers/*', 'server-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 235
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/servers', 'server-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 237
+insert into api_capability (http_method, route, capability) values ('PUT', '/api/*/servers/*', 'server-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 238
+insert into api_capability (http_method, route, capability) values ('DELETE', '/api/*/servers/*', 'server-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 239
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/servers/details', 'server-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 247
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/servers/totals', 'server-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 249
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/servers/checks', 'server-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 250a
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/servercheck/aadata', 'server-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 250b
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/servercheck', 'server-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 251
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/servers/*/queue_update', 'queue-updates-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 252
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/servers/*/queue_update', 'queue-updates-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 253
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/*/stats_summary', 'cdn-stats-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 258
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/*/stats_summary?lastSummaryDate=true', 'cdn-stats-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 259
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/*/stats_summary/create', 'cdn-stats-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 260
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/statuses', 'status-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 263
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/statuses/*', 'status-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 264
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/staticdnsentries', 'static-dns-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 270
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/system/info', 'basic-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 275
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/types', 'type-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 278
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/types/trimmed', 'type-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 279
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/types/*', 'type-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 280
+insert into api_capability (http_method, route, capability) values ('POST', '/api/*/types', 'type-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 281
+insert into api_capability (http_method, route, capability) values ('PUT', '/api/*/types/*', 'type-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 282
+insert into api_capability (http_method, route, capability) values ('DELETE', '/api/*/types/*', 'type-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 283
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/users', 'user-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 289
+insert into api_capability (http_method, route, capability) values ('GET', '/api/*/users/*', 'user-read') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 290
+insert into api_capability (http_method, route, capability) values ('PUT', '/api/*/users/*', 'user-write') ON CONFLICT (http_method, route, capability) DO NOTHING; -- 292
 
 
 -- types

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/b7eb8db4/traffic_ops/app/lib/API/ApiCapability.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/app/lib/API/ApiCapability.pm b/traffic_ops/app/lib/API/ApiCapability.pm
index 2e2ca73..2ee71ab 100644
--- a/traffic_ops/app/lib/API/ApiCapability.pm
+++ b/traffic_ops/app/lib/API/ApiCapability.pm
@@ -27,13 +27,19 @@ my $finfo = __FILE__ . ":";
 
 my %valid_http_methods = map { $_ => 1 } ('GET', 'POST', 'PUT', 'PATCH', 'DELETE');
 
-sub all {
-	my $self = shift;
+sub index {
+	my $self       = shift;
+	my $capability = $self->param('capability');
+
+	my %criteria;
+	if ( defined $capability ) {
+		$criteria{'me.capability'} = $capability;
+	}
 	my @data;
 	my $orderby = "capability";
 	$orderby = $self->param('orderby') if ( defined $self->param('orderby') );
 
-	my $rs_data = $self->db->resultset("ApiCapability")->search( undef, { order_by => $orderby } );
+	my $rs_data = $self->db->resultset("ApiCapability")->search( \%criteria, { prefetch => ['capability'], order_by => $orderby } );
 	while ( my $row = $rs_data->next ) {
 		push(
 			@data, {
@@ -68,15 +74,7 @@ sub renderResults {
 	$self->success( \@data );
 }
 
-sub capName {
-	my $self = shift;
-	my $capability = $self->param('name');
-
-	my $rs_data = $self->db->resultset("ApiCapability")->search( 'me.capability' => $capability );
-	$self->renderResults( $rs_data ) ;
-}
-
-sub index {
+sub show {
 	my $self = shift;
 	my $id = $self->param('id');
 

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/b7eb8db4/traffic_ops/app/lib/API/Capability.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/app/lib/API/Capability.pm b/traffic_ops/app/lib/API/Capability.pm
index 695434b..6a3212a 100644
--- a/traffic_ops/app/lib/API/Capability.pm
+++ b/traffic_ops/app/lib/API/Capability.pm
@@ -23,7 +23,7 @@ use Data::Dumper;
 
 my $finfo = __FILE__ . ":";
 
-sub all {
+sub index {
 	my $self = shift;
 	my @data;
 	my $orderby = "name";
@@ -33,9 +33,9 @@ sub all {
 	while ( my $row = $rs_data->next ) {
 		push(
 			@data, {
-				"name"          => $row->name,
-				"description"	=> $row->description,
-				"lastUpdated" 	=> $row->last_updated
+				"name"        => $row->name,
+				"description" => $row->description,
+				"lastUpdated" => $row->last_updated
 			}
 		);
 	}
@@ -46,14 +46,14 @@ sub name {
 	my $self = shift;
 	my $name = $self->param('name');
 
-	my $rs_data = $self->db->resultset("Capability")->search( 'me.name' => $name  );
+	my $rs_data = $self->db->resultset("Capability")->search( 'me.name' => $name );
 	my @data = ();
 	while ( my $row = $rs_data->next ) {
 		push(
 			@data, {
-				"name"          => $row->name,
-				"description"	=> $row->description,
-				"lastUpdated" 	=> $row->last_updated
+				"name"        => $row->name,
+				"description" => $row->description,
+				"lastUpdated" => $row->last_updated
 			}
 		);
 	}
@@ -61,7 +61,7 @@ sub name {
 }
 
 sub create {
-	my $self = shift;
+	my $self   = shift;
 	my $params = $self->req->json;
 
 	if ( !&is_oper($self) ) {
@@ -72,47 +72,47 @@ sub create {
 		return $self->alert("Parameters must be in JSON format.");
 	}
 
-	my $name = $params->{name} if defined($params->{name});
-	my $description = $params->{description} if defined($params->{description});
+	my $name        = $params->{name}        if defined( $params->{name} );
+	my $description = $params->{description} if defined( $params->{description} );
 
 	if ( !defined($name) or $name eq "" ) {
-		return $self->alert( "Name is required." );
+		return $self->alert("Name is required.");
 	}
 
 	if ( !defined($description) or $description eq "" ) {
-		return $self->alert( "Description is required." );
+		return $self->alert("Description is required.");
 	}
 
 	# check if capability exists
 	my $rs_data = $self->db->resultset("Capability")->search( { 'name' => { 'like', $name } } )->single();
-	if (defined($rs_data)) {
-		return $self->alert( "Capability '$name' already exists." );
+	if ( defined($rs_data) ) {
+		return $self->alert("Capability '$name' already exists.");
 	}
 
 	my $values = {
-		name		=> $name,
-		description	=> $description
+		name        => $name,
+		description => $description
 	};
 
 	my $insert = $self->db->resultset('Capability')->create($values);
-	my $rs = $insert->insert();
+	my $rs     = $insert->insert();
 	if ($rs) {
 		my $response;
-		$response->{name}			= $rs->name;
-		$response->{description}	= $rs->description;
+		$response->{name}        = $rs->name;
+		$response->{description} = $rs->description;
 
 		&log( $self, "Created Capability: '$response->{name}', '$response->{description}'", "APICHANGE" );
 
 		return $self->success( $response, "Capability was created." );
 	}
 	else {
-		return $self->alert( "Capability creation failed." );
+		return $self->alert("Capability creation failed.");
 	}
 }
 
 sub update {
-	my $self = shift;
-	my $name = $self->param('name');
+	my $self   = shift;
+	my $name   = $self->param('name');
 	my $params = $self->req->json;
 
 	if ( !&is_oper($self) ) {
@@ -123,7 +123,7 @@ sub update {
 		return $self->alert("Parameters must be in JSON format.");
 	}
 
-	my $description = $params->{description} if defined($params->{description});
+	my $description = $params->{description} if defined( $params->{description} );
 
 	my $capability = $self->db->resultset('Capability')->find( { name => $name } );
 	if ( !defined($capability) or $capability eq "" ) {
@@ -131,26 +131,24 @@ sub update {
 	}
 
 	if ( !defined($description) or $description eq "" ) {
-		return $self->alert( "Description is required." );
+		return $self->alert("Description is required.");
 	}
 
-	my $values = {
-		description => $description
-	};
+	my $values = { description => $description };
 
 	my $rs = $capability->update($values);
 	if ($rs) {
 		my $response;
-		$response->{name}			= $rs->name;
-		$response->{description}	= $rs->description;
-		$response->{lastUpdated}	= $rs->last_updated;
+		$response->{name}        = $rs->name;
+		$response->{description} = $rs->description;
+		$response->{lastUpdated} = $rs->last_updated;
 
 		&log( $self, "Updated Capability: '$response->{name}', '$response->{description}'", "APICHANGE" );
 
 		return $self->success( $response, "Capability was updated." );
 	}
 	else {
-		return $self->alert( "Capability update failed." );
+		return $self->alert("Capability update failed.");
 	}
 }
 
@@ -168,17 +166,18 @@ sub delete {
 	}
 
 	# make sure no api_capability refers to this capability
-	my $rs_data = $self->db->resultset("ApiCapability")->find( {'me.capability' => $name} );
-	if (defined($rs_data)) {
+	my $rs_data = $self->db->resultset("ApiCapability")->find( { 'me.capability' => $name } );
+	if ( defined($rs_data) ) {
 		my $reference_id = $rs_data->id;
-		return $self->alert( "Capability \'$name\' is refered by an api_capability mapping: $reference_id. Deletion failed." );
+		return $self->alert("Capability \'$name\' is refered by an api_capability mapping: $reference_id. Deletion failed.");
 	}
 
 	my $rs = $capability->delete();
 	if ($rs) {
 		return $self->success_message("Capability deleted.");
-	} else {
-		return $self->alert( "Capability deletion failed." );
+	}
+	else {
+		return $self->alert("Capability deletion failed.");
 	}
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/b7eb8db4/traffic_ops/app/lib/TrafficOpsRoutes.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/app/lib/TrafficOpsRoutes.pm b/traffic_ops/app/lib/TrafficOpsRoutes.pm
index e808b29..034edd9 100644
--- a/traffic_ops/app/lib/TrafficOpsRoutes.pm
+++ b/traffic_ops/app/lib/TrafficOpsRoutes.pm
@@ -683,7 +683,7 @@ sub api_routes {
 
 	# -- CAPABILITIES
 	# Supports ?orderby=key
-	$r->get("/api/$version/capabilities")->over( authenticated => 1 )->to( 'Capability#all', namespace => $namespace );
+	$r->get("/api/$version/capabilities")->over( authenticated => 1 )->to( 'Capability#index', namespace => $namespace );
 	$r->get("/api/$version/capabilities/:name")->over( authenticated => 1 )->to( 'Capability#name', namespace => $namespace );
 	$r->put("/api/$version/capabilities/:name")->over( authenticated => 1 )->to( 'Capability#update', namespace => $namespace );
 	$r->post("/api/$version/capabilities")->over( authenticated => 1 )->to( 'Capability#create', namespace => $namespace );
@@ -691,9 +691,8 @@ sub api_routes {
 
 	# -- API-CAPABILITIES
 	# Supports ?orderby=key
-	$r->get("/api/$version/api_capabilities")->over( authenticated => 1 )->to( 'ApiCapability#all', namespace => $namespace );
-	$r->get("/api/$version/api_capabilities/:id")->over( authenticated => 1 )->to( 'ApiCapability#index', namespace => $namespace );
-	$r->get("/api/$version/api_capabilities/capability/:name")->over( authenticated => 1 )->to( 'ApiCapability#capName', namespace => $namespace );
+	$r->get("/api/$version/api_capabilities")->over( authenticated => 1 )->to( 'ApiCapability#index', namespace => $namespace );
+	$r->get("/api/$version/api_capabilities/:id")->over( authenticated => 1 )->to( 'ApiCapability#show', namespace => $namespace );
 	$r->put("/api/$version/api_capabilities/:id")->over( authenticated => 1 )->to( 'ApiCapability#update', namespace => $namespace );
 	$r->post("/api/$version/api_capabilities")->over( authenticated => 1 )->to( 'ApiCapability#create', namespace => $namespace );
 	$r->delete("/api/$version/api_capabilities/:id")->over( authenticated => 1 )->to( 'ApiCapability#delete', namespace => $namespace );