Skip to content

Commit b54e54f

Browse files
committed
Added create brancher command
1 parent dd83704 commit b54e54f

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
namespace App\Commands;
4+
5+
use Hypernode\Api\Exception\HypernodeApiClientException;
6+
use Hypernode\Api\Exception\HypernodeApiServerException;
7+
use Hypernode\Api\HypernodeClientFactory;
8+
use LaravelZero\Framework\Commands\Command;
9+
10+
class CreateBrancherNode extends Command
11+
{
12+
/**
13+
* The signature of the command.
14+
*
15+
* @var string
16+
*/
17+
protected $signature = 'brancher:create {hypernode} {--label= : Add labels to your Brancher node (comma-separated, optional)} {--clear-services= : Clear the data for provided service(s) when creating the Brancher instance. Useful when you don\'t want to run the production cron or supervisor. Can also be useful if you want to supply your own anonymized database. Possible options: cron, elasticsearch, mysql, supervisor (comma-separated, optional)}';
18+
19+
/**
20+
* The description of the command.
21+
*
22+
* @var string
23+
*/
24+
protected $description = 'Create a new Brancher node';
25+
26+
/**
27+
* Execute the console command.
28+
*
29+
* @return mixed
30+
* @throws HypernodeApiClientException
31+
* @throws HypernodeApiServerException
32+
*/
33+
public function handle()
34+
{
35+
$client = HypernodeClientFactory::create(config('hypernode.api_token'));
36+
37+
$originHypernode = $this->argument('hypernode');
38+
39+
$clearServices = array_filter(array_map('trim', explode(',', $this->option('clear-services'))));
40+
$labels = array_filter(array_map('trim', explode(',', $this->option('label'))));
41+
42+
$client->brancherApp->create($originHypernode, [
43+
'labels' => $labels,
44+
'clear-services' => $clearServices,
45+
]);
46+
47+
$this->line('Brancher node creation for ' . $originHypernode . ' requested');
48+
}
49+
}

0 commit comments

Comments
 (0)