Add comprehensive cloud-init script management interface in the Security section, allowing users to create, edit, delete, and reuse cloud-init scripts across their team. New Components: - CloudInitScripts: Main listing page with grid view of scripts - CloudInitScriptForm: Modal form for create/edit operations Features: - Create new cloud-init scripts with name and content - Edit existing scripts - Delete scripts with confirmation (requires typing script name) - View script preview (first 200 characters) - Scripts are encrypted in database - Full authorization using CloudInitScriptPolicy - Real-time updates via Livewire events UI Location: - Added to Security section nav: /security/cloud-init-scripts - Positioned between Cloud Tokens and API Tokens - Follows existing security UI patterns Files Created: - app/Livewire/Security/CloudInitScripts.php - app/Livewire/Security/CloudInitScriptForm.php - resources/views/livewire/security/cloud-init-scripts.blade.php - resources/views/livewire/security/cloud-init-script-form.blade.php Files Modified: - routes/web.php - Added route - resources/views/components/security/navbar.blade.php - Added nav link 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
97 lines
2.6 KiB
PHP
97 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Security;
|
|
|
|
use App\Models\CloudInitScript;
|
|
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
|
use Livewire\Component;
|
|
|
|
class CloudInitScriptForm extends Component
|
|
{
|
|
use AuthorizesRequests;
|
|
|
|
public bool $modal_mode = true;
|
|
|
|
public ?int $scriptId = null;
|
|
|
|
public string $name = '';
|
|
|
|
public string $script = '';
|
|
|
|
public function mount(?int $scriptId = null)
|
|
{
|
|
if ($scriptId) {
|
|
$this->scriptId = $scriptId;
|
|
$cloudInitScript = CloudInitScript::ownedByCurrentTeam()->findOrFail($scriptId);
|
|
$this->authorize('update', $cloudInitScript);
|
|
|
|
$this->name = $cloudInitScript->name;
|
|
$this->script = $cloudInitScript->script;
|
|
} else {
|
|
$this->authorize('create', CloudInitScript::class);
|
|
}
|
|
}
|
|
|
|
protected function rules(): array
|
|
{
|
|
return [
|
|
'name' => 'required|string|max:255',
|
|
'script' => 'required|string',
|
|
];
|
|
}
|
|
|
|
protected function messages(): array
|
|
{
|
|
return [
|
|
'name.required' => 'Script name is required.',
|
|
'name.max' => 'Script name cannot exceed 255 characters.',
|
|
'script.required' => 'Cloud-init script content is required.',
|
|
];
|
|
}
|
|
|
|
public function save()
|
|
{
|
|
$this->validate();
|
|
|
|
try {
|
|
if ($this->scriptId) {
|
|
// Update existing script
|
|
$cloudInitScript = CloudInitScript::ownedByCurrentTeam()->findOrFail($this->scriptId);
|
|
$this->authorize('update', $cloudInitScript);
|
|
|
|
$cloudInitScript->update([
|
|
'name' => $this->name,
|
|
'script' => $this->script,
|
|
]);
|
|
|
|
$message = 'Cloud-init script updated successfully.';
|
|
} else {
|
|
// Create new script
|
|
$this->authorize('create', CloudInitScript::class);
|
|
|
|
CloudInitScript::create([
|
|
'team_id' => currentTeam()->id,
|
|
'name' => $this->name,
|
|
'script' => $this->script,
|
|
]);
|
|
|
|
$message = 'Cloud-init script created successfully.';
|
|
}
|
|
|
|
$this->reset(['name', 'script', 'scriptId']);
|
|
$this->dispatch('scriptSaved');
|
|
$this->dispatch('success', $message);
|
|
|
|
if ($this->modal_mode) {
|
|
$this->dispatch('closeModal');
|
|
}
|
|
} catch (\Throwable $e) {
|
|
return handleError($e, $this);
|
|
}
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.security.cloud-init-script-form');
|
|
}
|
|
}
|