UI: Device provisioning autogenerate device key and secret
This commit is contained in:
parent
ab18d74102
commit
e0ac59b94b
@ -403,3 +403,15 @@ export function deepTrim<T>(obj: T): T {
|
|||||||
return acc;
|
return acc;
|
||||||
}, (Array.isArray(obj) ? [] : {}) as T);
|
}, (Array.isArray(obj) ? [] : {}) as T);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function generateSecret(length?: number): string {
|
||||||
|
if (isUndefined(length) || length == null) {
|
||||||
|
length = 1;
|
||||||
|
}
|
||||||
|
const l = length > 10 ? 10 : length;
|
||||||
|
const str = Math.random().toString(36).substr(2, l);
|
||||||
|
if (str.length >= length) {
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
return str.concat(generateSecret(length - str.length));
|
||||||
|
}
|
||||||
|
|||||||
@ -32,7 +32,7 @@ import {
|
|||||||
DeviceProvisionType,
|
DeviceProvisionType,
|
||||||
deviceProvisionTypeTranslationMap
|
deviceProvisionTypeTranslationMap
|
||||||
} from "@shared/models/device.models";
|
} from "@shared/models/device.models";
|
||||||
import { isDefinedAndNotNull } from "@core/utils";
|
import { generateSecret, isDefinedAndNotNull } from '@core/utils';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'tb-device-profile-provision-configuration',
|
selector: 'tb-device-profile-provision-configuration',
|
||||||
@ -85,10 +85,18 @@ export class DeviceProfileProvisionConfigurationComponent implements ControlValu
|
|||||||
this.provisionConfigurationFormGroup.get('type').valueChanges.subscribe((type) => {
|
this.provisionConfigurationFormGroup.get('type').valueChanges.subscribe((type) => {
|
||||||
if (type === DeviceProvisionType.DISABLED) {
|
if (type === DeviceProvisionType.DISABLED) {
|
||||||
this.provisionConfigurationFormGroup.get('provisionDeviceSecret').disable({emitEvent: false});
|
this.provisionConfigurationFormGroup.get('provisionDeviceSecret').disable({emitEvent: false});
|
||||||
this.provisionConfigurationFormGroup.get('provisionDeviceSecret').patchValue(null,{emitEvent: false});
|
this.provisionConfigurationFormGroup.get('provisionDeviceSecret').patchValue(null, {emitEvent: false});
|
||||||
this.provisionConfigurationFormGroup.get('provisionDeviceKey').disable({emitEvent: false});
|
this.provisionConfigurationFormGroup.get('provisionDeviceKey').disable({emitEvent: false});
|
||||||
this.provisionConfigurationFormGroup.get('provisionDeviceKey').patchValue(null);
|
this.provisionConfigurationFormGroup.get('provisionDeviceKey').patchValue(null);
|
||||||
} else {
|
} else {
|
||||||
|
const provisionDeviceSecret: string = this.provisionConfigurationFormGroup.get('provisionDeviceSecret').value;
|
||||||
|
if (!provisionDeviceSecret || !provisionDeviceSecret.length) {
|
||||||
|
this.provisionConfigurationFormGroup.get('provisionDeviceSecret').patchValue(generateSecret(20), {emitEvent: false});
|
||||||
|
}
|
||||||
|
const provisionDeviceKey: string = this.provisionConfigurationFormGroup.get('provisionDeviceKey').value;
|
||||||
|
if (!provisionDeviceKey || !provisionDeviceKey.length) {
|
||||||
|
this.provisionConfigurationFormGroup.get('provisionDeviceKey').patchValue(generateSecret(20), {emitEvent: false});
|
||||||
|
}
|
||||||
this.provisionConfigurationFormGroup.get('provisionDeviceSecret').enable({emitEvent: false});
|
this.provisionConfigurationFormGroup.get('provisionDeviceSecret').enable({emitEvent: false});
|
||||||
this.provisionConfigurationFormGroup.get('provisionDeviceKey').enable({emitEvent: false});
|
this.provisionConfigurationFormGroup.get('provisionDeviceKey').enable({emitEvent: false});
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user