Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
FriedrichWeinmann committed Dec 27, 2024
1 parent 69f988a commit 63c1cbe
Show file tree
Hide file tree
Showing 18 changed files with 1,396 additions and 378 deletions.
3 changes: 2 additions & 1 deletion PSFramework.NuGet/PSFramework.NuGet.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
RootModule = 'PSFramework.NuGet.psm1'

# Version number of this module.
ModuleVersion = '1.0.0'
ModuleVersion = '0.9.0'

# ID used to uniquely identify this module
GUID = 'ad0f2a25-552f-4dd6-bd8e-5ddced2a5d88'
Expand Down Expand Up @@ -52,6 +52,7 @@
'Save-PSFPowerShellGet'
'Save-PSFResourceModule'
'Search-PSFPowerShellGet'
'Set-PSFRepository'
'Update-PSFRepository'
)

Expand Down
89 changes: 72 additions & 17 deletions PSFramework.NuGet/functions/Get/Find-PSFModule.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,60 @@
function Find-PSFModule {
<#
.SYNOPSIS
Search for modules in PowerShell repositories.
.DESCRIPTION
Search for modules in PowerShell repositories.
.PARAMETER Name
Name(s) of the module(s) to look for.
.PARAMETER Repository
The repositories to search in.
.PARAMETER Tag
Tags to search by.
.PARAMETER Credential
Credentials to use to access repositories.
.PARAMETER AllowPrerelease
Whether to include modules flagged as "Prerelease" as part of the results
.PARAMETER IncludeDependencies
Whether to also list all required dependencies.
.PARAMETER Version
Version constrains for the module to search.
Will use the latest version available within the limits.
Examples:
- "1.0.0": EXACTLY this one version
- "1.0.0-1.999.999": Any version between the two limits (including the limit values)
- "[1.0.0-2.0.0)": Any version greater or equal to 1.0.0 but less than 2.0.0
- "2.3.0-": Any version greater or equal to 2.3.0.
Supported Syntax:
<Prefix><Version><Connector><Version><Suffix>
Prefix: "[" (-ge) or "(" (-gt) or nothing (-ge)
Version: A valid version of 2-4 elements or nothing
Connector: A "," or a "-"
Suffix: "]" (-le) or ")" (-lt) or nothing (-le)
.PARAMETER AllVersions
Whether all versions available should be returned together
.PARAMETER Type
What kind of repository to search in.
+ All: (default) Use all, irrespective of type
+ V2: Only search classic repositories, as would be returned by Get-PSRepository
+ V3: Only search modern repositories, as would be returned by Get-PSResourceRepository
.EXAMPLE
PS C:\> Find-PSFModule -Name PSFramework
Search all configured repositories for the module "PSFramework"
#>
[CmdletBinding(DefaultParameterSetName = 'default')]
Param (
[Parameter(Position = 0)]
Expand All @@ -22,17 +78,9 @@
[switch]
$IncludeDependencies,

[Parameter(ParameterSetName = 'VersionRange')]
[version]
$MinimumVersion,

[Parameter(ParameterSetName = 'VersionRange')]
[version]
$MaximumVersion,

[Parameter(ParameterSetName = 'RequiredVersion')]
[version]
$RequiredVersion,
[Parameter(ParameterSetName = 'Version')]
[string]
$Version,

[Parameter(ParameterSetName = 'AllVersions')]
[switch]
Expand Down Expand Up @@ -71,11 +119,13 @@
}
#endregion Functions

$useVersionFilter = $MinimumVersion -or $MaximumVersion -or $RequiredVersion -or $AllVersions
switch ($PSCmdlet.ParameterSetName) {
'VersionRange' { $versionFilter = '[{0}, {1}]' -f $MinimumVersion, $MaximumVersion }
'RequiredVersion' { $versionFilter = "$RequiredVersion" }
'AllVersions' { $versionFilter = '*' }
$useVersionFilter = $Version -or $AllVersions
if ($Version) {
$convertedVersion = Read-VersionString -Version $Version -Cmdlet $PSCmdlet
$versionFilter = $convertedVersion.V3String
}
if ($PSCmdlet.ParameterSetName -eq 'AllVersions') {
$versionFilter = '*'
}

$param = $PSBoundParameters | ConvertTo-PSFHashtable -Include Name, Repository, Tag, Credential, IncludeDependencies
Expand All @@ -84,7 +134,12 @@
#region V2
if ($script:psget.V2 -and $Type -in 'All', 'V2') {
$paramClone = $param.Clone()
$paramClone += $PSBoundParameters | ConvertTo-PSFHashtable -Include MinimumVersion, MaximumVersion, RequiredVersion, AllVersions, AllowPrerelease
$paramClone += $PSBoundParameters | ConvertTo-PSFHashtable -Include AllVersions, AllowPrerelease
if ($Version) {
if ($convertedVersion.Required) { $paramClone.RequiredVersion = $convertedVersion.Required }
if ($convertedVersion.Minimum) { $paramClone.MinimumVersion = $convertedVersion.Minimum }
if ($convertedVersion.Maximum) { $paramClone.MaximumVersion = $convertedVersion.Maximum }
}
$execute = $true
if ($paramClone.Repository) {
$paramClone.Repository = $paramClone.Repository | Where-Object {
Expand Down
34 changes: 33 additions & 1 deletion PSFramework.NuGet/functions/Get/Get-PSFRepository.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,36 @@
function Get-PSFRepository {
<#
.SYNOPSIS
Lists available PowerShell repositories.
.DESCRIPTION
Lists available PowerShell repositories.
Includes both classic (V2 | Get-PSRepository) and new (V3 | Get-PSResourceRepository) repositories.
This will also include additional metadata, including priority, which in this module is also applicable to classic repositories.
Note on Status:
In V2 repositories, the status can show "NoPublish" or "NoInstall".
This is determined by whether it has been bootstrapped at the system level.
If you have already bootstrapped it in user-mode, this may not be reflected correctly.
If your computer is internet-facing, it can also automatically bootstrap itself without any issues.
.PARAMETER Name
Name of the repository to list.
.PARAMETER Type
What kind of repository to return:
+ All: (default) Return all, irrespective of type
+ V2: Only return classic repositories, as would be returned by Get-PSRepository
+ V3: Only return modern repositories, as would be returned by Get-PSResourceRepository
.EXAMPLE
PS C:\> Get-PSFRepository
List all available repositories.
#>
[CmdletBinding()]
Param (
[PsfArgumentCompleter('PSFramework.NuGet.Repository')]
[string[]]
$Name = '*',

Expand All @@ -21,9 +51,10 @@
Type = 'V3'
Status = 'OK'
Trusted = $repository.Trusted
Priority = $repository.Priority
Priority = Get-PSFConfigValue -FullName "PSFramework.NuGet.Repositories.$($repository.Name).Priority" -Fallback $repository.Priority
Uri = $repository.Uri
Object = $repository
Credential = Get-PSFConfigValue -FullName "PSFramework.NuGet.Repositories.$($repository.Name).Credential"
}
}
}
Expand All @@ -42,6 +73,7 @@
Priority = Get-PSFConfigValue -FullName "PSFramework.NuGet.Repositories.$($repository.Name).Priority" -Fallback 100
Uri = $repository.SourceLocation
Object = $repository
Credential = Get-PSFConfigValue -FullName "PSFramework.NuGet.Repositories.$($repository.Name).Credential"
}
}
}
Expand Down
165 changes: 161 additions & 4 deletions PSFramework.NuGet/functions/Get/Save-PSFModule.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,151 @@
function Save-PSFModule {
<#
.SYNOPSIS
Downloads modules to a specified path.
.DESCRIPTION
Downloads modules to a specified path.
Supports flexible repository resolution, modern versioning and deployment to remote systems.
When specifying remote computers, all file transfer is performed via PSRemoting only.
ErrorAction is only honored for local deployments.
.PARAMETER Name
Name of the module to download.
.PARAMETER Version
Version constrains for the module to save.
Will use the latest version available within the limits.
Examples:
- "1.0.0": EXACTLY this one version
- "1.0.0-1.999.999": Any version between the two limits (including the limit values)
- "[1.0.0-2.0.0)": Any version greater or equal to 1.0.0 but less than 2.0.0
- "2.3.0-": Any version greater or equal to 2.3.0.
Supported Syntax:
<Prefix><Version><Connector><Version><Suffix>
Prefix: "[" (-ge) or "(" (-gt) or nothing (-ge)
Version: A valid version of 2-4 elements or nothing
Connector: A "," or a "-"
Suffix: "]" (-le) or ")" (-lt) or nothing (-le)
.PARAMETER Prerelease
Whether to include prerelease versions in the potential results.
.PARAMETER Path
Where to store the modules.
If used together with the -ComputerName parameter, this is considered a local path from within the context of a remoting session to that computer,
If you want to deploy a module to "\\server1\C$\Scripts\Modules" provide "C:\Scripts\Modules" as -Path, with "-ComputerName server1".
Unless you actually WANT to deploy without remoting but with SMB (in which case do not provide a -ComputerName)
See examples for less confusion :)
.PARAMETER ComputerName
The computers to deploy the modules to.
Accepts both names or established PSRemoting sessions.
The -Path parameter will be considered as a local path from within a remoting session.
If you want to deploy a module to "\\ComputerName\C$\Scripts\Modules" provide "C:\Scripts\Modules" as -Path.
See examples for less confusion :)
If you provide names, by default this module will connect to the "Microsoft.PowerShell" configuration name.
To change that name, use the 'PSFramework.NuGet.Remoting.DefaultConfiguration' configuration setting.
.PARAMETER SkipDependency
Do not include any dependencies.
Works with PowerShellGet V1/V2 as well.
.PARAMETER AuthenticodeCheck
Whether modules must be correctly signed by a trusted source.
Uses "Get-PSFModuleSignature" for validation.
Defaults to: $false
Default can be configured under the 'PSFramework.NuGet.Install.AuthenticodeSignature.Check' setting.
.PARAMETER Force
Redeploy a module that already exists in the target path.
By default it will skip modules that do already exist in the target path.
.PARAMETER Credential
The credentials to use for connecting to the Repository (NOT the remote computers).
.PARAMETER RemotingCredential
The credentials to use for connecting to remote computers we want to deploy modules to via remoting.
These will NOT be used for repository access.
.PARAMETER ThrottleLimit
Up to how many computers to deploy the modules to in parallel.
Defaults to: 5
Default can be configured under the 'PSFramework.NuGet.Remoting.Throttling' setting.
.PARAMETER Repository
Repositories to install from. Respects the priority order of repositories.
See Get-PSFRepository for available repositories (and their priority).
Lower numbers are installed from first.
.PARAMETER TrustRepository
Whether we should trust the repository installed from and NOT ask users for confirmation.
.PARAMETER Type
What type of repository to download from.
V2 uses classic Save-Module.
V3 uses Save-PSResource.
Availability depends on the installed PSGet module versions and configured repositories.
Use Install-PSFPowerShellGet to deploy the latest versions of the package modules.
Only the version on the local computer matters, even when deploying to remote computers.
.PARAMETER InputObject
The module to install.
Takes the output of Get-Module, Find-Module, Find-PSResource and Find-PSFModule, to specify the exact version and name of the module.
Even when providing a locally available version, the module will still be downloaded from the repositories chosen.
.PARAMETER WhatIf
If this switch is enabled, no actions are performed but informational messages will be displayed that explain what would happen if the command were to run.
.PARAMETER Confirm
If this switch is enabled, you will be prompted for confirmation before executing any operations that change state.
.EXAMPLE
PS C:\> Save-PSFModule EntraAuth -Path C:\temp
Downloads the module "EntraAuth" to the local C:\temp path.
.EXAMPLE
PS C:\> Save-PSFModule -Name EntraAuth -Path 'C:\Program Files\WindowsPowerShell\Modules'
Downloads the latest version of EntraAuth and places it where both PowerShell versions look for modules.
.EXAMPLE
PS C:\> Save-PSFModule -Name EntraAuth -Path 'C:\Program Files\WindowsPowerShell\Modules' -Force
Downloads the latest version of EntraAuth and places it where both PowerShell versions look for modules.
If the module has already been installed previously in the same version, it will replace the old install with the newly downloaded one.
.EXAMPLE
PS C:\> Save-PSFModule -Name EntraAuth -Path '\\server1\C$\Program Files\WindowsPowerShell\Modules'
Downloads the latest version of EntraAuth and places it where both PowerShell versions look for modules ... on computer "server1".
File transfer happens via SMB - lets hope that works.
.EXAMPLE
PS C:\> Save-PSFModule -Name EntraAuth -Path 'C:\Program Files\WindowsPowerShell\Modules' -ComputerName server1
Downloads the latest version of EntraAuth and places it where both PowerShell versions look for modules ... on computer "server1".
File transfer happens via PSRemoting, assuming our account has local admin rights on the remote computer.
.EXAMPLE
PS C:\> Save-PSFModule -Name EntraAuth -Path 'C:\Program Files\WindowsPowerShell\Modules' -ComputerName server1 -RemotingCredential $cred
Downloads the latest version of EntraAuth and places it where both PowerShell versions look for modules ... on computer "server1".
File transfer happens via PSRemoting, assuming the account in $cred has local admin rights on the remote computer.
.EXAMPLE
PS C:\> Save-PSFModule -Name EntraAuth -Path '/usr/local/share/powershell/Modules' -ComputerName $sessions
Downloads the latest version of EntraAuth and places it where both PowerShell versions look for modules on linux distributions ... on the computers previously connected.
On PowerShell 7, these can be remoting sessions established via SSH.
File transfer happens via PSRemoting.
#>
[CmdletBinding(PositionalBinding = $false, DefaultParameterSetName = 'ByName', SupportsShouldProcess = $true)]
Param (
[Parameter(Mandatory = $true, Position = 0, ParameterSetName = 'ByName')]
Expand Down Expand Up @@ -32,13 +179,16 @@
[PSCredential]
$Credential,

[ValidateRange(1,[int]::MaxValue)]
[PSCredential]
$RemotingCredential,

[ValidateRange(1, [int]::MaxValue)]
[int]
$ThrottleLimit = 5,
$ThrottleLimit = (Get-PSFConfigValue -FullName 'PSFramework.NuGet.Remoting.Throttling'),

[PsfArgumentCompleter('PSFramework.NuGet.Repository')]
[string[]]
$Repository,
$Repository = ((Get-PSFrepository).Name | Sort-Object -Unique),

[switch]
$TrustRepository,
Expand All @@ -54,12 +204,18 @@

begin {
$repositories = Resolve-Repository -Name $Repository -Type $Type -Cmdlet $PSCmdlet # Terminates if no repositories found
$managedSessions = New-ManagedSession -ComputerName $ComputerName -Cmdlet $PSCmdlet -Type Temporary
$managedSessions = New-ManagedSession -ComputerName $ComputerName -Credential $RemotingCredential -Cmdlet $PSCmdlet -Type Temporary
if ($ComputerName -and -not $managedSessions) {
Stop-PSFFunction -String 'Save-PSFModule.Error.NoComputerValid' -EnableException ($ErrorActionPreference -eq 'Stop') -Cmdlet $PSCmdlet
return
}
$resolvedPaths = Resolve-RemotePath -Path $Path -ComputerName $managedSessions.Session -ManagedSession $managedSessions -TargetHandling Any -Cmdlet $PSCmdlet # Errors for bad paths, terminates if no path

$tempDirectory = New-PSFTempDirectory -Name Staging -ModuleName PSFramework.NuGet
}
process {
if (Test-PSFFunctionInterrupt) { return }

try {
$installData = switch ($PSCmdlet.ParameterSetName) {
ByObject { Resolve-ModuleTarget -InputObject $InputObject -Cmdlet $PSCmdlet }
Expand All @@ -73,6 +229,7 @@
Publish-StagingModule -Path $tempDirectory -TargetPath $resolvedPaths -Force:$Force -Cmdlet $PSCmdlet -ThrottleLimit $ThrottleLimit
}
finally {
$managedSessions | Where-Object Type -EQ 'Temporary' | ForEach-Object Session | Remove-PSSession
Remove-PSFTempItem -Name Staging -ModuleName PSFramework.NuGet
}
}
Expand Down
Loading

0 comments on commit 63c1cbe

Please sign in to comment.