Skip to content

Commit

Permalink
Adjust the unused container shell command
Browse files Browse the repository at this point in the history
Add some normalized endpoints
  • Loading branch information
austinwbest committed Oct 19, 2024
1 parent 0a3dd75 commit e48d3fc
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
5 changes: 5 additions & 0 deletions root/app/www/public/api/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
apiResponse(401, ['error' => 'Invalid apikey']);
}

//-- DO ANYTHING SPECIAL NEEDED BEFORE SENDING IT
if ($_GET['endpoint']) {
$_GET['request'] = $_GET['endpoint'];
}

$_POST = json_decode(file_get_contents('php://input'), true);
$response = ['result' => apiRequestLocal($_GET['request'], ($_POST ?: $_GET), $_POST)];

Expand Down
2 changes: 1 addition & 1 deletion root/app/www/public/classes/interfaces/Docker.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ interface DockerSock
public const START_CONTAINER = '/usr/bin/docker container start %s';
public const STOP_CONTAINER = '/usr/bin/docker container stop %s%s';
public const ORPHAN_CONTAINERS = '/usr/bin/docker images -f dangling=true --format="{{json . }}" | jq -s --tab .';
public const UNUSED_CONTAINERS = '/usr/bin/docker images --format \'{{.ID}}:{{.Repository}}:{{.Tag}}\' | grep -v "$(docker ps --format {{.Image}})"';
public const UNUSED_CONTAINERS = '/usr/bin/docker images --format \'{{.ID}}:{{.Repository}}:{{.Tag}}\' | grep -v "$(docker ps -a --format {{.Image}})"';
public const CONTAINER_PORT = '/usr/bin/docker port %s %s';
//-- IMAGE SPECIFIC
public const REMOVE_IMAGE = '/usr/bin/docker image rm %s';
Expand Down
24 changes: 24 additions & 0 deletions root/app/www/public/functions/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ function apiRequestLocal($endpoint, $parameters = [], $payload = [])

if (!$payload) { //-- GET
switch ($endpoint) {
case 'database/container/hash':
case 'database-getContainerFromHash':
if (!$parameters['hash']) {
apiResponse(400, ['error' => 'Missing hash parameter']);
Expand All @@ -140,19 +141,24 @@ function apiRequestLocal($endpoint, $parameters = [], $payload = [])
}

return $container;
case 'database/group/hash':
case 'database-getContainerGroupFromHash':
if (!$parameters['hash']) {
apiResponse(400, ['error' => 'Missing hash parameter']);
}
$groupsTable = $database->getContainerGroups();

return $database->getContainerGroupFromHash($parameters['hash'], $groupsTable);
case 'database/containers';
case 'database-getContainers':
return $database->getContainers();
case 'database/groups';
case 'database-getContainerGroups':
return $database->getContainerGroups();
case 'database/grouplinks';
case 'database-getContainerGroupLinks':
return $database->getContainerGroupLinks();
case 'database/grouplinks/containers/group':
case 'database-getGroupLinkContainersFromGroupId';
if (!$parameters['group']) {
apiResponse(400, ['error' => 'Missing group parameter']);
Expand All @@ -161,28 +167,36 @@ function apiRequestLocal($endpoint, $parameters = [], $payload = [])
$containerLinksTable = $database->getContainerGroupLinks();

return $database->getGroupLinkContainersFromGroupId($containerLinksTable, $containersTable, $parameters['group']);
case 'database/notification/links':
case 'database-getNotificationLinks':
return $database->getNotificationLinks();
case 'database/notification/link/platform/name':
case 'database-getNotificationLinkPlatformFromName':
if (!$parameters['name']) {
apiResponse(400, ['error' => 'Missing name parameter']);
}

return $database->getNotificationLinkPlatformFromName($parameters['name']);
case 'database/notification/platforms':
case 'database-getNotificationPlatforms':
return $database->getNotificationPlatforms();
case 'database/notification/triggers':
case 'database-getNotificationTriggers':
return $database->getNotificationTriggers();
case 'database/servers':
case 'database-getServers':
return $database->getServers();
case 'database/settings':
case 'database-getSettings':
return $database->getSettings();
case 'database/notification/trigger/enabled':
case 'database-isNotificationTriggerEnabled':
if (!$parameters['trigger']) {
apiResponse(400, ['error' => 'Missing trigger parameter']);
}

return $database->isNotificationTriggerEnabled($parameters['trigger']);
case 'database/migrations':
case 'database-migrations':
$database->migrations();
return 'migrations applied';
Expand Down Expand Up @@ -245,10 +259,15 @@ function apiRequestLocal($endpoint, $parameters = [], $payload = [])
}

return json_encode($docker->apiCreateContainer($inspect));
case 'file/dependency':
case 'file-dependency':
case 'file/pull':
case 'file-pull':
case 'file/sse':
case 'file-sse':
case 'file/state':
case 'file-state':
case 'file/stats':
case 'file-stats':
$file = strtoupper(str_replace('file-', '', $endpoint));
return getFile(constant($file . '_FILE'));
Expand Down Expand Up @@ -475,10 +494,15 @@ function apiRequestLocal($endpoint, $parameters = [], $payload = [])
}

return $payload['dependencies'] ? $return : $stopContainer;
case 'file/dependency':
case 'file-dependency':
case 'file/pull':
case 'file-pull':
case 'file/sse':
case 'file-sse':
case 'file/state':
case 'file-state':
case 'file/stats':
case 'file-stats':
$fileName = strtoupper(str_replace('file-', '', $endpoint));
$fileConstant = constant($fileName . '_FILE');
Expand Down

0 comments on commit e48d3fc

Please sign in to comment.