Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into pelican-dev#249
Browse files Browse the repository at this point in the history
  • Loading branch information
Poseidon281 committed Jun 6, 2024
2 parents d946b20 + e3699f3 commit c3ab0b0
Show file tree
Hide file tree
Showing 107 changed files with 1,347 additions and 1,051 deletions.
8 changes: 5 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ CACHE_STORE=file
QUEUE_CONNECTION=database
SESSION_DRIVER=file

HASHIDS_SALT=
HASHIDS_LENGTH=8

MAIL_MAILER=log
MAIL_HOST=smtp.example.com
MAIL_PORT=25
Expand All @@ -33,3 +30,8 @@ MAIL_FROM_NAME="Pelican Admin"
SESSION_ENCRYPT=false
SESSION_PATH=/
SESSION_DOMAIN=null

# Set this to true, and set start & end ports to auto create allocations.
PANEL_CLIENT_ALLOCATIONS_ENABLED=false
PANEL_CLIENT_ALLOCATIONS_RANGE_START=
PANEL_CLIENT_ALLOCATIONS_RANGE_END=
6 changes: 2 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ jobs:
MAIL_MAILER: array
SESSION_DRIVER: array
QUEUE_CONNECTION: sync
HASHIDS_SALT: alittlebitofsalt1234
DB_CONNECTION: mysql
DB_HOST: 127.0.0.1
DB_DATABASE: testing
Expand All @@ -60,7 +59,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: bcmath, cli, curl, gd, mbstring, mysql, openssl, pdo, tokenizer, xml, zip
extensions: bcmath, curl, gd, mbstring, mysql, openssl, pdo, tokenizer, xml, zip
tools: composer:v2
coverage: none

Expand Down Expand Up @@ -97,7 +96,6 @@ jobs:
MAIL_MAILER: array
SESSION_DRIVER: array
QUEUE_CONNECTION: sync
HASHIDS_SALT: alittlebitofsalt1234
DB_CONNECTION: sqlite
DB_DATABASE: testing.sqlite
steps:
Expand All @@ -121,7 +119,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: bcmath, cli, curl, gd, mbstring, mysql, openssl, pdo, tokenizer, xml, zip
extensions: bcmath, curl, gd, mbstring, mysql, openssl, pdo, tokenizer, xml, zip
tools: composer:v2
coverage: none

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
/public/hot
/public/storage
/storage/*.key
/storage/clockwork/*
/vendor
*.DS_Store*
.env
Expand Down
11 changes: 4 additions & 7 deletions app/Console/Commands/Environment/AppSettingsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class AppSettingsCommand extends Command
protected $description = 'Configure basic environment settings for the Panel.';

protected $signature = 'p:environment:setup
{--new-salt : Whether or not to generate a new salt for Hashids.}
{--url= : The URL that this Panel is running on.}
{--cache= : The cache driver backend to use.}
{--session= : The session driver backend to use.}
Expand Down Expand Up @@ -61,10 +60,6 @@ public function handle(): int
{
$this->variables['APP_TIMEZONE'] = 'UTC';

if (empty(config('hashids.salt')) || $this->option('new-salt')) {
$this->variables['HASHIDS_SALT'] = str_random(20);
}

$this->output->comment(__('commands.appsettings.comment.url'));
$this->variables['APP_URL'] = $this->option('url') ?? $this->ask(
'Application URL',
Expand Down Expand Up @@ -123,7 +118,9 @@ public function handle(): int
}

if ($this->variables['QUEUE_CONNECTION'] !== 'sync') {
Artisan::call('p:environment:queue-service', $redisUsed ? ['--use-redis'] : []);
$this->call('p:environment:queue-service', [
'--use-redis' => $redisUsed,
]);
}

$this->info($this->console->output());
Expand All @@ -132,7 +129,7 @@ public function handle(): int
}

/**
* Request connection details and verify them.
* Request redis connection details and verify them.
*/
private function requestRedisSettings(): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function handle(): int
} elseif ($this->variables['DB_CONNECTION'] === 'sqlite') {
$this->variables['DB_DATABASE'] = $this->option('database') ?? $this->ask(
'Database Path',
config('database.connections.sqlite.database', database_path('database.sqlite'))
env('DB_DATABASE', 'database.sqlite')
);
}

Expand Down
36 changes: 24 additions & 12 deletions app/Console/Commands/Environment/QueueWorkerServiceCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,18 @@ class QueueWorkerServiceCommand extends Command

public function handle(): void
{
$serviceName = $this->option('service-name') ?? $this->ask('Service name', 'pelican-queue');
$serviceName = $this->option('service-name') ?? $this->ask('Queue worker service name', 'pelican-queue');
$path = '/etc/systemd/system/' . $serviceName . '.service';

if (file_exists($path) && !$this->option('overwrite') && !$this->confirm('The service file already exists. Do you want to overwrite it?')) {
$this->line('Creation of queue worker service file aborted.');
$fileExists = file_exists($path);
if ($fileExists && !$this->option('overwrite') && !$this->confirm('The service file already exists. Do you want to overwrite it?')) {
$this->line('Creation of queue worker service file aborted because serive file already exists.');

return;
}

$user = $this->option('user') ?? $this->ask('User', 'www-data');
$group = $this->option('group') ?? $this->ask('Group', 'www-data');
$user = $this->option('user') ?? $this->ask('Webserver User', 'www-data');
$group = $this->option('group') ?? $this->ask('Webserver Group', 'www-data');

$afterRedis = $this->option('use-redis') ? '\nAfter=redis-server.service' : '';

Expand All @@ -45,7 +46,7 @@ public function handle(): void
User=$user
Group=$group
Restart=always
ExecStart=/usr/bin/php $basePath/artisan queue:work --queue=high,standard,low --tries=3
ExecStart=/usr/bin/php $basePath/artisan queue:work --tries=3
StartLimitInterval=180
StartLimitBurst=30
RestartSec=5s
Expand All @@ -60,13 +61,24 @@ public function handle(): void
return;
}

$result = Process::run("systemctl enable --now $serviceName.service");
if ($result->failed()) {
$this->error('Error enabling service: ' . $result->errorOutput());
if ($fileExists) {
$result = Process::run("systemctl restart $serviceName.service");
if ($result->failed()) {
$this->error('Error restarting service: ' . $result->errorOutput());

return;
}
return;
}

$this->line('Queue worker service file updated successfully.');
} else {
$result = Process::run("systemctl enable --now $serviceName.service");
if ($result->failed()) {
$this->error('Error enabling service: ' . $result->errorOutput());

$this->line('Queue worker service file created successfully.');
return;
}

$this->line('Queue worker service file created successfully.');
}
}
}
2 changes: 1 addition & 1 deletion app/Console/Commands/Schedule/ProcessRunnableCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ protected function processSchedule(Schedule $schedule)

$this->line(trans('command/messages.schedule.output_line', [
'schedule' => $schedule->name,
'hash' => $schedule->hashid,
'id' => $schedule->id,
]));
} catch (\Throwable|\Exception $exception) {
logger()->error($exception, ['schedule_id' => $schedule->id]);
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/User/MakeUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __construct(private UserCreationService $creationService)
public function handle(): int
{
try {
DB::select('select 1 where 1');
DB::connection()->getPdo();
} catch (Exception $exception) {
$this->error($exception->getMessage());

Expand Down
15 changes: 0 additions & 15 deletions app/Contracts/Extensions/HashidsInterface.php

This file was deleted.

2 changes: 1 addition & 1 deletion app/Exceptions/DisplayException.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function getHeaders(): array
*/
public function render(Request $request)
{
if (str($request->url())->contains('livewire')) {
if ($request->is('livewire/update')) {
Notification::make()
->title(static::class)
->body($this->getMessage())
Expand Down
2 changes: 1 addition & 1 deletion app/Extensions/DynamicDatabaseConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function set(string $connection, DatabaseHost|int $host, string $database
'port' => $host->port,
'database' => $database,
'username' => $host->username,
'password' => decrypt($host->password),
'password' => $host->password,
'charset' => self::DB_CHARSET,
'collation' => self::DB_COLLATION,
]);
Expand Down
22 changes: 0 additions & 22 deletions app/Extensions/Hashids.php

This file was deleted.

18 changes: 1 addition & 17 deletions app/Filament/Resources/ApiKeyResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

use App\Filament\Resources\ApiKeyResource\Pages;
use App\Models\ApiKey;
use Filament\Resources\Components\Tab;
use Filament\Resources\Resource;
use Illuminate\Database\Eloquent\Builder;

class ApiKeyResource extends Resource
{
Expand All @@ -16,28 +14,14 @@ class ApiKeyResource extends Resource

public static function getNavigationBadge(): ?string
{
return static::getModel()::count() ?: null;
return static::getModel()::where('key_type', '2')->count() ?: null;
}

public static function canEdit($record): bool
{
return false;
}

public function getTabs(): array
{
return [
'all' => Tab::make('All Keys'),
'application' => Tab::make('Application Keys')
->modifyQueryUsing(fn (Builder $query) => $query->where('key_type', ApiKey::TYPE_APPLICATION)),
];
}

public function getDefaultActiveTab(): string|int|null
{
return 'application';
}

public static function getRelations(): array
{
return [
Expand Down
22 changes: 4 additions & 18 deletions app/Filament/Resources/ApiKeyResource/Pages/CreateApiKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,16 @@ public function form(Form $form): Form
return $form
->schema([
Forms\Components\Hidden::make('identifier')->default(ApiKey::generateTokenIdentifier(ApiKey::TYPE_APPLICATION)),
Forms\Components\Hidden::make('token')->default(encrypt(str_random(ApiKey::KEY_LENGTH))),
Forms\Components\Hidden::make('token')->default(str_random(ApiKey::KEY_LENGTH)),

Forms\Components\Hidden::make('user_id')
->default(auth()->user()->id)
->required(),

Forms\Components\Select::make('key_type')
Forms\Components\Hidden::make('key_type')
->inlineLabel()
->options(function (ApiKey $apiKey) {
$originalOptions = [
//ApiKey::TYPE_NONE => 'None',
ApiKey::TYPE_ACCOUNT => 'Account',
ApiKey::TYPE_APPLICATION => 'Application',
//ApiKey::TYPE_DAEMON_USER => 'Daemon User',
//ApiKey::TYPE_DAEMON_APPLICATION => 'Daemon Application',
];

return collect($originalOptions)
->filter(fn ($value, $key) => $key <= ApiKey::TYPE_APPLICATION || $apiKey->key_type === $key)
->all();
})
->selectablePlaceholder(false)
->required()
->default(ApiKey::TYPE_APPLICATION),
->default(ApiKey::TYPE_APPLICATION)
->required(),

Forms\Components\Fieldset::make('Permissions')
->columns([
Expand Down
Loading

0 comments on commit c3ab0b0

Please sign in to comment.