Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Syndesi committed Aug 11, 2023
1 parent e9f842e commit c7fb921
Show file tree
Hide file tree
Showing 13 changed files with 441 additions and 28 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add POST '/token' endpoint.
- Add expiration date to tokens.

### Changed
- Reword application configuration, via internal Symfony bundle.
- Switch datetime format from temporary string type to datetime.

## 0.0.19 - 2023-08-10
### Added
- Add `/instance-configuration` endpoint for retrieving instance specific configurations.
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
},
"autoload": {
"psr-4": {
"EmberNexusBundle\\": "lib/EmberNexusBundle/src/",
"App\\": "src/"
}
},
Expand Down
1 change: 1 addition & 0 deletions config/bundles.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true],
Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true],
League\FlysystemBundle\FlysystemBundle::class => ['all' => true],
EmberNexusBundle\EmberNexusBundle::class => ['all' => true],
];
2 changes: 1 addition & 1 deletion config/default-parameters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ parameters:
register:

# If true, the /register endpoint is active and anonymous users can create accounts.
enabled: false
enabled: true

# The property name of the identifier. Identifier must be unique across the API, usually the email.
uniqueIdentifier: email
Expand Down
5 changes: 5 additions & 0 deletions config/packages/ember_nexus.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ember_nexus:
register:
enabled: true
instanceConfiguration:
showVersion: false
106 changes: 106 additions & 0 deletions lib/EmberNexusBundle/src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?php

namespace EmberNexusBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

class Configuration implements ConfigurationInterface
{
public const HALF_AN_HOUR_IN_SECONDS = 1800;
public const THREE_HOURS_IN_SECONDS = 3600 * 3;
public const THIRTEEN_MONTHS_IN_SECONDS = 3600 * 24 * (365 + 31);
public const TWO_WEEKS_IN_SECONDS = 3600 * 24 * 14;

public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('ember_nexus');
$rootNode = $treeBuilder->getRootNode();
$rootNode
->children()

->arrayNode('pageSize')
->info('Affects how many elements can be returned in collection responses.')
->addDefaultsIfNotSet()
->children()
->integerNode('min')
->info('Minimum number of elements which are always returned, if they exist.')
->min(1)
->defaultValue(5)
->end()
->integerNode('default')
->info('Default number of elements which are returned if they exist.')
->min(1)
->defaultValue(25)
->end()
->integerNode('max')
->info('Maximum number of elements which are returned in a single response. Should not be way more than 100, as performance problems may arise.')
->min(1)
->defaultValue(100)
->end()
->end()
->end()

->arrayNode('register')
->info('Handles the /register endpoint.')
->addDefaultsIfNotSet()
->children()
->booleanNode('enabled')
->info('If true, the /register endpoint is active and anonymous users can create accounts.')
->defaultTrue()
->end()
->scalarNode('uniqueIdentifier')
->info('The property name of the identifier. Identifier must be unique across the API, usually the email.')
->defaultValue('email')
->end()
->integerNode('uniqueIdentifierRegex')
->info('Either false or a regex for checking the identifier content.')
->defaultFalse()
->end()
->end()
->end()

->arrayNode('instanceConfiguration')
->info('Configures the /instance-configuration endpoint')
->addDefaultsIfNotSet()
->children()
->booleanNode('enabled')
->info('If true, enables the endpoint. If false, 403 error messages are returned.')
->defaultTrue()
->end()
->scalarNode('showVersion')
->info('If false, the version number is omitted.')
->defaultTrue()
->end()
->end()
->end()

->arrayNode('token')
->info('Configures the /instance-configuration endpoint')
->addDefaultsIfNotSet()
->children()
->integerNode('minLifetimeInSeconds')
->info('Minimum lifetime of created tokens.')
->defaultValue(self::HALF_AN_HOUR_IN_SECONDS)
->end()
->integerNode('defaultLifetimeInSeconds')
->info('Default lifetime of created tokens.')
->defaultValue(self::THREE_HOURS_IN_SECONDS)
->end()
->scalarNode('maxLifetimeInSeconds')
->info('Maximum lifetime of created tokens. Can be set to false to disable maximum limit.')
->defaultValue(self::THIRTEEN_MONTHS_IN_SECONDS)
->end()
->scalarNode('deleteExpiredTokensAutomaticallyInSeconds')
->info('Expired tokens will be deleted after defined time. Can be set to false to disable auto delete feature.')
->defaultValue(self::TWO_WEEKS_IN_SECONDS)
->end()
->end()
->end()

->end()
;

return $treeBuilder;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace EmberNexusBundle\DependencyInjection;

use EmberNexusBundle\Service\EmberNexusConfiguration;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;

class EmberNexusExtension extends Extension
{
public function getAlias(): string
{
return 'ember_nexus';
}

public function load(array $rawConfigurations, ContainerBuilder $container)
{
$configuration = $this->getConfiguration($rawConfigurations, $container);
$processedConfiguration = $this->processConfiguration($configuration, $rawConfigurations);

$container->setDefinition(
EmberNexusConfiguration::class,
(new Definition())
->setFactory([null, 'createFromConfiguration'])
->setArguments([$processedConfiguration])
);
}
}
9 changes: 9 additions & 0 deletions lib/EmberNexusBundle/src/EmberNexusBundle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace EmberNexusBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class EmberNexusBundle extends Bundle
{
}
Loading

0 comments on commit c7fb921

Please sign in to comment.