Skip to content

Commit 6d69f31

Browse files
committed
update to version 1.0.1
1 parent c2c9562 commit 6d69f31

12 files changed

+254
-91
lines changed

.github/workflows/build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
run: .\build\vsts-validate.ps1
1818
shell: powershell
1919
- name: Publish
20-
run: .\build\vsts-build.ps1 -ApiKey $env:APIKEY
20+
run: .\build\vsts-build.ps1 -ApiKey $env:APIKEY -AutoVersion
2121
shell: powershell
2222
env:
2323
APIKEY: ${{ secrets.APIKEY }}

.github/workflows/codecov.yml

-34
This file was deleted.

AzDnsAsCode/AzDnsAsCode.psd1

+15-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
RootModule = 'AzDnsAsCode.psm1'
44

55
# Version number of this module.
6-
ModuleVersion = '1.0.0'
6+
ModuleVersion = '1.0.1'
77

88
# ID used to uniquely identify this module
99
GUID = 'f3ccfc72-148e-4bd3-a8df-b4f1a6c67f05'
@@ -39,6 +39,11 @@
3939
# Format files (.ps1xml) to be loaded when importing this module
4040
# FormatsToProcess = @('xml\AzDnsAsCode.Format.ps1xml')
4141

42+
# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
43+
NestedModules = @(
44+
'Modules\AzDnsAsCodeTelemetryEngine.psm1'
45+
)
46+
4247
# Functions to export from this module
4348
FunctionsToExport = @(
4449
'New-AzDnsAsCodeZone'
@@ -47,22 +52,24 @@
4752
'Set-AzDnsAsCodeMulticonfig'
4853
'Get-AzDnsAsCodeZoneConfig'
4954
'Show-AzDnsAsCodeConfiguration'
55+
'Get-AzDnsAsCodeTelemetryOption'
56+
'Set-AzDnsAsCodeTelemetryOption'
5057
)
5158

5259
# Cmdlets to export from this module
5360
CmdletsToExport = ''
5461

5562
# Variables to export from this module
56-
VariablesToExport = ''
63+
#VariablesToExport = ''
5764

5865
# Aliases to export from this module
59-
AliasesToExport = ''
66+
#AliasesToExport = ''
6067

6168
# List of all modules packaged with this module
62-
ModuleList = @()
69+
#ModuleList = @()
6370

6471
# List of all files packaged with this module
65-
FileList = @()
72+
#FileList = @()
6673

6774
# Private data to pass to the module specified in ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
6875
PrivateData = @{
@@ -71,13 +78,13 @@
7178
PSData = @{
7279

7380
# Tags applied to this module. These help with module discovery in online galleries.
74-
# Tags = @()
81+
Tags = 'AzureDNS', 'ConfigasCode'
7582

7683
# A URL to the license for this module.
77-
# LicenseUri = ''
84+
LicenseUri = 'https://github.com/Timsto/AzDnsAsCode/blob/master/LICENSE'
7885

7986
# A URL to the main website for this project.
80-
# ProjectUri = ''
87+
ProjectUri = 'https://github.com/Timsto/AzDnsAsCode'
8188

8289
# A URL to an icon representing this module.
8390
# IconUri = ''

AzDnsAsCode/AzDnsAsCode.psm1

+1-5
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,4 @@ if ($importIndividualFiles)
7878
# End it here, do not load compiled code below
7979
return
8080
}
81-
#endregion Load individual files
82-
83-
#region Load compiled code
84-
"<compile code into here>"
85-
#endregion Load compiled code
81+
#endregion Load individual files
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
function Get-ApplicationInsightsTelemetryClient
2+
{
3+
[CmdletBinding()]
4+
param()
5+
6+
if ($null -eq $Global:AzDnsAsCodeTelemetryEngine)
7+
{
8+
#$AI = "$PSScriptRoot\..\Dependencies\Microsoft.ApplicationInsights.dll"
9+
$AI = "C:\git\AzDnsAsCode\AzDnsAsCode\Dependencies\Microsoft.ApplicationInsights.dll"
10+
[Reflection.Assembly]::LoadFile($AI) | Out-Null
11+
12+
$InstrumentationKey = "1b8dc953-96b6-4876-b127-b0d81e911831"
13+
if ($null -ne $env:AzDnsAsCodeTelemetryInstrumentationKey)
14+
{
15+
$InstrumentationKey = $env:AzDnsAsCodeTelemetryInstrumentationKey
16+
}
17+
$TelClient = [Microsoft.ApplicationInsights.TelemetryClient]::new()
18+
$TelClient.InstrumentationKey = $InstrumentationKey
19+
20+
$Global:AzDnsAsCodeTelemetryEngine = $TelClient
21+
}
22+
return $Global:AzDnsAsCodeTelemetryEngine
23+
}
24+
25+
function Add-AzDnsAsCodeTelemetryEvent
26+
{
27+
[CmdletBinding()]
28+
param(
29+
[Parameter()]
30+
[System.String]
31+
$Type = 'Flow',
32+
33+
[Parameter()]
34+
[System.Collections.Generic.Dictionary[[System.String], [System.String]]]
35+
$Data,
36+
37+
[Parameter()]
38+
[System.Collections.Generic.Dictionary[[System.String], [System.Double]]]
39+
$Metrics
40+
)
41+
42+
$TelemetryEnabled = [System.Environment]::GetEnvironmentVariable('AzDnsAsCodeTelemetryEnabled', `
43+
[System.EnvironmentVariableTarget]::Machine)
44+
45+
if ($null -eq $TelemetryEnabled -or $TelemetryEnabled -eq $true)
46+
{
47+
$TelemetryClient = Get-ApplicationInsightsTelemetryClient
48+
49+
try
50+
{
51+
if ($null -ne $Data.TenantId)
52+
{
53+
$principalValue = $Data.TenantId
54+
$Data.Add("Tenant", $principalValue)
55+
}
56+
57+
$Data.Remove("TenandId") | Out-Null
58+
59+
# Capture PowerShell Version Info
60+
$Data.Add("PSMainVersion", $PSVersionTable.PSVersion.Major.ToString() + "." + $PSVersionTable.PSVersion.Minor.ToString())
61+
$Data.Add("PSVersion", $PSVersionTable.PSVersion.ToString())
62+
$Data.Add("PSEdition", $PSVersionTable.PSEdition.ToString())
63+
64+
# Capture Console/Host Information
65+
if ($host.Name -eq "ConsoleHost" -and $null -eq $env:WT_SESSION)
66+
{
67+
$Data.Add("PowerShellAgent", "Console")
68+
}
69+
elseif ($host.Name -eq "Windows PowerShell ISE Host")
70+
{
71+
$Data.Add("PowerShellAgent", "ISE")
72+
}
73+
elseif ($host.Name -eq "ConsoleHost" -and $null -ne $env:WT_SESSION)
74+
{
75+
$Data.Add("PowerShellAgent", "Windows Terminal")
76+
}
77+
elseif ($host.Name -eq "ConsoleHost" -and $null -eq $env:WT_SESSION -and `
78+
$null -ne $env:BUILD_BUILDID -and $env:SYSTEM -eq "build")
79+
{
80+
$Data.Add("PowerShellAgent", "Azure DevOPS")
81+
$Data.Add("AzureDevOPSPipelineType", "Build")
82+
$Data.Add("AzureDevOPSAgent", $env:POWERSHELL_DISTRIBUTION_CHANNEL)
83+
}
84+
elseif ($host.Name -eq "ConsoleHost" -and $null -eq $env:WT_SESSION -and `
85+
$null -ne $env:BUILD_BUILDID -and $env:SYSTEM -eq "release")
86+
{
87+
$Data.Add("PowerShellAgent", "Azure DevOPS")
88+
$Data.Add("AzureDevOPSPipelineType", "Release")
89+
$Data.Add("AzureDevOPSAgent", $env:POWERSHELL_DISTRIBUTION_CHANNEL)
90+
}
91+
elseif ($host.Name -eq "Default Host" -and `
92+
$null -ne $env:APPSETTING_FUNCTIONS_EXTENSION_VERSION)
93+
{
94+
$Data.Add("PowerShellAgent", "Azure Function")
95+
$Data.Add("AzureFunctionWorkerVersion", $env:FUNCTIONS_WORKER_RUNTIME_VERSION)
96+
}
97+
elseif ($host.Name -eq "CloudShell")
98+
{
99+
$Data.Add("PowerShellAgent", "Cloud Shell")
100+
}
101+
102+
[array]$version = (Get-Module 'AzDnsAsCode').Version | Sort-Object -Descending
103+
$Data.Add("AzDnsAsCodeVersion", $version[0].ToString())
104+
105+
# Get Dependencies loaded versions
106+
try
107+
{
108+
$currentPath = Join-Path -Path $PSScriptRoot -ChildPath '..\' -Resolve
109+
$manifest = Import-PowerShellDataFile "$currentPath/AzDnsAsCode.psd1"
110+
$dependencies = $manifest.RequiredModules
111+
112+
$dependenciesContent = ""
113+
foreach ($dependency in $dependencies)
114+
{
115+
$dependenciesContent += Get-Module $dependency.ModuleName | Out-String
116+
}
117+
$Data.Add("DependenciesVersion", $dependenciesContent)
118+
}
119+
catch
120+
{
121+
Write-Verbose -Message $_
122+
}
123+
124+
$TelemetryClient.TrackEvent($Type, $Data, $Metrics)
125+
$TelemetryClient.Flush()
126+
}
127+
catch
128+
{
129+
Write-Error $_
130+
}
131+
}
132+
}
133+
134+
function Set-AzDnsAsCodeTelemetryOption
135+
{
136+
[CmdletBinding()]
137+
param(
138+
[Parameter()]
139+
[System.Boolean]
140+
$Enabled,
141+
142+
[Parameter()]
143+
[System.String]
144+
$InstrumentationKey
145+
)
146+
147+
if ($null -ne $Enabled)
148+
{
149+
[System.Environment]::SetEnvironmentVariable('AzDnsAsCodeTelemetryEnabled', $Enabled, `
150+
[System.EnvironmentVariableTarget]::Machine)
151+
}
152+
153+
if ($null -ne $InstrumentationKey)
154+
{
155+
[System.Environment]::SetEnvironmentVariable('AzDnsAsCodeTelemetryInstrumentationKey', $InstrumentationKey, `
156+
[System.EnvironmentVariableTarget]::Machine)
157+
}
158+
}
159+
160+
function Get-AzDnsAsCodeTelemetryOption
161+
{
162+
[CmdletBinding()]
163+
param()
164+
165+
try
166+
{
167+
return @{
168+
Enabled = [System.Environment]::GetEnvironmentVariable('AzDnsAsCodeTelemetryEnabled', `
169+
[System.EnvironmentVariableTarget]::Machine)
170+
InstrumentationKey = [System.Environment]::GetEnvironmentVariable('AzDnsAsCodeTelemetryInstrumentationKey', `
171+
[System.EnvironmentVariableTarget]::Machine)
172+
}
173+
}
174+
catch
175+
{
176+
throw $_
177+
}
178+
}

AzDnsAsCode/changelog.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
# Changelog
2+
## 1.0.1 (2021-04-22)
3+
- New: added Telemetry functionality
4+
- New: Added validation of TTL, Port and Prio
5+
26
## 1.0.0 (2021-04-08)
37
- New: init

AzDnsAsCode/en-us/about_AzDnsAsCode.help.txt

-11
This file was deleted.

AzDnsAsCode/functions/Set-AzDnsAsCodeConfig.ps1

+8
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@
4343
[Parameter (Mandatory=$true)][String]$ResourceGroup
4444
)
4545

46+
#region TelemetryData
47+
$data = [System.Collections.Generic.Dictionary[[String], [String]]]::new()
48+
#$data.Add("DNSZone", $DNSZone)
49+
$data.Add("Method", $Method)
50+
$data.Add("Type", $Type)
51+
$data.Add("TenantId", $TenantId)
52+
Add-AzDnsAsCodeTelemetryEvent -Data $data
53+
#endregion TelemetryData
4654

4755
#region URL
4856
$uri = "https://management.azure.com/subscriptions/$SubscriptionId/resourceGroups/$ResourceGroup/providers/Microsoft.Network/dnszones/$DNSZone/$Type/$($Domain)?api-version=$($script:APIversion)"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
function checkToken
2+
{
3+
<#
4+
.SYNOPSIS
5+
check if a valid token exist
6+
7+
.DESCRIPTION
8+
check if a valid token exist
9+
10+
.PARAMETER targetEndPoint
11+
Api Endpoint like 'MsGraphApi'
12+
13+
.EXAMPLE
14+
PS C:\> checkToken -targetEndpoint "MsGraphApi"
15+
16+
check Token
17+
#>
18+
[CmdletBinding()]
19+
param (
20+
$targetEndpoint
21+
)
22+
Write-Verbose "Check token"
23+
if ($script:htBearerAccessToken.$targetEndpoint.expire.LocalDateTime -lt $(Get-Date).AddMinutes(-5) -or ($null -eq $script:htBearerAccessToken.$targetEndpoint.expire))
24+
{
25+
Write-Output "Generate new token for Endpoint $($TargetEndpoint)"
26+
createBearerToken -targetEndPoint $targetEndpoint
27+
}
28+
}

0 commit comments

Comments
 (0)