Skip to content

Commit

Permalink
PSResourceGet API (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdriscoll authored Dec 21, 2024
1 parent 46c1e96 commit ab67f3a
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 0 deletions.
114 changes: 114 additions & 0 deletions APIs/PowerShellUniversal.API.PSResourceGet/.universal/endpoints.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
New-PSUEndpoint -Url "/psresourceget/module" -Description "Returns modules installed by PSResourceGet. " -Method @('GET') -Endpoint {
param($Name, $Version, $Path, $Scope)

$Parameters = @{}

if ($Name) {
$Parameters["Name"] = $Name
}

if ($Version) {
$Parameters["Version"] = $Version
}

if ($Path) {
$Parameters["Path"] = $Path
}

if ($Scope) {
$Parameters["Scope"] = $Scope
}

Get-PSResource @Parameters | Select-Object Name, Version, Prerelease, Repository, Description
} -Authentication -Role @('Administrator')
New-PSUEndpoint -Url "/psresourceget/module" -Description "Installs a new resource." -Method @('POST') -Endpoint {
param(
$Name,
$Version,
$Repository,
[ValidateSet("CurrentUser", "AllUsers")]
$Scope)

$Parameters = @{}

if ($Name) {
$Parameters["Name"] = $Name
}

if ($Version) {
$Parameters["Version"] = $Version
}

if ($Repository) {
$Parameters["Repository"] = $Repository
}

if ($Scope) {
$Parameters["Scope"] = $Scope
}

Install-PSResource @Parameters -PassThru | Select-Object Name, Version
} -Authentication -Role @('Administrator')
New-PSUEndpoint -Url "/psresourceget/module/:name" -Description "Find a resource from the registered repositories." -Method @('GET') -Endpoint {
param(
[Parameter(Mandatory)]
$Name,
[Parameter()]
$Repository,
[Parameter()]
[ValidateSet("Module", "Script", "Nupkg")]
$Type
)

$OptionalParameters = @{}

if ($Repository) {
$OptionalParameters["Repository"] = $Repository
}

if ($Type) {
$OptionalParameters["Type"] = $Type
}

Find-PSResource -Name $Name @OptionalParameters
} -Authentication -Role @('Administrator')
New-PSUEndpoint -Url "/psresourceget/module/:name" -Description "Uninstalls a PSResource." -Method @('DELETE') -Endpoint {
param(
[Parameter(Mandatory)]
$Name
)

Uninstall-PSResource -Name $Name
} -Authentication -Role @('Administrator')
New-PSUEndpoint -Url "/psresourceget/repository" -Description "Returns registered resource repositories." -Method @('GET') -Endpoint {
param($Name)

$Parameters = @{}

if ($Name) {
$Parameters["Name"] = $Name
}

Get-PSResourceRepository @Parameters
} -Authentication -Role @('Administrator')
New-PSUEndpoint -Url "/psresourceget/repository" -Description "Registers a new resource repository." -Method @('POST') -Endpoint {
param(
[Parameter(Mandatory)]
$Name,
[Parameter(Mandatory)]
$Uri,
[Parameter()]
[bool]$Trusted
)

$Parameters = @{
Name = $Name
Uri = $Uri
}

if ($Trusted) {
$Parameters["Trusted"] = $true
}

Register-PSResourceRepository @Pawrameters
} -Authentication -Role @('Administrator')
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@{
ModuleVersion = '1.0.0'
GUID = '384b8c8d-0aff-4b3c-b479-2e3dc1654f25'
Author = 'Ironman Software'
CompanyName = 'Ironman Software'
Copyright = '(c) Ironman Software. All rights reserved.'
Description = 'Provides API endpoints for managing PowerShell resources.'
PrivateData = @{
PSData = @{
Tags = @('PowerShell', 'PSResourceGet', "PowerShellUniversal")
LicenseUri = 'https://github.com/ironmansoftware/scripts/tree/main/LICENSE'
ProjectUri = 'https://github.com/ironmansoftware/scripts/tree/main/APIs/PowerShellUniversal.API.PSResourceGet'
IconUri = 'https://raw.githubusercontent.com/ironmansoftware/scripts/main/images/script.png'
}
}
}

12 changes: 12 additions & 0 deletions APIs/PowerShellUniversal.API.PSResourceGet/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# PSResourceGet API

This module provides a PowerShell Universal API for managed PowerShell resources. It uses `Microsoft.PowerShell.PSResourceGet` to find, install and remove PowerShell modules.

## Endpoints

- `GET /psresourceget/module` - Get a list of modules
- `GET /psresourceget/module/{name}` - Find a module by name.
- `POST /psresourceget/module` - Install a module.
- `DELETE /psresourceget/module/{name}` - Uninstall a module.
- `GET /psresourceget/repository` - Get a list of repositories.
- `POST /psresourceget/repository` - Register a new repository.

0 comments on commit ab67f3a

Please sign in to comment.