-
Notifications
You must be signed in to change notification settings - Fork 85
/
WorkflowValidator.ts
82 lines (74 loc) · 2.73 KB
/
WorkflowValidator.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright Contributors to the Zowe Project.
*
*/
import { AbstractSession, TextUtils, ImperativeExpect, ImperativeError } from "@zowe/imperative";
import { noSession } from "@zowe/core-for-zowe-sdk";
/**
* Class validates parameters for workflows commands.
* @export
* @class WorkflowValidator
*/
export class WorkflowValidator {
/**
* Validate session
* @static
* @param {AbstractSession} session - z/OSMF connection info
* @memberof WorkflowValidator
*/
public static validateSession(session: AbstractSession) {
ImperativeExpect.toNotBeNullOrUndefined(session,
TextUtils.formatMessage(noSession.message));
}
/**
* Validate supplied parameters
* @static
* @param {string} text - string to check if not null or undefined
* @param {string} errorMsg - message to show in case validation fails
* @memberof WorkflowValidator
*/
public static validateString(text: string, errorMsg: string) {
ImperativeExpect.toNotBeNullOrUndefined(text, errorMsg);
}
/**
* Validate supplied parameters
* @static
* @param {string} text - string to check if empty
* @param {string} errorMsg - message to show in case validation fails
* @memberof WorkflowValidator
*/
public static validateNotEmptyString(text: string, errorMsg: string) {
ImperativeExpect.toNotBeEqual("", text, errorMsg);
WorkflowValidator.validateString(text, errorMsg);
}
/**
* Validate supplied string for parameters if there is not value "?" or "&"
* @static
* @param {string} parameterValue - check if the provided parameters does not contain value "?" or "&"
* @param {string} errorMsg - message to show in case validation fails
* @memberof WorkflowValidator
*/
public static validateParameter(parameterValue: string, errorMsg: string) {
const result: boolean = /^[^+?&]+$/.test(parameterValue);
if(!result){
throw new ImperativeError({msg : errorMsg});
}
}
/**
* Validate supplied parameter
* @static
* @param {string} userID - string to check if it is valid user ID regarding IBM
* @param {string} errorMsg - message to show in case validation fails
* @memberof WorkflowValidator
*/
public static validateOwner(userID: string, errorMsg: string) {
const result = new RegExp(/^[a-zA-Z0-9#$@]{1,8}$/).test(userID);
ImperativeExpect.toBeEqual(true, result, errorMsg);
}
}