Skip to content

Commit

Permalink
!deploy v0.6.0 release (#32)
Browse files Browse the repository at this point in the history
## 0.6.0 - 2019-11-02

* [Issue #21](#21) - _Thank you [@corbob](https://github.com/corbob)!_
    * Fixed: Project folder discovery logic to ensure that project folders with the same name are added to the dictionary without conflict.
* [Issue #22](#22) - _Thank you [@corbob](https://github.com/corbob)!_
    * Added: `WithInsiders` switch parameter to `Open-Code`, `Edit-PSProfilePrompt`, and `Edit-PSProfileInitScript`.
* [Issue #23](#23)
    * Fixed: `$PSProfile` variable should exist regardless of when you import the module (removed conditional variable setting from PSM1).
* [Issue #26](#26)
    * Fixed: `$PSProfile._globalize()` internal method will now update `$PSDefaultParameterValue` to `$global":PSDefaultParameterValue` on InitScripts / ExternalScripts / etc so `$PSDefaultParameterValue` persists in the main session as intended.
* [Issue #27](#27)
    * Removed: `Set-Prompt` alias to prevent conflict with `oh-my-posh` module.
* [Issue #29](#29)
    * Fixed: Secrets now persist across refreshes and sessions as intended. Details:
        * Removed `PSProfileVault` class, replaced with pure hashtable.
        * Updated the Secrets management functions to work directly against the Vault hashtable.
* [Issue #31](#31)
    * Fixed: Same as [Issue #29](#29).
  • Loading branch information
scrthq authored Nov 2, 2019
2 parents 4239ac6 + 06e3451 commit 21487ea
Show file tree
Hide file tree
Showing 11 changed files with 186 additions and 174 deletions.
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
* [PSProfile - ChangeLog](#psprofile---changelog)
* [0.6.0 - 2019-11-02](#060---2019-11-02)
* [0.5.0 - 2019-10-08](#050---2019-10-08)
* [0.4.1 - 2019-10-08](#041---2019-10-08)
* [0.4.0 - 2019-09-22](#040---2019-09-22)
Expand All @@ -19,6 +20,25 @@

# PSProfile - ChangeLog

## 0.6.0 - 2019-11-02

* [Issue #21](https://github.com/scrthq/PSProfile/issues/21) - _Thank you [@corbob](https://github.com/corbob)!_
* Fixed: Project folder discovery logic to ensure that project folders with the same name are added to the dictionary without conflict.
* [Issue #22](https://github.com/scrthq/PSProfile/issues/22) - _Thank you [@corbob](https://github.com/corbob)!_
* Added: `WithInsiders` switch parameter to `Open-Code`, `Edit-PSProfilePrompt`, and `Edit-PSProfileInitScript`.
* [Issue #23](https://github.com/scrthq/PSProfile/issues/23)
* Fixed: `$PSProfile` variable should exist regardless of when you import the module (removed conditional variable setting from PSM1).
* [Issue #26](https://github.com/scrthq/PSProfile/issues/26)
* Fixed: `$PSProfile._globalize()` internal method will now update `$PSDefaultParameterValue` to `$global":PSDefaultParameterValue` on InitScripts / ExternalScripts / etc so `$PSDefaultParameterValue` persists in the main session as intended.
* [Issue #27](https://github.com/scrthq/PSProfile/issues/27)
* Removed: `Set-Prompt` alias to prevent conflict with `oh-my-posh` module.
* [Issue #29](https://github.com/scrthq/PSProfile/issues/29)
* Fixed: Secrets now persist across refreshes and sessions as intended. Details:
* Removed `PSProfileVault` class, replaced with pure hashtable.
* Updated the Secrets management functions to work directly against the Vault hashtable.
* [Issue #31](https://github.com/scrthq/PSProfile/issues/31)
* Fixed: Same as [Issue #29](https://github.com/scrthq/PSProfile/issues/29).

## 0.5.0 - 2019-10-08

* Miscellaneous
Expand Down
205 changes: 84 additions & 121 deletions PSProfile/Classes/PSProfile.Classes.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -52,45 +52,7 @@ class PSProfileSecret {
$this.SecureString = $secureString
}
}
class PSProfileVault : Hashtable {
[hashtable] $_secrets

PSProfileVault() {
$this._secrets = @{ }
}
[void] SetSecret([string]$name, [string]$userName, [securestring]$password) {
$this._secrets[$name] = [PSCredential]::new(
$userName,
$password
)
}
[void] SetSecret([pscredential]$psCredential) {
$this._secrets[$psCredential.UserName] = $psCredential
}
[void] SetSecret([string]$name, [pscredential]$psCredential) {
$this._secrets[$name] = $psCredential
}
[void] SetSecret([string]$name, [securestring]$secureString) {
$this._secrets[$name] = $secureString
}
[pscredential] GetSecret() {
if ($env:USERNAME) {
return $this._secrets[$env:USERNAME]
}
elseif ($env:USER) {
return $this._secrets[$env:USER]
}
else {
return $null
}
}
[object] GetSecret([string]$name) {
return $this._secrets[$name]
}
[void] RemoveSecret([string]$name) {
$this._secrets.Remove($name)
}
}
class PSProfile {
hidden [System.Collections.Generic.List[PSProfileEvent]] $Log
[hashtable] $_internal
Expand All @@ -112,11 +74,11 @@ class PSProfile {
[string[]] $ScriptPaths
[hashtable] $SymbolicLinks
[hashtable] $Variables
[PSProfileVault] $Vault
[hashtable] $Vault

PSProfile() {
$this.Log = [System.Collections.Generic.List[PSProfileEvent]]::new()
$this.Vault = [PSProfileVault]::new()
$this.Vault = @{_secrets = @{}}
$this._internal = @{ }
$this.GitPathMap = @{ }
$this.PSBuildPathMap = @{ }
Expand Down Expand Up @@ -150,17 +112,17 @@ class PSProfile {
Default = "AWS: "
}
}
PSReadline = @{
Options = @{}
KeyHandlers = @{}
PSReadline = @{
Options = @{ }
KeyHandlers = @{ }
}
}
$this.RefreshFrequency = (New-TimeSpan -Hours 1).ToString()
$this.LastRefresh = [datetime]::Now.AddHours(-2)
$this.LastSave = [datetime]::Now
$this.ProjectPaths = @()
$this.PluginPaths = @()
$this.InitScripts = @{}
$this.InitScripts = @{ }
$this.ScriptPaths = @()
$this.PathAliases = @{
'~' = [System.Environment]::GetFolderPath([System.Environment+SpecialFolder]::UserProfile)
Expand Down Expand Up @@ -245,7 +207,7 @@ if ($env:AWS_PROFILE) {
"`n>> "'
$plugPaths = @((Join-Path $PSScriptRoot "Plugins"))
$curVer = (Import-Metadata (Join-Path $PSScriptRoot "PSProfile.psd1")).ModuleVersion
$this.PluginPaths | Where-Object {-not [string]::IsNullOrEmpty($_) -and ($_ -match "[\/\\](Modules|BuildOutput)[\/\\]PSProfile[\/\\]$curVer" -or $_ -notmatch "[\/\\](Modules|BuildOutput)[\/\\]PSProfile[\/\\]\d+\.\d+\.\d+") } | ForEach-Object {
$this.PluginPaths | Where-Object { -not [string]::IsNullOrEmpty($_) -and ($_ -match "[\/\\](Modules|BuildOutput)[\/\\]PSProfile[\/\\]$curVer" -or $_ -notmatch "[\/\\](Modules|BuildOutput)[\/\\]PSProfile[\/\\]\d+\.\d+\.\d+") } | ForEach-Object {
$plugPaths += $_
}
$this.PluginPaths = $plugPaths | Select-Object -Unique
Expand Down Expand Up @@ -336,6 +298,7 @@ if ($env:AWS_PROFILE) {
$content = $content.Replace($fullValue, "function global:$funcName {")
}
}
$content = $content -replace '\$PSDefaultParameterValues','$global:PSDefaultParameterValues'
return $content
}
hidden [void] _cleanConfig() {
Expand All @@ -351,16 +314,16 @@ if ($env:AWS_PROFILE) {
"Verbose"
)
[hashtable[]]$final = @()
$this.$section | Where-Object {$_ -is [hashtable] -and $_.Name} | ForEach-Object {
$this.$section | Where-Object { $_ -is [hashtable] -and $_.Name } | ForEach-Object {
$final += $_
}
$this.$section | Where-Object {$_ -is [string]} | ForEach-Object {
$this.$section | Where-Object { $_ -is [string] } | ForEach-Object {
$this._log(
"[$section] Converting module string to hashtable: $_",
"CleanConfig",
"Verbose"
)
$final += @{Name = $_}
$final += @{Name = $_ }
}
$this.$section = $final
}
Expand All @@ -371,7 +334,7 @@ if ($env:AWS_PROFILE) {
"Verbose"
)
[string[]]$final = @()
$this.$section | Where-Object {-not [string]::IsNullOrEmpty($_)} | ForEach-Object {
$this.$section | Where-Object { -not [string]::IsNullOrEmpty($_) } | ForEach-Object {
$final += $_
}
$this.$section = $final
Expand Down Expand Up @@ -638,33 +601,33 @@ if ($env:AWS_PROFILE) {
$g = 0
$b = 0
$pInfo.EnumerateDirectories('.git',[System.IO.SearchOption]::AllDirectories) | ForEach-Object {
$PathName = $_.Parent.BaseName
$PathName = $_.Parent.Name
$FullPathName = $_.Parent.FullName
$g++
$this._log(
"Found git project @ $($FullPathName)",
'FindProjects',
'Verbose'
)
$currPath = $_
while($this.GitPathMap.ContainsKey($PathName)){
$currPath = $currPath.Parent
$doublePath = [System.IO.DirectoryInfo]::new($this.GitPathMap[$PathName])
$this.GitPathMap["$($doublePath.Parent)\$($doublePath.BaseName)"] = $doublePath.FullName
$this.GitPathMap.Remove($PathName)
if($this.PSBuildPathMap.ContainsKey($PathName)){
$PSBuildPath = [System.IO.DirectoryInfo]::new($this.PSBuildPathMap[$PathName])
$this.PSBuildPathMap["$($PSBuildPath.Parent)\$($PSBuildPath.BaseName)"] = $doublePath.FullName
$this.PSBuildPathMap.Remove($PathName)
}
$PathName = "$($currPath.Parent.BaseName)\$PathName"
$currPath = $_
while ($this.GitPathMap.ContainsKey($PathName)) {
$currPath = $currPath.Parent
$doublePath = [System.IO.DirectoryInfo]::new($this.GitPathMap[$PathName])
$this.GitPathMap["$($doublePath.Parent.Name)$([System.IO.Path]::DirectorySeparatorChar)$($doublePath.Name)"] = $doublePath.FullName
$this.GitPathMap.Remove($PathName)
if ($this.PSBuildPathMap.ContainsKey($PathName)) {
$PSBuildPath = [System.IO.DirectoryInfo]::new($this.PSBuildPathMap[$PathName])
$this.PSBuildPathMap["$($PSBuildPath.Parent.Name)$([System.IO.Path]::DirectorySeparatorChar)$($PSBuildPath.Name)"] = $doublePath.FullName
$this.PSBuildPathMap.Remove($PathName)
}
$PathName = "$($currPath.Parent.BaseName)$([System.IO.Path]::DirectorySeparatorChar)$PathName"
}
$this.GitPathMap[$PathName] = $FullPathName
$bldPath = [System.IO.Path]::Combine($FullPathName,'build.ps1')
if ([System.IO.File]::Exists($bldPath)) {
$b++
$this._log(
"Found build script @ $($_.FullName)",
"Found build script @ $($bldPath)",
'FindProjects',
'Verbose'
)
Expand Down Expand Up @@ -954,74 +917,74 @@ if ($env:AWS_PROFILE) {
)
if ($this.Plugins.Count) {
$this.Plugins.ForEach( {
if ($_.Name -ne 'PSProfile.PowerTools') {
$plugin = $_
$this._log(
"'$($plugin.Name)' Searching for plugin",
'LoadPlugins',
'Verbose'
)
try {
$found = $null
$importParams = @{
ErrorAction = 'Stop'
Global = $true
}
if ($plugin.ArgumentList) {
$importParams['ArgumentList'] = $plugin.ArgumentList
}
[string[]]$pathsToSearch = @($this.PluginPaths)
$env:PSModulePath.Split([System.IO.Path]::PathSeparator) | ForEach-Object {
$pathsToSearch += $_
}
foreach ($plugPath in $pathsToSearch) {
$fullPath = [System.IO.Path]::Combine($plugPath,"$($plugin.Name).ps1")
$this._log(
"'$($plugin.Name)' Checking path: $fullPath",
'LoadPlugins',
'Debug'
)
if (Test-Path $fullPath) {
$sb = [scriptblock]::Create($this._globalize(([System.IO.File]::ReadAllText($fullPath))))
if ($plugin.ArgumentList) {
.$sb($plugin.ArgumentList)
}
else {
.$sb
}
$found = $fullPath
break
if ($_.Name -ne 'PSProfile.PowerTools') {
$plugin = $_
$this._log(
"'$($plugin.Name)' Searching for plugin",
'LoadPlugins',
'Verbose'
)
try {
$found = $null
$importParams = @{
ErrorAction = 'Stop'
Global = $true
}
}
if ($null -ne $found) {
$this._log(
"'$($plugin.Name)' plugin loaded from path: $found",
'LoadPlugins',
'Verbose'
)
}
else {
if ($null -ne $plugin.Name -and $null -ne (Get-Module $plugin.Name -ListAvailable -ErrorAction SilentlyContinue)) {
Import-Module $plugin.Name @importParams
if ($plugin.ArgumentList) {
$importParams['ArgumentList'] = $plugin.ArgumentList
}
[string[]]$pathsToSearch = @($this.PluginPaths)
$env:PSModulePath.Split([System.IO.Path]::PathSeparator) | ForEach-Object {
$pathsToSearch += $_
}
foreach ($plugPath in $pathsToSearch) {
$fullPath = [System.IO.Path]::Combine($plugPath,"$($plugin.Name).ps1")
$this._log(
"'$($plugin.Name)' plugin loaded from PSModulePath!",
'LoadPlugins'
"'$($plugin.Name)' Checking path: $fullPath",
'LoadPlugins',
'Debug'
)
if (Test-Path $fullPath) {
$sb = [scriptblock]::Create($this._globalize(([System.IO.File]::ReadAllText($fullPath))))
if ($plugin.ArgumentList) {
.$sb($plugin.ArgumentList)
}
else {
.$sb
}
$found = $fullPath
break
}
}
else {
if ($null -ne $found) {
$this._log(
"'$($plugin.Name)' plugin not found! To remove this plugin from your profile, run 'Remove-PSProfilePlugin $($plugin.Name)'",
"'$($plugin.Name)' plugin loaded from path: $found",
'LoadPlugins',
'Warning'
'Verbose'
)
}
else {
if ($null -ne $plugin.Name -and $null -ne (Get-Module $plugin.Name -ListAvailable -ErrorAction SilentlyContinue)) {
Import-Module $plugin.Name @importParams
$this._log(
"'$($plugin.Name)' plugin loaded from PSModulePath!",
'LoadPlugins'
)
}
else {
$this._log(
"'$($plugin.Name)' plugin not found! To remove this plugin from your profile, run 'Remove-PSProfilePlugin $($plugin.Name)'",
'LoadPlugins',
'Warning'
)
}
}
}
catch {
throw
}
}
catch {
throw
}
}
})
})
}
else {
$this._log(
Expand Down
1 change: 0 additions & 1 deletion PSProfile/PSProfile.Aliases.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
'Save-Prompt' = 'Add-PSProfilePrompt'
'Get-Prompt' = 'Get-PSProfilePrompt'
'Edit-Prompt' = 'Edit-PSProfilePrompt'
'Set-Prompt' = 'Switch-PSProfilePrompt'
'Switch-Prompt' = 'Switch-PSProfilePrompt'
'Remove-Prompt' = 'Remove-PSProfilePrompt'
'Copy-DynamicParameters' = 'Copy-Parameters'
Expand Down
2 changes: 1 addition & 1 deletion PSProfile/PSProfile.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'PSProfile.psm1'

# Version number of this module.
ModuleVersion = '0.5.0'
ModuleVersion = '0.6.0'

# Supported PSEditions
CompatiblePSEditions = @('Desktop','Core')
Expand Down
38 changes: 17 additions & 21 deletions PSProfile/PSProfile.psm1
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
# If we're in an interactive shell, load the profile.
if ([Environment]::UserInteractive -or ($null -eq [Environment]::UserInteractive -and $null -eq ([Environment]::GetCommandLineArgs() | Where-Object { $_ -like '-NonI*' }))) {
$global:OriginalPrompt =
$global:PSProfile = [PSProfile]::new()
$global:PSProfile.Load()
Export-ModuleMember -Variable PSProfile
$global:PSProfileConfigurationWatcher = [System.IO.FileSystemWatcher]::new($(Split-Path $global:PSProfile.Settings.ConfigurationPath -Parent),'Configuration.psd1')
$job = Register-ObjectEvent -InputObject $global:PSProfileConfigurationWatcher -EventName Changed -Action {
[PSProfile]$conf = Import-Configuration -Name PSProfile -CompanyName 'SCRT HQ' -Verbose:$false
$conf._internal = $global:PSProfile._internal
$global:PSProfile = $conf
$global:PSProfile = [PSProfile]::new()
$global:PSProfile.Load()
Export-ModuleMember -Variable PSProfile
$global:PSProfileConfigurationWatcher = [System.IO.FileSystemWatcher]::new($(Split-Path $global:PSProfile.Settings.ConfigurationPath -Parent),'Configuration.psd1')
$job = Register-ObjectEvent -InputObject $global:PSProfileConfigurationWatcher -EventName Changed -Action {
[PSProfile]$conf = Import-Configuration -Name PSProfile -CompanyName 'SCRT HQ' -Verbose:$false
$conf._internal = $global:PSProfile._internal
$global:PSProfile = $conf
}
$PSProfile_OnRemoveScript = {
try {
$global:PSProfileConfigurationWatcher.Dispose()
}
$PSProfile_OnRemoveScript = {
try {
$global:PSProfileConfigurationWatcher.Dispose()
}
finally {
Remove-Variable PSProfile -Scope Global -Force
Remove-Variable PSProfileConfigurationWatcher -Scope Global -Force
}
finally {
Remove-Variable PSProfile -Scope Global -Force
Remove-Variable PSProfileConfigurationWatcher -Scope Global -Force
}
$ExecutionContext.SessionState.Module.OnRemove += $PSProfile_OnRemoveScript
Register-EngineEvent -SourceIdentifier ([System.Management.Automation.PsEngineEvent]::Exiting) -Action $PSProfile_OnRemoveScript
}
$ExecutionContext.SessionState.Module.OnRemove += $PSProfile_OnRemoveScript
Register-EngineEvent -SourceIdentifier ([System.Management.Automation.PsEngineEvent]::Exiting) -Action $PSProfile_OnRemoveScript
Loading

0 comments on commit 21487ea

Please sign in to comment.