Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## CHANGELOG.md

## v0.2 (2025-01-12)

- Added support to endpoint groups `endpoints` (incomplete), `gitops`, `ldap`, `motd`, `registries`

## v0.1 (2024-12-15)

- Initial release
133 changes: 133 additions & 0 deletions src/Endpoints/Endpoints/Endpoints.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
<?php
namespace Portainer\Endpoints;
class Endpoints {
private \Portainer\Portainer $portainer;

public function __construct(\Portainer\Portainer $portainer){
$this->portainer = $portainer;
}

/**
* `delete_endpoint()` - Remove multiple environments and optionally clean-up associated resources
* @param array $body Request body
* @return bool Returns true if the endpoint is deleted
*/
public function delete_endpoints(array $body){
$response = $this->portainer->sendRequest(["endpoints" => $body], "endpoints", "DELETE", false, false);
return !$response;
}

/**
* `get_endpoints()` - List all endpoints
* @param array $body Filter settings
* @return array
*/
public function get_endpoints(array $body){
$response = $this->portainer->sendRequest([$body], "endpoints", "GET", false, false);
return $response;
}

/**
* `create_endpoint()` - Create a new endpoint
* @param array $body endpoint configuration
* @return array
*/
public function create_endpoint(array $body){
$response = $this->portainer->sendRequest([$body], "endpoints", "POST", false, false);
return $response;
}

/**
* `delete_endpoint()` - Remove an endpoint
* @param int $id Endpoint ID
* @return bool Returns true if the endpoint is deleted
*/
public function delete_endpoint(int $id){
$response = $this->portainer->sendRequest(["id" => $id], "endpoints/{$id}", "DELETE", false, true);
return !$response;
}

/**
* `get_endpoint()` - Get an endpoint
* @param int $id Endpoint ID
* @return array
*/
public function get_endpoint(int $id){
$response = $this->portainer->sendRequest(["id" => $id], "endpoints/{$id}", "GET", false, true);
return $response;
}

/**
* `update_endpoint()` - Update an endpoint
* @param int $id Endpoint ID
* @param array $body endpoint configuration
* @return array
*/
public function update_endpoint(int $id, array $body){
$response = $this->portainer->sendRequest(["id" => $id, "body" => $body], "endpoints/{$id}", "PUT", false, true);
return $response;
}

/**
* `fetch_endpoint_registry_limits()` - Retrieve endpoint registry limits
* @param int $id Endpoint ID
* @return array
*/
public function fetch_endpoint_registry_limits(int $id, int $registryId){
$response = $this->portainer->sendRequest(["id" => $id, "registryId" => $registryId], "endpoints/{$id}/dockerhub/{$registryId}", "GET", false, true);
return $response;
}

/**
* `update_endpoint_registry_limits()` - Update endpoint docker service
* @param int $id Endpoint ID
* @param int $serviceId service ID
* @param array $body configuration
* @return array
*/
public function force_update_dockerService_endpoint(int $id, string $serviceId, bool $pullImage = true){
$response = $this->portainer->sendRequest(["id" => $id, "serviceId" => $serviceId, "pullImage" => $pullImage], "endpoints/{$id}/forceupdateservice", "PUT", false, true);
return $response;
}

/**
* `list_endpoint_registries()` - List endpoint registries
* @param int $id Endpoint ID
* @param string $namespace
* @return array
*/
public function list_endpoint_registries(int $id, string $namespace = ""){
$response = $this->portainer->sendRequest(["id" => $id, "namespace" => $namespace], "endpoints/{$id}/registries", "GET", false, true);
return $response;
}

/**
* `update_endpoint_settings()` - Update endpoint settings
* @param int $id Endpoint ID
* @param array $body configuration
* @return array
*/
public function update_endpoint_settings(int $id, array $body){
$response = $this->portainer->sendRequest(["id" => $id, "body" => $body], "endpoints/{$id}/settings", "PUT", false, true);
return $response;
}

/**
* `snapshot_endpoint()` - Snapshot an endpoint
* @param int $id Endpoint ID
* @return bool
*/
public function snapshot_endpoint(int $id){
$response = $this->portainer->sendRequest(["id" => $id], "endpoints/{$id}/snapshot", "POST", false, true);
return !$response;
}

/**
* `snapshot_all_endpoints()` - Snapshot all endpoints
* @return bool
*/
public function snapshot_all_endpoints(){
$response = $this->portainer->sendRequest([], "endpoints/snapshot", "POST", false, false);
return !$response;
}
}
24 changes: 24 additions & 0 deletions src/Endpoints/Gitops/Gitops.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
namespace Portainer\Endpoints;
class Gitops {
private \Portainer\Portainer $portainer;

public function __construct(\Portainer\Portainer $portainer){
$this->portainer = $portainer;
}

/**
* `preview()` - Preview a compose file based on git repository configuration
* @param string $username
* @param string $password
* @param string $reference
* @param string $repository
* @param string $targetFile
* @param bool $tlsskipverify
* @return bool
*/
public function preview(string $username, string $password, string $reference = "refs/heads/master", string $repository, string $targetFile, bool $tlsskipverify = false): bool{
$response = $this->portainer->sendRequest(["username" => $username, "password" => $password, "reference" => $reference, "repository" => $repository, "targetFile" => $targetFile, "tlsskipverify" => $tlsskipverify], "gitops/preview", "POST", false, false);
return !$response;
}
}
19 changes: 19 additions & 0 deletions src/Endpoints/LDAP/LDAP.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
namespace Portainer\Endpoints;
class LDAP {
private \Portainer\Portainer $portainer;

public function __construct(\Portainer\Portainer $portainer){
$this->portainer = $portainer;
}

/**
* `check()` - Check LDAP settings
* @param array $body LDAP settings
* @return bool
*/
public function check(array $body){
$response = $this->portainer->sendRequest([$body], "ldap/check", "POST", false, false);
return $response;
}
}
18 changes: 18 additions & 0 deletions src/Endpoints/Motd/Motd.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
namespace Portainer\Endpoints;
class Motd {
private \Portainer\Portainer $portainer;

public function __construct(\Portainer\Portainer $portainer){
$this->portainer = $portainer;
}

/**
* `motd()` - Get the message of the day
* @return array
*/
public function motd(){
$response = $this->portainer->sendRequest([], "motd", "GET", false, false);
return $response;
}
}
70 changes: 70 additions & 0 deletions src/Endpoints/Registries/Registries.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php
namespace Portainer\Endpoints;
class Registries {
private \Portainer\Portainer $portainer;

public function __construct(\Portainer\Portainer $portainer){
$this->portainer = $portainer;
}

/**
* `get_registries()` - Get all registries
* @return array
*/
public function get_registries(){
$response = $this->portainer->sendRequest([], "registries", "GET", false, false);
return $response;
}

/**
* `create_registry()` - Create a registry
* @param array $body Registry configuration
* @return array
*/
public function create_registry(array $body){
$response = $this->portainer->sendRequest([$body], "registries", "POST", false, false);
return $response;
}

/**
* `delete_registry()` - Delete a registry
* @param int $id Registry ID
* @return bool
*/
public function delete_registry(int $id){
$response = $this->portainer->sendRequest([], "registries/" . $id, "DELETE", false, true);
return $response;
}

/**
* `get_registry()` - Get a registry
* @param int $id Registry ID
* @return array
*/
public function get_registry(int $id){
$response = $this->portainer->sendRequest([], "registries/" . $id, "GET", false, true);
return $response;
}

/**
* `update_registry()` - Update a registry
* @param int $id Registry ID
* @param array $body Registry configuration
* @return array
*/
public function update_registry(int $id, array $body){
$response = $this->portainer->sendRequest([$body], "registries/" . $id, "PUT", false, true);
return $response;
}

/**
* `configure_registry()` - Configure a registry
* @param int $id Registry ID
* @param array $body Registry configuration
* @return bool
*/
public function configure_registry(int $id, array $body){
$response = $this->portainer->sendRequest([$body], "registries/" . $id . "/configure", "POST", false, true);
return !$response;
}
}
17 changes: 16 additions & 1 deletion src/Helper/endpoints.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,20 @@
"custom_templates",
"custom_templates/create/file",
"custom_templates/create/string",
"custom_templates/create/repository"
"custom_templates/create/repository",

"endpoints",
"endpoints/global-key",
"endpoints/relations",
"endpoints/snapshot",

"gitops/repo/file/preview",

"templates/helm",

"ldap/check",

"motd",

"registries"
]
12 changes: 12 additions & 0 deletions src/Portainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
use Portainer\Endpoints\Backup;
use Portainer\Endpoints\CustomTemplates;
use Portainer\Endpoints\Docker;
use Portainer\Endpoints\Endpoints;
use Portainer\Endpoints\Gitops;
use Portainer\Endpoints\LDAP;
use Portainer\Endpoints\Motd;
use Portainer\Endpoints\Registries;
class Portainer {

private $username;
Expand All @@ -22,6 +27,7 @@ class Portainer {
private $backup;
private $customTemplates;
private $docker;
private $endpoints;

public function __construct(string $envPath, string $envName , string $username = null, string $password = null, string $host = null){
$this->loader();
Expand Down Expand Up @@ -58,6 +64,7 @@ public function loader(){
require_once __DIR__ . "/Endpoints/Backup/Backup.php";
require_once __DIR__ . "/Endpoints/CustomTemplates/CustomTemplates.php";
require_once __DIR__ . "/Endpoints/Docker/Docker.php";
require_once __DIR__ . "/Endpoints/Endpoints/Endpoints.php";
}

public function login(){
Expand Down Expand Up @@ -237,4 +244,9 @@ public function docker(){
if(!$this->docker) $this->docker = new Docker($this);
return $this->docker;
}

public function endpoints(){
if(!$this->endpoints) $this->endpoints = new Endpoints($this);
return $this->endpoints;
}
}