Skip to content

Commit fc3c832

Browse files
jonathangreenwhikloj
authored andcommitted
Add YAML configuration files for micro services (#8)
* Rename * Update and Add Service Providers * Update IslandoraServiceProvider to be more idiomatic in the way it uses configuration variables. * Add a new YamlConfigServiceProvider to load configuration from YAML files for Crayfish services. * Update some variable names * Fix coding standards issues * Add tests for islandora service provider * Add tests for bug found in settings parser. * Update doctrine settings a bit * Update readme to include codecob * Fix db settings.
1 parent bdd33fb commit fc3c832

10 files changed

+387
-157
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
[![Build Status](https://travis-ci.org/Islandora-CLAW/Crayfish-Commons.svg?branch=master)](https://travis-ci.org/Islandora-CLAW/Crayfish-Commons)
55
[![Contribution Guidelines](http://img.shields.io/badge/CONTRIBUTING-Guidelines-blue.svg)](./CONTRIBUTING.md)
66
[![LICENSE](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](./LICENSE)
7+
[![codecov](https://codecov.io/gh/Islandora-CLAW/Crayfish-Commons/branch/master/graph/badge.svg)](https://codecov.io/gh/Islandora-CLAW/Crayfish-Commons)
78

89
Crayfish Commons is a library housing shared code for Crayfish microservices.
910

composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"namshi/jose": "^7.2",
1212
"pimple/pimple": "~3.0",
1313
"monolog/monolog": "^1.22",
14-
"silex/silex": "^2.0"
14+
"silex/silex": "^2.0",
15+
"symfony/yaml": "^3.2"
1516
},
1617
"require-dev": {
1718
"phpunit/phpunit": "^5.0",

composer.lock

+56-56
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/IslandoraServiceProvider.php

-98
This file was deleted.
+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
<?php
2+
3+
namespace Islandora\Crayfish\Commons\Provider;
4+
5+
use Islandora\Crayfish\Commons\CmdExecuteService;
6+
use Islandora\Crayfish\Commons\FedoraResourceConverter;
7+
use Pimple\Container;
8+
use Pimple\ServiceProviderInterface;
9+
use Silex\Provider\DoctrineServiceProvider;
10+
use Silex\Provider\MonologServiceProvider;
11+
use Silex\Provider\ServiceControllerServiceProvider;
12+
use Silex\Provider\SecurityServiceProvider;
13+
use Islandora\Chullo\FedoraApi;
14+
use Islandora\Crayfish\Commons\Syn\SettingsParser;
15+
use Islandora\Crayfish\Commons\Syn\JwtAuthenticator;
16+
use Islandora\Crayfish\Commons\Syn\JwtFactory;
17+
18+
class IslandoraServiceProvider implements ServiceProviderInterface
19+
{
20+
/**
21+
* @inheritDoc
22+
*/
23+
public function register(Container $container)
24+
{
25+
// Register services we rely on
26+
$container->register(new MonologServiceProvider());
27+
$container->register(new ServiceControllerServiceProvider());
28+
$container->register(new SecurityServiceProvider());
29+
$container->register(new DoctrineServiceProvider());
30+
31+
// Configure external services
32+
$container['monolog.logfile'] = function ($container) {
33+
return strtolower($container['crayfish.log.level']) == 'none' ? null : $container['crayfish.log.file'];
34+
};
35+
$container['monolog.level'] = function ($container) {
36+
return $container['crayfish.log.level'];
37+
};
38+
39+
$container['security.firewalls'] = function ($container) {
40+
if ($container['crayfish.syn.enable']) {
41+
return [
42+
'default' => [
43+
'stateless' => true,
44+
'anonymous' => false,
45+
'guard' => [
46+
'authenticators' => [
47+
'crayfish.syn.jwt_authentication'
48+
],
49+
],
50+
],
51+
];
52+
} else {
53+
return [];
54+
}
55+
};
56+
57+
$this->registerDbOptions($container);
58+
59+
// Register our services
60+
$container['crayfish.cmd_execute_service'] = function ($container) {
61+
return new CmdExecuteService(
62+
$container['monolog']->withName('crayfish.cmd_execute_service')
63+
);
64+
};
65+
66+
$container['crayfish.fedora_resource'] = function ($container) {
67+
return new FedoraResourceConverter(
68+
FedoraApi::create($container['crayfish.fedora_resource.base_url'])
69+
);
70+
};
71+
72+
$container['crayfish.syn.settings_parser'] = function ($container) {
73+
if (file_exists($container['crayfish.syn.config'])) {
74+
$xml = file_get_contents($container['crayfish.syn.config']);
75+
} else {
76+
$xml = '';
77+
$container['monolog']
78+
->error("Securty configuration not found. ${container['crayfish.syn.config']}");
79+
}
80+
81+
return new SettingsParser(
82+
$xml,
83+
$container['monolog']->withName('crayfish.syn.settings_parser')
84+
);
85+
};
86+
87+
$container['crayfish.syn.jwt_authentication'] = function ($app) {
88+
return new JwtAuthenticator(
89+
$app['crayfish.syn.settings_parser'],
90+
new JwtFactory(),
91+
$app['monolog']->withName('crayfish.syn.jwt_authentication')
92+
);
93+
};
94+
}
95+
96+
protected function registerDbOptions($container)
97+
{
98+
$container['db.options'] = function ($container) {
99+
$setoption = function (&$settings, $container, $name) {
100+
if (isset($container["crayfish.db.options.$name"])) {
101+
$settings[$name] = $container["crayfish.db.options.$name"];
102+
}
103+
};
104+
105+
$settings = [];
106+
$setoption($settings, $container, 'host');
107+
$setoption($settings, $container, 'port');
108+
$setoption($settings, $container, 'dbname');
109+
$setoption($settings, $container, 'user');
110+
$setoption($settings, $container, 'password');
111+
$setoption($settings, $container, 'charset');
112+
$setoption($settings, $container, 'path');
113+
$setoption($settings, $container, 'url');
114+
115+
return $settings;
116+
};
117+
}
118+
}

0 commit comments

Comments
 (0)