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;
|
$connectionSuccessfull = false;
|
||||||
$interConnectionResult = [];
|
$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) {
|
if ($connectionSuccessfull) {
|
||||||
$this->discard($id, $requestData);
|
$this->discard($id, $requestData);
|
||||||
}
|
}
|
||||||
|
|
|
@ -118,7 +118,7 @@ class InboxController extends AppController
|
||||||
$this->set('data', $data);
|
$this->set('data', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createProcessorInboxEntry($scope, $action)
|
public function createInboxEntry($scope, $action)
|
||||||
{
|
{
|
||||||
if (!$this->request->is('post')) {
|
if (!$this->request->is('post')) {
|
||||||
throw new MethodNotAllowedException(__('Only POST method is accepted'));
|
throw new MethodNotAllowedException(__('Only POST method is accepted'));
|
||||||
|
|
|
@ -186,11 +186,8 @@ class LocalToolsController extends AppController
|
||||||
},
|
},
|
||||||
'afterFind' => function($data) {
|
'afterFind' => function($data) {
|
||||||
foreach ($data as $connector) {
|
foreach ($data as $connector) {
|
||||||
$connector = [
|
$connectorClass = array_values($this->LocalTools->getConnectorByConnectionId($connector['id']))[0];
|
||||||
'id' => $connector['id'],
|
$connector['toolName'] = $connectorClass->name;
|
||||||
'name' => $connector['name'],
|
|
||||||
'connector' => $connector['connector']
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
@ -222,18 +219,23 @@ class LocalToolsController extends AppController
|
||||||
'cerebrate_id' => $cerebrate_id,
|
'cerebrate_id' => $cerebrate_id,
|
||||||
'remote_tool_id' => $remote_tool_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'])) {
|
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'])) {
|
if (empty($postParams['local_tool_id'])) {
|
||||||
throw new MethodNotAllowedException(__('No local tool ID supplied.'));
|
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'];
|
$params['local_tool_id'] = $postParams['local_tool_id'];
|
||||||
$result = $this->LocalTools->encodeConnection($params);
|
$encodingResult = $this->LocalTools->encodeConnection($params);
|
||||||
// Send message to remote inbox
|
$encodingResult['toolName'] = $tool_name;
|
||||||
debug($result);
|
$urlPath = '/inbox/createInboxEntry/LocalTool/IncomingConnectionRequest';
|
||||||
|
$response = $this->Inbox->sendRequest($remoteCerebrate, $urlPath, true, $encodingResult);
|
||||||
|
$this->redirect();
|
||||||
} else {
|
} else {
|
||||||
$this->loadModel('Broods');
|
|
||||||
$remoteCerebrate = $this->Broods->find()->where(['id' => $params['cerebrate_id']])->first();
|
|
||||||
$remoteTool = $this->LocalTools->getRemoteToolById($params);
|
$remoteTool = $this->LocalTools->getRemoteToolById($params);
|
||||||
$local_tools = $this->LocalTools->encodeConnectionChoice($params);
|
$local_tools = $this->LocalTools->encodeConnectionChoice($params);
|
||||||
if (empty($local_tools)) {
|
if (empty($local_tools)) {
|
||||||
|
|
|
@ -62,4 +62,27 @@ class InboxTable extends AppTable
|
||||||
|
|
||||||
return $rules;
|
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
|
'connector_description' => $connector_class->description
|
||||||
];
|
];
|
||||||
if ($includeConnections) {
|
if ($includeConnections) {
|
||||||
$connector['connections'] = $this->healthCheck($connector_type, $connector_class);
|
// $connector['connections'] = $this->healthCheck($connector_type, $connector_class);
|
||||||
}
|
}
|
||||||
$connectors[] = $connector;
|
$connectors[] = $connector;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,12 @@
|
||||||
'field' => 'local_tool_id',
|
'field' => 'local_tool_id',
|
||||||
'options' => $dropdown,
|
'options' => $dropdown,
|
||||||
'type' => 'dropdown'
|
'type' => 'dropdown'
|
||||||
]
|
],
|
||||||
|
[
|
||||||
|
'field' => 'tool_name',
|
||||||
|
'default' => $data['remoteTool']['toolName'],
|
||||||
|
'type' => 'hidden'
|
||||||
|
],
|
||||||
],
|
],
|
||||||
'submit' => [
|
'submit' => [
|
||||||
'action' => $this->request->getParam('action')
|
'action' => $this->request->getParam('action')
|
||||||
|
|
Loading…
Reference in New Issue