Commit 1cd55450 authored by François Agneray's avatar François Agneray
Browse files

Merge branch 'develop' into 'master'

3.1

See merge request !43
parents 2cef4687 a952197c
AMQP_HOST=amqp_host
\ No newline at end of file
......@@ -2,6 +2,7 @@ nbproject/
.vscode/
.idea/
vendor/*
phpunit-coverage/
data/
build/*
logs/*
......@@ -14,5 +15,4 @@ cache
.project
.settings
.phpunit*
anis_v3.sqlite
.env
stages:
- metrics
- metrics-build
- metrics-deploy
- install
- test
- sonar
- build
- deploy
variables:
VERSION: "3.0"
VERSION: "3.1"
SONARQUBE_URL: https://sonarqube.lam.fr
METRICS_IMAGE: portus.lam.fr/anis/anis-server-metrics
CONTAINER_IMAGE: portus.lam.fr/anis/anis-server
php-metrics:
image: jakzal/phpqa
stage: metrics
script:
- phpmetrics --report-html=var/php-metrics .
allow_failure: true
cache:
paths:
- var
policy: push
only:
refs:
- develop
php-metrics-build:
image: docker:stable
stage: metrics-build
script:
- echo "FROM nginx" > var/Dockerfile
- echo "COPY php-metrics /usr/share/nginx/html" >> var/Dockerfile
- docker login -u fagneray -p $PORTUS_TOKEN portus.lam.fr
- docker pull $METRICS_IMAGE:latest || true
- docker build --cache-from $METRICS_IMAGE:latest -t $METRICS_IMAGE:latest var
- docker push $METRICS_IMAGE:latest
allow_failure: true
cache:
paths:
- var
policy: pull
only:
refs:
- develop
php-metrics-deploy:
image: alpine
stage: metrics-deploy
script:
- apk add --update curl
- curl -XPOST $METRICS_WEBHOOK
only:
refs:
- develop
install:
image: jakzal/phpqa
stage: install
......@@ -102,9 +54,9 @@ build:
stage: build
script:
- docker login -u fagneray -p $PORTUS_TOKEN portus.lam.fr
- docker pull $CONTAINER_IMAGE:latest-dev || true
- docker build --cache-from $CONTAINER_IMAGE:latest-dev -t $CONTAINER_IMAGE:latest-dev .
- docker push $CONTAINER_IMAGE:latest-dev
- docker pull $CONTAINER_IMAGE:latest || true
- docker build --cache-from $CONTAINER_IMAGE:latest -t $CONTAINER_IMAGE:latest .
- docker push $CONTAINER_IMAGE:latest
cache:
paths:
- vendor
......@@ -112,13 +64,3 @@ build:
only:
refs:
- develop
deploy:
image: alpine
stage: deploy
script:
- apk add --update curl
- curl -XPOST $DEV_WEBHOOK
only:
refs:
- develop
\ No newline at end of file
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [3.0.0] - yyyy-mm-dd
### Added
- Pour les nouvelles fonctionnalités.
### Changed
- Pour les changements au sein des fonctionnalités déjà existantes.
### Deprecated
- Pour les fonctionnalités qui seront supprimées dans la prochaine publication.
### Removed
- Pour les anciennes fonctionnalités Deprecated qui viennent d’être supprimées.
### Fixed
- Pour les corrections de bugs.
### Security
- Pour encourager les utilisateurs à mettre à niveau afin d’éviter des failles de sécurité.
......@@ -3,13 +3,13 @@ FROM php:7.3-apache
# Install modules
RUN apt-get update \
&& apt-get install -y zlib1g zlib1g-dev libpq-dev libpq5 libzip-dev zip unzip \
&& docker-php-ext-install pgsql pdo_pgsql zip
&& docker-php-ext-install pgsql pdo_pgsql zip bcmath
RUN a2enmod rewrite
COPY . /srv/app
COPY . /project
COPY ./conf-dev/vhost.conf /etc/apache2/sites-available/000-default.conf
WORKDIR /srv/app
WORKDIR /project
CMD ["apache2-foreground"]
AstroNomical Information System - Server
AstroNomical Information System - Server API
Copyright: François Agneray & Chrystel Moreau 2012 - 2019
Copyright: CNRS - 2019
Address: Centre de donneeS Astrophysique de Marseille (CeSAM)
Laboratoire d'Astrophysique de Marseille
Ple de l'Etoile, site de Chteau-Gombert
......@@ -9,14 +8,12 @@ AstroNomical Information System - Server API
13388 Marseille cedex 13 France
CNRS U.M.R 7326
ANIS Server API is governed by the CeCILL license under French law and
Anis Server is governed by the CeCILL license under French law and
abiding by the rules of distribution of free software. You can use,
modify and/ or redistribute the software under the terms of the CeCILL
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info" and/or below.
CeCILL FREE SOFTWARE LICENSE AGREEMENT
======================================
......
UID := $(id -u)
GID := $(id -g)
UID := 1000
GID := 1000
list:
@echo ""
@echo "Useful targets:"
@echo ""
@echo " install > install php composer dependancies"
@echo " up > build php image and start anis-server containers for dev only (php + mailer)"
@echo " start > start anis-server containers"
@echo " restart > restart anis-server containers"
@echo " stop > stop and kill running anis-server containers"
@echo " logs > display anis-server containers logs"
@echo " shell > shell into php anis-server container"
@echo " rebuild > rebuild php image and start containers for dev only"
@echo " start > start containers"
@echo " restart > restart containers"
@echo " stop > stop and kill running containers"
@echo " status > display stack containers status"
@echo " logs > display containers logs"
@echo " shell > shell into php container"
@echo " phpunit > run php unit test suite"
@echo " phpcs > run php code sniffer test suite"
@echo " anis-init > generate a new anis admin database and a default metamodel database (anis-server containers running needed)"
@echo " dev-init > add metadata datasets for devlopment purpose"
@echo " create-db > create a database for dev only"
@echo " remove-pgdata > remove the metadata database"
@echo " gen-key > generate a new encryption key that you can use to encrypt data (see anis server config file)"
@echo ""
install:
......@@ -26,7 +25,7 @@ install:
-v $(CURDIR):/project \
-w /project jakzal/phpqa composer install --ignore-platform-reqs
up:
rebuild:
@docker-compose up --build -d
start:
......@@ -38,6 +37,9 @@ stop:
@docker-compose kill
@docker-compose rm -v --force
status:
@docker-compose ps
logs:
@docker-compose logs -f -t
......@@ -48,21 +50,15 @@ phpunit:
@docker run --init -it --rm --user $(UID):$(GID) \
-v $(CURDIR):/project \
-w /project jakzal/phpqa phpdbg -qrr ./vendor/bin/phpunit --bootstrap ./tests/bootstrap.php \
--whitelist src --coverage-text --colors=never ./tests
--whitelist src --colors --coverage-html ./phpunit-coverage ./tests
phpcs:
@docker run --init -it --rm --user $(UID):$(GID) \
-v $(CURDIR):/project \
-w /project jakzal/phpqa phpcs --standard=PSR2 --extensions=php --colors src tests
anis-init:
@docker-compose exec php sh ./conf-dev/anis_init.sh
-w /project jakzal/phpqa phpcs --standard=PSR12 --extensions=php --colors src tests
dev-init:
@docker-compose exec php sh ./conf-dev/dev-init.sh
create-db:
@docker-compose exec php sh ./conf-dev/create-db.sh
remove-pgdata:
@docker volume rm anis-server_pgdata
gen-key:
@docker-compose exec php php ./conf-dev/generate_encryption_key.php
\ No newline at end of file
......@@ -6,7 +6,7 @@ AstroNomical Information System is a generic web tool that aims to facilitate th
This software allows you to control one or more databases related to astronomical projects and allows access to datasets via URLs.
Anis is protected by the `CeCILL` licence (see LICENCE file at the software root).
Anis is protected by the CeCILL licence (see LICENCE file at the software root).
## Authors
......@@ -16,111 +16,36 @@ Here is the list of people involved in the development:
* `Chrystel Moreau` : Laboratoire d'Astrophysique de Marseille (CNRS)
* `Tifenn Guillas` : Laboratoire d'Astrophysique de Marseille (CNRS)
# Installation guide
## Functionalities
## Prerequisites
Anis Server allows :
Before to start to install the anis-server you must make sure that you have the following commands installed on your computer:
- Add project/database that will contain a set of datasets
- Add and configure a dataset that references a table or view of a business database
- The possibility to search in a referenced dataset with search criteria
1. `make`
2. `docker`
3. `docker-compose`
## Installing and starting the application
You also need an Internet connection to download packages and dependancies.
Anis Server contains a Makefile that helps the developer to install and start the application.
## List of commands
To list all operations availables just type `make` in your terminal at the root of this application.
The `Makefile` at the root of the project provides a list of commands available to manage the application in a development mode.
- To install all dependancies : `make install`
- To start/stop/restart/status all services : `make start|stop|restart|status`
- To display logs for all services : `make logs`
- To open a shell command into php container : `make shell`
- To execute tests suite : `make phpunit`
- To execute php code sniffer : `make phpcs`
- To create the metamodel database : `make create-db`
- To load metamodel information for testing : `make dev-meta`
To see the list of commands just open a terminal in the root of the project and type:
## Open API
> make
You can find an open api documentation into the `anis-server.yaml` file.
**Warning**: The `docker-compose.yml` and the` Makefile` commands must be used only for development or testing but no in production mode.
## Few examples with curl
## Dependancies installation
To start installing dependancies, use the following command at the software root:
> make install
The `Composer.phar` software will be downloaded and it will automatically use the `composer.json` and `composer.lock` files to download all the dependancies and save them to the `vendor` directory at the root of the application.
After that anis-server can work!
## Start anis-server
Anis server has been developed to be used with docker containers. If you open the `docker-compose.yml` file you can see all containers needed for the **development or test configuration** of anis server.
`Makefile` provides a command to build install and run all the containers that you need for a fresh installation of anis-server software:
> make up
**Note:** This command use `docker-compose` to work. These operations may take a few minutes as it is necessary to download docker images
If you want to list all anis stack containers running:
> docker-compose ps
And if you want to print anis stack logs:
> make logs
## Databases installation
Anis server need at least two databases to work:
1. An admin database to store users and the list of available metamodel databases.
2. A default metamodel database to store information about business databases, projects and datasets availables.
Our `Makefile` provides a command to generate these two databases:
> make anis-init
## Datasets for beginning to use
Our `Makefile` also provides a command to add a business database and configure datasets into the default metamodel database to beginning to test or develop the anis-server. To install the test datasets type:
> make dev-init
## Anis server is now ready to use
Open a browser and go => [http://localhost:8080/](http://localhost:8080/)
Few examples:
* To list all datasets available in the default instance => [http://localhost:8080/metadata/default/dataset](http://localhost:8080/metadata/default/dataset)
* To print all data for the obs_cat dataset with column 1, 2 and 3 => [http://localhost:8080/search/default/data/obs_cat?a=1;2;3](http://localhost:8080/search/default/data/obs_cat?a=1;2;3)
* To print only 3 obs_cat data (search by id) => [http://localhost:8080/search/default/data/obs_cat?a=1;2;3&c=1::in::104600094|104600095|104600108](http://localhost:8080/search/default/data/obs_cat?a=1;2;3&c=1::in::104600094|104600095|104600108)
# More about Anis-Server
First of all, you will find the user manual at the root of the project: [MANUAL.md](MANUAL.md)
## Software directories
* `conf-dev`: Configuration files used by make commands and docker-compose to work
* `public`: Web server root (index.php)
* `src`: Source code of Anis Server
* `test`: Anis Unit Tests `phpunit`
## Key files
* `public/index.php`: Bootstrap file for starting application (file used by an http web server like nginx or apache)
* `src/settings.php`: Anis server configuration file
* `src/routes.php`: Anis server configured routes (list all availables URL)
## Technologies
You can see here just a few direct links about softwares or dependancies used by anis-team for the devlopment of anis-server:
* `Slim` : [http://www.slimframework.com/](http://www.slimframework.com/)
* `Doctrine 2` : [https://www.doctrine-project.org/](https://www.doctrine-project.org/)
* `Swiftmailer` : [https://swiftmailer.symfony.com/](https://swiftmailer.symfony.com/)
* `Monolog` : [https://seldaek.github.io/monolog/](https://seldaek.github.io/monolog/)
* `Composer` : [https://getcomposer.org/](https://getcomposer.org/)
* `PHP-FIG` : [http://www.php-fig.org/](http://www.php-fig.org/)
* `PHP-Unit` : [http://phpunit.de/](http://phpunit.de/)
* `Docker` : [https://www.docker.com/](https://www.docker.com/)
* `GIT` : [http://git-scm.com/](http://git-scm.com/)
* `CeCILL`: [http://www.cecill.info/index.en.html](http://www.cecill.info/index.en.html)
\ No newline at end of file
* To list all datasets available in the default instance => http://localhost:8080/dataset
* To print all data for the obs_cat dataset with column 1, 2 and 3 => http://localhost:8080/search/obs_cat?a=1;2;3
* To count the number of data available for a request => http://localhost:8080/search/obs_cat?a=count
* To print only 3 obs_cat data (search by id) => http://localhost:8080/search/obs_cat?a=1;2;3&c=1::in::104600094|104600095|104600108
\ No newline at end of file
3.0.3
\ No newline at end of file
3.1
\ No newline at end of file
This diff is collapsed.
<?php declare(strict_types=1);
<?php
/*
* This file is part of ANIS SERVER API.
* This file is part of Anis Server.
*
* (c) François Agneray <francois.agneray@lam.fr>
* (c) Chrystel Moreau <chrystel.moreau@lam.fr>
* (c) Laboratoire d'Astrophysique de Marseille / CNRS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
$app->add(App\Middleware\CorsMiddleware::class);
define('GET', 'GET');
define('POST', 'POST');
define('PUT', 'PUT');
define('DELETE', 'DELETE');
define('OPTIONS', 'OPTIONS');
define('SETTINGS', 'settings');
<?php
/*
* This file is part of Anis Server.
*
* (c) Laboratoire d'Astrophysique de Marseille / CNRS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
use Psr\Container\ContainerInterface;
// Load settings
$container->set(SETTINGS, function () {
return include __DIR__ . '/../app/settings.php';
});
// Doctrine factory
$container->set('em', function (ContainerInterface $c) {
$settings = $c->get(SETTINGS)['database'];
$dc = \Doctrine\ORM\Tools\Setup::createAnnotationMetadataConfiguration(
array('src/Entity'),
$settings['dev_mode']
);
$dc->setProxyDir($settings['path_proxy']);
if ($settings['dev_mode']) {
$dc->setAutoGenerateProxyClasses(true);
} else {
$dc->setAutoGenerateProxyClasses(false);
}
return \Doctrine\ORM\EntityManager::create($settings['connection_options'], $dc);
});
// Monolog factory
$container->set('logger', function (ContainerInterface $c) {
$loggerSettings = $c->get('settings')['logger'];
$logger = new \Monolog\Logger($loggerSettings['name']);
$logger->pushProcessor(new \Monolog\Processor\UidProcessor());
$logger->pushHandler(new \Monolog\Handler\StreamHandler($loggerSettings['path'], $loggerSettings['level']));
return $logger;
});
// Actions
$container->set('App\Action\RootAction', function () {
return new App\Action\RootAction();
});
$container->set('App\Action\DatabaseListAction', function (ContainerInterface $c) {
return new App\Action\DatabaseListAction($c->get('em'));
});
$container->set('App\Action\DatabaseAction', function (ContainerInterface $c) {
return new App\Action\DatabaseAction($c->get('em'));
});
$container->set('App\Action\TableListAction', function (ContainerInterface $c) {
return new App\Action\TableListAction($c->get('em'), new App\Utils\DBALConnectionFactory());
});
$container->set('App\Action\ProjectListAction', function (ContainerInterface $c) {
return new App\Action\ProjectListAction($c->get('em'));
});
$container->set('App\Action\ProjectAction', function (ContainerInterface $c) {
return new App\Action\ProjectAction($c->get('em'));
});
$container->set('App\Action\FamilyListAction', function (ContainerInterface $c) {
return new App\Action\FamilyListAction($c->get('em'));
});
$container->set('App\Action\FamilyAction', function (ContainerInterface $c) {
return new App\Action\FamilyAction($c->get('em'));
});
$container->set('App\Action\InstanceListAction', function (ContainerInterface $c) {
return new App\Action\InstanceListAction($c->get('em'));
});
$container->set('App\Action\InstanceAction', function (ContainerInterface $c) {
return new App\Action\InstanceAction($c->get('em'));
});
$container->set('App\Action\DatasetFamilyListAction', function (ContainerInterface $c) {
return new App\Action\DatasetFamilyListAction($c->get('em'));
});
$container->set('App\Action\DatasetListByInstanceAction', function (ContainerInterface $c) {
return new App\Action\DatasetListByInstanceAction($c->get('em'));
});
$container->set('App\Action\DatasetFamilyAction', function (ContainerInterface $c) {
return new App\Action\DatasetFamilyAction($c->get('em'));
});
$container->set('App\Action\DatasetListAction', function (ContainerInterface $c) {
return new App\Action\DatasetListAction($c->get('em'), new App\Utils\DBALConnectionFactory());
});
$container->set('App\Action\DatasetAction', function (ContainerInterface $c) {
return new App\Action\DatasetAction($c->get('em'));
});
$container->set('App\Action\CriteriaFamilyListAction', function (ContainerInterface $c) {
return new App\Action\CriteriaFamilyListAction($c->get('em'));
});
$container->set('App\Action\CriteriaFamilyAction', function (ContainerInterface $c) {
return new App\Action\CriteriaFamilyAction($c->get('em'));
});
$container->set('App\Action\OutputFamilyListAction', function (ContainerInterface $c) {
return new App\Action\OutputFamilyListAction($c->get('em'));
});
$container->set('App\Action\OutputFamilyAction', function (ContainerInterface $c) {
return new App\Action\OutputFamilyAction($c->get('em'));
});
$container->set('App\Action\OutputCategoryListByDatasetAction', function (ContainerInterface $c) {
return new App\Action\OutputCategoryListByDatasetAction($c->get('em'));
});
$container->set('App\Action\OutputCategoryListAction', function (ContainerInterface $c) {
return new App\Action\OutputCategoryListAction($c->get('em'));
});
$container->set('App\Action\OutputCategoryAction', function (ContainerInterface $c) {
return new App\Action\OutputCategoryAction($c->get('em'));
});
$container->set('App\Action\AttributeListAction', function (ContainerInterface $c) {
return new App\Action\AttributeListAction($c->get('em'));
});
$container->set('App\Action\AttributeAction', function (ContainerInterface $c) {
return new App\Action\AttributeAction($c->get('em'));
});
$container->set('App\Action\SearchAction', function (ContainerInterface $c) {
return new App\Action\SearchAction(
$c->get('em'),
new App\Utils\DBALConnectionFactory(),
new App\Utils\Operator\OperatorFactory()
);
});
// Middlewares
$container->set('App\Middleware\AuthorizationMiddleware', function (ContainerInterface $c) {
return new App\Middleware\AuthorizationMiddleware($c->get('em'), $c->get(SETTINGS)['token_options']);
});
<?php
/*
* This file is part of Anis Server.
*
* (c) Laboratoire d'Astrophysique de Marseille / CNRS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
$app->add(new App\Middleware\JsonBodyParserMiddleware());
$app->add(new App\Middleware\ContentTypeJsonMiddleware());
$app->add(new App\Middleware\CorsMiddleware());
<?php
/*
* This file is part of Anis Server.
*
* (c) Laboratoire d'Astrophysique de Marseille / CNRS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
use Slim\Routing\RouteCollectorProxy;
$app->get('/', App\Action\RootAction::class);
$app->map([OPTIONS, GET, POST], '/database', App\Action\DatabaseListAction::class);
$app->map([OPTIONS, GET, PUT, DELETE], '/database/{id}', App\Action\DatabaseAction::class);
$app->map([OPTIONS, GET], '/database/{id}/table', App\Action\TableListAction::class);
$app->map([OPTIONS, GET, POST], '/project', App\Action\ProjectListAction::class);
$app->map([OPTIONS, GET, PUT, DELETE], '/project/{name}', App\Action\ProjectAction::class);
$app->map([OPTIONS, GET, POST], '/instance', App\Action\InstanceListAction::class);
$app->map([OPTIONS, GET, PUT, DELETE], '/instance/{name}', App\Action\InstanceAction::class);
$app->map([OPTIONS, GET, POST], '/instance/{name}/dataset-family', App\Action\DatasetFamilyListAction::class);
$app->map([OPTIONS, GET], '/instance/{name}/dataset', App\Action\DatasetListByInstanceAction::class);
$app->map([OPTIONS, GET, PUT, DELETE], '/dataset-family/{id}', App\Action\DatasetFamilyAction::class);
$app->map([OPTIONS, GET, POST], '/dataset-family/{id}/dataset', App\Action\DatasetListAction::class);
$app->map([OPTIONS, GET, PUT, DELETE], '/dataset/{name}', App\Action\DatasetAction::class);
$app->map([OPTIONS, GET, POST], '/dataset/{name}/criteria-family', App\Action\CriteriaFamilyListAction::class);
$app->map([OPTIONS, GET,