Skip to content

Commit

Permalink
Merge branch 'development' into feature/CONNECTOR-144/rate-limits-sync
Browse files Browse the repository at this point in the history
  • Loading branch information
WilcoLouwerse committed Nov 29, 2024
2 parents 927e629 + 4d13dea commit 2eba4fd
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,21 @@
"description": "",
"version": "0.0.1",
"mapping": {
"title": "Name"
"title": "d.woo_x005f_titel",
"description": "d.woo_x005f_beschrijving",
"summary": "d.woo_x005f_samenvatting",
"category": "d.woo_x005f_categorie",
"published": "d.woo_x005f_publicatiedatum",
"modified": "d.vti_x005f_nexttolasttimemodified"
},
"unset": [],
"cast": [],
"cast": {
"title": "d.woo_x005f_titel",
"description": "d.woo_x005f_beschrijving",
"summary": "d.woo_x005f_samenvatting",
"category": "d.woo_x005f_categorie",
"published": "d.woo_x005f_publicatiedatum",
"modified": "d.vti_x005f_nexttolasttimemodified"
},
"passThrough": false
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
"reference": "",
"mapping": {
"title": "omschrijving",
"summary": "statustoelichting",
"description": "statusomschrijving"
"summary": "zaaktypeomschrijving",
"description": "zaaktypeomschrijving",
"published" : "startdatum",
"modified" : "{{ 'now'|date(H:i:sTm-d-Y') }}"
},
"unset": [],
"cast": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
"sourceHash": "",
"sourceTargetMapping": "1",
"sourceConfig": {
"idPosition": "UniqueId",
"idPosition": "Properties.__deferred.uri",
"resultsPosition": "d.results",
"endpoint": "/Web/GetFolderByServerRelativePath(decodedurl='/WOO/Convenanten')/folders",
"singleEndpoint": "{{ originId }}",
"mergeDataSingleEndpoint": true,
"headers": [],
"query": []
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
"sourceHash": "",
"sourceTargetMapping": "1",
"sourceConfig": {
"idPosition": "UniqueId",
"idPosition": "Properties.__deferred.uri",
"resultsPosition": "d.results",
"endpoint": "/Web/GetFolderByServerRelativePath(decodedurl='/WOO/Woo-verzoeken en -besluiten')/folders",
"singleEndpoint": "{{ originId }}",
"mergeDataSingleEndpoint": true,
"headers": [],
"query": []
},
Expand Down
29 changes: 29 additions & 0 deletions lib/Service/AuthenticationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,35 @@ public function fetchOAuthTokens (array $configuration): string
return $result['access_token'];
}

/**
* Fetch an access token from the DeCOS non-implementation of OAuth 2.0
*
* @param array $configuration The configuration of the source.
*
* @return string The access token
*
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function fetchDecosToken(array $configuration): string
{
$url = $configuration['tokenUrl'];
$tokenLocation = $configuration['tokenLocation'];
unset($configuration['tokenUrl']);

$callConfig['json'] = $configuration;

$client = new Client();
$response = $client->post(uri: $url, options: $callConfig);

$result = json_decode(json: $response->getBody()->getContents(), associative: true);

if (isset($tokenLocation) === true) {
return $result[$tokenLocation];
}

return $result['token'];
}

/**
* Get RSA key for RS and PS (asymmetrical) encryption.
*
Expand Down
16 changes: 11 additions & 5 deletions lib/Service/SynchronizationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ class SynchronizationService
private ObjectService $objectService;
private Source $source;

const SINGLE_ENDPOINT = 'singleEndpoint';
const MERGE_DATA_SINGLE_ENDPOINT = 'mergeDataSingleEndpoint';


public function __construct(
CallService $callService,
Expand Down Expand Up @@ -243,16 +246,19 @@ public function getObjectFromSource(Synchronization $synchronization, string $en
*/
public function synchronizeContract(SynchronizationContract $synchronizationContract, Synchronization $synchronization = null, array $object = [], ?bool $isTest = false): SynchronizationContract|Exception|array
{

if ($synchronization !== null && isset($synchronization->getSourceConfig()['singleEndpoint']) === true) {
$sourceConfig = $synchronization->getSourceConfig();
if ($synchronization !== null && isset($sourceConfig[$this::SINGLE_ENDPOINT]) === true) {

// Update endpoint
$endpoint = str_replace(search: '{{ originId }}', replace: $this->getOriginId($synchronization, $object), subject: $synchronization->getSourceConfig()['singleEndpoint']);
$endpoint = str_replace(search: '{{ originId }}', replace: $this->getOriginId($synchronization, $object), subject: $sourceConfig[$this::SINGLE_ENDPOINT]);
$endpoint = str_replace(search: '{{originId}}', replace: $this->getOriginId($synchronization, $object), subject: $endpoint);

// Get object from source
$object = $this->getObjectFromSource(synchronization: $synchronization, endpoint: $endpoint);

if (isset($sourceConfig[$this::MERGE_DATA_SINGLE_ENDPOINT]) === true && $sourceConfig[$this::MERGE_DATA_SINGLE_ENDPOINT] === true) {
$object = array_merge($object, $this->getObjectFromSource(synchronization: $synchronization, endpoint: $endpoint));
} else {
$object = $this->getObjectFromSource(synchronization: $synchronization, endpoint: $endpoint);
}
}


Expand Down
1 change: 1 addition & 0 deletions lib/Twig/AuthenticationExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public function getFunctions(): array
{
return [
new TwigFunction(name: 'oauthToken', callable: [AuthenticationRuntime::class, 'oauthToken']),
new TwigFunction(name: 'decosToken', callable: [AuthenticationRuntime::class, 'decosToken']),
new TwigFunction(name: 'jwtToken', callable: [AuthenticationRuntime::class, 'jwtToken']),
];
//return parent::getFunctions(); // TODO: Change the autogenerated stub
Expand Down
19 changes: 19 additions & 0 deletions lib/Twig/AuthenticationRuntime.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,25 @@ public function oauthToken(Source $source): string
);
}

/**
* Add a decos non-oauth token to the configuration.
*
* @param Source $source
* @return string
*
* @throws GuzzleException
*/
public function decosToken(Source $source): string
{
$configuration = new Dot($source->getConfiguration(), true);

$authConfig = $configuration->get('authentication');

return $this->authService->fetchDecosToken(
configuration: $authConfig
);
}

/**
* Add a jwt token to the configuration.
*
Expand Down

0 comments on commit 2eba4fd

Please sign in to comment.