File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ function Get-DomeneshopApiBaseUri {
2+ [CmdletBinding ()]
3+ param (
4+ [Parameter (Mandatory )]
5+ [object ] $Context
6+ )
7+
8+ $apiBaseUri = [string ] $Context.ApiBaseUri
9+ if ([string ]::IsNullOrEmpty($apiBaseUri )) {
10+ $apiBaseUri = ' https://api.domeneshop.no/v0'
11+ }
12+
13+ $apiBaseUri.TrimEnd (' /' )
14+ }
Original file line number Diff line number Diff line change 1+ function Update-DomeneshopDdns {
2+ <#
3+ . SYNOPSIS
4+ Updates dynamic DNS for a hostname.
5+
6+ . DESCRIPTION
7+ Calls the Domeneshop DDNS update endpoint. The API creates the A/AAAA record if it does not exist.
8+ #>
9+ [OutputType ([object ])]
10+ [CmdletBinding ()]
11+ param (
12+ [Parameter (Mandatory )]
13+ [Alias (' Host' )]
14+ [string ] $Hostname ,
15+
16+ [Parameter ()]
17+ [Alias (' IP' )]
18+ [string ] $MyIP ,
19+
20+ [Parameter ()]
21+ [string ] $Context
22+ )
23+
24+ $resolvedContext = Resolve-DomeneshopContext - Context $Context
25+ $apiBaseUri = Get-DomeneshopApiBaseUri - Context $resolvedContext
26+ $uri = " $apiBaseUri /dyndns/update?hostname=$ ( [uri ]::EscapeDataString($Hostname )) "
27+ if ($PSBoundParameters.ContainsKey (' MyIP' )) {
28+ $uri = " $uri &myip=$ ( [uri ]::EscapeDataString($MyIP )) "
29+ }
30+
31+ Invoke-DomeneshopApiRequest - Method Get - Uri $uri - Context $resolvedContext
32+ }
Original file line number Diff line number Diff line change 1+ function Add-DomeneshopDnsRecord {
2+ <#
3+ . SYNOPSIS
4+ Adds a DNS record to a Domeneshop domain.
5+ #>
6+ [OutputType ([object ])]
7+ [CmdletBinding ()]
8+ param (
9+ [Parameter (Mandatory )]
10+ [int ] $DomainID ,
11+
12+ [Parameter (Mandatory )]
13+ [object ] $Record ,
14+
15+ [Parameter ()]
16+ [string ] $Context
17+ )
18+
19+ $resolvedContext = Resolve-DomeneshopContext - Context $Context
20+ $apiBaseUri = Get-DomeneshopApiBaseUri - Context $resolvedContext
21+ $uri = " $apiBaseUri /domains/$DomainID /dns"
22+
23+ Invoke-DomeneshopApiRequest - Method Post - Uri $uri - Context $resolvedContext - Body $Record
24+ }
Original file line number Diff line number Diff line change 1+ function Get-DomeneshopDnsRecord {
2+ <#
3+ . SYNOPSIS
4+ Gets DNS records for a Domeneshop domain.
5+
6+ . DESCRIPTION
7+ Lists DNS records for a domain, or gets one DNS record by ID.
8+ #>
9+ [OutputType ([object []])]
10+ [CmdletBinding (DefaultParameterSetName = ' List' )]
11+ param (
12+ [Parameter (Mandatory )]
13+ [int ] $DomainID ,
14+
15+ [Parameter (Mandatory , ParameterSetName = ' GetByID' )]
16+ [int ] $RecordID ,
17+
18+ [Parameter (ParameterSetName = ' List' )]
19+ [Alias (' Host' )]
20+ [string ] $RecordHost ,
21+
22+ [Parameter (ParameterSetName = ' List' )]
23+ [string ] $Type ,
24+
25+ [Parameter (ParameterSetName = ' List' )]
26+ [string ] $Data ,
27+
28+ [Parameter ()]
29+ [string ] $Context
30+ )
31+
32+ $resolvedContext = Resolve-DomeneshopContext - Context $Context
33+ $apiBaseUri = Get-DomeneshopApiBaseUri - Context $resolvedContext
34+ $uri = " $apiBaseUri /domains/$DomainID /dns"
35+
36+ if ($PSCmdlet.ParameterSetName -eq ' GetByID' ) {
37+ $uri = " $uri /$RecordID "
38+ } else {
39+ $queryParts = @ ()
40+ if ($PSBoundParameters.ContainsKey (' RecordHost' )) {
41+ $queryParts += " host=$ ( [uri ]::EscapeDataString($RecordHost )) "
42+ }
43+ if ($PSBoundParameters.ContainsKey (' Type' )) {
44+ $queryParts += " type=$ ( [uri ]::EscapeDataString($Type )) "
45+ }
46+ if ($PSBoundParameters.ContainsKey (' Data' )) {
47+ $queryParts += " data=$ ( [uri ]::EscapeDataString($Data )) "
48+ }
49+ if ($queryParts.Count -gt 0 ) {
50+ $uri = " ${uri} ?{0}" -f ($queryParts -join ' &' )
51+ }
52+ }
53+
54+ Invoke-DomeneshopApiRequest - Method Get - Uri $uri - Context $resolvedContext
55+ }
Original file line number Diff line number Diff line change 1+ function Remove-DomeneshopDnsRecord {
2+ <#
3+ . SYNOPSIS
4+ Removes a DNS record from a Domeneshop domain.
5+ #>
6+ [OutputType ([object ])]
7+ [CmdletBinding (SupportsShouldProcess , ConfirmImpact = ' High' )]
8+ param (
9+ [Parameter (Mandatory )]
10+ [int ] $DomainID ,
11+
12+ [Parameter (Mandatory )]
13+ [int ] $RecordID ,
14+
15+ [Parameter ()]
16+ [string ] $Context
17+ )
18+
19+ $resolvedContext = Resolve-DomeneshopContext - Context $Context
20+ $apiBaseUri = Get-DomeneshopApiBaseUri - Context $resolvedContext
21+ $uri = " $apiBaseUri /domains/$DomainID /dns/$RecordID "
22+
23+ if ($PSCmdlet.ShouldProcess (" Domain $DomainID DNS record $RecordID " , ' Remove' )) {
24+ Invoke-DomeneshopApiRequest - Method Delete - Uri $uri - Context $resolvedContext
25+ }
26+ }
Original file line number Diff line number Diff line change 1+ function Set-DomeneshopDnsRecord {
2+ <#
3+ . SYNOPSIS
4+ Updates a DNS record on a Domeneshop domain.
5+ #>
6+ [OutputType ([object ])]
7+ [CmdletBinding ()]
8+ param (
9+ [Parameter (Mandatory )]
10+ [int ] $DomainID ,
11+
12+ [Parameter (Mandatory )]
13+ [int ] $RecordID ,
14+
15+ [Parameter (Mandatory )]
16+ [object ] $Record ,
17+
18+ [Parameter ()]
19+ [string ] $Context
20+ )
21+
22+ $resolvedContext = Resolve-DomeneshopContext - Context $Context
23+ $apiBaseUri = Get-DomeneshopApiBaseUri - Context $resolvedContext
24+ $uri = " $apiBaseUri /domains/$DomainID /dns/$RecordID "
25+
26+ Invoke-DomeneshopApiRequest - Method Put - Uri $uri - Context $resolvedContext - Body $Record
27+ }
Original file line number Diff line number Diff line change @@ -13,25 +13,31 @@ function Get-DomeneshopDomain {
1313 Get-DomeneshopDomain -Domain '.no'
1414 #>
1515 [OutputType ([object []])]
16- [CmdletBinding ()]
16+ [CmdletBinding (DefaultParameterSetName = ' List ' )]
1717 param (
18- [Parameter ()]
18+ [Parameter (ParameterSetName = ' List ' )]
1919 [string ] $Domain ,
2020
21+ [Parameter (Mandatory , ParameterSetName = ' GetByID' )]
22+ [int ] $DomainID ,
23+
2124 [Parameter ()]
2225 [string ] $Context
2326 )
2427
2528 $resolvedContext = Resolve-DomeneshopContext - Context $Context
26- $apiBaseUri = [string ] $resolvedContext.ApiBaseUri
27- if ([string ]::IsNullOrEmpty($apiBaseUri )) {
28- $apiBaseUri = ' https://api.domeneshop.no/v0'
29- }
29+ $apiBaseUri = Get-DomeneshopApiBaseUri - Context $resolvedContext
3030
31- $uri = " $apiBaseUri /domains"
32- if ($Domain ) {
33- $encodedDomain = [uri ]::EscapeDataString($Domain )
34- $uri = " ${uri} ?domain=$encodedDomain "
31+ $uri = switch ($PSCmdlet.ParameterSetName ) {
32+ ' GetByID' { " $apiBaseUri /domains/$DomainID " ; break }
33+ default {
34+ $listUri = " $apiBaseUri /domains"
35+ if ($Domain ) {
36+ $encodedDomain = [uri ]::EscapeDataString($Domain )
37+ $listUri = " ${listUri} ?domain=$encodedDomain "
38+ }
39+ $listUri
40+ }
3541 }
3642
3743 Invoke-DomeneshopApiRequest - Method Get - Uri $uri - Context $resolvedContext
Original file line number Diff line number Diff line change 1+ function Add-DomeneshopForward {
2+ <#
3+ . SYNOPSIS
4+ Adds an HTTP forward to a Domeneshop domain.
5+ #>
6+ [OutputType ([object ])]
7+ [CmdletBinding ()]
8+ param (
9+ [Parameter (Mandatory )]
10+ [int ] $DomainID ,
11+
12+ [Parameter (Mandatory )]
13+ [object ] $Forward ,
14+
15+ [Parameter ()]
16+ [string ] $Context
17+ )
18+
19+ $resolvedContext = Resolve-DomeneshopContext - Context $Context
20+ $apiBaseUri = Get-DomeneshopApiBaseUri - Context $resolvedContext
21+ $uri = " $apiBaseUri /domains/$DomainID /forwards/"
22+
23+ Invoke-DomeneshopApiRequest - Method Post - Uri $uri - Context $resolvedContext - Body $Forward
24+ }
Original file line number Diff line number Diff line change 1+ function Get-DomeneshopForward {
2+ <#
3+ . SYNOPSIS
4+ Gets HTTP forwards for a Domeneshop domain.
5+
6+ . DESCRIPTION
7+ Lists forwards for a domain, or gets one forward by host.
8+ #>
9+ [OutputType ([object []])]
10+ [CmdletBinding (DefaultParameterSetName = ' List' )]
11+ param (
12+ [Parameter (Mandatory )]
13+ [int ] $DomainID ,
14+
15+ [Parameter (Mandatory , ParameterSetName = ' GetByHost' )]
16+ [Alias (' Host' )]
17+ [string ] $ForwardHost ,
18+
19+ [Parameter ()]
20+ [string ] $Context
21+ )
22+
23+ $resolvedContext = Resolve-DomeneshopContext - Context $Context
24+ $apiBaseUri = Get-DomeneshopApiBaseUri - Context $resolvedContext
25+
26+ $uri = if ($PSCmdlet.ParameterSetName -eq ' GetByHost' ) {
27+ $encodedHost = [uri ]::EscapeDataString($ForwardHost )
28+ " $apiBaseUri /domains/$DomainID /forwards/$encodedHost "
29+ } else {
30+ " $apiBaseUri /domains/$DomainID /forwards/"
31+ }
32+
33+ Invoke-DomeneshopApiRequest - Method Get - Uri $uri - Context $resolvedContext
34+ }
Original file line number Diff line number Diff line change 1+ function Remove-DomeneshopForward {
2+ <#
3+ . SYNOPSIS
4+ Removes an HTTP forward from a Domeneshop domain.
5+ #>
6+ [OutputType ([object ])]
7+ [CmdletBinding (SupportsShouldProcess , ConfirmImpact = ' High' )]
8+ param (
9+ [Parameter (Mandatory )]
10+ [int ] $DomainID ,
11+
12+ [Parameter (Mandatory )]
13+ [Alias (' Host' )]
14+ [string ] $ForwardHost ,
15+
16+ [Parameter ()]
17+ [string ] $Context
18+ )
19+
20+ $resolvedContext = Resolve-DomeneshopContext - Context $Context
21+ $apiBaseUri = Get-DomeneshopApiBaseUri - Context $resolvedContext
22+ $encodedHost = [uri ]::EscapeDataString($ForwardHost )
23+ $uri = " $apiBaseUri /domains/$DomainID /forwards/$encodedHost "
24+
25+ if ($PSCmdlet.ShouldProcess (" Domain $DomainID forward $ForwardHost " , ' Remove' )) {
26+ Invoke-DomeneshopApiRequest - Method Delete - Uri $uri - Context $resolvedContext
27+ }
28+ }
You can’t perform that action at this time.
0 commit comments