Repository navigation
Add changes from upstream #2076
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
7b34f7d
change "Github" to "GitHub" for consistency
Boy132 768023e
Disconnect SFTP/Websocket when a user is removed as a subuser
Boy132 34c86c7
Clear allocation notes on server deletion
Boy132 bda9ddd
Don't be strict about upload size, so long as it is a positive integer
Boy132 5fd2c47
Add throttling to resource creation endpoints
Boy132 1c4c68c
Lock the server's resource models when adding new ones
Boy132 5060038
small fix
Boy132 9eca887
fix tests
Boy132 0085fe5
remove duplicate
Boy132 fad5868
fix tests part two
Boy132 02dddcf
fix postgresql
Boy132 85fd11a
remove info about webserver limit
Boy132 c89aa4f
add migration to clear unused allocation notes
Boy132 a28111e
Cast presigned URL lifespan to integer
Boy132 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| <?php | ||
|
|
||
| namespace App\Enums; | ||
|
|
||
| use App\Models\Server; | ||
| use Illuminate\Cache\RateLimiting\Limit; | ||
| use Illuminate\Http\Request; | ||
| use Illuminate\Routing\Middleware\ThrottleRequests; | ||
| use Illuminate\Support\Facades\RateLimiter; | ||
| use Webmozart\Assert\Assert; | ||
|
|
||
| /** | ||
| * A basic resource throttler for individual servers. This is applied in addition | ||
| * to existing rate limits and allows the code to slow down speedy users that might | ||
| * be creating resources a little too quickly for comfort. This throttle generally | ||
| * only applies to creation flows, and not general view/edit/delete flows. | ||
| */ | ||
| enum ResourceLimit: string | ||
| { | ||
| case Websocket = 'websocket'; | ||
| case AllocationCreate = 'allocation-create'; | ||
| case BackupRestore = 'backup-restore'; | ||
| case DatabaseCreate = 'database-create'; | ||
| case ScheduleCreate = 'schedule-create'; | ||
| case SubuserCreate = 'subuser-create'; | ||
| case FilePull = 'file-pull'; | ||
|
|
||
| public function throttleKey(): string | ||
| { | ||
| return "api.client:server-resource:{$this->name}"; | ||
| } | ||
|
|
||
| /** | ||
| * Returns a middleware that will throttle the specific resource by server. This | ||
| * throttle applies to any user making changes to that resource on the specific | ||
| * server, it is NOT per-user. | ||
| */ | ||
| public function middleware(): string | ||
| { | ||
| return ThrottleRequests::using($this->throttleKey()); | ||
| } | ||
|
|
||
| public function limit(): Limit | ||
| { | ||
| return match ($this) { | ||
| self::Websocket => Limit::perMinute(5), | ||
| self::BackupRestore => Limit::perMinutes(15, 3), | ||
| self::DatabaseCreate => Limit::perMinute(2), | ||
| self::SubuserCreate => Limit::perMinutes(15, 10), | ||
| self::FilePull => Limit::perMinutes(10, 5), | ||
| default => Limit::perMinute(2), | ||
| }; | ||
| } | ||
|
|
||
| public static function boot(): void | ||
| { | ||
| foreach (self::cases() as $case) { | ||
| RateLimiter::for($case->throttleKey(), function (Request $request) use ($case) { | ||
| Assert::isInstanceOf($server = $request->route()->parameter('server'), Server::class); | ||
|
|
||
| return $case->limit()->by($server->uuid); | ||
| }); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
database/migrations/2026_01_09_134116_clear_unused_allocation_notes.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| <?php | ||
|
|
||
| use Illuminate\Database\Migrations\Migration; | ||
| use Illuminate\Support\Facades\DB; | ||
|
|
||
| return new class extends Migration | ||
| { | ||
| /** | ||
| * Run the migrations. | ||
| */ | ||
| public function up(): void | ||
| { | ||
| DB::table('allocations') | ||
| ->whereNull('server_id') | ||
| ->update(['notes' => null]); | ||
| } | ||
|
Boy132 marked this conversation as resolved.
|
||
|
|
||
| /** | ||
| * Reverse the migrations. | ||
| */ | ||
| public function down(): void | ||
| { | ||
| // Not needed | ||
| } | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.