Skip to content

Commit 2542def

Browse files
committed
Cleanup functions and DNS tweaks
Removing unused modules Removing ListDomainTests function Removing old AzTable code Adding DNS Config to tables
1 parent 4e08a8a commit 2542def

File tree

79 files changed

+27
-140453
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+27
-140453
lines changed

DNSHelper.psm1

+13-6
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,22 @@ function Resolve-DnsHttpsQuery {
2929
[string]$RecordType = 'A'
3030
)
3131

32-
if (Test-Path -Path 'Config\DnsConfig.json') {
33-
try {
34-
$Config = Get-Content 'Config\DnsConfig.json' | ConvertFrom-Json
35-
$Resolver = $Config.Resolver
36-
}
37-
catch { $Resolver = 'Google' }
32+
$ConfigTable = Get-CippTable -tablename Config
33+
$Filter = "PartitionKey eq 'Domains' and RowKey eq 'Domains'"
34+
$Config = Get-AzDataTableEntity @ConfigTable -Filter $Filter
35+
36+
$ValidResolvers = @('Google', 'CloudFlare', 'Quad9')
37+
if ($ValidResolvers -contains $Config.Resolver) {
38+
$Resolver = $Config.Resolver
3839
}
3940
else {
4041
$Resolver = 'Google'
42+
$Config = @{
43+
PartitionKey = 'Domains'
44+
RowKey = 'Domains'
45+
Resolver = $Resolver
46+
}
47+
Add-AzDataTableEntity @ConfigTable -Entity $Config -Force
4148
}
4249

4350
switch ($Resolver) {

ExecDnsConfig/run.ps1

+14-18
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,22 @@ $ValidResolvers = @(
1313
'Quad9'
1414
)
1515

16-
$ConfigPath = 'Config/DnsConfig.json'
17-
1816
# Write to the Azure Functions log stream.
1917
Write-Host 'PowerShell HTTP trigger function processed a request.'
2018

2119
$StatusCode = [HttpStatusCode]::OK
2220
try {
23-
$Config = ''
24-
if (Test-Path $ConfigPath) {
25-
try {
26-
# Try to parse config file and catch exceptions
27-
$Config = Get-Content -Path $ConfigPath | ConvertFrom-Json
28-
}
29-
catch {}
30-
}
31-
if ($Config -eq '') {
32-
New-Item 'Config' -ItemType Directory -ErrorAction SilentlyContinue | Out-Null
33-
$Config = [PSCustomObject]@{
34-
Resolver = 'Google'
21+
$ConfigTable = Get-CippTable -tablename Config
22+
$Filter = "PartitionKey eq 'Domains' and RowKey eq 'Domains'"
23+
$Config = Get-AzDataTableEntity @ConfigTable -Filter $Filter
24+
25+
if ($ValidResolvers -notcontains $Config.Resolver) {
26+
$Config = @{
27+
PartitionKey = 'Domains'
28+
RowKey = 'Domains'
29+
Resolver = 'Google'
3530
}
36-
$Config | ConvertTo-Json | Set-Content $ConfigPath
31+
Add-AzDataTableEntity @ConfigTable -Entity $Config -Force
3732
}
3833

3934
$updated = $false
@@ -47,15 +42,16 @@ try {
4742
$Config.Resolver = $Resolver
4843
}
4944
catch {
50-
$Config = [PSCustomObject]@{
45+
$Config = @{
5146
Resolver = $Resolver
5247
}
5348
}
5449
$updated = $true
5550
}
5651
}
5752
if ($updated) {
58-
$Config | ConvertTo-Json | Set-Content $ConfigPath
53+
Add-AzDataTableEntity @ConfigTable -Entity $Config -Force
54+
#$Config | ConvertTo-Json | Set-Content $ConfigPath
5955
Write-LogMessage -API $APINAME -tenant 'Global' -user $request.headers.'x-ms-client-principal' -message 'DNS configuration updated' -Sev 'Info'
6056
$body = [pscustomobject]@{'Results' = 'Success: DNS configuration updated.' }
6157
}
@@ -65,7 +61,7 @@ try {
6561
}
6662
}
6763
elseif ($Request.Query.Action -eq 'GetConfig') {
68-
$body = $Config
64+
$body = [pscustomobject]$Config
6965
Write-LogMessage -API $APINAME -tenant 'Global' -user $request.headers.'x-ms-client-principal' -message 'Retrieved DNS configuration' -Sev 'Info'
7066
}
7167
}

GraphHelper.psm1

-10
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,6 @@ function Get-CIPPTable {
33
param (
44
$tablename = 'CippLogs'
55
)
6-
#$context = New-AzStorageContext -ConnectionString $ENV:AzureWebJobsStorage
7-
#try {
8-
# $StorageTable = Get-AzStorageTable -Context $context -Name $tablename -ErrorAction Stop
9-
#}
10-
#catch {
11-
# New-AzStorageTable -Context $context -Name $tablename | Out-Null
12-
# $StorageTable = Get-AzStorageTable -Context $context -Name $tablename
13-
#}
14-
#return $StorageTable.CloudTable
15-
166
@{
177
ConnectionString = $ENV:AzureWebJobsStorage
188
TableName = $tablename

ListDomainTests/function.json

-19
This file was deleted.

ListDomainTests/run.ps1

-175
This file was deleted.

0 commit comments

Comments
 (0)