-
-
Notifications
You must be signed in to change notification settings - Fork 254
feat: add support for changing docker labels via application api #1939
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
base: main
Are you sure you want to change the base?
Changes from all commits
2254c38
12053f7
13814b8
785124a
3a401a5
70ae7e9
a5350c2
321e9fe
605b3e7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,27 @@ | ||||||||||||||||||||
| <?php | ||||||||||||||||||||
|
|
||||||||||||||||||||
| namespace App\Rules; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| use Closure; | ||||||||||||||||||||
| use Illuminate\Contracts\Validation\ValidationRule; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| class DockerLabel implements ValidationRule | ||||||||||||||||||||
| { | ||||||||||||||||||||
| /** | ||||||||||||||||||||
| * Run the validation rule. | ||||||||||||||||||||
| * | ||||||||||||||||||||
| * @param \Closure(string, ?string=): \Illuminate\Translation\PotentiallyTranslatedString $fail | ||||||||||||||||||||
| */ | ||||||||||||||||||||
| public function validate(string $attribute, mixed $value, Closure $fail): void | ||||||||||||||||||||
| { | ||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check if it's an array
Suggested change
|
||||||||||||||||||||
| foreach (array_keys($value) as $key) { | ||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add type check before calling array_keys(). The Apply this diff: public function validate(string $attribute, mixed $value, Closure $fail): void
{
+ if (!is_array($value)) {
+ $fail("{$attribute} must be an array.");
+ return;
+ }
+
foreach (array_keys($value) as $key) {📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||
| // Docker labels are validated via https://regex101.com/r/FiYrwo/2 following Docker key format | ||||||||||||||||||||
| // recommendations: https://docs.docker.com/engine/manage-resources/labels/ | ||||||||||||||||||||
| if (!preg_match('/^(?!(?:com\.docker\.|io\.docker\.|org\.dockerproject\.))(?=.*[a-z]$)[a-z](?:[a-z0-9]|(?<!\.)\.(?!\.)|(?<!-)-(?!-)|\/|_)*$/', $key)) { | ||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please make this a constant with a description: Keep those same comments with the constant. @Boy132 we can piggyback off this later with real validation. |
||||||||||||||||||||
| $fail("{$attribute} contains an invalid label: {$key}"); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| return; | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add
use HasValidation { getRules as getValidationRules; }