-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathManagerCore.ps1
77 lines (64 loc) · 1.74 KB
/
ManagerCore.ps1
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
function Get-Data {
param(
[string]$Path,
[Parameter(Mandatory = $true)]
[string]$LeftKey,
[Parameter(Mandatory = $true)]
[string]$RightKey
)
if ( -not (Test-Path $Path)) {
Write-Host "Error: Missing data file."
exit 1
}
$data = @()
$lines = Get-Content $Path
foreach ($line in $lines) {
if ($line -match '^\s*#') {
continue
}
$line = $line -replace '\s*#.*$'
$parts = $line -split ':'
if ($parts.Count -eq 2) {
if($null -eq $parts[0] -or $null -eq $parts[1]) {
continue
}
$project = @{
"$LeftKey" = $parts[0]
"$RightKey" = $parts[1]
}
$data += $project
}
else {
Write-Host "Error: Missing parameter(s) in the line: $line"
exit
}
}
if($data.Count -eq 0) {
Write-Host "Warning: No usable data found"
exit
}
Write-Host $("Discovered data count: " + $data.Count)
Write-Host ""
return $data
}
function Get-Environment-Variables {
param(
[string]$Path,
[string[]]$RequiredVariables
)
if (-not (Test-Path $Path)) {
Write-Host "The .env file does not exist."
exit 1
}
$envVariables = @{}
get-content $Path | ForEach-Object {
$name, $value = $_.split('=')
set-content env:\$name $value
$envVariables[$name] = $value
}
$missingVariables = $RequiredVariables | Where-Object { $null -eq $envVariables[$_] }
if ($missingVariables.Count -gt 0) {
Write-Host "Missing required variables: $($missingVariables -join ', ')"
exit 1
}
}