Skip to content

Commit b692f0b

Browse files
committed
simplify dependendencies, add actions
1 parent 0636035 commit b692f0b

File tree

14 files changed

+107
-397
lines changed

14 files changed

+107
-397
lines changed

glued/Classes/Sql.php

Lines changed: 0 additions & 15 deletions
This file was deleted.

glued/Config/Pgsql/20240331205651_actions.sql

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
11
-- migrate:up
22

33
CREATE TABLE glued.if__actions (
4-
uuid uuid generated always as (((doc ->> 'uuid'::text))::uuid) stored not null,
5-
doc jsonb not null,
6-
nonce bytea generated always as ( decode( md5((doc - 'uuid')::text), 'hex')) stored,
7-
created_at timestamp with time zone default CURRENT_TIMESTAMP,
8-
updated_at timestamp with time zone default CURRENT_TIMESTAMP,
9-
svc_name text generated always as (doc->>'service.name') stored,
10-
svc_version text generated always as (doc->>'service.version') stored,
11-
svc_method text generated always as (doc->>'service.method') stored,
12-
svc_deployment uuid generated always as (((doc ->> 'service.deployment'::text))::uuid) stored not null,
13-
PRIMARY KEY (uuid),
14-
UNIQUE (nonce),
15-
FOREIGN KEY (svc_deployment) REFERENCES glued.if__deployments(uuid)
4+
uuid uuid generated always as (((doc ->> 'uuid'::text))::uuid) stored not null,
5+
doc jsonb not null,
6+
nonce bytea generated always as ( decode( md5((doc - 'uuid')::text), 'hex')) stored,
7+
created_at timestamp with time zone default CURRENT_TIMESTAMP,
8+
updated_at timestamp with time zone default CURRENT_TIMESTAMP,
9+
path text generated always as (doc->>'path') stored,
10+
method text generated always as (doc->>'method') stored,
11+
deployment uuid generated always as (((doc ->> 'deployment'::text))::uuid) stored not null,
12+
PRIMARY KEY (uuid),
13+
UNIQUE (nonce),
14+
FOREIGN KEY (deployment) REFERENCES glued.if__deployments(uuid)
1615
);
1716

1817
COMMENT ON TABLE glued.if__actions IS 'IF service actions are service methods available in an deployment configuration/authorization context.';
19-
COMMENT ON COLUMN glued.if__actions.svc_name IS 'IF microservice name (i.e. gov_ares_cz)';
20-
COMMENT ON COLUMN glued.if__actions.svc_version IS 'IF microservice version (i.e. v1)';
21-
COMMENT ON COLUMN glued.if__actions.svc_method IS 'IF microservice method (i.e. search)';
22-
COMMENT ON COLUMN glued.if__actions.svc_deployment IS 'IF Deployment reference, a.k.a. the configuration/authorization context to a microservice';
18+
COMMENT ON COLUMN glued.if__actions.path IS 'Request path (i.e. /api/if/svc/some_if_service/v1/some_method)';
19+
COMMENT ON COLUMN glued.if__actions.method IS 'Request method (i.e. get/post/put/delete/patch)';
20+
COMMENT ON COLUMN glued.if__actions.deployment IS 'Deployment UUID whose endpoints are requested, defines the configuration/authorization context to a microservice';
2321

2422
-- migrate:down
2523

glued/Config/openapi.yaml

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ paths:
6969
responses:
7070
'200':
7171
description: Ok
72-
/v1/deployments/{pattern}/{key}:
72+
/v1/deployments/{uuid}:
7373
x-glued-pathname: be_if_deployment
7474
x-glued-provides: service
7575
get:
@@ -79,15 +79,7 @@ paths:
7979
operationId: IfGetDeployment
8080
parameters:
8181
- in: path
82-
name: pattern
83-
required: true
84-
schema:
85-
type: string
86-
anyOf:
87-
- name
88-
- uuid
89-
- in: path
90-
name: key
82+
name: uuid
9183
required: true
9284
schema:
9385
type: string
@@ -101,7 +93,7 @@ paths:
10193
description: Update (replace) a deployment config
10294
parameters:
10395
- in: path
104-
name: deploy
96+
name: uuid
10597
required: true
10698
schema:
10799
type: string

glued/Config/routes.yaml

Lines changed: 0 additions & 90 deletions
This file was deleted.

glued/Controllers/AbstractController.php

Lines changed: 0 additions & 42 deletions
This file was deleted.

glued/Controllers/IfController.php

Lines changed: 59 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -4,68 +4,46 @@
44

55
namespace Glued\Controllers;
66

7-
use Glued\Classes\Sql;
8-
use mysql_xdevapi\Exception;
9-
use Psr\Container\ContainerInterface;
7+
use Glued\Lib\Sql;
108
use Psr\Http\Message\ResponseInterface as Response;
119
use Psr\Http\Message\ServerRequestInterface as Request;
12-
use \PDO;
13-
use Glued\Lib\IfUtils;
10+
use Glued\Lib\Controllers\AbstractService;
1411

15-
class IfController extends AbstractController
12+
class IfController extends AbstractService
1613
{
1714

1815

1916
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2017
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2118
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2219

23-
public function getOpenapi(Request $request, Response $response, array $args = []): Response
24-
{
25-
// Directory to look for paths
26-
$path = "{$this->settings['glued']['datapath']}/{$this->settings['glued']['uservice']}/cache" ;
27-
$filesWhitelist = ["openapi.json", "openapi.yaml", "openapi.yml"]; // Potential file names
28-
29-
foreach ($filesWhitelist as $file) {
30-
$fullPath = rtrim($path, '/') . '/' . $file;
31-
if (file_exists($fullPath)) {
32-
$content = file_get_contents($fullPath);
33-
$response->getBody()->write($content);
34-
$contentType = 'application/json';
35-
if (pathinfo($fullPath, PATHINFO_EXTENSION) === 'yaml' || pathinfo($fullPath, PATHINFO_EXTENSION) === 'yml') { $contentType = 'application/x-yaml'; }
36-
return $response->withHeader('Content-Type', $contentType);
20+
/*
21+
public function getHealth(Request $request, Response $response, array $args = []): Response {
22+
try {
23+
$check['service'] = basename(__ROOT__);
24+
$check['timestamp'] = microtime();
25+
$check['healthy'] = true;
26+
$check['status']['postgres'] = $this->pg->query("select true as test")->fetch()['test'] ?? false;
27+
$check['status']['auth'] = $_SERVER['X-GLUED-AUTH-UUID'] ?? 'anonymous';
28+
} catch (Exception $e) {
29+
$check['healthy'] = false;
30+
return $response->withJson($check);
3731
}
38-
}
39-
throw new \Exception("OpenAPI specification not found", 404);
40-
}
41-
42-
43-
public function getHealth(Request $request, Response $response, array $args = []): Response {
44-
try {
45-
$check['service'] = basename(__ROOT__);
46-
$check['timestamp'] = microtime();
47-
$check['healthy'] = true;
48-
$check['status']['postgres'] = $this->pg->query("select true as test")->fetch()['test'] ?? false;
49-
$check['status']['auth'] = $_SERVER['X-GLUED-AUTH-UUID'] ?? 'anonymous';
50-
} catch (Exception $e) {
51-
$check['healthy'] = false;
5232
return $response->withJson($check);
53-
}
54-
return $response->withJson($check);
55-
/*
56-
$db = new \Glued\Lib\Sql($this->pg, 'your_table');
57-
$db->where('uuid', '=', '8f337987-9b3e-4285-a0f4-4bd70101bd07');
58-
//$db->createBatch([['prca' => 'puc'],['prcb' => 'puc'],['prca' => 'pucaaaaaaaaaaaaaa', "uuid" => "92955e5d-76d6-4b8b-8376-2d1be820ee7d"]], true);
59-
//$db->stmt->debugDumpParams();
60-
$db->update("92955e5d-76d6-4b8b-8376-2d1be820ee7d", ['prca' => '11113', "uuid" => "92955e5d-76d6-4b8b-8376-2d1be820ee7d"]);
61-
//$data['d'] = $db->debug();
62-
$db->delete('92955e5d-76d6-4b8b-8376-2d1be820ee7d');
63-
//echo $db->stmt->rowCount();
64-
$data['r'] = $db->getAll();
65-
//$data = $db->get('8f337987-9b3e-4285-a0f4-4bd70101bd07');
66-
//$data = $db->getAll();
67-
//return $response;*/
68-
}
33+
34+
$db = new \Glued\Lib\Sql($this->pg, 'your_table');
35+
$db->where('uuid', '=', '8f337987-9b3e-4285-a0f4-4bd70101bd07');
36+
//$db->createBatch([['prca' => 'puc'],['prcb' => 'puc'],['prca' => 'pucaaaaaaaaaaaaaa', "uuid" => "92955e5d-76d6-4b8b-8376-2d1be820ee7d"]], true);
37+
//$db->stmt->debugDumpParams();
38+
$db->update("92955e5d-76d6-4b8b-8376-2d1be820ee7d", ['prca' => '11113', "uuid" => "92955e5d-76d6-4b8b-8376-2d1be820ee7d"]);
39+
//$data['d'] = $db->debug();
40+
$db->delete('92955e5d-76d6-4b8b-8376-2d1be820ee7d');
41+
//echo $db->stmt->rowCount();
42+
$data['r'] = $db->getAll();
43+
//$data = $db->get('8f337987-9b3e-4285-a0f4-4bd70101bd07');
44+
//$data = $db->getAll();
45+
//return $response;*
46+
}*/
6947

7048
public function getServices(Request $request, Response $response, array $args = []): Response {
7149
$filteredRoutes = array_filter($this->settings['routes'], function ($route) {
@@ -76,16 +54,44 @@ public function getServices(Request $request, Response $response, array $args =
7654
$svc = str_replace('if/', '', $service);
7755
return [
7856
'service' => $svc,
79-
'deployments' => $this->settings['glued']['baseuri'] . $this->settings['routes']['be_if_deployments']['pattern'] . "/name/" . $svc
57+
'deployments' => $this->settings['glued']['baseuri'] . $this->settings['routes']['be_if_deployments']['pattern'] . "?service=" . $svc
8058
];
8159
}, $uniqueServices));
8260
return $response->withJson($uniqueServices);
8361
}
8462

8563
public function getDeployments(Request $request, Response $response, array $args = []): Response
8664
{
87-
$db = new \Glued\Lib\Sql($this->pg, 'if__deployments');
88-
$db->selectModifier = "jsonb_build_object('uri', concat('{$this->settings['glued']['baseuri']}/{$this->settings['routes']['be_if_svc_s4s']['pattern']}v1/', doc->>'uuid'), 'nonce', nonce, 'created_at', created_at, 'updated_at', updated_at) || ";
65+
$db = new Sql($this->pg, 'if__deployments');
66+
$qp = $request->getQueryParams();
67+
$filters = ['uuid', 'service'];
68+
foreach ($filters as $filter) {
69+
if (!empty($qp[$filter])) { $db->where($filter, '=', $qp[$filter]); }
70+
}
71+
$db->selectModifier = "jsonb_build_object('uri', concat('{$this->settings['glued']['baseuri']}{$this->settings['routes']['be_if']['pattern']}svc/', doc->>'service', '/v1/', doc->>'uuid'), 'nonce', nonce, 'created_at', created_at, 'updated_at', updated_at) || ";
72+
$data = $db->getAll();
73+
//$db->stmt->debugDumpParams();
74+
return $response->withJson($data);
75+
}
76+
77+
public function getDeployment(Request $request, Response $response, array $args = []): Response
78+
{
79+
if (empty($args['uuid'])) { throw new \Exception('No uuid specified', 404); }
80+
$db = new Sql($this->pg, 'if__deployments');
81+
$db->selectModifier = "jsonb_build_object('uri', concat('{$this->settings['glued']['baseuri']}{$this->settings['routes']['be_if']['pattern']}svc/', doc->>'service', '/v1/', doc->>'uuid'), 'nonce', nonce, 'created_at', created_at, 'updated_at', updated_at) || ";
82+
$data = $db->get($args['uuid']);
83+
return $response->withJson($data);
84+
}
85+
86+
public function getActions(Request $request, Response $response, array $args = []): Response
87+
{
88+
$db = new Sql($this->pg, 'if__actions');
89+
$qp = $request->getQueryParams();
90+
$filters = ['svc_name', 'svc_version', 'svc_method', 'svc_deployment'];
91+
foreach ($filters as $filter) {
92+
if (!empty($qp[$filter])) { $db->where($filter, '=', $qp[$filter]); }
93+
}
94+
$db->selectModifier = "jsonb_build_object('uri', concat('{$this->settings['glued']['baseuri']}{$this->settings['routes']['be_if']['pattern']}svc/', doc->>'svc_name', '/v1/', doc->>'uuid'), 'nonce', nonce, 'created_at', created_at, 'updated_at', updated_at) || ";
8995
$data = $db->getAll();
9096
//$db->stmt->debugDumpParams();
9197
return $response->withJson($data);

0 commit comments

Comments
 (0)