diff --git a/src/Endpoint/IncusOS.php b/src/Endpoint/IncusOS.php new file mode 100644 index 0000000..c388fbe --- /dev/null +++ b/src/Endpoint/IncusOS.php @@ -0,0 +1,26 @@ +client); + } else { + throw new InvalidEndpointException( + 'Endpoint ' . $class . ', not implemented.' + ); + } + } +} diff --git a/src/Endpoint/IncusOS/Applications.php b/src/Endpoint/IncusOS/Applications.php new file mode 100644 index 0000000..75ab439 --- /dev/null +++ b/src/Endpoint/IncusOS/Applications.php @@ -0,0 +1,28 @@ +get($this->getEndpoint()) as $application) { + $applications[] = str_replace($this->getEndpoint() . "/", '', $application); + } + return $applications; + } + + public function info(string $application) + { + return $this->get($this->getEndpoint() . "/" . $application); + } +} diff --git a/src/Endpoint/IncusOS/Services.php b/src/Endpoint/IncusOS/Services.php new file mode 100644 index 0000000..842ff83 --- /dev/null +++ b/src/Endpoint/IncusOS/Services.php @@ -0,0 +1,28 @@ +get($this->getEndpoint()) as $service) { + $services[] = str_replace($this->getEndpoint() . "/", '', $service); + } + return $services; + } + + public function info(string $service) + { + return $this->get($this->getEndpoint() . "/" . $service); + } +} diff --git a/src/Endpoint/IncusOS/System.php b/src/Endpoint/IncusOS/System.php new file mode 100644 index 0000000..6288744 --- /dev/null +++ b/src/Endpoint/IncusOS/System.php @@ -0,0 +1,52 @@ +get($this->getEndpoint()) as $endpoint) { + $endpoints[] = str_replace($this->getEndpoint() . "/", '', $endpoint); + } + return $endpoints; + } + + public function factoryReset() + { + $this->post($this->getEndpoint() . "/:factory-reset"); + } + + public function powerOff() + { + $this->post($this->getEndpoint() . "/:poweroff"); + } + + public function reboot() + { + $this->post($this->getEndpoint() . "/:reboot"); + } + + public function __get($endpoint) + { + $class = __NAMESPACE__ . '\\System\\' . ucfirst($endpoint); + + if (class_exists($class)) { + return new $class($this->client); + } else { + throw new InvalidEndpointException( + 'Endpoint ' . $class . ', not implemented.' + ); + } + } +} diff --git a/src/Endpoint/IncusOS/System/Logging.php b/src/Endpoint/IncusOS/System/Logging.php new file mode 100644 index 0000000..4d4b7bd --- /dev/null +++ b/src/Endpoint/IncusOS/System/Logging.php @@ -0,0 +1,19 @@ +get($this->getEndpoint()); + } +} diff --git a/src/Endpoint/IncusOS/System/Network.php b/src/Endpoint/IncusOS/System/Network.php new file mode 100644 index 0000000..e849c88 --- /dev/null +++ b/src/Endpoint/IncusOS/System/Network.php @@ -0,0 +1,19 @@ +get($this->getEndpoint()); + } +} diff --git a/src/Endpoint/IncusOS/System/Provider.php b/src/Endpoint/IncusOS/System/Provider.php new file mode 100644 index 0000000..7c7b729 --- /dev/null +++ b/src/Endpoint/IncusOS/System/Provider.php @@ -0,0 +1,19 @@ +get($this->getEndpoint()); + } +} diff --git a/src/Endpoint/IncusOS/System/Resources.php b/src/Endpoint/IncusOS/System/Resources.php new file mode 100644 index 0000000..2cad5f8 --- /dev/null +++ b/src/Endpoint/IncusOS/System/Resources.php @@ -0,0 +1,19 @@ +get($this->getEndpoint()); + } +} diff --git a/src/Endpoint/IncusOS/System/Security.php b/src/Endpoint/IncusOS/System/Security.php new file mode 100644 index 0000000..2f91bcc --- /dev/null +++ b/src/Endpoint/IncusOS/System/Security.php @@ -0,0 +1,19 @@ +get($this->getEndpoint()); + } +} diff --git a/src/Endpoint/IncusOS/System/Storage.php b/src/Endpoint/IncusOS/System/Storage.php new file mode 100644 index 0000000..b92e28b --- /dev/null +++ b/src/Endpoint/IncusOS/System/Storage.php @@ -0,0 +1,19 @@ +get($this->getEndpoint()); + } +} diff --git a/src/Endpoint/IncusOS/System/Update.php b/src/Endpoint/IncusOS/System/Update.php new file mode 100644 index 0000000..261c5ee --- /dev/null +++ b/src/Endpoint/IncusOS/System/Update.php @@ -0,0 +1,24 @@ +get($this->getEndpoint()); + } + + public function check() + { + return $this->post($this->getEndpoint() . "/:check"); + } +} diff --git a/src/HttpClient/Plugin/PathPrepend.php b/src/HttpClient/Plugin/PathPrepend.php index be5ec94..c9decbc 100644 --- a/src/HttpClient/Plugin/PathPrepend.php +++ b/src/HttpClient/Plugin/PathPrepend.php @@ -29,8 +29,12 @@ public function __construct($path) public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise { $currentPath = $request->getUri()->getPath(); - $uri = $request->getUri()->withPath($this->path.$currentPath); - $request = $request->withUri($uri); + // Incus proxies requests to its OS management API but the path + // is like `/os/1.0/X` instead of `/1.0/X` for normal operations + if(substr($currentPath, 0, strlen("/os/")) !== "/os/"){ + $uri = $request->getUri()->withPath($this->path . $currentPath); + $request = $request->withUri($uri); + } return $next($request); }