Skip to content

Credential handling needs reworked #34

Description

@jasonrush

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions