Skip to content

Commit

Permalink
Merge pull request #46 from fodderstompf/add-tenants-resource
Browse files Browse the repository at this point in the history
Add tenants resource
  • Loading branch information
Cannonb4ll authored Dec 15, 2021
2 parents 0a59ec9 + fbe9173 commit 36b8f92
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 2 deletions.
26 changes: 24 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ $ploi->servers(123)->sites()->create(
$projectDirectory = '/',
$systemUser = 'ploi',
$systemUserPassword = null,
$webserverTemplate = null
$webserverTemplate = null,
$projectType = null
);

// List sites
Expand Down Expand Up @@ -177,7 +178,9 @@ Available methods for databases:
$ploi->servers(123)->databases()->create(
$databaseName,
$databaseUser,
$databaseUserPassword
$databaseUserPassword,
$description = null,
$siteId = null
);

// List databases
Expand Down Expand Up @@ -452,6 +455,25 @@ $ploi->servers(123)->sites(123)->fastCgi()->disable();
$ploi->servers(123)->sites(123)->fastCgi()->flush();
```

### Tenants

```php
// Create tenant
$ploi->servers(123)->sites(123)->tenants()->create($tenants);

// List tenants
$ploi->servers(123)->sites(123)->tenants()->get();

// Delete tenant
$ploi->servers(123)->sites(123)->tenants()->delete($tenant);

// Request tenant certificate
$ploi->servers(123)->sites(123)->tenants()->requestCertificate($tenant);

// Revoke tenant certificate
$ploi->servers(123)->sites(123)->tenants()->revokeCertificate($tenant);
```

### Robot Access

```php
Expand Down
5 changes: 5 additions & 0 deletions src/Ploi/Resources/Site.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,4 +275,9 @@ public function robots(): Robot
{
return new Robot($this->getServer(), $this);
}

public function tenants(): Tenant
{
return new Tenant($this);
}
}
72 changes: 72 additions & 0 deletions src/Ploi/Resources/Tenant.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

namespace Ploi\Resources;

use Ploi\Http\Response;

class Tenant extends Resource
{
public function __construct(Site $site)
{
parent::__construct($site->getPloi());

$this->setSite($site);

$this->buildEndpoint();
}

public function buildEndpoint(): self
{
$this->setEndpoint($this->getSite()->getEndpoint() . '/tenants');

return $this;
}

public function get(): Response
{
return $this->getPloi()->makeAPICall($this->getEndpoint());
}

public function create(array $tenants): Response
{
$options = [
'body' => json_encode([
'tenants' => $tenants,
])
];

return $this->getPloi()->makeApiCall($this->getEndpoint(), 'post', $options);
}

public function delete(string $tenant = null): Response
{
$url = "{$this->getEndpoint()}/{$tenant}";
return $this->getPloi()->makeAPICall($url, 'delete');
}

public function requestCertificate(string $tenant, string $webhook): Response
{
$options = [
'body' => json_encode([
'webhook' => $webhook,
])
];

$url = "{$this->getEndpoint()}/{$tenant}/request-certificate";

return $this->getPloi()->makeApiCall($url, 'post', $options);
}

public function revokeCertificate(string $tenant, string $webhook): Response
{
$options = [
'body' => json_encode([
'webhook' => $webhook,
])
];

$url = "{$this->getEndpoint()}/{$tenant}/revoke-certificate";

return $this->getPloi()->makeApiCall($url, 'post', $options);
}
}

0 comments on commit 36b8f92

Please sign in to comment.