-
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for setting passwords on Windows Server and utilize QEMU …
…Guest Agent for setting passwords on Linux
- Loading branch information
1 parent
bdc9c41
commit c431a7b
Showing
4 changed files
with
165 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
namespace Convoy\Jobs\Server; | ||
|
||
use Convoy\Models\Server; | ||
use Convoy\Services\Servers\ServerAuthService; | ||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Foundation\Bus\Dispatchable; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
use Illuminate\Queue\Middleware\SkipIfBatchCancelled; | ||
use Illuminate\Queue\Middleware\WithoutOverlapping; | ||
use Illuminate\Queue\SerializesModels; | ||
|
||
class SyncWindowsSettings implements ShouldQueue | ||
{ | ||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; | ||
|
||
public int $tries = 15; | ||
|
||
public int $timeout = 20; | ||
|
||
public function __construct(protected int $serverId, protected string $password) | ||
{ | ||
// | ||
} | ||
|
||
public function middleware(): array | ||
{ | ||
return [new SkipIfBatchCancelled(), new WithoutOverlapping( | ||
"server.sync-windows-settings#{$this->serverId}", | ||
)]; | ||
} | ||
|
||
public function handle(ServerAuthService $service): void | ||
{ | ||
$server = Server::findOrFail($this->serverId); | ||
|
||
$service->updateWindowsPassword($server, $this->password); | ||
} | ||
|
||
/** | ||
* Determine the time at which the job should retry. | ||
* | ||
* @return \DateTime | ||
*/ | ||
public function retryAfter(): \DateTime | ||
{ | ||
return now()->addSeconds(20); | ||
} | ||
|
||
/** | ||
* Determine the time at which the job should timeout. | ||
* | ||
* @return \DateTime | ||
*/ | ||
public function retryUntil(): \DateTime | ||
{ | ||
return now()->addSeconds($this->timeout * $this->tries); | ||
} | ||
|
||
/** | ||
* Handle a job failure. | ||
* | ||
* @return void | ||
*/ | ||
public function failed(): void | ||
{ | ||
// Mark the job as completed | ||
$this->delete(); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
app/Repositories/Proxmox/Server/ProxmoxGuestAgentRepository.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
namespace Convoy\Repositories\Proxmox\Server; | ||
|
||
use Convoy\Models\Server; | ||
use Webmozart\Assert\Assert; | ||
use Convoy\Repositories\Proxmox\ProxmoxRepository; | ||
use Convoy\Exceptions\Repository\Proxmox\ProxmoxConnectionException; | ||
|
||
class ProxmoxGuestAgentRepository extends ProxmoxRepository | ||
{ | ||
/** | ||
* Get Guest Agent status. | ||
* | ||
* @return mixed | ||
* | ||
* @throws ProxmoxConnectionException | ||
*/ | ||
public function guestAgentOs() | ||
{ | ||
Assert::isInstanceOf($this->server, Server::class); | ||
|
||
$response = $this->getHttpClient() | ||
->withUrlParameters([ | ||
'node' => $this->node->cluster, | ||
'server' => $this->server->vmid, | ||
]) | ||
->get('/api2/json/nodes/{node}/qemu/{server}/agent/get-osinfo') | ||
->json(); | ||
|
||
return $this->getData($response); | ||
} | ||
|
||
/** | ||
* Update Guest Agent password for Administrator user. | ||
* | ||
* @param string $password | ||
* @return mixed | ||
* | ||
* @throws ProxmoxConnectionException | ||
*/ | ||
public function updateGuestAgentPassword(string $username, string $password) | ||
{ | ||
Assert::isInstanceOf($this->server, Server::class); | ||
|
||
$params = [ | ||
'username' => $username, | ||
'password' => $password, | ||
]; | ||
|
||
$response = $this->getHttpClient() | ||
->withUrlParameters([ | ||
'node' => $this->node->cluster, | ||
'server' => $this->server->vmid, | ||
]) | ||
->post('/api2/json/nodes/{node}/qemu/{server}/agent/set-user-password', $params) | ||
->json(); | ||
|
||
return $this->getData($response); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters