-
app/Mail/ServerProvisioned.php
Open in GitHubuse App\Models\Server; use Illuminate\Bus\Queueable; use Illuminate\Mail\Mailable; use Illuminate\Mail\Mailables\Content; use Illuminate\Mail\Mailables\Envelope; use Illuminate\Queue\SerializesModels; class ServerProvisioned extends Mailable { use Queueable, SerializesModels; public function __construct(public Server $server) { // } public function envelope(): Envelope { return new Envelope( subject: __('Server Provisioned'), ); } public function content(): Content { return new Content( markdown: 'emails.server-provisioned', ); } }
-
app/Tasks/ProvisionFreshServer.php
Open in GitHubuse App\Infrastructure\Entities\ServerStatus; use App\Jobs\UpdateUserPublicKey; use App\Mail\ServerProvisioned; use App\Models\FirewallRule; use App\Models\Task as TaskModel; use App\Rules\PublicKey; use App\Server\Firewall\RuleAction; use Illuminate\Http\Request; use Illuminate\Support\Facades\Mail; class ProvisionFreshServer extends Task implements HasCallbacks { // ... protected function onFinished(TaskModel $task, Request $request) { // Store default firewall rules in the database... $this->server->firewallRules()->createMany([ ['name' => 'SSH', 'port' => 22, 'action' => RuleAction::Allow], ['name' => 'HTTP', 'port' => 80, 'action' => RuleAction::Allow], ['name' => 'HTTPS', 'port' => 443, 'action' => RuleAction::Allow], ])->each(function (FirewallRule $firewallRule) { $firewallRule->forceFill(['installed_at' => now()])->save(); }); $this->server->forceFill([ 'provisioned_at' => now(), 'status' => ServerStatus::Running, ])->save(); dispatch(new UpdateUserPublicKey($this->server)); Mail::to($this->server->createdByUser)->queue(new ServerProvisioned($this->server)); } // ... }