AutomateAPI
AutomateAPI copied to clipboard
Credential handling needs reworked
Credential storage to local disk does not include Control credentials (#32), and helper functions are not intuitive nor follow Microsoft Verb best practices. See example code below for possible additional ideas:
#region *-CwaCredential
function Set-CwaCredential {
[CmdletBinding()]
Param (
[parameter(Mandatory=$true,ValueFromPipelineByPropertyName,ValueFromPipeline)]
[ValidateNotNull()]
[System.Management.Automation.PSCredential]
[System.Management.Automation.Credential()]
$Credential = [System.Management.Automation.PSCredential]::Empty
)
# Store credential for later use.
Write-Verbose "Credential username = '$($Credential.UserName)'"
$Script:CwaCredential = $credential
}
function Get-CwaCredential {
[CmdletBinding()]
Param (
)
$Script:CwaCredential.UserName
}
function Remove-CwaCredential {
[CmdletBinding()]
Param (
)
$Script:CwaCredential = $null
}
function Save-CwaCredential {
[CmdletBinding()]
Param (
[String]
$Path = "$env:USERPROFILE/.CwaCredential.xml"
)
$Script:CwaCredential | Export-CliXml -Path $path
}
function Load-CwaCredential {
[CmdletBinding()]
Param (
[String]
$Path = "$env:USERPROFILE/.CwaCredential.xml"
)
if( Test-Path -Path $Path ){
$Script:CwaCredential = Import-CliXml -Path $Path
}
}
#endregion *-CwaCredential
Completely agree - they are significantly over complicated. I like your suggestions and their simplicity @jasonrush