Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Sep 27, 2019. It is now read-only.

Commit d0f9f1f

Browse files
Copy utility module to generated module to remove dependency (#396)
Copy utility module to generated module to remove dependency (#396)
1 parent ca98c0d commit d0f9f1f

18 files changed

+1017
-756
lines changed

‎PSSwagger/PSSwagger.Constants.ps1‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,12 @@ Microsoft.PowerShell.Core\Set-StrictMode -Version Latest
4141
# If the user supplied -Prefix to Import-Module, that applies to the nested module as well
4242
# Force import the nested module again without -Prefix
4343
if (-not (Get-Command Get-OperatingSystemInfo -Module PSSwaggerUtility -ErrorAction Ignore)) {
44-
Import-Module PSSwaggerUtility -Force
44+
# Simply doing "Import-Module PSSwaggerUtility" doesn't work for local case
45+
if (Test-Path -Path (Join-Path -Path `$PSScriptRoot -ChildPath PSSwaggerUtility)) {
46+
Import-Module (Join-Path -Path `$PSScriptRoot -ChildPath PSSwaggerUtility) -Force
47+
} else {
48+
Import-Module PSSwaggerUtility -Force
49+
}
4550
}
4651
4752
if ((Get-OperatingSystemInfo).IsCore) {

‎PSSwagger/PSSwagger.Resources.psd1‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,5 +96,9 @@ ConvertFrom-StringData @'
9696
CouldntFindClientSideParameterSet=Couldn't find client-side parameter set: {0}
9797
MissingRequiredFilterParameter=Required server-side parameter '{0}' is not required by the client-side, which will cause issues in client-side filtering. Can't include client-side filtering.
9898
FailedToAddAutomaticFilter=Failed to add automatic client-side filter for candidate command '{0}': Mandatory List parameter '{1}' has no matching Get mandatory parameter. It will be impossible to guarantee execution of the List method before client-side filtering occurs.
99+
CopyingUtilityModule=Copying utility module to generated module
100+
ReSignUtilityModuleWarning=The local copy of the utility module at '{0}' should be signed or re-signed before distribution.
101+
TracingDisabled=Local utility module copies have service-level tracing disabled. This includes, but is not limited to, tracing what is sent and received from the service.
102+
CredentialsDisabled=Local utility module copies have built-in service credential types disabled.
99103
###PSLOC
100104
'@

‎PSSwagger/PSSwagger.psm1‎

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,14 @@ Microsoft.PowerShell.Utility\Import-LocalizedData LocalizedData -filename PSSwa
132132
133133
.PARAMETER Formatter
134134
Specify a formatter to use.
135+
136+
.PARAMETER CopyUtilityModuleToOutput
137+
Copy the utility module to the output generated module. This has the effect of hardcoding the version of the utility module used by the generated module. The copied utility module must be re-signed if it was originally signed.
138+
139+
.PARAMETER AddUtilityDependencies
140+
Ensure any external assemblies required by the utility module are included somewhere in the module. This has the effect of making the utility module offline-compatible.
141+
142+
135143
.INPUTS
136144
137145
.OUTPUTS
@@ -248,7 +256,21 @@ function New-PSSwaggerModule {
248256
[Parameter(Mandatory = $false, ParameterSetName = 'SdkAssemblyWithSpecificationUri')]
249257
[string]
250258
[ValidateSet('None', 'PSScriptAnalyzer')]
251-
$Formatter
259+
$Formatter,
260+
261+
[Parameter(Mandatory = $false, ParameterSetName = 'SpecificationPath')]
262+
[Parameter(Mandatory = $false, ParameterSetName = 'SpecificationUri')]
263+
[Parameter(Mandatory = $false, ParameterSetName = 'SdkAssemblyWithSpecificationPath')]
264+
[Parameter(Mandatory = $false, ParameterSetName = 'SdkAssemblyWithSpecificationUri')]
265+
[switch]
266+
$CopyUtilityModuleToOutput,
267+
268+
[Parameter(Mandatory = $false, ParameterSetName = 'SpecificationPath')]
269+
[Parameter(Mandatory = $false, ParameterSetName = 'SpecificationUri')]
270+
[Parameter(Mandatory = $false, ParameterSetName = 'SdkAssemblyWithSpecificationPath')]
271+
[Parameter(Mandatory = $false, ParameterSetName = 'SdkAssemblyWithSpecificationUri')]
272+
[switch]
273+
$AddUtilityDependencies
252274
)
253275

254276
if ($NoAssembly -and $IncludeCoreFxAssembly) {
@@ -589,9 +611,9 @@ function New-PSSwaggerModule {
589611

590612
# Add extra metadata based on service type
591613
if (($PowerShellCodeGen['ServiceType'] -eq 'azure') -or ($PowerShellCodeGen['ServiceType'] -eq 'azure_stack') -and
592-
($PowerShellCodeGen.ContainsKey('azureDefaults') -and $PowerShellCodeGen['azureDefaults'] -and
593-
(-not (Get-Member -InputObject $PowerShellCodeGen['azureDefaults'] -Name 'clientSideFiltering')) -or
594-
($PowerShellCodeGen['azureDefaults'].ClientSideFiltering))) {
614+
($PowerShellCodeGen.ContainsKey('azureDefaults') -and $PowerShellCodeGen['azureDefaults'] -and
615+
(-not (Get-Member -InputObject $PowerShellCodeGen['azureDefaults'] -Name 'clientSideFiltering')) -or
616+
($PowerShellCodeGen['azureDefaults'].ClientSideFiltering))) {
595617
foreach ($entry in $PathFunctionDetails.GetEnumerator()) {
596618
$hyphenIndex = $entry.Name.IndexOf("-")
597619
if ($hyphenIndex -gt -1) {
@@ -800,6 +822,42 @@ function New-PSSwaggerModule {
800822
-PSHeaderComment $PSHeaderComment
801823
}
802824

825+
if ($CopyUtilityModuleToOutput) {
826+
Write-Verbose -Message $LocalizedData.CopyingUtilityModule
827+
$utilityModuleInfo = Get-Module PSSwaggerUtility
828+
$existingPath = (Join-Path -Path $outputDirectory -ChildPath PSSwaggerUtility)
829+
Write-Warning -Message ($LocalizedData.ReSignUtilityModuleWarning -f $existingPath)
830+
if (Test-Path -Path $existingPath) {
831+
$null = Remove-Item -Path $existingPath -Recurse -Force
832+
}
833+
834+
$null = New-Item -Path $existingPath -ItemType Directory -Force
835+
foreach ($item in Get-ChildItem -Path $utilityModuleInfo.ModuleBase) {
836+
$filePath = $item.FullName
837+
if ($item.Name -eq 'PSSwaggerClientTracing.psm1') {
838+
Write-Warning -Message $LocalizedData.TracingDisabled
839+
$filePath = Join-Path -Path $PSScriptRoot -ChildPath 'PSSwaggerClientTracing_Dummy.psm1'
840+
}
841+
elseif ($item.Name -eq 'PSSwaggerServiceCredentialsHelpers.psm1') {
842+
Write-Warning -Message $LocalizedData.CredentialsDisabled
843+
$filePath = Join-Path -Path $PSScriptRoot -ChildPath 'PSSwaggerServiceCredentialsHelpers_Dummy.psm1'
844+
}
845+
elseif (($item.Name -eq 'PSSwaggerNetUtilities.Code.ps1') -or ($item.Name -eq 'PSSwaggerNetUtilities.Unsafe.Code.ps1')) {
846+
$filePath = $null
847+
}
848+
849+
if ($filePath) {
850+
$content = Remove-AuthenticodeSignatureBlock -Path $filePath
851+
if ($item.Name -eq 'PSSwaggerUtility.Resources.psd1') {
852+
$namespaceIndex = $content | Select-String -Pattern "CSharpNamespace=Microsoft.PowerShell.Commands.PSSwagger"
853+
$content[$namespaceIndex.LineNumber - 1] = " CSharpNamespace=$($SwaggerDict['info'].NameSpace)"
854+
}
855+
856+
$content | Out-File -FilePath (Join-Path -Path $existingPath -ChildPath $item.Name)
857+
}
858+
}
859+
}
860+
803861
Write-Verbose -Message ($LocalizedData.SuccessfullyGeneratedModule -f $Name, $outputDirectory)
804862
}
805863

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#########################################################################################
2+
#
3+
# Copyright (c) Microsoft Corporation. All rights reserved.
4+
#
5+
# Licensed under the MIT license.
6+
#
7+
# PSSwaggerUtility Module
8+
#
9+
#########################################################################################
10+
11+
12+
function New-PSSwaggerClientTracingInternal {
13+
[CmdletBinding()]
14+
param()
15+
16+
$null
17+
}
18+
19+
function Register-PSSwaggerClientTracingInternal {
20+
[CmdletBinding()]
21+
param(
22+
[object]$TracerObject
23+
)
24+
}
25+
26+
function Unregister-PSSwaggerClientTracingInternal {
27+
[CmdletBinding()]
28+
param(
29+
[object]$TracerObject
30+
)
31+
}
32+
33+
Export-ModuleMember -Function *
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#########################################################################################
2+
#
3+
# Copyright (c) Microsoft Corporation. All rights reserved.
4+
#
5+
# Licensed under the MIT license.
6+
#
7+
# PSSwaggerUtility Module
8+
#
9+
#########################################################################################
10+
Microsoft.PowerShell.Core\Set-StrictMode -Version Latest
11+
Microsoft.PowerShell.Utility\Import-LocalizedData LocalizedData -filename PSSwaggerUtility.Resources.psd1
12+
13+
function Get-BasicAuthCredentialInternal {
14+
[CmdletBinding()]
15+
param(
16+
[Parameter(Mandatory=$true)]
17+
[PSCredential]
18+
$Credential
19+
)
20+
}
21+
22+
function Get-ApiKeyCredentialInternal {
23+
[CmdletBinding()]
24+
param(
25+
[Parameter(Mandatory=$true)]
26+
[string]
27+
$APIKey,
28+
29+
[Parameter(Mandatory=$false)]
30+
[string]
31+
$Location,
32+
33+
[Parameter(Mandatory=$false)]
34+
[string]
35+
$Name
36+
)
37+
}
38+
39+
function Get-EmptyAuthCredentialInternal {
40+
[CmdletBinding()]
41+
param()
42+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /