Skip to content

Commit

Permalink
Minor version change
Browse files Browse the repository at this point in the history
Moved to PSResource functionality
Make it available for MacOS
  • Loading branch information
Pascal Haag committed May 22, 2024
1 parent c852594 commit 03692f4
Show file tree
Hide file tree
Showing 17 changed files with 340 additions and 71 deletions.
9 changes: 6 additions & 3 deletions PSGetInternal/PSGetInternal.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
RootModule = 'PSGetInternal.psm1'

# Version number of this module.
ModuleVersion = '1.0.6'
ModuleVersion = '2.0.0'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand All @@ -25,7 +25,7 @@
Description = 'PowerShell GetInternal Module'

# Minimum version of the PowerShell engine required by this module
# PowerShellVersion = ''
# PowerShellVersion = '7.4' (Microsoft.PowerShell.PSResourceGet installed per default on this version)

# Name of the PowerShell host required by this module
# PowerShellHostName = ''
Expand All @@ -43,7 +43,9 @@
# ProcessorArchitecture = ''

# Modules that must be imported into the global environment prior to importing this module
# RequiredModules = @()
RequiredModules = @(
'Microsoft.PowerShell.PSResourceGet'
)

# Assemblies that must be loaded prior to importing this module
# RequiredAssemblies = @()
Expand All @@ -65,6 +67,7 @@
'Find-GIModule'
'Install-GIModule'
'Save-GIModule'
'Set-GIRepoCredential'
'Set-GIRepository'
'Update-GIModule'
)
Expand Down
28 changes: 19 additions & 9 deletions PSGetInternal/functions/Find-GIModule.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,44 @@
.PARAMETER Name
Name of the module.
.PARAMETER RepositoryName
Name of the repository.
.PARAMETER Credential
Credential to get access to the configured Company-Internal repository.
.EXAMPLE
PS C:\> Find-GIModule
Will list all modules in the configured Company-Internal repository.
Will list all modules in the default configured Company-Internal repository.
.EXAMPLE
PS C:\> Find-GIModule -Name "Company-Module"
Will search the module "Company-Module" in the configured Company-Internal repository.
Will search the module "Company-Module" in the default configured Company-Internal repository.
.EXAMPLE
PS C:\> Find-GIModule -Name "Company-Module" -RepositoryName "Company-Repository"
Will search the module "Company-Module" in the "Company-Repository" repository.
#>
[CmdletBinding()]
Param (
[string]
$Name = "*",

[ArgumentCompleter({ Get-RepoNameCompletion $args })]
[ValidateScript({ Assert-RepoName -Name $_ })]
[string]
$RepositoryName = (Get-DefaultRepo),

[pscredential]
$Credential = (Get-RepoCredential)
$Credential = (Get-RepoCredential -RepositoryName $RepositoryName)
)
begin{
if(-not $Script:Config){
throw "Internal PSGallery not configured! Use Set-GIRepository to set up an internal Repository."
}
}

process {
Find-Module -Repository $Script:Config.Name -Name $Name -Credential $Credential
Write-Verbose "Seach Modules in $($RepositoryName)"
Find-PSResource -Repository $RepositoryName -Name $Name -Credential $Credential | Sort-Object -Unique Name, Version
}
}
26 changes: 18 additions & 8 deletions PSGetInternal/functions/Install-GIModule.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
.PARAMETER Name
Name of the module.
.PARAMETER RepositoryName
Name of the repository.
.PARAMETER Credential
Credential to get access to the configured Company-Internal repository.
Expand Down Expand Up @@ -56,16 +59,26 @@
.EXAMPLE
PS C:\> Install-GIModule -Name "Company-Module"
Will install the module "Company-Module" from the configured Company-Internal repository.
Will install the module "Company-Module" from the default configured Company-Internal repository.
.EXAMPLE
PS C:\> Install-GIModule -Name "Company-Module" -RepositoryName "Company-Repository"
Will install the module "Company-Module" from the "Company-Repository" repository.
#>
[CmdletBinding()]
Param (
[Parameter(Mandatory = $true)]
[string]
$Name,

[ArgumentCompleter({ Get-RepoNameCompletion $args })]
[ValidateScript({ Assert-RepoName -Name $_ })]
[string]
$RepositoryName = (Get-DefaultRepo),

[pscredential]
$Credential = (Get-RepoCredential),
$Credential = (Get-RepoCredential -RepositoryName $RepositoryName),

[switch]
$Force,
Expand All @@ -90,12 +103,9 @@
$Scope = 'CurrentUser'
)
begin {
if (-not $Script:Config) {
throw "Internal PSGallery not configured! Use Set-GIRepository to set up an internal Repository."
}


$param = @{
Repository = $Script:Config.Name
Repository = $RepositoryName
Name = $Name
Credential = $Credential
Scope = $Scope
Expand All @@ -108,6 +118,6 @@
if ($RequiredVersion) { $param.RequiredVersion = $RequiredVersion }
}
process {
Install-Module @param
Install-PSResource @param
}
}
14 changes: 11 additions & 3 deletions PSGetInternal/functions/Save-GIModule.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@
.PARAMETER Path
Path where the module should be saved.
.PARAMETER RepositoryName
Name of the repository.
.PARAMETER Credential
Credential to get access to the configured Company-Internal repository.
.EXAMPLE
PS C:\> Save-GIModule -Name "Company-Module" -Path .
Will save the module "Company-Module" from the configured Company-Internal repository to the current path.
Will save the module "Company-Module" from the default configured Company-Internal repository to the current path.
#>
[CmdletBinding()]
Param (
Expand All @@ -30,10 +33,15 @@
[string]
$Path,

[ArgumentCompleter({ Get-RepoNameCompletion $args })]
[ValidateScript({ Assert-RepoName -Name $_ })]
[string]
$RepositoryName = (Get-DefaultRepo),

[pscredential]
$Credential = (Get-RepoCredential)
$Credential = (Get-RepoCredential -RepositoryName $RepositoryName)
)
process {
Save-Module -Repository $Script:Config.Name -Name $Name -Credential $Credential -Path $Path
Save-PSResource -Repository $RepositoryName -Name $Name -Credential $Credential -Path $Path
}
}
35 changes: 35 additions & 0 deletions PSGetInternal/functions/Set-GIRepoCredential.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
function Set-GIRepoCredential {
<#
.SYNOPSIS
Creates or sets the repository credential.
.DESCRIPTION
Creates or sets the repository credential for internal repositories.
.PARAMETER RepositoryName
Name of the repository, to link the credentails.
.PARAMETER Credential
Credentials that should be set.
.EXAMPLE
C:\> Set-GIRepoCredential -RepositoryName "Company-Repository" -Credential $cred
Will create or set for the repository "Company-Repository" the credential $cred.
#>
[CmdletBinding()]
param (
[ArgumentCompleter({ Get-RepoNameCompletion $args })]
[ValidateScript({ Assert-RepoName -Name $_ })]
[Parameter(Mandatory)]
$RepositoryName,

[Parameter(Mandatory)]
[pscredential]
$Credential
)
process {
$credFile = Join-Path $Script:configPath "$($RepositoryName)_RepoCred.clixml"
$Credential | Export-Clixml -Path $credFile -Force
}
}
44 changes: 22 additions & 22 deletions PSGetInternal/functions/Set-GIRepository.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
.PARAMETER Name
Name of repository which should be registered.
.PARAMETER SourceLocation
.PARAMETER Uri
URL of the repository, which should be registered.
.PARAMETER Credential
Expand All @@ -19,63 +19,63 @@
Parameter to trust or untrust the source of the repository.
.EXAMPLE
PS C:\> Set-GIRepository -Name "Contoso-Repository" -SourceLocation "https://pkgs.dev.azure.com/contosoINF/_packaging/InfernalAccounting/nuget/v2" -InstallationPolicy Trusted -Credential $cred
PS C:\> Set-GIRepository -Name "Company-Repository" -Uri "https://pkgs.dev.azure.com/contosoINF/_packaging/InfernalAccounting/nuget/v2" -InstallationPolicy Trusted -Credential $cred
Will register the trusted repository "Contoso-Repository" with SourceLocation "https://pkgs.dev.azure.com/contosoINF/_packaging/InfernalAccounting/nuget/v2".
Will register the trusted repository "Company-Repository" with Uri "https://pkgs.dev.azure.com/contosoINF/_packaging/InfernalAccounting/nuget/v2".
And will generate a config and credential file.
#>
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions','')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '')]
[CmdletBinding()]
Param (
[Parameter(Mandatory)]
[string]
$Name,

[Alias('SourceLocation')]
[Parameter(Mandatory)]
[uri]
$SourceLocation,
$Uri,

[Parameter(Mandatory)]
[pscredential]
$Credential,

[ValidateSet('Trusted', 'Untrusted')]
[string]
$InstallationPolicy = 'Trusted'
$InstallationPolicy = 'Trusted',

[switch]
$Default
)
process {
$existingRepo = Get-PSRepository -Name $Name -ErrorAction Ignore
$existingRepo = Get-PSResourceRepository -Name $Name -ErrorAction Ignore
if (-not $existingRepo) {
try {
Register-PSRepository -Name $Name -SourceLocation $SourceLocation -InstallationPolicy $InstallationPolicy -Credential $Credential -ErrorAction Stop
Register-PSResourceRepository -Name $Name -Uri $Uri -Trusted:$($InstallationPolicy -eq "Trusted") -ErrorAction Stop
}
catch {
Write-Warning -Message "Error register Company-Internal Repository: $_"
return
}
}else{
if (($existingRepo.SourceLocation -ne $SourceLocation) -or ($existingRepo.InstallationPolicy -ne $InstallationPolicy)) {
}
else {
if (($existingRepo.Uri -ne $Uri) -or ($existingRepo.Trusted -ne ($InstallationPolicy -eq "Trusted"))) {
try {
Unregister-PSRepository -Name $Name -ErrorAction Stop
Set-PSRepository -Name $Name -SourceLocation $SourceLocation -InstallationPolicy $InstallationPolicy -Credential $Credential -ErrorAction Stop
Unregister-PSResourceRepository -Name $Name -ErrorAction Stop
Register-PSResourceRepository -Name $Name -Uri $Uri -Trusted:$($InstallationPolicy -eq "Trusted") -ErrorAction Stop
}
catch {
Write-Warning -Message "Error to update Company-Internal Repository: $_"
return
}
}
}

$credFile = Join-Path $Script:configPath "RepoCred.clixml"
$Credential | Export-Clixml -Path $credFile -Force

$repository = [PSCustomObject]@{
Name = $Name
SourceLocation = $SourceLocation
InstallationPolicy = $InstallationPolicy
Set-GIRepoCredential -RepositoryName $Name -Credential $Credential

if ($Default) {
$defaultRepoFile = Join-Path $Script:configPath "DefaultRepo.clixml"
$Name | Export-Clixml -Path $defaultRepoFile -Force
}
$repoFile = Join-Path $Script:configPath "config.clixml"
$repository | Export-Clixml -Path $repoFile -Force
$Script:Config = $repository
}
}
24 changes: 17 additions & 7 deletions PSGetInternal/functions/Update-GIModule.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
.PARAMETER Name
Name of the module.
.PARAMETER RepositoryName
Name of the repository.
.PARAMETER Credential
Credential to get access to the configured Company-Internal repository.
Expand Down Expand Up @@ -49,6 +52,11 @@
PS C:\> Update-GIModule -Name "Company-Module"
Will update the module "Company-Module" from the configured Company-Internal repository.
.EXAMPLE
PS C:\> Update-GIModule -Name "Company-Module" -RepositoryName "Company-Repository"
Will update the module "Company-Module" from the "Company-Internal" repository.
#>
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions','')]
[CmdletBinding()]
Expand All @@ -57,9 +65,14 @@
[string]
$Name,

[pscredential]
$Credential = (Get-RepoCredential),
[ArgumentCompleter({ Get-RepoNameCompletion $args })]
[ValidateScript({ Assert-RepoName -Name $_ })]
[string]
$RepositoryName,

[pscredential]
$Credential = (Get-RepoCredential -RepositoryName $RepositoryName),

[switch]
$Force,

Expand All @@ -77,13 +90,10 @@

)
begin {
if (-not $Script:Config) {
throw "Internal PSGallery not configured! Use Set-GIRepository to set up an internal Repository."
}

$param = @{
Name = $Name
Credential = $Credential
Repository = $RepositoryName
}
if ($Force) { $param.Force = $Force }
if ($AllowClobber) { $param.AllowClobber = $AllowClobber }
Expand All @@ -92,6 +102,6 @@
if ($RequiredVersion) { $param.RequiredVersion = $RequiredVersion }
}
process {
Update-Module @param
Update-PSResource @param
}
}
Loading

0 comments on commit 03692f4

Please sign in to comment.