13 namespace Fossology\UI\Api\Controllers;
19 use Psr\Http\Message\ServerRequestInterface;
20 use Symfony\Component\Yaml\Exception\ParseException;
21 use Symfony\Component\Yaml\Parser;
37 public function getInfo($request, $response)
43 $yamlDocArray = $yaml->parse(file_get_contents(
44 dirname(__DIR__) .
"/documentation/openapiv2.yaml"));
46 $yamlDocArray = $yaml->parse(file_get_contents(
47 dirname(__DIR__) .
"/documentation/openapi.yaml"));
49 }
catch (ParseException $exception) {
50 printf(
"Unable to parse the YAML string: %s", $exception->getMessage());
54 $apiTitle = $yamlDocArray[
"info"][
"title"];
55 $apiDescription = $yamlDocArray[
"info"][
"description"];
56 $apiVersion = $yamlDocArray[
"info"][
"version"];
57 $apiContact = $yamlDocArray[
"info"][
"contact"][
"email"];
58 $apiLicense = $yamlDocArray[
"info"][
"license"];
60 foreach ($yamlDocArray[
"security"] as $secMethod) {
61 $security[] = key($secMethod);
70 if (array_key_exists(
'BUILD', $SysConf)) {
71 $fossInfo[
"version"] = $SysConf[
'BUILD'][
'VERSION'];
72 $fossInfo[
"branchName"] = $SysConf[
'BUILD'][
'BRANCH'];
73 $fossInfo[
"commitHash"] = $SysConf[
'BUILD'][
'COMMIT_HASH'];
74 if (strcasecmp($SysConf[
'BUILD'][
'COMMIT_DATE'],
"unknown") != 0) {
75 $fossInfo[
"commitDate"] = date(DATE_ATOM,
76 strtotime($SysConf[
'BUILD'][
'COMMIT_DATE']));
78 if (strcasecmp($SysConf[
'BUILD'][
'BUILD_DATE'],
"unknown") != 0) {
79 $fossInfo[
"buildDate"] = date(DATE_ATOM,
80 strtotime($SysConf[
'BUILD'][
'BUILD_DATE']));
83 return $response->withJson(array(
85 "description" => $apiDescription,
86 "version" => $apiVersion,
87 "security" => $security,
88 "contact" => $apiContact,
90 "name" => $apiLicense[
"name"],
91 "url" => $apiLicense[
"url"]
93 "fossology" => $fossInfo
107 $dbStatus = ($args === -1) ?
"ERROR" :
"OK";
110 && strstr($error_msg,
"Connection refused") !==
false) {
111 $schedStatus =
"ERROR";
115 if ($schedStatus !==
"OK") {
118 if ($dbStatus !==
"OK") {
122 return $response->withJson(array(
125 "status" => $schedStatus
128 "status" => $dbStatus
143 $isJsonRequest =
false;
144 $requestFormat = $request->getHeader(
"Accept");
145 if (!empty($requestFormat) && !empty($requestFormat[0])) {
146 $requestFormat = $requestFormat[0];
150 if (strcasecmp($requestFormat,
"application/vnd.oai.openapi+json") === 0
151 || strcasecmp($requestFormat,
"application/json") === 0) {
152 $isJsonRequest =
true;
156 $yamlContent = file_get_contents(
157 dirname(__DIR__) .
"/documentation/openapiv2.yaml");
159 $yamlContent = file_get_contents(
160 dirname(__DIR__) .
"/documentation/openapi.yaml");
162 if ($isJsonRequest) {
164 $yaml =
new Parser();
165 $yamlDocArray = $yaml->parse($yamlContent);
166 }
catch (ParseException $exception) {
167 printf(
"Unable to parse the YAML string: %s", $exception->getMessage());
172 ->withHeader(
"Content-Disposition",
"inline; filename=\"openapi.json\"")
173 ->withJson($yamlDocArray, 200);
175 if (empty($yamlContent)) {
178 $response->getBody()->write($yamlContent);
180 ->withHeader(
"Content-Type",
"application/vnd.oai.openapi;charset=utf-8")
181 ->withHeader(
"Content-Disposition",
"inline; filename=\"openapi.yaml\"")
Controller for REST API version.
getInfo($request, $response)
getHealth($request, $response, $args)
getOpenApi($request, $response)
Base controller for REST calls.
Override Slim response for withJson function.
static getVersion(ServerRequestInterface $request)
fo_communicate_with_scheduler($input, &$output, &$error_msg)
Communicate with scheduler, send commands to the scheduler, then get the output.