Skip to content

Commit

Permalink
Initial implementation of ApiSource (CFM-115)
Browse files Browse the repository at this point in the history
  • Loading branch information
Benn Oshrin committed Dec 31, 2023
1 parent c54ccfc commit f88d8a6
Show file tree
Hide file tree
Showing 35 changed files with 1,964 additions and 17 deletions.
11 changes: 11 additions & 0 deletions app/availableplugins/ApiConnector/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# ApiSource plugin for CakePHP

## Installation

You can install this plugin into your CakePHP application using [composer](https://getcomposer.org).

The recommended way to install composer packages is:

```
composer require your-name-here/api-source
```
24 changes: 24 additions & 0 deletions app/availableplugins/ApiConnector/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "your-name-here/api-connector",
"description": "ApiConnector plugin for CakePHP",
"type": "cakephp-plugin",
"license": "MIT",
"require": {
"php": ">=7.2",
"cakephp/cakephp": "4.4.*"
},
"require-dev": {
"phpunit/phpunit": "^8.5 || ^9.3"
},
"autoload": {
"psr-4": {
"ApiConnector\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"ApiConnector\\Test\\": "tests/",
"Cake\\Test\\": "vendor/cakephp/cakephp/tests/"
}
}
}
77 changes: 77 additions & 0 deletions app/availableplugins/ApiConnector/config/routes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php
/**
* ApiSource plugin specific routes.
*
* Portions licensed to the University Corporation for Advanced Internet
* Development, Inc. ("UCAID") under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership.
*
* UCAID licenses this file to you 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.
*
* @link https://www.internet2.edu/comanage COmanage Project
* @package registry-plugins
* @since COmanage Registry v5.0.0
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
*/

use Cake\Http\Middleware\BodyParserMiddleware;
use Cake\Http\Middleware\CsrfProtectionMiddleware;
use Cake\Routing\Route\DashedRoute;
use Cake\Routing\RouteBuilder;
use Cake\Routing\Router;

// In general, we're probably trying to set up API routes if we're doing
// something within a plugin, but not necessarily. API routes are a subset
// of Cake routes, so either can be specified here.

// ApiSource API routes
// We place these under /v2 since the Registry v4 plugin essentially implemented v1

$routes->scope('/api/apisource', function (RouteBuilder $builder) {
// Register scoped middleware for in scopes.
// Do not enable CSRF for the REST API, it will break standard (non-AJAX) clients
// $builder->registerMiddleware('csrf', new CsrfProtectionMiddleware(['httponly' => true]));
// BodyParserMiddleware will automatically parse JSON bodies, but we only
// want that for API transactions, so we only apply it to the /api scope.
$builder->registerMiddleware('bodyparser', new BodyParserMiddleware());
/*
* Apply a middleware to the current route scope.
* Requires middleware to be registered through `Application::routes()` with `registerMiddleware()`
*/
// Do not enable CSRF for the REST API, it will break standard (non-AJAX) clients
// $builder->applyMiddleware('csrf');
$builder->setExtensions(['json']);
$builder->applyMiddleware('bodyparser');

$builder->delete(
'/{id}/v2/sorPeople/{sorlabel}/{sorid}',
['plugin' => 'ApiConnector', 'controller' => 'ApiV2', 'action' => 'delete']
)
->setPass(['id', 'sorlabel', 'sorid'])
->setPatterns(['id' => '[0-9]+']);

$builder->get(
'/{id}/v2/sorPeople/{sorlabel}/{sorid}',
['plugin' => 'ApiConnector', 'controller' => 'ApiV2', 'action' => 'get']
)
->setPass(['id', 'sorlabel', 'sorid'])
->setPatterns(['id' => '[0-9]+']);

$builder->put(
'/{id}/v2/sorPeople/{sorlabel}/{sorid}',
['plugin' => 'ApiConnector', 'controller' => 'ApiV2', 'action' => 'upsert']
)
->setPass(['id', 'sorlabel', 'sorid'])
->setPatterns(['id' => '[0-9]+']);
});
30 changes: 30 additions & 0 deletions app/availableplugins/ApiConnector/phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
colors="true"
processIsolation="false"
stopOnFailure="false"
bootstrap="tests/bootstrap.php"
>
<php>
<ini name="memory_limit" value="-1"/>
<ini name="apc.enable_cli" value="1"/>
</php>

<!-- Add any additional test suites you want to run here -->
<testsuites>
<testsuite name="ApiSource">
<directory>tests/TestCase/</directory>
</testsuite>
</testsuites>

<!-- Setup fixture extension -->
<extensions>
<extension class="Cake\TestSuite\Fixture\PHPUnitExtension" />
</extensions>

<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
</phpunit>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# COmanage Registry Localizations (api_connector domain)
#
# Portions licensed to the University Corporation for Advanced Internet
# Development, Inc. ("UCAID") under one or more contributor license agreements.
# See the NOTICE file distributed with this work for additional information
# regarding copyright ownership.
#
# UCAID licenses this file to you 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.
#
# @link https://www.internet2.edu/comanage COmanage Project
# @package registry
# @since COmanage Registry v5.0.0
# @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)

msgid "controller.ApiSources"
#msgstr "{0,plural,=1{API Source} other{API Sources}}"

msgid "field.ApiSources.push_mode"
msgstr "Push Mode"

msgid "information.endpoint.push"
msgstr "The API endpoint for using this plugin in Push Mode is {0}"
Loading

0 comments on commit f88d8a6

Please sign in to comment.