Skip to content
This repository was archived by the owner on Dec 8, 2021. It is now read-only.
This repository was archived by the owner on Dec 8, 2021. It is now read-only.

[SecretManagement] ArgumentCompleter / cached secret info #87

Open
@itfranck

Description

@itfranck

#Implement an argument completer for the SecretManagement module.

Currently if you want to use the cmdlet, you need to know your secrets / vault name.
The Get-SecretInfo cmdlet is super useful for that.

That being said, it could be implemented directly into the module using an argument completer for the vaults and secrets name

Proposed technical implementation details (optional)

Here's a simple example that work with cmdlets for the Vault parameters and secrets parameters.


Register-ArgumentCompleter -CommandName Get-Secret, Set-Secret, Get-SecretInfo -ParameterName Vault -ScriptBlock {
    Get-SecretVault  | Select -ExpandProperty Name | foreach-object {
        [System.Management.Automation.CompletionResult]::new($_)
    }
}
 
Register-ArgumentCompleter -CommandName Get-Secret, Remove-Secret -ParameterName Name -ScriptBlock {
    param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)
 
    $VaultNameFilter = $fakeBoundParameter.Vault
    (Get-SecretInfo -Vault $VaultNameFilter )  | Select -ExpandProperty Name  | foreach-object {
        [System.Management.Automation.CompletionResult]::new($_)
    }
}

The only drawback is that relying on Get-SecretInfo as it is means that you have to wait on remote vault querying, which can add a couple of seconds. (But since the value completion is not triggered automatically, that shouldn't be a problem)

Still, for the Vault parameter, it is perfect.
For the Name, I think it make sense anyway (value completion must be manuall triggered so it's a choice of whether you enter your name manually (if you know it) or trigger the value completion, which is the equivalent of running a Get-SecretInfo in the console then copy/paste the name.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions