-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSet-SnowflakePassword.ps1
More file actions
62 lines (53 loc) · 1.72 KB
/
Copy pathSet-SnowflakePassword.ps1
File metadata and controls
62 lines (53 loc) · 1.72 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
$ErrorActionPreference = "Stop"
$ProjectRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
$EnvPath = Join-Path $ProjectRoot ".env"
if (!(Test-Path $EnvPath)) {
Copy-Item (Join-Path $ProjectRoot ".env.example") $EnvPath
}
Write-Host ""
Write-Host "Compass Ultra Web Intel - Snowflake Password Setup"
Write-Host "This writes the password only to your local .env file. It does not print it."
Write-Host ""
$SecurePassword = Read-Host "Enter Snowflake password for DACAMERAGIRL" -AsSecureString
$Bstr = [Runtime.InteropServices.Marshal]::SecureStringToBSTR($SecurePassword)
try {
$PlainPassword = [Runtime.InteropServices.Marshal]::PtrToStringBSTR($Bstr)
} finally {
[Runtime.InteropServices.Marshal]::ZeroFreeBSTR($Bstr)
}
$updates = [ordered]@{
"SNOWFLAKE_ACCOUNT" = "CLTFCIZ-ED38268"
"SNOWFLAKE_USER" = "DACAMERAGIRL"
"SNOWFLAKE_AUTHENTICATOR" = ""
"SNOWFLAKE_PASSWORD" = $PlainPassword
"SNOWFLAKE_ROLE" = "ACCOUNTADMIN"
"SNOWFLAKE_WAREHOUSE" = "COMPUTE_WH"
"SNOWFLAKE_DATABASE" = "DATA_OPS"
"SNOWFLAKE_WEB_SCHEMA" = "RAW_WEBSITE_INTEL"
"SNOWFLAKE_STAGING_SCHEMA" = "STAGING"
"SNOWFLAKE_ANALYTICS_SCHEMA" = "ANALYTICS"
"DBT_TARGET" = "prod_password"
}
$lines = Get-Content -LiteralPath $EnvPath
$seen = @{}
$newLines = foreach ($line in $lines) {
if ($line -match '^\s*([A-Za-z_][A-Za-z0-9_]*)\s*=') {
$key = $matches[1]
if ($updates.Contains($key)) {
$seen[$key] = $true
"$key=$($updates[$key])"
} else {
$line
}
} else {
$line
}
}
foreach ($key in $updates.Keys) {
if (!$seen.ContainsKey($key)) {
$newLines += "$key=$($updates[$key])"
}
}
Set-Content -LiteralPath $EnvPath -Value $newLines
Write-Host ""
Write-Host "Snowflake password saved locally. Tell Codex: done"