Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds support for "Deployments" and add penant #9

Open
wants to merge 34 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
bc2791f
wip
austinkregel Jun 1, 2024
9d679c2
Cs fixes from pint
austinkregel Jun 1, 2024
d70ff4e
Add vue multiselect
austinkregel Jun 1, 2024
522d544
big wip. Update the ssh service so it works properly again. Update cr…
austinkregel Jun 3, 2024
f21f90f
Update the search to have white text and actually submit to the searc…
austinkregel Jun 3, 2024
39bbf53
wip
austinkregel Jun 4, 2024
dffaf8d
Add tag individual tag page
austinkregel Jun 9, 2024
d940893
Copy new sounds
austinkregel Jun 9, 2024
39122f1
Add stateful api support
austinkregel Jun 9, 2024
2ff9720
Make some routes stateless
austinkregel Jun 9, 2024
6ea8392
wip
austinkregel Jun 9, 2024
09bd358
Add static copy for vite
austinkregel Jun 9, 2024
344e8c9
Update how we handle the search page(s). Updates the layout of the mu…
austinkregel Jun 9, 2024
ce03aed
wip
austinkregel Jun 9, 2024
0fefeab
wip
austinkregel Jun 11, 2024
a7f1da1
wip
austinkregel Jun 11, 2024
406ddc4
Remove phpstan
austinkregel Jun 11, 2024
16e56ee
add server test for provisioning
austinkregel Jun 11, 2024
a850062
Add new server service functionallity to track which of our desired t…
austinkregel Jun 13, 2024
ab42953
Update model bindings
austinkregel Jun 23, 2024
dded986
wip
austinkregel Jun 23, 2024
028a8b9
cs fix from pint
austinkregel Jun 23, 2024
dc6e637
wip
austinkregel Jul 11, 2024
6e59076
wip
austinkregel Jul 22, 2024
a17043d
Implement flight login because I wanna stop writing passwords.
austinkregel Jul 22, 2024
430d3f2
Add asset
austinkregel Aug 3, 2024
8f8df5d
Fix how the conditional service groups items
austinkregel Aug 3, 2024
69c2918
wip
austinkregel Aug 3, 2024
2df388b
Basic asset tracker
austinkregel Aug 5, 2024
0b3fb17
Update asset manager
austinkregel Aug 12, 2024
c98389f
Add missing package
austinkregel Aug 12, 2024
3533131
Use sail npm instead of ubuntu npm
austinkregel Aug 14, 2024
81931cb
wip
austinkregel Aug 31, 2024
9506368
Merge branch 'focus-crud-manager' of github.com:austinkregel/spork in…
austinkregel Aug 31, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/php-unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ jobs:
touch storage/logs/crontab.log
touch storage/logs/horizon.log
touch database/database.sqlite
npm install
./bin/sail npm install
cp .env.ci .env
./bin/sail up -d
npm run build
./bin/sail npm run build
- name: Run tests
run: |
./bin/sail art key:generate
Expand Down
30 changes: 0 additions & 30 deletions .github/workflows/phpstan.yml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# What is spork?
Spork is a personal multi-tool, a place to let my creativity run while and automate random tasks.
Spork is a personal multi-tool, a place to let my creativity run wild and automate random tasks.

# How do I run it?
If you'd like to get this project up and running, it's pretty straight forward using docker and Laravel sail. Other deployment methods are not supported officially, but will likely work with little issue. I deploy this personally using Laravel Forge.
Expand Down
47 changes: 47 additions & 0 deletions app/Actions/Spork/Servers/Manage/RestartAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

namespace App\Actions\Spork\Servers\Manage;

use App\Actions\Spork\CustomAction;
use App\Contracts\ActionInterface;
use App\Models\Server;
use App\Services\SshService;
use Illuminate\Http\Request;

class RestartAction extends CustomAction implements ActionInterface
{
public function __construct(
$name = 'Restart server',
$slug = 'restart-servers'
) {
parent::__construct($name, $slug, models: [Server::class]);
}

/**
* @throws \Exception
*/
public function __invoke(Request $request)
{
$request->validate([
'items' => 'required|array',
]);

$servers = Server::query()
->whereIn('id', $request->input('items'))
->get();

foreach ($servers as $server) {
$sshService = new SshService(
$server->ip,
$server->username,
$server->credential->public_key,
$server->credential->private_key,
$server->port,
decrypt($server->credential->pass_key)
);
$sshService->execute('reboot');
}
}
}
36 changes: 36 additions & 0 deletions app/Actions/Spork/Servers/Manage/StartAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace App\Actions\Spork\Servers\Manage;

use App\Actions\Spork\CustomAction;
use App\Contracts\ActionInterface;
use App\Models\Server;
use Illuminate\Http\Request;

class StartAction extends CustomAction implements ActionInterface
{
public function __construct(
$name = 'Start a server',
$slug = 'start-servers'
) {
parent::__construct($name, $slug, models: [Server::class]);
}

/**
* @throws \Exception
*/
public function __invoke(Request $request)
{
$request->validate([
'items' => 'required|array',
]);

$servers = Server::query()
->whereIn('id', $request->input('items'))
->get();

/// Hmm can't exactly ssh to turn these things on...
}
}
47 changes: 47 additions & 0 deletions app/Actions/Spork/Servers/Manage/StopAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

namespace App\Actions\Spork\Servers\Manage;

use App\Actions\Spork\CustomAction;
use App\Contracts\ActionInterface;
use App\Models\Server;
use App\Services\SshService;
use Illuminate\Http\Request;

class StopAction extends CustomAction implements ActionInterface
{
public function __construct(
$name = 'Stop a server',
$slug = 'stop-servers'
) {
parent::__construct($name, $slug, models: [Server::class]);
}

/**
* @throws \Exception
*/
public function __invoke(Request $request)
{
$request->validate([
'items' => 'required|array',
]);

$servers = Server::query()
->whereIn('id', $request->input('items'))
->get();

foreach ($servers as $server) {
$sshService = new SshService(
$server->ip,
$server->username,
$server->credential->public_key,
$server->credential->private_key,
$server->port,
decrypt($server->credential->pass_key)
);
$sshService->execute('shutdown -h');
}
}
}
14 changes: 12 additions & 2 deletions app/Actions/Spork/SyncDataFromCredential.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use App\Models\Credential;
use Illuminate\Contracts\Bus\Dispatcher;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Bus;

class SyncDataFromCredential extends CustomAction implements ActionInterface
{
Expand All @@ -19,10 +20,19 @@ public function __construct($name = 'Sync Data From Credential', $slug = 'sync-d

public function __invoke(Dispatcher $dispatcher, Request $request)
{
$credentials = Credential::where('user_id', $request->user()->id)->whereIn('id', $request->get('items'))->get();
$credentials = Credential::query()
->where('user_id', $request->user()->id)
->whereIn('id', $request->get('items'))
->whereNotIn('type', [
// These aren't managed by a syncing php process.
'matrix',
'ssh',
])
->get();

foreach ($credentials as $credential) {
$dispatcher->dispatch(new FetchResourcesFromCredential($credential));
Bus::batch([new FetchResourcesFromCredential($credential)])
->dispatch();
}
}
}
29 changes: 29 additions & 0 deletions app/Console/Commands/BulkScoutImport.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace App\Console\Commands;

use App\Services\Code;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Artisan;
use Laravel\Scout\Searchable;

class BulkScoutImport extends Command
{
protected $signature = 'scout:bulk-import';

protected $description = 'Command description';

public function handle()
{
$searchableModels = Code::instancesOf(Searchable::class)
->getClasses();

foreach ($searchableModels as $model) {
Artisan::call('scout:import', [
'model' => $model,
], $this->output);
}
}
}
59 changes: 59 additions & 0 deletions app/Console/Commands/Initialize.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

declare(strict_types=1);

namespace App\Console\Commands;

use App\Models\Credential;
use App\Models\User;
use App\Services\SshKeyGeneratorService;
use Illuminate\Console\Command;
use Illuminate\Support\Str;

class Initialize extends Command
{
protected $signature = 'app:initialize';

protected $description = 'Initialize the application';

public function handle()
{
if (Credential::where('type', Credential::TYPE_SSH)->exists()) {
$this->info('SSH key already exists');

return;
}

if (! User::exists()) {
$this->call('make:user');
}

$randomName = Str::random(16);
$passKey = Str::random(16);

[$privateKey, $publicKey] = SshKeyGeneratorService::generate($passKey);

$publicKeyFile = storage_path('app/keys/'.$randomName.'.pub');
$privateKeyFile = storage_path('app/keys/'.$randomName);

file_put_contents($publicKeyFile, $publicKey);
chmod($publicKeyFile, 0600);
file_put_contents($privateKeyFile, $privateKey);
chmod($privateKeyFile, 0600);

Credential::create([
'service' => Credential::TYPE_SSH,
'type' => Credential::TYPE_SSH,
'name' => 'SSH',
'user_id' => User::first()->id,
'api_key' => Str::random(32),
'settings' => [
'pub_key' => $publicKey,
'pub_key_file' => $publicKeyFile,
'private_key' => encrypt($privateKey),
'private_key_file' => $privateKeyFile,
'pass_key' => ! empty($passKey) ? encrypt($passKey) : '',
],
]);
}
}
12 changes: 12 additions & 0 deletions app/Contracts/Services/Documents/PdfParserServiceContract.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace App\Contracts\Services\Documents;

interface PdfParserServiceContract
{
public function getPdfTextFromFile(string $filename): string;

public function getPdfTextFromRawContent(string $contents): string;
}
5 changes: 0 additions & 5 deletions app/Events/AbstractLogicalEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,4 @@
abstract class AbstractLogicalEvent implements LogicalEvent
{
use Dispatchable, InteractsWithQueue, InteractsWithSockets, SerializesModels;

public function broadcastConnections(): array
{
return ['pusher'];
}
}
2 changes: 2 additions & 0 deletions app/Events/Models/Article/ArticleCreated.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ public function __construct(
) {
}
}


13 changes: 12 additions & 1 deletion app/Events/Models/Server/ServerCreated.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,22 @@

use App\Events\AbstractLogicalEvent;
use App\Models\Server;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;

class ServerCreated extends AbstractLogicalEvent
class ServerCreated extends AbstractLogicalEvent implements ShouldBroadcastNow
{
public function __construct(
public Server $model,
) {
}

public function broadcastOn()
{
$this->model->load('credential');

return [
new PrivateChannel('App.Models.User.'.$this->model->credential->user_id),
];
}
}
13 changes: 12 additions & 1 deletion app/Events/Models/Server/ServerCreating.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,22 @@

use App\Events\AbstractLogicalEvent;
use App\Models\Server;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;

class ServerCreating extends AbstractLogicalEvent
class ServerCreating extends AbstractLogicalEvent implements ShouldBroadcastNow
{
public function __construct(
public Server $model,
) {
}

public function broadcastOn()
{
$this->model->load('credential');

return [
new PrivateChannel('App.Models.User.'.$this->model->credential->user_id),
];
}
}
Loading
Loading