aws / aws-tools-for-powershell

The AWS Tools for PowerShell lets developers and administrators manage their AWS services from the PowerShell scripting environment.
Apache License 2.0
236 stars 78 forks source link

Remove unnecessary Find-Module #84

Closed tlindsay42 closed 4 years ago

tlindsay42 commented 4 years ago

Description

When multiple versions are found for the specified modules, the minimum version is selected, and then another series of Find-Module is run to query the PowerShell Gallery for each specified module, which is unnecessary and slow.

Motivation and Context

Improves performance by pruning slow & unnecessary code. Resolves #83

Testing

Imported working version and re-ran Install-AWSToolsModule -Name '*' (unsupported, but effective for demonstrating the test). Arrives at the confirmation prompt much faster that specifies the version to install.

Example 1

C:\> Install-AWSToolsModule -Name AWS.Tools.* -Verbose
VERBOSE: [Install-AWSToolsModule] ConfirmPreference=High WhatIfPreference=False VerbosePreference=Continue Force=False
VERBOSE: [Get-AvailableModuleVersion] ConfirmPreference=High WhatIfPreference=False VerbosePreference=Continue Force=False
VERBOSE: [Get-AvailableModuleVersion] Found multiple modules versions: 1.0.0.1, 4.0.1.0, 4.0.1.1.)
VERBOSE: [Get-AvailableModuleVersion] End
VERBOSE: [Install-AWSToolsModule] Installing AWS Tools version 1.0.0.1
VERBOSE: [Install-AWSToolsModule] Searching installed modules
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.APIGateway.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.ApiGatewayV2.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.Common.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.Common.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.EC2.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.EC2.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.ECR.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.Installer.
VERBOSE: [Install-AWSToolsModule] Merging existing modules into the list of modules to install
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.APIGateway.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.ApiGatewayV2.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.Common.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.Common.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.EC2.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.EC2.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.ECR.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.Installer.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.APIGateway.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.ApiGatewayV2.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.Common.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.Common.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.EC2.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.EC2.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.ECR.

Confirm
Are you sure you want to perform this action?
Performing the operation "Install-AWSToolsModule" on target "AWS Tools version 1.0.0.1".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"):
VERBOSE: [Install-AWSToolsModule] Create folder for temporary repository ~\AppData\Local\Temp\jopffh3j.u2v
VERBOSE: [Install-AWSToolsModule] Registering temporary repository AWSToolsTemp
VERBOSE: [Install-AWSToolsModule] Downloading modules to temporary repository
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.APIGateway.
VERBOSE: [Save-AWSToolsModule] ConfirmPreference=None WhatIfPreference=False VerbosePreference=Continue Force=False
VERBOSE: [Install-AWSToolsModule] Unregistering temporary repository AWSToolsTemp
VERBOSE: [Install-AWSToolsModule] Delete repository folder ~\AppData\Local\Temp\jopffh3j.u2v
PackageManagement\Find-Package : No match was found for the specified search criteria and module name 'AWS.Tools.APIGateway'. Try Get-PSRepository to see all available registered module repositories.
At ~\Documents\PowerShell\Modules\PowerShellGet\2.2.1\PSModule.psm1:8871 char:9
+         PackageManagement\Find-Package @PSBoundParameters | Microsoft ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : ObjectNotFound: (Microsoft.PowerShel\u2026Cmdlets.FindPackage:FindPackage) [Find-Package], Exception
+ FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackage

Example 2

~> Install-AWSToolsModule -Name AWS.Tools.* -Verbose -RequiredVersion '4.0.1.1'
VERBOSE: [Install-AWSToolsModule] ConfirmPreference=High WhatIfPreference=False VerbosePreference=Continue Force=False
VERBOSE: [Install-AWSToolsModule] Searching installed modules
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.APIGateway.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.ApiGatewayV2.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.Common.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.Common.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.EC2.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.EC2.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.ECR.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.Installer.
VERBOSE: [Install-AWSToolsModule] Merging existing modules into the list of modules to install
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.APIGateway.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.ApiGatewayV2.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.Common.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.Common.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.EC2.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.EC2.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.ECR.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.Installer.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.APIGateway.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.ApiGatewayV2.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.Common.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.Common.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.EC2.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.EC2.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.ECR.

Confirm
Are you sure you want to perform this action?
Performing the operation "Install-AWSToolsModule" on target "AWS Tools version 4.0.1.1".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"):
VERBOSE: [Install-AWSToolsModule] Create folder for temporary repository ~\AppData\Local\Temp\rvr2aclh.uhb
VERBOSE: [Install-AWSToolsModule] Registering temporary repository AWSToolsTemp
VERBOSE: [Install-AWSToolsModule] Downloading modules to temporary repository
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.APIGateway.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.ApiGatewayV2.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.Common.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.Common.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.EC2.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.EC2.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.ECR.
VERBOSE: Populating RepositorySourceLocation property for module AWS.Tools.Installer.
VERBOSE: [Save-AWSToolsModule] ConfirmPreference=None WhatIfPreference=False VerbosePreference=Continue Force=False
VERBOSE: [Install-AWSToolsModule] Unregistering temporary repository AWSToolsTemp
VERBOSE: [Install-AWSToolsModule] Delete repository folder ~\AppData\Local\Temp\rvr2aclh.uhb
Find-Module : The RequiredVersion, MinimumVersion, MaximumVersion, AllVersions or AllowPrerelease parameters are allowed only when you specify a single name as the value of the Name parameter, without any wildcard characters.
At ~\git\aws-tools-for-powershell\modules\installer\AWS.Tools.Installer.psm1:313 char:27
+             $moduleInfo = Find-Module @findModuleParams @proxyParams
+                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidArgument: (:) [Find-Module], ArgumentException
+ FullyQualifiedErrorId : VersionParametersAreAllowedOnlyWithSingleName,Find-Module

Types of changes

Checklist

License

matteo-prosperi commented 4 years ago

This looks fine to me. I have to run tests on the module in the next few days, so I will run it through some tests to be extra sure. Thanks for the PR.