1- $ErrorActionPreference = “ Stop”
2- $userSecretsId = " dibix"
3-
4- # region Functions
5- function Read-ValueFromUserInput ([string ] $msg , [string ] $currentValue )
6- {
7- if ($silent )
8- {
9- $currentValue
10- }
11- else
12- {
13- $prompt = Read-Host " $msg [$ ( $currentValue ) ]"
14- ($currentValue , $prompt )[[bool ]$prompt ]
15- }
16- }
17-
18- function Exec ($cmd )
19- {
20- Invoke-Expression " & $cmd "
21-
22- if ($LASTEXITCODE -ne 0 )
23- {
24- throw " Command '$cmd ' returned exit code $LASTEXITCODE ."
25- }
26- }
27-
28- function Get-Secret ($key , $id )
29- {
30- $secretsDirectory = & {
31- if ($IsWindows -ne $False ) { Join-Path $env: APPDATA - ChildPath " Microsoft" | Join-Path - ChildPath " UserSecrets" }
32- else { Join-Path $env: HOME - ChildPath " .microsoft" | Join-Path - ChildPath " usersecrets" }
33- }
34- $secretsPath = Join-Path $secretsDirectory - ChildPath " $id " | Join-Path - ChildPath " secrets.json"
35- if (Test-Path $secretsPath )
36- {
37- $secrets = Get-Content $secretsPath | Out-String | ConvertFrom-Json
38- $secrets .$key
39- }
40- }
41-
42- function Set-Secret ($key , $value , $id )
43- {
44- Exec " dotnet user-secrets set $key "" $value "" --id $id "
45- }
46- # endregion
47-
48- $connectionStringKey = " Database:ConnectionString"
49-
50- $connectionString = Get-Secret $connectionStringKey $userSecretsId
51- $connectionString = Read-ValueFromUserInput " Enter connection string:" $connectionString
52-
1+ $ErrorActionPreference = “ Stop”
2+ $userSecretsId = " dibix"
3+
4+ # region Functions
5+ function Read-ValueFromUserInput ([string ] $msg , [string ] $currentValue )
6+ {
7+ if ($silent )
8+ {
9+ $currentValue
10+ }
11+ else
12+ {
13+ $prompt = Read-Host " $msg [$ ( $currentValue ) ]"
14+ ($currentValue , $prompt )[[bool ]$prompt ]
15+ }
16+ }
17+
18+ function Exec ($cmd )
19+ {
20+ Invoke-Expression " & $cmd "
21+
22+ if ($LASTEXITCODE -ne 0 )
23+ {
24+ throw " Command '$cmd ' returned exit code $LASTEXITCODE ."
25+ }
26+ }
27+
28+ function Get-Secret ($key , $id )
29+ {
30+ $secretsDirectory = & {
31+ if ($IsWindows -ne $False ) { Join-Path $env: APPDATA - ChildPath " Microsoft" | Join-Path - ChildPath " UserSecrets" }
32+ else { Join-Path $env: HOME - ChildPath " .microsoft" | Join-Path - ChildPath " usersecrets" }
33+ }
34+ $secretsPath = Join-Path $secretsDirectory - ChildPath " $id " | Join-Path - ChildPath " secrets.json"
35+ if (Test-Path $secretsPath )
36+ {
37+ $secrets = Get-Content $secretsPath | Out-String | ConvertFrom-Json
38+ $secrets .$key
39+ }
40+ }
41+
42+ function Set-Secret ($key , $value , $id )
43+ {
44+ Exec " dotnet user-secrets set $key "" $value "" --id $id "
45+ }
46+ # endregion
47+
48+ $connectionStringKey = " Database:ConnectionString"
49+
50+ $connectionString = Get-Secret $connectionStringKey $userSecretsId
51+ $connectionString = Read-ValueFromUserInput " Enter connection string:" $connectionString
52+
5353Set-Secret $connectionStringKey $connectionString $userSecretsId
0 commit comments