1+ # Requires -Modules @ { ModuleName = ' Context' ; ModuleVersion = ' 8.1.6' }
2+
13function Connect-DomeneshopAccount {
24 <#
35 . SYNOPSIS
@@ -8,22 +10,52 @@ function Connect-DomeneshopAccount {
810
911 . EXAMPLE
1012 Connect-DomeneshopAccount -Token 'my-token' -Secret (Read-Host -AsSecureString)
13+
14+ Store credentials in the default named context.
15+
16+ . INPUTS
17+ None
18+
19+ You can't pipe objects to Connect-DomeneshopAccount.
20+
21+ . OUTPUTS
22+ System.Object
23+
24+ The stored context when PassThru is specified.
25+
26+ . NOTES
27+ Credentials are encrypted by the Context module.
28+
29+ . LINK
30+ https://api.domeneshop.no/docs/
1131 #>
32+ [Diagnostics.CodeAnalysis.SuppressMessageAttribute (
33+ ' PSAvoidUsingConvertToSecureStringWithPlainText' , ' ' ,
34+ Justification = ' String secrets remain supported for compatibility and are converted before storage.'
35+ )]
1236 [OutputType ([object ])]
13- [CmdletBinding ()]
37+ [CmdletBinding (SupportsShouldProcess )]
1438 param (
39+ # The Domeneshop API token used as the Basic authentication username.
1540 [Parameter (Mandatory )]
41+ [ValidateNotNullOrEmpty ()]
1642 [string ] $Token ,
1743
44+ # The Domeneshop API secret as a string or secure string.
1845 [Parameter (Mandatory )]
46+ [ValidateNotNull ()]
1947 [object ] $Secret ,
2048
49+ # The name used to store and retrieve this credential context.
2150 [Parameter ()]
51+ [ValidateNotNullOrEmpty ()]
2252 [string ] $Context = ' default' ,
2353
54+ # Set this context as the default for commands that omit Context.
2455 [Parameter ()]
2556 [switch ] $Default ,
2657
58+ # Emit the stored context after it is saved.
2759 [Parameter ()]
2860 [switch ] $PassThru
2961 )
@@ -43,14 +75,16 @@ function Connect-DomeneshopAccount {
4375 ConnectedAt = Get-Date
4476 }
4577
46- Set-Context - ID $Context - Vault ' Domeneshop' - Context $contextObject
78+ if ($PSCmdlet.ShouldProcess (" Domeneshop context [$Context ]" , ' Store API credentials' )) {
79+ $null = Set-Context - ID $Context - Vault ' Domeneshop' - Context $contextObject
4780
48- $config = Get-DomeneshopConfig
49- if ($Default -or [string ]::IsNullOrEmpty( $config.DefaultContext )) {
50- Set-DomeneshopDefaultContext - Context $Context
51- }
81+ $config = Get-DomeneshopConfig
82+ if ($Default -or [string ]::IsNullOrWhiteSpace([ string ] $config.DefaultContext )) {
83+ Set-DomeneshopDefaultContext - Context $Context
84+ }
5285
53- if ($PassThru ) {
54- Get-DomeneshopContext - Context $Context
86+ if ($PassThru ) {
87+ Get-DomeneshopContext - Context $Context
88+ }
5589 }
5690}
0 commit comments