From: Avan Thakkar Date: Fri, 28 Jan 2022 16:38:56 +0000 (+0530) Subject: mgr/dashboard: add snmp destination validation X-Git-Tag: v16.2.8~207^2~1 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=9f482f9fe319d5f53471483b3c99d8db88ac1597;p=ceph.git mgr/dashboard: add snmp destination validation Signed-off-by: Avan Thakkar (cherry picked from commit 81c93a21ff64e6aeeeba2c88db4f61b13352f565) --- diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.html b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.html index 34b272baea079..8e4623be367f1 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.html +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.html @@ -464,6 +464,9 @@ This field is required. + The value does not match the pattern: hostname:port diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.spec.ts index 1667f6697b6e5..3cc921403f9bc 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.spec.ts @@ -484,6 +484,12 @@ x4Ea7kGVgx9kWh5XjWz9wjZvY49UKIT5ppIAWPMbLl3UpfckiuNhTA== } }); }); + it('should submit invalid snmp destination', () => { + formHelper.setValue('snmp_version', 'V2c'); + formHelper.setValue('snmp_destination', '192.168.20.1'); + formHelper.setValue('snmp_community', 'public'); + formHelper.expectError('snmp_destination', 'snmpDestinationPattern'); + }); }); describe('check edit fields', () => { diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.ts index 28bae956298b0..517f05597ad09 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.ts @@ -28,6 +28,7 @@ import { TaskWrapperService } from '~/app/shared/services/task-wrapper.service'; }) export class ServiceFormComponent extends CdForm implements OnInit { readonly RGW_SVC_ID_PATTERN = /^([^.]+)(\.([^.]+)\.([^.]+))?$/; + readonly SNMP_DESTINATION_PATTERN = /^[^\:]+:[0-9]/; @ViewChild(NgbTypeahead, { static: false }) typeahead: NgbTypeahead; @@ -217,12 +218,20 @@ export class ServiceFormComponent extends CdForm implements OnInit { snmp_version: [null, [Validators.required]], snmp_destination: [ null, - [ - CdValidators.requiredIf({ - service_type: 'snmp-gateway', - unmanaged: false - }) - ] + { + validators: [ + CdValidators.requiredIf({ + service_type: 'snmp-gateway', + unmanaged: false + }), + CdValidators.custom('snmpDestinationPattern', (value: string) => { + if (_.isEmpty(value)) { + return false; + } + return !this.SNMP_DESTINATION_PATTERN.test(value); + }) + ] + } ], engine_id: [ null,