chg: [inbox] Started integrating local tools within the inbox - WiP
parent
af69834727
commit
034ff034df
|
@ -117,6 +117,14 @@ class IncomingConnectionRequestProcessor extends LocalToolRequestProcessor imple
|
|||
{
|
||||
$connectionSuccessfull = false;
|
||||
$interConnectionResult = [];
|
||||
|
||||
$remoteCerebrate = $this->getIssuerBrood($request);
|
||||
$connector = $this->getConnector($request);
|
||||
$connectorResult = $connector->acceptConnection($requestData['data']);
|
||||
$connectorResult['toolName'] = $requestData->local_tool_name;
|
||||
$urlPath = '/inbox/createInboxEntry/LocalTool/AcceptedRequest';
|
||||
$response = $this->Inbox->sendRequest($remoteCerebrate, $urlPath, true, $connectorResult);
|
||||
|
||||
if ($connectionSuccessfull) {
|
||||
$this->discard($id, $requestData);
|
||||
}
|
||||
|
|
|
@ -118,7 +118,7 @@ class InboxController extends AppController
|
|||
$this->set('data', $data);
|
||||
}
|
||||
|
||||
public function createProcessorInboxEntry($scope, $action)
|
||||
public function createInboxEntry($scope, $action)
|
||||
{
|
||||
if (!$this->request->is('post')) {
|
||||
throw new MethodNotAllowedException(__('Only POST method is accepted'));
|
||||
|
|
|
@ -186,11 +186,8 @@ class LocalToolsController extends AppController
|
|||
},
|
||||
'afterFind' => function($data) {
|
||||
foreach ($data as $connector) {
|
||||
$connector = [
|
||||
'id' => $connector['id'],
|
||||
'name' => $connector['name'],
|
||||
'connector' => $connector['connector']
|
||||
];
|
||||
$connectorClass = array_values($this->LocalTools->getConnectorByConnectionId($connector['id']))[0];
|
||||
$connector['toolName'] = $connectorClass->name;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
@ -222,18 +219,23 @@ class LocalToolsController extends AppController
|
|||
'cerebrate_id' => $cerebrate_id,
|
||||
'remote_tool_id' => $remote_tool_id
|
||||
];
|
||||
$this->loadModel('Broods');
|
||||
$remoteCerebrate = $this->Broods->find()->where(['id' => $params['cerebrate_id']])->first();
|
||||
if ($this->request->is(['post', 'put'])) {
|
||||
$postParams = $this->ParamHandler->harvestParams(['local_tool_id']);
|
||||
$postParams = $this->ParamHandler->harvestParams(['local_tool_id', 'tool_name']);
|
||||
if (empty($postParams['local_tool_id'])) {
|
||||
throw new MethodNotAllowedException(__('No local tool ID supplied.'));
|
||||
}
|
||||
if (empty($postParams['tool_name'])) {
|
||||
throw new MethodNotAllowedException(__('No local tool name supplied.'));
|
||||
}
|
||||
$params['local_tool_id'] = $postParams['local_tool_id'];
|
||||
$result = $this->LocalTools->encodeConnection($params);
|
||||
// Send message to remote inbox
|
||||
debug($result);
|
||||
$encodingResult = $this->LocalTools->encodeConnection($params);
|
||||
$encodingResult['toolName'] = $tool_name;
|
||||
$urlPath = '/inbox/createInboxEntry/LocalTool/IncomingConnectionRequest';
|
||||
$response = $this->Inbox->sendRequest($remoteCerebrate, $urlPath, true, $encodingResult);
|
||||
$this->redirect();
|
||||
} else {
|
||||
$this->loadModel('Broods');
|
||||
$remoteCerebrate = $this->Broods->find()->where(['id' => $params['cerebrate_id']])->first();
|
||||
$remoteTool = $this->LocalTools->getRemoteToolById($params);
|
||||
$local_tools = $this->LocalTools->encodeConnectionChoice($params);
|
||||
if (empty($local_tools)) {
|
||||
|
|
|
@ -62,4 +62,27 @@ class InboxTable extends AppTable
|
|||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
public function sendRequest($brood, $urlPath, $methodPost = true, $data = []): boolean
|
||||
{
|
||||
$http = new Client();
|
||||
$config = [
|
||||
'headers' => [
|
||||
'AUTHORIZATION' => $brood->authkey,
|
||||
'Accept' => 'application/json'
|
||||
],
|
||||
'type' => 'json'
|
||||
];
|
||||
$url = $brood->url . $urlPath;
|
||||
if ($methodPost) {
|
||||
$response = $http->post($url, json_encode(data), $config);
|
||||
} else {
|
||||
$response = $http->get($brood->url, json_encode(data), $config);
|
||||
}
|
||||
if ($response->isOk()) {
|
||||
return $response;
|
||||
} else {
|
||||
throw new NotFoundException(__('Could not post to the requested resource.'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -112,7 +112,7 @@ class LocalToolsTable extends AppTable
|
|||
'connector_description' => $connector_class->description
|
||||
];
|
||||
if ($includeConnections) {
|
||||
$connector['connections'] = $this->healthCheck($connector_type, $connector_class);
|
||||
// $connector['connections'] = $this->healthCheck($connector_type, $connector_class);
|
||||
}
|
||||
$connectors[] = $connector;
|
||||
}
|
||||
|
|
|
@ -16,7 +16,12 @@
|
|||
'field' => 'local_tool_id',
|
||||
'options' => $dropdown,
|
||||
'type' => 'dropdown'
|
||||
]
|
||||
],
|
||||
[
|
||||
'field' => 'tool_name',
|
||||
'default' => $data['remoteTool']['toolName'],
|
||||
'type' => 'hidden'
|
||||
],
|
||||
],
|
||||
'submit' => [
|
||||
'action' => $this->request->getParam('action')
|
||||
|
|
Loading…
Reference in New Issue