4
4
5
5
namespace Glued \Controllers ;
6
6
7
- use Glued \Classes \Sql ;
8
- use mysql_xdevapi \Exception ;
9
- use Psr \Container \ContainerInterface ;
7
+ use Glued \Lib \Sql ;
10
8
use Psr \Http \Message \ResponseInterface as Response ;
11
9
use Psr \Http \Message \ServerRequestInterface as Request ;
12
- use \PDO ;
13
- use Glued \Lib \IfUtils ;
10
+ use Glued \Lib \Controllers \AbstractService ;
14
11
15
- class IfController extends AbstractController
12
+ class IfController extends AbstractService
16
13
{
17
14
18
15
19
16
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
20
17
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
21
18
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
22
19
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);
37
31
}
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 ;
52
32
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
+ }*/
69
47
70
48
public function getServices (Request $ request , Response $ response , array $ args = []): Response {
71
49
$ filteredRoutes = array_filter ($ this ->settings ['routes ' ], function ($ route ) {
@@ -76,16 +54,44 @@ public function getServices(Request $request, Response $response, array $args =
76
54
$ svc = str_replace ('if/ ' , '' , $ service );
77
55
return [
78
56
'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
80
58
];
81
59
}, $ uniqueServices ));
82
60
return $ response ->withJson ($ uniqueServices );
83
61
}
84
62
85
63
public function getDeployments (Request $ request , Response $ response , array $ args = []): Response
86
64
{
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) || " ;
89
95
$ data = $ db ->getAll ();
90
96
//$db->stmt->debugDumpParams();
91
97
return $ response ->withJson ($ data );
0 commit comments