Skip to content

Commit

Permalink
Fix proxmox with offline node (#730)
Browse files Browse the repository at this point in the history
* Exclude .idea from beeing tracked in repository
* Ensure encoded body is of type stdClass before accessing it. This will prevent throwing an exception if one node is offline.
* Use correct ident config for phpfiles. Fix phpcs errors.
  • Loading branch information
aseemann authored May 3, 2024
1 parent db5a902 commit 7d509a6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ indent_style = space
[*.{json,json5,webmanifest}]
indent_size = 2
indent_style = space

[*.php]
indent_size = 4
indent_style = space
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ dist
Vaultwarden/Thumbs.db
BrotherPrinter/Thumbs.db
Rustdesk/Thumbs.db
.idea
19 changes: 12 additions & 7 deletions Proxmox/Proxmox.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,22 +92,27 @@ public function livestats()
];
return parent::getLiveStats($status, $data);
}

public function url($endpoint)
{
$api_stub = "api2/json/";
$api_url =
parent::normaliseurl(
$this->getConfigValue("override_url", $this->config->url)
) .
$api_stub .
$endpoint;
$api_url = parent::normaliseurl(
$this->getConfigValue("override_url", $this->config->url)
) .
$api_stub .
$endpoint;
return $api_url;
}

public function apiCall($endpoint)
{
$res = parent::execute($this->url($endpoint), $this->getRequestAttrs());
return json_decode($res->getBody())->data;
$object = json_decode($res->getBody());

if (!$object instanceof \stdClass) {
return null;
}
return $object->data;
}

public function getConfigValue($key, $default = null)
Expand Down

0 comments on commit 7d509a6

Please sign in to comment.