Skip to content

Commit

Permalink
Configure feature flag in yaml
Browse files Browse the repository at this point in the history
The jira_enable_test_mode feature flag should be configured as a yaml
parameter as this can not be read during compile time from the .env
file. That would defeat the purpose of the .env files being overridable
during runtime.

That's why services.yml files where added for all environments. Allowing
to override the setting for any environment to enable/disable the jira
test mode.
  • Loading branch information
MKodde committed Jun 27, 2023
1 parent a726293 commit 8a0a565
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 14 deletions.
9 changes: 7 additions & 2 deletions .env.dist
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,13 @@ [email protected]
[email protected]
[email protected]

# When 'jira_enable_test_mode' is enabled (in services.yaml), 'jira_test_mode_storage_path'
# must be configured with a filename in a directory that is writable for the user run ning the application.
# When 'jira_enable_test_mode' is enabled, 'jira_test_mode_storage_path' must be configured with a filename in a
# directory that is writable for the user run ning the application.
# See the:
# - Compiler pass (IssueRepositoryCompilerPass),
# - environment specific services.yml file
# - docs/jira.md readme
# for details on how to enable the test stand in.
jira_test_mode_storage_path='../var/issues.json'

# Jira settings
Expand Down
7 changes: 4 additions & 3 deletions config/packages/dev/framework.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
imports:
# Load the dev services.yml overload file
- { resource: services.yml }

framework:
# router:
# resource: '%kernel.root_dir%/config/routes_dev.yaml'
# strict_requirements: true
profiler: { only_exceptions: false }
session:
save_path: '/tmp/sp-dashboard-sessions'
1 change: 1 addition & 0 deletions config/packages/dev/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ services:
public: true

parameters:
# By enabling 'jira_enable_test_mode', no real Jira backend is required to still simulate the Jira integration
jira_enable_test_mode: true
3 changes: 3 additions & 0 deletions config/packages/prod/framework.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
imports:
# Load the dev services.yml overload file
- { resource: services.yml }
2 changes: 2 additions & 0 deletions config/packages/prod/services.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
parameters:
jira_enable_test_mode: false
4 changes: 4 additions & 0 deletions config/packages/test/framework.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
imports:
# Load the test services.yml overload file
- { resource: services.yml }

framework:
test: true
session:
Expand Down
1 change: 1 addition & 0 deletions config/packages/test/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ services:
public: true

parameters:
# By enabling 'jira_enable_test_mode', no real Jira backend is required to still simulate the Jira integration
jira_enable_test_mode: true
Empty file removed config/services.dev.yaml
Empty file.
3 changes: 1 addition & 2 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
parameters:
locale: en
router.request_context.base_url: ''
# By enabling 'jira_enable_test_mode', no real Jira backend is required to still simulate the Jira integration
jira_enable_test_mode: true

services:
# default configuration for services in *this* file
Expand All @@ -19,4 +17,5 @@ services:
arguments:
- '%env(DATABASE_URL)%'

# This service is configured in the Jira IssueRepositoryCompilerPass
surfnet.dashboard.repository.issue: ~
Empty file removed config/test/monolog.yaml
Empty file.
23 changes: 21 additions & 2 deletions docs/jira.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
# Use a Jira test stand in

By default SP dashboard is configured to not use the test stand in option in dev or production modes. To enable this
By default SP dashboard is configured to not use the test stand in option in production mode. To enable this
feature. Simply configure the `jira_enable_test_mode: true` and `jira_test_mode_storage_path: '../var/issues.json'` to
your liking. The values above are sensible defaults.

The feature flag must be configured in yaml config, as the container is configured during compile time at which point
the .env vars are not available. This requires you to configure this flag in the parameters section of the environment
corresponding `config/packages/%env%/services.yml`.

If for example, in dev mode you want to enable the Jira mock test stand in you configure:

`config/packages/dev/services.yml`

```yaml
parameters:
jira_enable_test_mode: true
```
And in `.env`

```dotenv
jira_test_mode_storage_path='../var/issues.json'
```

The Jira interaction is now skipped, and all actions are handled in a happy flow manner. Resulting in a JSON file that
is filled with ticket id's that are then used by the application to track the Jira workflow state.

Expand Down Expand Up @@ -112,4 +131,4 @@ Repeat the steps below for the following users:
- Fill the form field, making sure you save the username/password somewhere.


[1](https://hub.docker.com/r/ivantichy/jira/)
[1](https://hub.docker.com/r/ivantichy/jira/)
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use Surfnet\ServiceProviderDashboard\Infrastructure\Jira\Repository\IssueRepository;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use function is_bool;

class IssueRepositoryCompilerPass implements CompilerPassInterface
{
Expand All @@ -40,15 +41,13 @@ class IssueRepositoryCompilerPass implements CompilerPassInterface
*/
public function process(ContainerBuilder $container)
{
$hasParameter = $container->getParameter(self::ENABLE_TEST_MODE_FEATURE_FLAG);
$enableJiraTestMode = $container->getParameter(self::ENABLE_TEST_MODE_FEATURE_FLAG);
$hasDefinition = $container->getDefinition(self::JIRA_REPOSITORY_ISSUE_SERVICE);
if (!$hasParameter || !$hasDefinition) {
if (!is_bool($enableJiraTestMode) && !$hasDefinition) {
return;
}

$isTestModeEnabled = (bool) $hasParameter;

if ($isTestModeEnabled) {
if ($enableJiraTestMode) {
$this->configureServiceInTestMode($container);
} else {
$this->configureService($container);
Expand All @@ -71,6 +70,7 @@ private function configureService(ContainerBuilder $container)
$container->getParameter('env(jira_issue_manageid_fieldname)'),
$container->getParameter('env(jira_issue_manageid_field_label)')
]);
$container->setDefinition(self::JIRA_REPOSITORY_ISSUE_SERVICE, $service);
}

/**
Expand All @@ -84,5 +84,6 @@ private function configureServiceInTestMode(ContainerBuilder $container)
$service->setArguments([
$container->getParameter('env(jira_test_mode_storage_path)')
]);
$container->setDefinition(self::JIRA_REPOSITORY_ISSUE_SERVICE, $service);
}
}

0 comments on commit 8a0a565

Please sign in to comment.