-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate.ps1
More file actions
84 lines (70 loc) · 2.63 KB
/
Copy pathvalidate.ps1
File metadata and controls
84 lines (70 loc) · 2.63 KB
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
83
84
function Test-SetupParams([ref] $messages,
[string[]] $stringParameterNames,
[string[]] $positiveIntParameterNames,
[string] $rootPwd,
[string] $replicatorPwd,
[int] $replicaCount,
[int] $lowerCaseTableNames,
[string] $workDirectory,
[string[]] $extraValuesFiles) {
$messages.Value = @()
$useReplication = $replicaCount -gt 0
### Validate string parameters
$emptyStringExceptionList = @()
if (-not $useReplication) {
$emptyStringExceptionList += ('replicatorPwd','replicaName')
}
$stringParameterNames | ForEach-Object {
$var = Get-Variable -Name $_
$onExceptionList = $emptyStringExceptionList -contains $_
if (-not $onExceptionList -and [string]::IsNullOrWhiteSpace($var.Value)) {
$messages.Value += "Invalid string value for parameter; please specify a value for -$($var.Name)."
}
}
### Validate positive int parameters
$positiveIntParameterNames | ForEach-Object {
$var = (Get-Variable -Name $_)
if ($var.Value -lt 0) {
$messages.Value += "Invalid int value for parameter; please specify a number greater than 0 for -$($var.Name)."
}
}
### Validate choice parameters
$validLowerCaseTableNames = 0,1,2
if ($validLowerCaseTableNames -notcontains $lowerCaseTableNames) {
$messages.Value += "Invalid choice for parameter; please specify a valid value ($validLowerCaseTableNames) for -lowerCaseTableNames."
}
### Validate work directory
if (-not (Test-Path $workDirectory -PathType Container)) {
$messages.Value += "Invalid directory ($workDir) for parameter -workDir; please specify an existing directory."
}
### Validate extra values files
$extraValuesFiles | ForEach-Object {
if (-not (Test-Path $_ -PathType Any)) {
$messages.Value += "Invalid values file ($_); please specify existing values files."
}
}
$passwordsToCheck = @([tuple]::create('rootPwd', $rootPwd))
if ($useReplication) {
$passwordsToCheck += [tuple]::create('replicatorPwd', $replicatorPwd)
}
$passwordsToCheck | ForEach-Object {
$passwordMessages = @()
if (-not (Test-MariaDBPassword ([ref]$passwordMessages) $_.item1 $_.item2 )) {
$passwordMessages | ForEach-Object {
$messages.Value += $_
}
}
}
$messages.Value.count -eq 0
}
function Test-MariaDBPassword([ref] $messages, [string] $paramName, [string] $paramValue) {
$messages.Value = @()
$paramValueLength = $paramValue.Length
if ($paramValueLength -lt 8 -or $paramValueLength -gt 32) {
$messages.Value += "Value for parameter -$paramName must be between 8 and 32 characters"
}
if ($paramValue.Contains("-")) {
$messages.Value += "Value for parameter -$paramName must not contain a single quote character"
}
$messages.Value.count -eq 0
}