Skip to content

Commit

Permalink
Api tool section usable via basic auth
Browse files Browse the repository at this point in the history
  • Loading branch information
lucatacconi committed May 19, 2023
1 parent 17dda8c commit 1c52b7e
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,9 @@ RUN_MODE = "PRODU" #PRODU | DEVEL
#Configuring the parameter CHECK_PHP_TASKS_SYNTAX to false in case of syntax errors in the tasks could cause anomalous behavior in the Crunz-ui interfaces

CHECK_PHP_TASKS_SYNTAX = true #true | false

#TOOLS BASIC AUTH CONFIGURATION
TOOLS_LOGIN = "tools_user"
TOOLS_PASSWORD = "tools_password"

#Please, update tools user grant as soon as possible
33 changes: 33 additions & 0 deletions routes/api/tools.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Routing\RouteCollectorProxy;

use Ramsey\Uuid\Uuid;

use Crunz\Configuration\Configuration;
use Crunz\Schedule;
use Crunz\Filesystem;
use Crunz\Task\Collection;
use Crunz\Task\WrongTaskInstanceException;

foreach (glob(__DIR__ . '/../classes/*.php') as $filename){
require_once $filename;
}

use Symfony\Component\Yaml\Yaml;

$app->group('/tools', function (RouteCollectorProxy $group) {

$group->get('/test-conn', function (Request $request, Response $response, array $args) {

$data = [];


$response->getBody()->write(json_encode($data, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
return $response->withStatus(200)
->withHeader("Content-Type", "application/json");
});

});
19 changes: 18 additions & 1 deletion routes/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,24 @@
"secure" => false,
"secret" => $_ENV["JWT_SECRET"],

"ignore" => [$base_path."/auth/login", $base_path."/test"],
"ignore" => [$base_path."/auth/login", $base_path."/tools" ],

"error" => function ($response, $arguments) {
$data = [];
$data["status"] = "Authentication error";
$data["message"] = $arguments["message"];

$response->getBody()->write(json_encode($data, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
return $response->withHeader("Content-Type", "application/json");
}
]));

$app->add(new Tuupola\Middleware\HttpBasicAuthentication([
"path" => [ $base_path."/tools" ],
"realm" => "Protected",
"users" => [
$_ENV["TOOLS_LOGIN"] => $_ENV["TOOLS_PASSWORD"]
],

"error" => function ($response, $arguments) {
$data = [];
Expand Down

0 comments on commit 1c52b7e

Please sign in to comment.