@@ -52,45 +52,7 @@ class PSProfileSecret {
52
52
$this.SecureString = $secureString
53
53
}
54
54
}
55
- class PSProfileVault : Hashtable {
56
- [hashtable ] $_secrets
57
55
58
- PSProfileVault() {
59
- $this._secrets = @ { }
60
- }
61
- [void ] SetSecret([string ]$name , [string ]$userName , [securestring ]$password ) {
62
- $this._secrets [$name ] = [PSCredential ]::new(
63
- $userName ,
64
- $password
65
- )
66
- }
67
- [void ] SetSecret([pscredential ]$psCredential ) {
68
- $this._secrets [$psCredential.UserName ] = $psCredential
69
- }
70
- [void ] SetSecret([string ]$name , [pscredential ]$psCredential ) {
71
- $this._secrets [$name ] = $psCredential
72
- }
73
- [void ] SetSecret([string ]$name , [securestring ]$secureString ) {
74
- $this._secrets [$name ] = $secureString
75
- }
76
- [pscredential ] GetSecret() {
77
- if ($env: USERNAME ) {
78
- return $this._secrets [$env: USERNAME ]
79
- }
80
- elseif ($env: USER ) {
81
- return $this._secrets [$env: USER ]
82
- }
83
- else {
84
- return $null
85
- }
86
- }
87
- [object ] GetSecret([string ]$name ) {
88
- return $this._secrets [$name ]
89
- }
90
- [void ] RemoveSecret([string ]$name ) {
91
- $this._secrets.Remove ($name )
92
- }
93
- }
94
56
class PSProfile {
95
57
hidden [System.Collections.Generic.List [PSProfileEvent ]] $Log
96
58
[hashtable ] $_internal
@@ -112,11 +74,11 @@ class PSProfile {
112
74
[string []] $ScriptPaths
113
75
[hashtable ] $SymbolicLinks
114
76
[hashtable ] $Variables
115
- [PSProfileVault ] $Vault
77
+ [hashtable ] $Vault
116
78
117
79
PSProfile() {
118
80
$this.Log = [System.Collections.Generic.List [PSProfileEvent ]]::new()
119
- $this.Vault = [ PSProfileVault ]::new()
81
+ $this.Vault = @ { _secrets = @ {}}
120
82
$this._internal = @ { }
121
83
$this.GitPathMap = @ { }
122
84
$this.PSBuildPathMap = @ { }
@@ -150,17 +112,17 @@ class PSProfile {
150
112
Default = " AWS: "
151
113
}
152
114
}
153
- PSReadline = @ {
154
- Options = @ {}
155
- KeyHandlers = @ {}
115
+ PSReadline = @ {
116
+ Options = @ { }
117
+ KeyHandlers = @ { }
156
118
}
157
119
}
158
120
$this.RefreshFrequency = (New-TimeSpan - Hours 1 ).ToString()
159
121
$this.LastRefresh = [datetime ]::Now.AddHours(-2 )
160
122
$this.LastSave = [datetime ]::Now
161
123
$this.ProjectPaths = @ ()
162
124
$this.PluginPaths = @ ()
163
- $this.InitScripts = @ {}
125
+ $this.InitScripts = @ { }
164
126
$this.ScriptPaths = @ ()
165
127
$this.PathAliases = @ {
166
128
' ~' = [System.Environment ]::GetFolderPath([System.Environment + SpecialFolder ]::UserProfile)
@@ -245,7 +207,7 @@ if ($env:AWS_PROFILE) {
245
207
"`n>> "'
246
208
$plugPaths = @ ((Join-Path $PSScriptRoot " Plugins" ))
247
209
$curVer = (Import-Metadata (Join-Path $PSScriptRoot " PSProfile.psd1" )).ModuleVersion
248
- $this.PluginPaths | Where-Object {-not [string ]::IsNullOrEmpty($_ ) -and ($_ -match " [\/\\](Modules|BuildOutput)[\/\\]PSProfile[\/\\]$curVer " -or $_ -notmatch " [\/\\](Modules|BuildOutput)[\/\\]PSProfile[\/\\]\d+\.\d+\.\d+" ) } | ForEach-Object {
210
+ $this.PluginPaths | Where-Object { -not [string ]::IsNullOrEmpty($_ ) -and ($_ -match " [\/\\](Modules|BuildOutput)[\/\\]PSProfile[\/\\]$curVer " -or $_ -notmatch " [\/\\](Modules|BuildOutput)[\/\\]PSProfile[\/\\]\d+\.\d+\.\d+" ) } | ForEach-Object {
249
211
$plugPaths += $_
250
212
}
251
213
$this.PluginPaths = $plugPaths | Select-Object - Unique
@@ -336,6 +298,7 @@ if ($env:AWS_PROFILE) {
336
298
$content = $content.Replace ($fullValue , " function global:$funcName {" )
337
299
}
338
300
}
301
+ $content = $content -replace ' \$PSDefaultParameterValues' , ' $global:PSDefaultParameterValues'
339
302
return $content
340
303
}
341
304
hidden [void ] _cleanConfig() {
@@ -351,16 +314,16 @@ if ($env:AWS_PROFILE) {
351
314
" Verbose"
352
315
)
353
316
[hashtable []]$final = @ ()
354
- $this .$section | Where-Object {$_ -is [hashtable ] -and $_.Name } | ForEach-Object {
317
+ $this .$section | Where-Object { $_ -is [hashtable ] -and $_.Name } | ForEach-Object {
355
318
$final += $_
356
319
}
357
- $this .$section | Where-Object {$_ -is [string ]} | ForEach-Object {
320
+ $this .$section | Where-Object { $_ -is [string ] } | ForEach-Object {
358
321
$this._log (
359
322
" [$section ] Converting module string to hashtable: $_ " ,
360
323
" CleanConfig" ,
361
324
" Verbose"
362
325
)
363
- $final += @ {Name = $_ }
326
+ $final += @ {Name = $_ }
364
327
}
365
328
$this .$section = $final
366
329
}
@@ -371,7 +334,7 @@ if ($env:AWS_PROFILE) {
371
334
" Verbose"
372
335
)
373
336
[string []]$final = @ ()
374
- $this .$section | Where-Object {-not [string ]::IsNullOrEmpty($_ )} | ForEach-Object {
337
+ $this .$section | Where-Object { -not [string ]::IsNullOrEmpty($_ ) } | ForEach-Object {
375
338
$final += $_
376
339
}
377
340
$this .$section = $final
@@ -638,33 +601,33 @@ if ($env:AWS_PROFILE) {
638
601
$g = 0
639
602
$b = 0
640
603
$pInfo.EnumerateDirectories (' .git' , [System.IO.SearchOption ]::AllDirectories) | ForEach-Object {
641
- $PathName = $_.Parent.BaseName
604
+ $PathName = $_.Parent.Name
642
605
$FullPathName = $_.Parent.FullName
643
606
$g ++
644
607
$this._log (
645
608
" Found git project @ $ ( $FullPathName ) " ,
646
609
' FindProjects' ,
647
610
' Verbose'
648
611
)
649
- $currPath = $_
650
- while ($this.GitPathMap.ContainsKey ($PathName )){
651
- $currPath = $currPath.Parent
652
- $doublePath = [System.IO.DirectoryInfo ]::new($this.GitPathMap [$PathName ])
653
- $this.GitPathMap [" $ ( $doublePath.Parent ) \$ ( $doublePath.BaseName ) " ] = $doublePath.FullName
654
- $this.GitPathMap.Remove ($PathName )
655
- if ($this.PSBuildPathMap.ContainsKey ($PathName )){
656
- $PSBuildPath = [System.IO.DirectoryInfo ]::new($this.PSBuildPathMap [$PathName ])
657
- $this.PSBuildPathMap [" $ ( $PSBuildPath.Parent ) \$ ( $PSBuildPath.BaseName ) " ] = $doublePath.FullName
658
- $this.PSBuildPathMap.Remove ($PathName )
659
- }
660
- $PathName = " $ ( $currPath.Parent.BaseName ) \$PathName "
612
+ $currPath = $_
613
+ while ($this.GitPathMap.ContainsKey ($PathName )) {
614
+ $currPath = $currPath.Parent
615
+ $doublePath = [System.IO.DirectoryInfo ]::new($this.GitPathMap [$PathName ])
616
+ $this.GitPathMap [" $ ( $doublePath.Parent.Name ) $ ( [System.IO.Path ]::DirectorySeparatorChar) $ ( $doublePath.Name ) " ] = $doublePath.FullName
617
+ $this.GitPathMap.Remove ($PathName )
618
+ if ($this.PSBuildPathMap.ContainsKey ($PathName )) {
619
+ $PSBuildPath = [System.IO.DirectoryInfo ]::new($this.PSBuildPathMap [$PathName ])
620
+ $this.PSBuildPathMap [" $ ( $PSBuildPath.Parent.Name ) $ ( [System.IO.Path ]::DirectorySeparatorChar) $ ( $PSBuildPath.Name ) " ] = $doublePath.FullName
621
+ $this.PSBuildPathMap.Remove ($PathName )
661
622
}
623
+ $PathName = " $ ( $currPath.Parent.BaseName ) $ ( [System.IO.Path ]::DirectorySeparatorChar) $PathName "
624
+ }
662
625
$this.GitPathMap [$PathName ] = $FullPathName
663
626
$bldPath = [System.IO.Path ]::Combine($FullPathName , ' build.ps1' )
664
627
if ([System.IO.File ]::Exists($bldPath )) {
665
628
$b ++
666
629
$this._log (
667
- " Found build script @ $ ( $_ .FullName ) " ,
630
+ " Found build script @ $ ( $bldPath ) " ,
668
631
' FindProjects' ,
669
632
' Verbose'
670
633
)
@@ -954,74 +917,74 @@ if ($env:AWS_PROFILE) {
954
917
)
955
918
if ($this.Plugins.Count ) {
956
919
$this.Plugins.ForEach ( {
957
- if ($_.Name -ne ' PSProfile.PowerTools' ) {
958
- $plugin = $_
959
- $this._log (
960
- " '$ ( $plugin.Name ) ' Searching for plugin" ,
961
- ' LoadPlugins' ,
962
- ' Verbose'
963
- )
964
- try {
965
- $found = $null
966
- $importParams = @ {
967
- ErrorAction = ' Stop'
968
- Global = $true
969
- }
970
- if ($plugin.ArgumentList ) {
971
- $importParams [' ArgumentList' ] = $plugin.ArgumentList
972
- }
973
- [string []]$pathsToSearch = @ ($this.PluginPaths )
974
- $env: PSModulePath.Split ([System.IO.Path ]::PathSeparator) | ForEach-Object {
975
- $pathsToSearch += $_
976
- }
977
- foreach ($plugPath in $pathsToSearch ) {
978
- $fullPath = [System.IO.Path ]::Combine($plugPath , " $ ( $plugin.Name ) .ps1" )
979
- $this._log (
980
- " '$ ( $plugin.Name ) ' Checking path: $fullPath " ,
981
- ' LoadPlugins' ,
982
- ' Debug'
983
- )
984
- if (Test-Path $fullPath ) {
985
- $sb = [scriptblock ]::Create($this._globalize (([System.IO.File ]::ReadAllText($fullPath ))))
986
- if ($plugin.ArgumentList ) {
987
- .$sb ($plugin.ArgumentList )
988
- }
989
- else {
990
- .$sb
991
- }
992
- $found = $fullPath
993
- break
920
+ if ($_.Name -ne ' PSProfile.PowerTools' ) {
921
+ $plugin = $_
922
+ $this._log (
923
+ " '$ ( $plugin.Name ) ' Searching for plugin" ,
924
+ ' LoadPlugins' ,
925
+ ' Verbose'
926
+ )
927
+ try {
928
+ $found = $null
929
+ $importParams = @ {
930
+ ErrorAction = ' Stop'
931
+ Global = $true
994
932
}
995
- }
996
- if ($null -ne $found ) {
997
- $this._log (
998
- " '$ ( $plugin.Name ) ' plugin loaded from path: $found " ,
999
- ' LoadPlugins' ,
1000
- ' Verbose'
1001
- )
1002
- }
1003
- else {
1004
- if ($null -ne $plugin.Name -and $null -ne (Get-Module $plugin.Name - ListAvailable - ErrorAction SilentlyContinue)) {
1005
- Import-Module $plugin.Name @importParams
933
+ if ($plugin.ArgumentList ) {
934
+ $importParams [' ArgumentList' ] = $plugin.ArgumentList
935
+ }
936
+ [string []]$pathsToSearch = @ ($this.PluginPaths )
937
+ $env: PSModulePath.Split ([System.IO.Path ]::PathSeparator) | ForEach-Object {
938
+ $pathsToSearch += $_
939
+ }
940
+ foreach ($plugPath in $pathsToSearch ) {
941
+ $fullPath = [System.IO.Path ]::Combine($plugPath , " $ ( $plugin.Name ) .ps1" )
1006
942
$this._log (
1007
- " '$ ( $plugin.Name ) ' plugin loaded from PSModulePath!" ,
1008
- ' LoadPlugins'
943
+ " '$ ( $plugin.Name ) ' Checking path: $fullPath " ,
944
+ ' LoadPlugins' ,
945
+ ' Debug'
1009
946
)
947
+ if (Test-Path $fullPath ) {
948
+ $sb = [scriptblock ]::Create($this._globalize (([System.IO.File ]::ReadAllText($fullPath ))))
949
+ if ($plugin.ArgumentList ) {
950
+ .$sb ($plugin.ArgumentList )
951
+ }
952
+ else {
953
+ .$sb
954
+ }
955
+ $found = $fullPath
956
+ break
957
+ }
1010
958
}
1011
- else {
959
+ if ( $null -ne $found ) {
1012
960
$this._log (
1013
- " '$ ( $plugin.Name ) ' plugin not found! To remove this plugin from your profile, run 'Remove-PSProfilePlugin $ ( $plugin .Name ) ' " ,
961
+ " '$ ( $plugin.Name ) ' plugin loaded from path: $found " ,
1014
962
' LoadPlugins' ,
1015
- ' Warning '
963
+ ' Verbose '
1016
964
)
1017
965
}
966
+ else {
967
+ if ($null -ne $plugin.Name -and $null -ne (Get-Module $plugin.Name - ListAvailable - ErrorAction SilentlyContinue)) {
968
+ Import-Module $plugin.Name @importParams
969
+ $this._log (
970
+ " '$ ( $plugin.Name ) ' plugin loaded from PSModulePath!" ,
971
+ ' LoadPlugins'
972
+ )
973
+ }
974
+ else {
975
+ $this._log (
976
+ " '$ ( $plugin.Name ) ' plugin not found! To remove this plugin from your profile, run 'Remove-PSProfilePlugin $ ( $plugin.Name ) '" ,
977
+ ' LoadPlugins' ,
978
+ ' Warning'
979
+ )
980
+ }
981
+ }
982
+ }
983
+ catch {
984
+ throw
1018
985
}
1019
986
}
1020
- catch {
1021
- throw
1022
- }
1023
- }
1024
- })
987
+ })
1025
988
}
1026
989
else {
1027
990
$this._log (
0 commit comments