Skip to content

Commit

Permalink
Support for developer auth, config fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasRos committed Jan 18, 2020
1 parent ae042ac commit 091eb7c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 23 deletions.
35 changes: 25 additions & 10 deletions classes/Configurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,29 @@
class Configurator {

public static function getContainer(array $config) {
// Object Retriever Definition
$objectRetrieverDefinition = DI\autowire();
$orConstructorParameters = [
'cache_provider' => 'file',
'cache_provider.file.directory' => $config['cache_dir'] . '/config',
'static_config_path' => $config['uploads_dir'] . '/config',
'logger' => DI\get(Logger::class)
];

if (!isset($config['co.auth_ns']) && CredentialManager::isConfigured()) {
// Access Object API via Account Gateway using local developer account
$objectRetrieverDefinition->constructor($orConstructorParameters)
->method('setClient', function() {
return CredentialManager::getAccountContext()->getClient();
}, '/ws/');
} else {
// Access Object API with specified namespace credentials
$objectRetrieverDefinition->constructor(array_merge([
'auth_ns' => $config['co.auth_ns'],
'auth_secret' => $config['co.auth_secret'],
], $orConstructorParameters));
}

// Create Dependency Injection Container
$builder = new DI\ContainerBuilder();
$builder->addDefinitions($config);
Expand All @@ -32,22 +55,14 @@ public static function getContainer(array $config) {
}
return $logger;
},
ObjectRetriever::class => $objectRetrieverDefinition,
ObjectRetrieverPool::class => DI\autowire()
->constructorParameter('baseHostname', $config['co.auth_ns'])
->constructorParameter('baseHostname', @$config['co.auth_ns'])
->constructorParameter('options', [
'cache_provider' => 'file',
'cache_provider.file.directory' => $config['cache_dir'] . '/config',
'static_config_path' => $config['uploads_dir'] . '/config',
'logger' => DI\get(Logger::class)
]),
ObjectRetriever::class => DI\autowire()
->constructor([
'auth_ns' => $config['co.auth_ns'],
'auth_secret' => $config['co.auth_secret'],
'cache_provider' => 'file',
'cache_provider.file.directory' => $config['cache_dir'] . '/config',
'static_config_path' => $config['uploads_dir'] . '/config',
'logger' => DI\get(Logger::class)
])
]);

Expand Down
23 changes: 10 additions & 13 deletions config.php.default
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
<?php

return array(
'enable_vhost_controllers' => false,
'exclude_vhosts' => [],
'debug' => false,
'account_data_cache' => 'none',
'object_cache' => 'file',
'redis' => [],
'classes' => [
'cache_dir' => '/tmp/cache',
'uploads_dir' => '/tmp/uploads'
],
'accountgateways.base_url_template' => ''
);
return [
'uploads' => true,
'client_authentication' => 'none',
'mode' => 'default',
'agws.data_cache' => 'file',
'log.target' => 'errorlog',
'log.level' => Monolog\Logger::DEBUG,
'cache_dir' => sys_get_temp_dir() . '/phpMAE/cache',
'uploads_dir' => sys_get_temp_dir() . '/phpMAE/uploads',
];

0 comments on commit 091eb7c

Please sign in to comment.