@@ -7,13 +7,19 @@ function Connect-DomeneshopAccount {
77
88 . DESCRIPTION
99 Stores Domeneshop API credentials using the Context module. The first stored context becomes the
10- default automatically, and Default replaces an existing default.
10+ default automatically, and Default replaces an existing default. When Secret is omitted, opens the
11+ Domeneshop API settings page and securely prompts for it.
1112
1213 . EXAMPLE
1314 Connect-DomeneshopAccount -Token 'my-token' -Secret (Read-Host -AsSecureString)
1415
1516 Store credentials in the default named context.
1617
18+ . EXAMPLE
19+ Connect-DomeneshopAccount -Token 'my-token'
20+
21+ Open the Domeneshop API settings page and securely prompt for the API secret.
22+
1723 . INPUTS
1824 None
1925
@@ -43,9 +49,10 @@ function Connect-DomeneshopAccount {
4349 [string ] $Token ,
4450
4551 # The Domeneshop API secret as a string or secure string.
46- [Parameter (Mandatory )]
52+ [Parameter ()]
4753 [ValidateNotNull ()]
4854 [ValidateScript ({ Test-DomeneshopSecret - Secret $_ })]
55+ [Alias (' Key' )]
4956 [object ] $Secret ,
5057
5158 # The name used to store and retrieve this credential context.
@@ -63,22 +70,28 @@ function Connect-DomeneshopAccount {
6370 [switch ] $PassThru
6471 )
6572
66- $secureSecret = switch ($Secret ) {
67- { $_ -is [securestring ] } { $_ ; break }
68- { $_ -is [string ] } { ConvertTo-SecureString - AsPlainText $Secret - Force; break }
69- default { throw ' Secret must be a SecureString or String value.' }
70- }
73+ if ($PSCmdlet.ShouldProcess (" Domeneshop context [$Context ]" , ' Store API credentials' )) {
74+ if (-not $PSBoundParameters.ContainsKey (' Secret' )) {
75+ Start-Process - FilePath ' https://domene.shop/admin?view=api'
76+ $Secret = Read-Host - Prompt ' Enter the Domeneshop API secret' - AsSecureString
77+ $null = Test-DomeneshopSecret - Secret $Secret
78+ }
7179
72- $contextObject = [ordered ]@ {
73- Name = $Context
74- Token = $Token
75- Secret = $secureSecret
76- AuthType = ' BasicAuth'
77- ApiBaseUri = ' https://api.domeneshop.no/v0'
78- ConnectedAt = Get-Date
79- }
80+ $secureSecret = if ($Secret -is [securestring ]) {
81+ $Secret
82+ } else {
83+ ConvertTo-SecureString - AsPlainText $Secret - Force
84+ }
85+
86+ $contextObject = [ordered ]@ {
87+ Name = $Context
88+ Token = $Token
89+ Secret = $secureSecret
90+ AuthType = ' BasicAuth'
91+ ApiBaseUri = ' https://api.domeneshop.no/v0'
92+ ConnectedAt = Get-Date
93+ }
8094
81- if ($PSCmdlet.ShouldProcess (" Domeneshop context [$Context ]" , ' Store API credentials' )) {
8295 $null = Set-Context - ID $Context - Vault ' Domeneshop' - Context $contextObject
8396
8497 $config = Get-DomeneshopConfig
0 commit comments