Skip to content
This repository was archived by the owner on May 14, 2025. It is now read-only.

Commit d1876e2

Browse files
committed
Task / Scheduler: enforce rules for deployment properties
Resolves #937 Deployment properties: the key should start with ‘app.’ or ‘deployer.’ or ‘scheduler.’
1 parent 672ad9f commit d1876e2

File tree

6 files changed

+63
-23
lines changed

6 files changed

+63
-23
lines changed

ui/src/app/tasks/task-launch/task-launch.component.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ <h2>Task Arguments</h2>
3131
<td>
3232
<div [class.has-error]="form.get('args.' + i).invalid">
3333
<input formControlName="key" type="text" class="form-control"/>
34-
<div *ngIf="form.get('args.' + i + '.key').invalid"
35-
class="help-block">Invalid key
34+
<div *ngIf="form.get('args.' + i + '.key').invalid" class="help-block">
35+
Invalid key
3636
</div>
3737
<div *ngIf="form.get('args.' + i).invalid" class="help-block">
3838
Invalid key
@@ -79,10 +79,10 @@ <h2>Task Properties</h2>
7979
<td>
8080
<div [class.has-error]="form.get('params.' + i).invalid">
8181
<input formControlName="key" type="text" class="form-control"/>
82-
<div *ngIf="form.get('params.' + i + '.key').invalid"
83-
class="help-block">Invalid key
82+
<div *ngIf="form.get('params.' + i + '.key').invalid" class="help-block">
83+
The key should start with `app.` or `deployer.` or `scheduler.`.
8484
</div>
85-
<div *ngIf="form.get('params.' + i).invalid" class="help-block">
85+
<div *ngIf="form.get('params.' + i).invalid && !form.get('params.' + i + '.key').invalid" class="help-block">
8686
Invalid key
8787
</div>
8888
</div>

ui/src/app/tasks/task-launch/task-launch.component.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,23 +80,23 @@ export class TaskLaunchComponent implements OnInit, OnDestroy {
8080
'args': new FormArray([])
8181
});
8282
const isEmpty = (dictionary): boolean => Object.entries(dictionary).every((a) => a[1] === '');
83-
const clean = (array: FormArray, addFunc) => {
83+
const clean = (array: FormArray, addFunc, keyValidator: boolean) => {
8484
if (!isEmpty(array.controls[array.controls.length - 1].value)) {
85-
return addFunc(array);
85+
return addFunc(array, keyValidator);
8686
}
8787
};
88-
const add = (arr: FormArray) => {
88+
const add = (arr: FormArray, keyValidator: boolean) => {
8989
const group = new FormGroup({
90-
'key': new FormControl(''),
90+
'key': new FormControl('', keyValidator ? TaskLaunchValidator.key : null),
9191
'val': new FormControl('')
9292
}, { validators: TaskLaunchValidator.keyRequired });
9393
group.valueChanges.subscribe(() => {
94-
clean(arr, add);
94+
clean(arr, add, keyValidator);
9595
});
9696
arr.push(group);
9797
};
98-
add(this.form.get('params') as FormArray);
99-
add(this.form.get('args') as FormArray);
98+
add(this.form.get('params') as FormArray, true);
99+
add(this.form.get('args') as FormArray, false);
100100
}
101101

102102
/**

ui/src/app/tasks/task-launch/task-launch.validator.spec.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {FormControl, FormGroup} from '@angular/forms';
1+
import { FormControl, FormGroup } from '@angular/forms';
22
import { TaskLaunchValidator } from './task-launch.validator';
33

44
/**
@@ -35,4 +35,27 @@ describe('TaskLaunchValidator', () => {
3535
});
3636
});
3737

38+
describe('key', () => {
39+
it('invalid', () => {
40+
[
41+
'foo',
42+
'foo.bar',
43+
'apps.aaa'
44+
].forEach((mock) => {
45+
const control: FormControl = new FormControl(mock);
46+
expect(TaskLaunchValidator.key(control).invalid).toBeTruthy();
47+
});
48+
});
49+
it('valid', () => {
50+
[
51+
'app.foo',
52+
'deployer.foo',
53+
'scheduler.foo',
54+
].forEach((mock) => {
55+
const control: FormControl = new FormControl(mock);
56+
expect(TaskLaunchValidator.key(control)).toBeNull();
57+
});
58+
});
59+
});
60+
3861
});

ui/src/app/tasks/task-launch/task-launch.validator.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,18 @@ export class TaskLaunchValidator {
2424
return { invalid: true };
2525
}
2626

27+
/**
28+
* Key should start with app. or deployer. or scheduler if not empty
29+
*
30+
* @param {FormControl} control
31+
* @returns {any}
32+
*/
33+
static key(control: FormControl) {
34+
const value = control.value;
35+
if (value && !value.startsWith('app.') && !value.startsWith('deployer.') && !value.startsWith('scheduler.')) {
36+
return { invalid: true };
37+
}
38+
return null;
39+
}
40+
2741
}

ui/src/app/tasks/task-schedule-create/task-schedule-create.component.html

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,13 @@ <h3>Task Properties</h3>
163163
<td>
164164
<div [class.has-error]="submitted && form.get('params.' + i).invalid">
165165
<input formControlName="key" type="text" class="form-control input-sm"/>
166-
<div *ngIf="submitted && form.get('params.' + i + '.key').invalid" class="help-block">Invalid
167-
key
166+
<div *ngIf="submitted && form.get('params.' + i + '.key').invalid" class="help-block">
167+
The key should start with `app.` or `deployer.` or `scheduler.`.
168+
</div>
169+
<div class="help-block"
170+
*ngIf="submitted && form.get('params.' + i).invalid && !form.get('params.' + i + '.key').invalid">
171+
Invalid key
168172
</div>
169-
<div *ngIf="submitted && form.get('params.' + i).invalid" class="help-block">Invalid key</div>
170173
</div>
171174
</td>
172175
<td>

ui/src/app/tasks/task-schedule-create/task-schedule-create.component.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,23 +139,23 @@ export class TaskScheduleCreateComponent implements OnInit {
139139
'args': new FormArray([])
140140
});
141141
const isEmpty = (dictionary): boolean => Object.entries(dictionary).every((a) => a[1] === '');
142-
const clean = (array: FormArray, addFunc) => {
142+
const clean = (array: FormArray, addFunc, keyValidator: boolean) => {
143143
if (!isEmpty(array.controls[array.controls.length - 1].value)) {
144-
return addFunc(array);
144+
return addFunc(array, keyValidator);
145145
}
146146
};
147-
const add = (arr: FormArray) => {
147+
const add = (arr: FormArray, keyValidator: boolean) => {
148148
const group = new FormGroup({
149-
'key': new FormControl(''),
149+
'key': new FormControl('', keyValidator ? TaskLaunchValidator.key : null),
150150
'val': new FormControl('')
151151
}, { validators: TaskLaunchValidator.keyRequired });
152152
group.valueChanges.subscribe(() => {
153-
clean(arr, add);
153+
clean(arr, add, keyValidator);
154154
});
155155
arr.push(group);
156156
};
157-
add(this.form.get('params') as FormArray);
158-
add(this.form.get('args') as FormArray);
157+
add(this.form.get('params') as FormArray, true);
158+
add(this.form.get('args') as FormArray, false);
159159
}
160160

161161
/**

0 commit comments

Comments
 (0)