Skip to content

Commit 6d9e20a

Browse files
authored
Fix/export connect cmdlet (#69)
* Fix cmdlet export
1 parent 5df6208 commit 6d9e20a

2 files changed

Lines changed: 39 additions & 41 deletions

File tree

src/PSRule.Rules.AzureDevOps/PSRule.Rules.AzureDevOps.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ RequiredModules = @('PSRule')
6969
# NestedModules = @()
7070

7171
# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
72-
FunctionsToExport = @('Export-AzDevOpsRuleData','*')
72+
FunctionsToExport = @('Export-AzDevOpsRuleData','Export-AzDevOpsOrganizationRuleData','Connect-AzDevOps','Disconnect-AzDevOps','*')
7373

7474
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
7575
CmdletsToExport = @()

src/PSRule.Rules.AzureDevOps/PSRule.Rules.AzureDevOps.psm1

Lines changed: 38 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -14,45 +14,6 @@ Get-ChildItem -Path "$PSScriptRoot/Functions/*.ps1" | ForEach-Object {
1414
. $_.FullName
1515
}
1616

17-
# Define the types to export with type accelerators.
18-
$ExportableTypes =@(
19-
[AzureDevOpsConnection]
20-
)
21-
# Get the internal TypeAccelerators class to use its static methods.
22-
$TypeAcceleratorsClass = [psobject].Assembly.GetType(
23-
'System.Management.Automation.TypeAccelerators'
24-
)
25-
# Ensure none of the types would clobber an existing type accelerator.
26-
# If a type accelerator with the same name exists, throw an exception.
27-
$ExistingTypeAccelerators = $TypeAcceleratorsClass::Get
28-
foreach ($Type in $ExportableTypes) {
29-
if ($Type.FullName -in $ExistingTypeAccelerators.Keys) {
30-
$Message = @(
31-
"Unable to register type accelerator '$($Type.FullName)'"
32-
'Accelerator already exists.'
33-
) -join ' - '
34-
35-
throw [System.Management.Automation.ErrorRecord]::new(
36-
[System.InvalidOperationException]::new($Message),
37-
'TypeAcceleratorAlreadyExists',
38-
[System.Management.Automation.ErrorCategory]::InvalidOperation,
39-
$Type.FullName
40-
)
41-
}
42-
}
43-
# Add type accelerators for every exportable type.
44-
foreach ($Type in $ExportableTypes) {
45-
$TypeAcceleratorsClass::Add($Type.FullName, $Type) | Out-Null
46-
}
47-
# Remove type accelerators when the module is removed.
48-
$MyInvocation.MyCommand.ScriptBlock.Module.OnRemove = {
49-
foreach($Type in $ExportableTypes) {
50-
$TypeAcceleratorsClass::Remove($Type.FullName) | Out-Null
51-
}
52-
}.GetNewClosure()
53-
54-
55-
5617
<#
5718
.SYNOPSIS
5819
Run all JSON export functions for Azure DevOps for analysis by PSRule
@@ -126,4 +87,41 @@ Export-ModuleMember -Function Export-AzDevOpsOrganizationRuleData
12687

12788
Export-ModuleMember -Function Get-AzDevOpsProjects
12889
Export-ModuleMember -Function Connect-AzDevOps
129-
Export-ModuleMember -Function Disconnect-AzDevOps
90+
Export-ModuleMember -Function Disconnect-AzDevOps
91+
92+
# Define the types to export with type accelerators.
93+
$ExportableTypes =@(
94+
[AzureDevOpsConnection]
95+
)
96+
# Get the internal TypeAccelerators class to use its static methods.
97+
$TypeAcceleratorsClass = [psobject].Assembly.GetType(
98+
'System.Management.Automation.TypeAccelerators'
99+
)
100+
# Ensure none of the types would clobber an existing type accelerator.
101+
# If a type accelerator with the same name exists, throw an exception.
102+
$ExistingTypeAccelerators = $TypeAcceleratorsClass::Get
103+
foreach ($Type in $ExportableTypes) {
104+
if ($Type.FullName -in $ExistingTypeAccelerators.Keys) {
105+
$Message = @(
106+
"Unable to register type accelerator '$($Type.FullName)'"
107+
'Accelerator already exists.'
108+
) -join ' - '
109+
110+
throw [System.Management.Automation.ErrorRecord]::new(
111+
[System.InvalidOperationException]::new($Message),
112+
'TypeAcceleratorAlreadyExists',
113+
[System.Management.Automation.ErrorCategory]::InvalidOperation,
114+
$Type.FullName
115+
)
116+
}
117+
}
118+
# Add type accelerators for every exportable type.
119+
foreach ($Type in $ExportableTypes) {
120+
$TypeAcceleratorsClass::Add($Type.FullName, $Type) | Out-Null
121+
}
122+
# Remove type accelerators when the module is removed.
123+
$MyInvocation.MyCommand.ScriptBlock.Module.OnRemove = {
124+
foreach($Type in $ExportableTypes) {
125+
$TypeAcceleratorsClass::Remove($Type.FullName) | Out-Null
126+
}
127+
}.GetNewClosure()

0 commit comments

Comments
 (0)