save things

This commit is contained in:
Andras Bacsai
2023-05-08 13:36:49 +02:00
parent dfecf2cc60
commit d77d32853f
22 changed files with 240 additions and 18 deletions

View File

@@ -35,7 +35,7 @@ class Change extends Component
$this->private_key->save();
session('currentTeam')->privateKeys = PrivateKey::where('team_id', session('currentTeam')->id)->get();
} catch (\Exception $e) {
$this->addError('private_key_value', $e->getMessage());
return generalErrorHandlerLivewire($e, $this);
}
}
}

View File

@@ -23,7 +23,7 @@ class Deploy extends Component
public function mount()
{
$this->parameters = saveParameters();
$this->parameters = getParameters();
$this->application = Application::where('id', $this->applicationId)->first();
$this->destination = $this->application->destination->getMorphClass()::where('id', $this->application->destination->id)->first();
}

View File

@@ -23,7 +23,7 @@ class Add extends Component
];
public function mount()
{
$this->parameters = saveParameters();
$this->parameters = getParameters();
}
public function submit()
{

View File

@@ -20,7 +20,7 @@ class Show extends Component
];
public function mount()
{
$this->parameters = saveParameters();
$this->parameters = getParameters();
}
public function submit()
{

View File

@@ -23,7 +23,7 @@ class Add extends Component
];
public function mount()
{
$this->parameters = saveParameters();
$this->parameters = getParameters();
}
public function submit()
{

View File

@@ -130,12 +130,12 @@ class GithubPrivateRepository extends Component
'environment_name' => $environment->name
]);
} catch (\Exception $e) {
$this->emit('error', $e->getMessage());
return generalErrorHandlerLivewire($e, $this);
}
}
public function mount()
{
$this->parameters = saveParameters();
$this->parameters = getParameters();
$this->repositories = $this->branches = $this->servers = $this->destinations = collect();
$this->github_apps = GithubApp::private();
}

View File

@@ -42,7 +42,7 @@ class PublicGitRepository extends Component
$this->public_repository_url = 'https://github.com/coollabsio/coolify-examples/tree/nodejs-fastify';
$this->port = 3000;
}
$this->parameters = saveParameters();
$this->parameters = getParameters();
$this->servers = session('currentTeam')->load(['servers'])->servers;
}
public function chooseServer($server)

View File

@@ -54,6 +54,7 @@ class Form extends Component
$this->dockerComposeVersion = 'Not installed.';
}
} catch (\Exception $e) {
return generalErrorHandlerLivewire($e, $this);
}
}
public function delete()

View File

@@ -20,7 +20,7 @@ class PrivateKey extends Component
}
public function mount()
{
$this->parameters = saveParameters();
$this->parameters = getParameters();
$this->private_keys = ModelsPrivateKey::where('team_id', session('currentTeam')->id)->get();
}
}

View File

@@ -0,0 +1,48 @@
<?php
namespace App\Http\Livewire\Source;
use App\Models\GithubApp;
use Livewire\Component;
class Create extends Component
{
public string $name;
public string|null $organization = null;
public string $api_url = 'https://api.github.com';
public string $html_url = 'https://github.com';
public string $custom_user = 'git';
public int $custom_port = 22;
public bool $is_system_wide = false;
public function mount()
{
$this->name = generateRandomName();
}
public function createGitHubApp()
{
try {
$this->validate([
"name" => 'required|string',
"organization" => 'nullable|string',
"api_url" => 'required|string',
"html_url" => 'required|string',
"custom_user" => 'required|string',
"custom_port" => 'required|int',
"is_system_wide" => 'required|bool',
]);
GithubApp::create([
'name' => $this->name,
'organization' => $this->organization,
'api_url' => $this->api_url,
'html_url' => $this->html_url,
'custom_user' => $this->custom_user,
'custom_port' => $this->custom_port,
'is_system_wide' => $this->is_system_wide,
'team_id' => session('currentTeam')->id,
]);
} catch (\Exception $e) {
return generalErrorHandlerLivewire($e, $this);
}
}
}

View File

@@ -0,0 +1,99 @@
<?php
namespace App\Http\Livewire\Source\Github;
use App\Models\GithubApp;
use App\Models\InstanceSettings;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Route;
use Livewire\Component;
use Illuminate\Support\Str;
class Change extends Component
{
public string $host;
public $parameters;
public GithubApp $github_app;
public bool $is_system_wide;
protected $rules = [
'github_app.name' => 'required|string',
'github_app.organization' => 'nullable|string',
'github_app.api_url' => 'required|string',
'github_app.html_url' => 'required|string',
'github_app.custom_user' => 'required|string',
'github_app.custom_port' => 'required|int',
'github_app.app_id' => 'required|int',
'github_app.installation_id' => 'required|int',
'github_app.client_id' => 'required|string',
'github_app.client_secret' => 'required|string',
'github_app.webhook_secret' => 'required|string',
'github_app.is_system_wide' => 'required|bool',
];
public function submit()
{
try {
$this->validate();
$this->github_app->save();
} catch (\Exception $e) {
return generalErrorHandlerLivewire($e, $this);
}
}
public function instantSave()
{
try {
$this->github_app->is_system_wide = $this->is_system_wide;
$this->github_app->save();
} catch (\Exception $e) {
return generalErrorHandlerLivewire($e, $this);
}
}
public function mount()
{
$this->parameters = getParameters();
$this->github_app = GithubApp::where('uuid', $this->parameters['github_app_uuid'])->first();
$this->is_system_wide = $this->github_app->is_system_wide;
}
public function createGithubApp()
{
$settings = InstanceSettings::first();
$fqdn = $settings->fqdn;
if (!$fqdn) {
$fqdn = $this->host;
}
if ($this->github_app->organization) {
$url = 'organizations/' . $this->github_app->organization . '/settings/apps/new';
} else {
$url = 'settings/apps/new';
}
$name = Str::kebab('coolify' . $this->github_app->name);
$data = [
"name" => $name,
"url" => $fqdn,
"hook_attributes" => [
"url" => "$fqdn/webhooks/github/events"
],
"redirect_url" => "$fqdn/webhooks/github",
"callback_url" => [
"$fqdn/login/github/app",
],
"public" => false,
"request_oauth_on_install" => false,
"setup_url" => "$fqdn/webhooks/github/install?source_id=" . $this->github_app->uuid,
"setup_on_update" => true,
"default_permissions" => [
"contents" => 'read',
"metadata" => 'read',
"pull_requests" => 'read',
"emails" => 'read'
],
"default_events" => ['pull_request', 'push']
];
$response = Http::asForm()->post("{$this->github_app->html_url}/{$url}?state={$this->github_app->uuid}", [
'id' => 'manifest',
'name' => 'manifest',
'data' => json_encode($data),
]);
dd($response);
}
}