Skip to content

Commit

Permalink
API fix
Browse files Browse the repository at this point in the history
According to the issue 13 specifically on the most recent comment MrKampf#13 (comment)
This seems to solve the issue ''cannot represent a stream of type Output as a STDIO FILE*'' and as well fixing the CSRF token occuring ''must be of type string, null given''. 
When testing I stumbled upon an issue according how the params are sent, it was already patched in the delete function I added these as well to post and put.

About the debug setting,
guzzle/guzzle#1413
  • Loading branch information
KingMotro authored Dec 29, 2021
1 parent ea6fa33 commit 95cbac9
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/Proxmox/Helper/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function get(string $path, array $params = []): ?array
try {
return $this->getBody($this->PVE->getHttpClient()->request('GET', $this->PVE->getApiURL() . $path, [
'verify' => false,
'debug' => $this->PVE->getDebug(),
'debug' => $this->PVE->getDebug() ? fopen('php://stderr', 'w') : null,
'headers' => [
'CSRFPreventionToken' => $this->PVE->getCSRFPreventionToken(),
'Accept' => 'application/json',
Expand Down Expand Up @@ -79,7 +79,7 @@ public function post(string $path, array $params = []): ?array
try {
return $this->getBody($this->PVE->getHttpClient()->request('POST', $this->PVE->getApiURL() . $path, [
'verify' => false,
'debug' => $this->PVE->getDebug(),
'debug' => $this->PVE->getDebug() ? fopen('php://stderr', 'w') : null,
'headers' => [
'CSRFPreventionToken' => $this->PVE->getCSRFPreventionToken(),
'Content-Type' => (count($params) > 0) ? 'application/json' : null,
Expand All @@ -88,7 +88,7 @@ public function post(string $path, array $params = []): ?array
],
'exceptions' => false,
'cookies' => $this->PVE->getCookie(),
'json' => $params,
'json' => (count($params) > 0) ? $params : null,
]));
} catch (GuzzleException $exception) {
if ($this->PVE->getDebug()) {
Expand All @@ -109,7 +109,7 @@ public function put(string $path, array $params = []): ?array
try {
return $this->getBody($this->PVE->getHttpClient()->request('PUT', $this->PVE->getApiURL() . $path, [
'verify' => false,
'debug' => $this->PVE->getDebug(),
'debug' => $this->PVE->getDebug() ? fopen('php://stderr', 'w') : null,
'headers' => [
'CSRFPreventionToken' => $this->PVE->getCSRFPreventionToken(),
'Content-Type' => (count($params) > 0) ? 'application/json' : null,
Expand All @@ -118,7 +118,7 @@ public function put(string $path, array $params = []): ?array
],
'exceptions' => false,
'cookies' => $this->PVE->getCookie(),
'json' => $params,
'json' => (count($params) > 0) ? $params : null,
]));
} catch (GuzzleException $exception) {
if ($this->PVE->getDebug()) {
Expand All @@ -139,7 +139,7 @@ public function delete(string $path, array $params = []): ?array
try {
return $this->getBody($this->PVE->getHttpClient()->request('DELETE', $this->PVE->getApiURL() . $path, [
'verify' => false,
'debug' => $this->PVE->getDebug(),
'debug' => $this->PVE->getDebug() ? fopen('php://stderr', 'w') : null,
'headers' => [
'CSRFPreventionToken' => $this->PVE->getCSRFPreventionToken(),
'Content-Type' => (count($params) > 0) ? 'application/json' : null,
Expand Down Expand Up @@ -178,7 +178,7 @@ public function getCSRFToken(): ?array
try {
return $this->getBody($this->PVE->getHttpClient()->request('POST', $this->PVE->getApiURL() . 'access/ticket', [
'verify' => false,
'debug' => $this->PVE->getDebug(),
'debug' => $this->PVE->getDebug() ? fopen('php://stderr', 'w') : null,
'headers' => [
'Accept' => 'application/json',
'Accept-Encoding' => 'gzip',
Expand Down Expand Up @@ -208,4 +208,4 @@ public function getCookies(): CookieJar
], $this->PVE->getHostname());
}

}
}

0 comments on commit 95cbac9

Please sign in to comment.