├── src ├── nuget │ ├── tools │ │ ├── .skipAutoUninstaller │ │ ├── chocolateyBeforeModify.ps1 │ │ ├── chocolateyUninstall.ps1 │ │ └── chocolateyInstall.ps1 │ ├── Verification.txt │ └── NexuShell.nuspec ├── Suffix.ps1 ├── private │ ├── Get-UseChunkedUpload.ps1 │ ├── Configure-Tls.ps1 │ ├── Convert-ObjectToHashtable.ps1 │ ├── Get-NexusConfiguration.ps1 │ ├── New-HttpQueryString.ps1 │ ├── Send-PreAuthenticate.ps1 │ ├── Get-BufferSize.ps1 │ ├── Get-NexusUserToken.ps1 │ ├── Get-NexusCertificateDomain.ps1 │ ├── Get-NexusRepositoryServiceInstall.ps1 │ ├── New-HttpWebRequest.ps1 │ └── Invoke-Nexus.ps1 ├── public │ ├── ReadOnly │ │ ├── Get-NexusReadOnlyState.ps1 │ │ └── Set-NexusReadOnlyMode.ps1 │ ├── Anonymous │ │ ├── Get-NexusAnonymousAuthStatus.ps1 │ │ └── Set-NexusAnonymousAuth.ps1 │ ├── Tag │ │ ├── Get-NexusTag.ps1 │ │ ├── Set-NexusTag.ps1 │ │ ├── Add-NexusTagAssociation.ps1 │ │ ├── New-NexusTag.ps1 │ │ ├── Remove-NexusTag.ps1 │ │ └── Remove-NexusTagAssociation.ps1 │ ├── Email │ │ ├── Test-NexusEmailConfig.ps1 │ │ ├── Get-NexusEmailConfig.ps1 │ │ ├── Clear-NexusEmailConfig.ps1 │ │ └── Set-NexusEmailConfig.ps1 │ ├── Script │ │ ├── Start-NexusScript.ps1 │ │ ├── New-NexusScript.ps1 │ │ ├── Set-NexusScript.ps1 │ │ ├── Get-NexusScript.ps1 │ │ └── Remove-NexusScript.ps1 │ ├── Lifecycle │ │ ├── Get-NexusCurrentLifecyclePhase.ps1 │ │ ├── New-NexusLifecyclePhase.ps1 │ │ └── Restart-NexusLifecyclePhase.ps1 │ ├── License │ │ ├── Get-NexusLicenseStatus.ps1 │ │ ├── Install-NexusLicense.ps1 │ │ └── Remove-NexusLicense.ps1 │ ├── User Source │ │ └── Get-NexusUserSource.ps1 │ ├── BlobStore │ │ ├── Get-NexusBlobStoreQuota.ps1 │ │ ├── Remove-NexusBlobStore.ps1 │ │ ├── Get-NexusBlobStore.ps1 │ │ └── Update-NexusFileBlobStore.ps1 │ ├── User │ │ ├── Set-NexusUserPassword.ps1 │ │ ├── Remove-NexusUser.ps1 │ │ ├── Get-NexusUser.ps1 │ │ ├── New-NexusUser.ps1 │ │ └── Set-NexusUser.ps1 │ ├── Security │ │ ├── LDAP │ │ │ ├── Switch-NexusLdapOrder.ps1 │ │ │ └── Remove-NexusLDAPServer.ps1 │ │ ├── Roles │ │ │ ├── Get-NexusRole.ps1 │ │ │ ├── Remove-NexusRole.ps1 │ │ │ ├── New-NexusRole.ps1 │ │ │ └── Set-NexusRole.ps1 │ │ └── Privileges │ │ │ ├── Get-NexusPrivilege.ps1 │ │ │ └── Remove-NexusPrivilege.ps1 │ ├── Component │ │ ├── Remove-NexusComponent.ps1 │ │ ├── New-NexusRawComponent.ps1 │ │ ├── New-NexusNugetComponent.ps1 │ │ └── Get-NexusComponent.ps1 │ ├── Task │ │ ├── Start-NexusTask.ps1 │ │ ├── Stop-NexusTask.ps1 │ │ └── Get-NexusTask.ps1 │ ├── Repository │ │ ├── Cleanup Policy │ │ │ ├── Get-NexusCleanupPolicy.ps1 │ │ │ ├── Remove-NexusCleanupPolicy.ps1 │ │ │ ├── Set-NexusCleanupPolicy.ps1 │ │ │ └── New-NexusCleanupPolicy.ps1 │ │ ├── New-NexusGoGroupRepository.ps1 │ │ ├── New-NexusBowerGroupRepository.ps1 │ │ ├── Get-NexusRepository.ps1 │ │ ├── Remove-NexusRepository.ps1 │ │ ├── New-NexusRawGroupRepository.ps1 │ │ ├── New-NexusGitLfsHostedRepository.ps1 │ │ ├── New-NexusBowerHostedRepository.ps1 │ │ ├── New-NexusNugetHostedRepository.ps1 │ │ ├── New-NexusDockerGroupRepository.ps1 │ │ └── New-NexusRawHostedRepository.ps1 │ ├── Format │ │ └── Get-NexusFormat.ps1 │ ├── Realm │ │ ├── Get-NexusRealm.ps1 │ │ ├── Enable-NexusRealm.ps1 │ │ └── Disable-NexusRealm.ps1 │ ├── Certificate │ │ ├── Get-NexusCertificate.ps1 │ │ ├── New-NexusCertificate.ps1 │ │ └── Remove-NexusCertificate.ps1 │ ├── Asset │ │ ├── Remove-NexusAsset.ps1 │ │ ├── Remove-NexusRepositoryFolder.ps1 │ │ └── Get-NexusAsset.ps1 │ ├── ContentSelector │ │ ├── New-NexusContentSelector.ps1 │ │ ├── Get-NexusContentSelector.ps1 │ │ ├── Set-NexusContentSelector.ps1 │ │ └── Remove-NexusContentSelector.ps1 │ ├── APIKey │ │ └── Get-NexusNuGetApiKey.ps1 │ ├── RoutingRule │ │ ├── New-NexusRoutingRule.ps1 │ │ ├── Get-NexusRoutingRule.ps1 │ │ ├── Set-NexusRoutingRule.ps1 │ │ └── Remove-NexusRoutingRule.ps1 │ ├── Support │ │ └── New-NexusSupportZip.ps1 │ └── Get-NexusLocalServiceUri.ps1 └── NexuShell.psd1 ├── RequiredModules.psd1 ├── GitVersion.yml ├── .github ├── FUNDING.yml └── workflows │ └── build.yml ├── Build.psd1 ├── treasuredocs └── mkdocs.yml ├── .gitignore ├── .vscode └── tasks.json ├── README.md ├── Requirements.ps1 ├── docs ├── CHANGELOG.md └── index.md ├── LICENSE ├── tests └── public │ └── BlobStore │ └── Update-NexusFileBlobStore.Tests.ps1 └── specifications └── apt.md /src/nuget/tools/.skipAutoUninstaller: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /RequiredModules.psd1: -------------------------------------------------------------------------------- 1 | @{ 2 | ModuleBuilder = "[2.0.0,3.0)" 3 | } -------------------------------------------------------------------------------- /GitVersion.yml: -------------------------------------------------------------------------------- 1 | mode: ContinuousDelivery 2 | branches: {} 3 | merge-message-formats: {} 4 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: steviecoaster 4 | -------------------------------------------------------------------------------- /src/Suffix.ps1: -------------------------------------------------------------------------------- 1 | $script:InstalledNexusService = Get-NexusRepositoryServiceInstall -ErrorAction SilentlyContinue -------------------------------------------------------------------------------- /Build.psd1: -------------------------------------------------------------------------------- 1 | @{ 2 | ModuleManifest = ".\src\NexuShell.psd1" 3 | SourceDirectories = "private", "public" 4 | Suffix = "Suffix.ps1" 5 | } -------------------------------------------------------------------------------- /src/nuget/tools/chocolateyBeforeModify.ps1: -------------------------------------------------------------------------------- 1 | $ErrorActionPreference = 'Stop' 2 | Remove-Module -Name $env:ChocolateyPackageName -Force -ErrorAction SilentlyContinue -------------------------------------------------------------------------------- /treasuredocs/mkdocs.yml: -------------------------------------------------------------------------------- 1 | site_name: NexuShell Documentation 2 | theme: readthedocs 3 | repo_url: https://github.com/steviecoaster/NexuShell 4 | docs_dir: ../docs/ 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_STORE 2 | Output\* 3 | Output 4 | [0-9]\.[0-9]\.[0-9] 5 | specifications 6 | specifications\* 7 | site\ 8 | site 9 | site\* 10 | TestResults.xml 11 | Coverage.xml 12 | vagrant 13 | vagrant\ 14 | docs 15 | docs\* 16 | -------------------------------------------------------------------------------- /src/private/Get-UseChunkedUpload.ps1: -------------------------------------------------------------------------------- 1 | function Get-UseChunkedUpload 2 | { 3 | <# 4 | .NOTES 5 | Taken from: https://stackoverflow.com/a/48323495 6 | #> 7 | param( 8 | [Parameter(Mandatory=$true)] 9 | [long]$FileSize, 10 | 11 | [Parameter(Mandatory=$true)] 12 | [long]$BufferSize 13 | ) 14 | 15 | return $FileSize -gt $BufferSize; 16 | } -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | // See https://go.microsoft.com/fwlink/?LinkId=733558 3 | // for the documentation about the tasks.json format 4 | "version": "2.0.0", 5 | "tasks": [ 6 | { 7 | "label": "Build Module", 8 | "type": "shell", 9 | "command": "${workspaceFolder}\\Build.ps1 -Build", 10 | "problemMatcher": [], 11 | "group": { 12 | "kind": "build", 13 | "isDefault": true 14 | } 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /src/private/Configure-Tls.ps1: -------------------------------------------------------------------------------- 1 | function Configure-Tls 2 | { 3 | <# 4 | .NOTES 5 | Take from: https://stackoverflow.com/a/48323495 6 | #> 7 | param( 8 | [Parameter(Mandatory=$true)] 9 | [ValidateNotNullOrEmpty()] 10 | [string]$Url 11 | ) 12 | 13 | [System.Uri]$uri = $Url; 14 | if ($uri.Scheme -eq "https") 15 | { 16 | Write-Verbose "Using TLS 1.2"; 17 | [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12; 18 | } 19 | } -------------------------------------------------------------------------------- /src/nuget/Verification.txt: -------------------------------------------------------------------------------- 1 | VERIFICATION 2 | 3 | To verify the files using the project source: 4 | 5 | 1. Please go to the project source location (https://github.com/steviecoaster/NexuShell) and download the source files 6 | 2. Run `Requirements.ps1` (if required) and `build.ps1 -Build` to compile the module 7 | 3. Use `Get-FileHash` on the resultant psm1/psd1 to get the file hash value from both the built file (from step 1 above) and the file from the package and compare them - as they're currently not being signed before publishing, they should be identical. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # NexuShell 2 | 3 | ![NexuShell logo](https://cdn.jsdelivr.net/gh/steviecoaster/NexuShell@develop/logo/nexushell.svg) 4 | 5 | A PowerShell module for Sonatype Nexus repository server administration 6 | 7 | ## Installation 8 | 9 | ### From the PowerShell Gallery 10 | 11 | ```powershell 12 | Install-Module NexuShell -Scope CurrentUser -Force 13 | ``` 14 | 15 | ### From Chocolatey CLI 16 | 17 | ```powershell 18 | choco install NexuShell -y -s https://community.chocolatey.org/api/v2 19 | ``` 20 | 21 | 22 | ### Documentation 23 | 24 | Information about currently supported functions and their usage can be found on the [docs](https://nexushell.dev/) site. -------------------------------------------------------------------------------- /Requirements.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .Synopsis 3 | Installs prerequisites for building, testing, and publishing the module 4 | #> 5 | [CmdletBinding()] 6 | param() 7 | 8 | if (-not (Get-Command gitversion -ErrorAction SilentlyContinue)) { 9 | # We use GitVersion to generate the version based on history in source control 10 | choco install gitversion -y 11 | } 12 | 13 | if (-not ($Script = (Get-Command Install-RequiredModule -ErrorAction SilentlyContinue).Source)) { 14 | $Install = Install-Script Install-RequiredModule -Force -PassThru 15 | $Script = Join-Path $Install.InstalledLocation $Install.Name 16 | } 17 | & $Script -Path $PSScriptRoot\RequiredModules.psd1 -------------------------------------------------------------------------------- /src/public/ReadOnly/Get-NexusReadOnlyState.ps1: -------------------------------------------------------------------------------- 1 | function Get-NexusReadOnlyState { 2 | <# 3 | .SYNOPSIS 4 | Returns the Read-Only state of the nexus instance 5 | 6 | .DESCRIPTION 7 | Returns the Read-Only state of the nexus instance 8 | 9 | .EXAMPLE 10 | Get-NexusReadOnlyState 11 | #> 12 | [CmdletBinding(HelpUri='https://nexushell.dev/Get-NexusReadOnlyState/')] 13 | Param() 14 | begin { 15 | 16 | if (-not $header) { 17 | throw "Not connected to Nexus server! Run Connect-NexusServer first." 18 | } 19 | 20 | $urislug = "/service/rest/v1/read-only" 21 | } 22 | 23 | process { 24 | 25 | Invoke-Nexus -UriSlug $urislug -Method 'GET' 26 | } 27 | } -------------------------------------------------------------------------------- /docs/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # NexuShell Changelog 2 | 3 | ## 1.0 4 | 5 | Initial release 6 | 7 | ## 1.0.1 (21 July 2021) 8 | 9 | ### Bug Fixes 10 | 11 | - #9 Set-NexusUserPassword reports "Unsupported Media Type" 12 | - #8 Set-NexusUser requires parameters (some of which can't be supplied) 13 | - #7 Get-NexusNuGetApiKey does not work with a user not authenticated through Connect-NexusServer 14 | - Fixes parameter typo in ChocolateyInstall.ps1 15 | - Switches to `Join-Path` for building zip archive path in ChocolateyInstall.ps1 16 | 17 | ### Maintenance 18 | 19 | - Added a `-Force` Parameter to `Compress-Archive` in the build script to allow the choco package to be created locally without having to manually delete files. 20 | - Adds logo to Project README -------------------------------------------------------------------------------- /src/public/Anonymous/Get-NexusAnonymousAuthStatus.ps1: -------------------------------------------------------------------------------- 1 | function Get-NexusAnonymousAuthStatus { 2 | <# 3 | .SYNOPSIS 4 | Returns the state of Nexus Anonymous Auth 5 | 6 | .DESCRIPTION 7 | Returns the state of Nexus Anonymous Auth 8 | 9 | .EXAMPLE 10 | Get-NexusAnonymousAuth 11 | #> 12 | [CmdletBinding(HelpUri='https://nexushell.dev/Get-NexusAnonymousAuthStatus/')] 13 | Param() 14 | 15 | begin { 16 | 17 | if (-not $header) { 18 | throw "Not connected to Nexus server! Run Connect-NexusServer first." 19 | } 20 | 21 | $urislug = "/service/rest/v1/security/anonymous" 22 | } 23 | process { 24 | 25 | Invoke-Nexus -UriSlug $urislug -Method 'GET' 26 | } 27 | } -------------------------------------------------------------------------------- /src/private/Convert-ObjectToHashtable.ps1: -------------------------------------------------------------------------------- 1 | function Convert-ObjectToHashtable { 2 | <# 3 | .SYNOPSIS 4 | Converts a PSObject to a Hashtable 5 | 6 | .DESCRIPTION 7 | Invoke-Nexus outputs PSObjects, due to the underlying use of Invoke-RestMethod. 8 | Invoke-Nexus takes a Hashtable as body. This allows some pass-between. 9 | 10 | .PARAMETER InputObject 11 | The object to convert. 12 | 13 | .EXAMPLE 14 | Get-NexusBlobStorage -Name default -Type File | Convert-ObjectToHashtable 15 | #> 16 | param( 17 | [Parameter(Mandatory, ValueFromPipeline)] 18 | $InputObject 19 | ) 20 | process { 21 | $Hashtable = @{} 22 | $InputObject.PSObject.Properties.ForEach{ 23 | $Hashtable[$_.Name] = $_.Value 24 | } 25 | 26 | $Hashtable 27 | } 28 | } -------------------------------------------------------------------------------- /src/public/Tag/Get-NexusTag.ps1: -------------------------------------------------------------------------------- 1 | function Get-NexusTag { 2 | [Cmdletbinding(HelpUri = 'https://nexushell.dev/Tags/Get-NexusTag/')] 3 | Param( 4 | [Parameter()] 5 | [String] 6 | $Name 7 | ) 8 | 9 | begin { 10 | 11 | if (-not $header) { 12 | throw "Not connected to Nexus server! Run Connect-NexusServer first." 13 | } 14 | 15 | $urislug = if (-not $Name) { 16 | '/service/rest/v1/tags' 17 | } 18 | else { 19 | "/service/rest/v1/tags/$Name" 20 | } 21 | 22 | } 23 | 24 | process { 25 | if(-not $Name){ 26 | $result = Invoke-Nexus -Urislug $urislug -Method GET 27 | $result.items 28 | } else { 29 | Invoke-Nexus -UriSlug $urislug -Method GET 30 | } 31 | } 32 | 33 | } -------------------------------------------------------------------------------- /src/public/Email/Test-NexusEmailConfig.ps1: -------------------------------------------------------------------------------- 1 | function Test-NexusEmailConfig { 2 | <# 3 | .SYNOPSIS 4 | Verifies Nexus Smtp configuration 5 | 6 | .DESCRIPTION 7 | Verifies Nexus Smtp configuration 8 | 9 | .PARAMETER Recipient 10 | Email address to send test message too 11 | 12 | .EXAMPLE 13 | Test-NexusEmailConfig -Recipient tim@foo.org 14 | 15 | .NOTES 16 | 17 | #> 18 | [CmdletBinding()] 19 | Param( 20 | [Parameter(Mandatory)] 21 | [String] 22 | $Recipient 23 | ) 24 | 25 | begin { 26 | if (-not $header) { 27 | throw "Not connected to Nexus server! Run Connect-NexusServer first." 28 | } 29 | } 30 | 31 | process { 32 | $urislug = '/service/rest/v1/email/verify' 33 | 34 | Invoke-Nexus -Urislug $urislug -BodyAsString $Recipient -Method POST 35 | } 36 | } -------------------------------------------------------------------------------- /src/public/Script/Start-NexusScript.ps1: -------------------------------------------------------------------------------- 1 | function Start-NexusScript { 2 | <# 3 | .SYNOPSIS 4 | Executes a saved script in Nexus 5 | 6 | .DESCRIPTION 7 | Executes a saved script in Nexus 8 | 9 | .PARAMETER Name 10 | The name of the script to execute 11 | 12 | .EXAMPLE 13 | Start-NexusScript -Name TestScript 14 | 15 | .NOTES 16 | 17 | #> 18 | [CmdletBinding()] 19 | Param( 20 | [Parameter(Mandatory)] 21 | [String] 22 | $Name 23 | ) 24 | 25 | begin { 26 | if (-not $header) { 27 | throw "Not connected to Nexus server! Run Connect-NexusServer first." 28 | } 29 | } 30 | 31 | process { 32 | $urislug = "/service/rest/v1/script/$Name/run" 33 | 34 | Invoke-Nexus -Urislug $urislug -BodyAsString $Name -ContentType 'text/plain' -Method POST -ErrorAction Stop 35 | } 36 | } -------------------------------------------------------------------------------- /src/private/Get-NexusConfiguration.ps1: -------------------------------------------------------------------------------- 1 | function Get-NexusConfiguration { 2 | <# 3 | .SYNOPSIS 4 | Returns a list of settings configured in nexus.properties. 5 | 6 | .DESCRIPTION 7 | Retrieves the specified file (defaulting to the default install location) and returns each active setting. 8 | 9 | .PARAMETER Path 10 | The path to the properties file to return. 11 | 12 | .EXAMPLE 13 | Get-NexusConfiguration 14 | # Returns all properties and values 15 | 16 | .EXAMPLE 17 | (Get-NexusConfiguration).'application-port-ssl' 18 | # Returns the value for a single property, 'application-port-ssl' 19 | #> 20 | [CmdletBinding()] 21 | param( 22 | $Path = (Join-Path $script:InstalledNexusService.DataFolder "etc\nexus.properties") 23 | ) 24 | Get-Content $Path | Where-Object { 25 | $_ -and $_ -notmatch "^\W*#" 26 | } | ConvertFrom-StringData 27 | } -------------------------------------------------------------------------------- /src/public/Lifecycle/Get-NexusCurrentLifecyclePhase.ps1: -------------------------------------------------------------------------------- 1 | function Get-NexusCurrentLifecyclePhase { 2 | <# 3 | .SYNOPSIS 4 | Move to new lifecycle phase 5 | 6 | .DESCRIPTION 7 | Move to new lifecycle phase 8 | 9 | .EXAMPLE 10 | Get-NexusCurrentLifecyclePhase 11 | 12 | .EXAMPLE 13 | Get-NexusLifecycle 14 | 15 | .NOTES 16 | 17 | #> 18 | [Alias('Get-NexusLifecycle')] 19 | [CmdletBinding(HelpUri='')] 20 | Param() 21 | 22 | begin { 23 | if (-not $header) { 24 | throw "Not connected to Nexus server! Run Connect-NexusServer first." 25 | } 26 | 27 | if( -not (Get-NexusLicenseStatus)) { 28 | throw "Cmdlet requires Nexus Pro" 29 | } 30 | } 31 | 32 | process { 33 | $urislug = '/service/rest/v1/lifecycle/phase' 34 | 35 | Invoke-Nexus -Urislug $urislug -Method GET 36 | } 37 | 38 | } -------------------------------------------------------------------------------- /src/public/License/Get-NexusLicenseStatus.ps1: -------------------------------------------------------------------------------- 1 | function Get-NexusLicenseStatus { 2 | <# 3 | .SYNOPSIS 4 | Gets license information from a Nexus instance, if available 5 | 6 | .DESCRIPTION 7 | Gets license information from a Nexus instance, if available 8 | 9 | .EXAMPLE 10 | Get-NexusLicenseStatus 11 | #> 12 | [CmdletBinding(HelpUri='https://nexushell.dev/Get-NexusLicenseStatus/')] 13 | Param() 14 | begin { 15 | 16 | if (-not $header) { 17 | throw "Not connected to Nexus server! Run Connect-NexusServer first." 18 | } 19 | 20 | $urislug = "/service/rest/v1/system/license" 21 | } 22 | 23 | process { 24 | try { 25 | Invoke-Nexus -UriSlug $urislug -Method 'GET' -ErrorAction Stop 26 | } 27 | 28 | catch { 29 | 30 | Write-Warning "Nexus license not found, running in OSS mode" 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /src/public/User Source/Get-NexusUserSource.ps1: -------------------------------------------------------------------------------- 1 | Function Get-NexusUserSource { 2 | <# 3 | .SYNOPSIS 4 | Retrieve a list of available user sources 5 | 6 | .DESCRIPTION 7 | Retrieve a list of available user sources. These sources are things that can handle authentication to Nexus 8 | 9 | .EXAMPLE 10 | Get-NexusUserSource 11 | 12 | .NOTES 13 | 14 | #> 15 | [CmdletBinding(HelpUri='https://nexushell.dev/Security/User%20Sources/Get-NexusUserSource/')] 16 | Param() 17 | begin { 18 | if (-not $header) { 19 | throw "Not connected to Nexus server! Run Connect-NexusServer first." 20 | } 21 | 22 | } 23 | 24 | process { 25 | $urislug = '/service/rest/v1/security/user-sources' 26 | 27 | $result = Invoke-Nexus -Urislug $urislug -Method GET 28 | 29 | $result | ForEach-Object { 30 | [pscustomobject]@{ 31 | Id = $_.id 32 | Name = $_.Name 33 | } 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /src/private/New-HttpQueryString.ps1: -------------------------------------------------------------------------------- 1 | function New-HttpQueryString 2 | { 3 | #Shamelessly taken from https://powershellmagazine.com/2019/06/14/pstip-a-better-way-to-generate-http-query-strings-in-powershell/ 4 | [CmdletBinding()] 5 | param 6 | ( 7 | [Parameter(Mandatory = $true)] 8 | [String] 9 | $Uri, 10 | 11 | [Parameter(Mandatory = $true)] 12 | [Hashtable] 13 | $QueryParameter 14 | ) 15 | # Add System.Web 16 | Add-Type -AssemblyName System.Web 17 | 18 | # Create a http name value collection from an empty string 19 | $nvCollection = [System.Web.HttpUtility]::ParseQueryString([String]::Empty) 20 | 21 | foreach ($key in $QueryParameter.Keys) 22 | { 23 | $nvCollection.Add($key, $QueryParameter.$key) 24 | } 25 | 26 | # Build the uri 27 | $uriRequest = [System.UriBuilder]$uri 28 | $uriRequest.Query = $nvCollection.ToString() 29 | 30 | return $uriRequest.Uri.OriginalString 31 | } -------------------------------------------------------------------------------- /src/public/Lifecycle/New-NexusLifecyclePhase.ps1: -------------------------------------------------------------------------------- 1 | function New-NexusLifecyclePhase { 2 | <# 3 | .SYNOPSIS 4 | Move to new lifecycle phase 5 | 6 | .DESCRIPTION 7 | Move to new lifecycle phase 8 | 9 | .PARAMETER Phase 10 | The phase to move to 11 | 12 | .EXAMPLE 13 | New-NexusLifecyclePhase -Phase NextPhase 14 | 15 | .NOTES 16 | 17 | #> 18 | [Alias('New-NexusLifecycle')] 19 | [CmdletBinding(HelpUri='')] 20 | Param( 21 | [Parameter(Mandatory)] 22 | [String] 23 | $Phase 24 | ) 25 | 26 | begin { 27 | if (-not $header) { 28 | throw "Not connected to Nexus server! Run Connect-NexusServer first." 29 | } 30 | 31 | if( -not (Get-NexusLicenseStatus)) { 32 | throw "Cmdlet requires Nexus Pro" 33 | } 34 | } 35 | 36 | process { 37 | $urislug = '/service/rest/v1/lifecycle' 38 | Invoke-Nexus -Urislug $urislug -BodyAsString $Phase -Method PUT 39 | } 40 | } -------------------------------------------------------------------------------- /src/public/BlobStore/Get-NexusBlobStoreQuota.ps1: -------------------------------------------------------------------------------- 1 | function Get-NexusBlobStoreQuota { 2 | <# 3 | .SYNOPSIS 4 | Get the quota settings of a blob store 5 | 6 | .DESCRIPTION 7 | Get the quota settings of a blob store 8 | 9 | .PARAMETER Name 10 | The blob store to retrieve quota settings 11 | 12 | .EXAMPLE 13 | Get-NexusBlobStoreQuota -Name TestBlob 14 | #> 15 | [CmdletBinding(HelpUri='https://nexushell.dev/Get-NexusBlobStoreQuota/')] 16 | Param( 17 | [Parameter(Mandatory)] 18 | [String[]] 19 | $Name 20 | ) 21 | 22 | begin { 23 | 24 | if (-not $header) { 25 | throw "Not connected to Nexus server! Run Connect-NexusServer first." 26 | } 27 | 28 | $urislug = "/service/rest/v1/blobstores" 29 | } 30 | process { 31 | 32 | $Name | Foreach-Object { 33 | 34 | $Uri = $urislug + "/$_/quota-status" 35 | Invoke-Nexus -UriSlug $Uri -Method 'GET' 36 | 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /src/public/User/Set-NexusUserPassword.ps1: -------------------------------------------------------------------------------- 1 | function Set-NexusUserPassword { 2 | <# 3 | .SYNOPSIS 4 | Change a user's password. 5 | 6 | .DESCRIPTION 7 | Change a user's password. 8 | 9 | .PARAMETER Username 10 | The userid the request should apply to 11 | 12 | .PARAMETER NewPassword 13 | The new password to use. 14 | 15 | .EXAMPLE 16 | Set-NexusUserPassword -Username jimmy -NewPassword ("Sausage2021" | ConvertTo-SecureString -AsPlainText -Force) 17 | 18 | .NOTES 19 | 20 | #> 21 | [CmdletBinding(HelpUri='https://nexushell.dev/Security/User/Set-NexusUserPassword/')] 22 | Param( 23 | [Parameter(Mandatory)] 24 | [String] 25 | $Username, 26 | 27 | [Parameter(Mandatory)] 28 | [SecureString] 29 | $NewPassword 30 | ) 31 | 32 | process { 33 | $urislug = "/service/rest/v1/security/users/$Username/change-password" 34 | 35 | Invoke-Nexus -Urislug $urislug -BodyAsSecureString $NewPassword -Method PUT -ContentType 'text/plain' 36 | } 37 | } -------------------------------------------------------------------------------- /src/public/Lifecycle/Restart-NexusLifecyclePhase.ps1: -------------------------------------------------------------------------------- 1 | function Restart-NexusLifecyclePhase { 2 | <# 3 | .SYNOPSIS 4 | Re-runs all phases from the given phase to the current phase 5 | 6 | .DESCRIPTION 7 | Re-runs all phases from the given phase to the current phase 8 | 9 | .PARAMETER Phase 10 | The phase to bounce 11 | 12 | .EXAMPLE 13 | Restart-NexusLifecyclePhase -Phase 'SomePreviousPhase' 14 | 15 | .NOTES 16 | 17 | #> 18 | [CmdletBinding()] 19 | Param( 20 | [Parameter(Mandatory)] 21 | [String] 22 | $Phase 23 | ) 24 | 25 | begin { 26 | if (-not $header) { 27 | throw "Not connected to Nexus server! Run Connect-NexusServer first." 28 | } 29 | 30 | if( -not (Get-NexusLicenseStatus)) { 31 | throw "Cmdlet requires Nexus Pro" 32 | } 33 | } 34 | 35 | process { 36 | $urislug = '/service/rest/v1/lifecycle/bounce' 37 | Invoke-Nexus -Urislug $urislug -BodyAsString $Phase -Method PUT 38 | } 39 | } -------------------------------------------------------------------------------- /src/public/License/Install-NexusLicense.ps1: -------------------------------------------------------------------------------- 1 | function Install-NexusLicense { 2 | <# 3 | .SYNOPSIS 4 | Installs a license on a nexus instance. 5 | 6 | .DESCRIPTION 7 | Installs a license on a nexus instance. 8 | 9 | .PARAMETER NexusLicense 10 | The license file to install 11 | 12 | .EXAMPLE 13 | Install-NexusLicense -NexusLicense 'C:\temp\sonatype-repository-manager.lic' 14 | #> 15 | [CmdletBinding(HelpUri='https://nexushell.dev/Install-NexusLicense/')] 16 | Param( 17 | [Parameter(Mandatory)] 18 | [ValidateScript({ Test-Path $_})] 19 | [String] 20 | $NexusLicense 21 | ) 22 | 23 | begin { 24 | 25 | if (-not $header) { 26 | throw "Not connected to Nexus server! Run Connect-NexusServer first." 27 | } 28 | 29 | $urislug = "/service/rest/v1/system/license" 30 | } 31 | 32 | process { 33 | $file = Get-Item $NexusLicense 34 | 35 | Invoke-Nexus -UriSlug $urislug -Method 'POST' -Body $file -ContentType 'application/octetstream' 36 | } 37 | } -------------------------------------------------------------------------------- /src/public/Security/LDAP/Switch-NexusLdapOrder.ps1: -------------------------------------------------------------------------------- 1 | function Switch-NexusLdapOrder { 2 | <# 3 | .SYNOPSIS 4 | Reorders LDAP Server priority if there are multiple 5 | 6 | .DESCRIPTION 7 | Reorders LDAP Server priority if there are multiple 8 | 9 | .PARAMETER NewOrder 10 | The new order of LDAP Server Names. You can't retrieve these via API, so you'll need to look in the web interface or know what they are 11 | 12 | .EXAMPLE 13 | Switch-NexusLdapOrder -NewOrder ProductionLDAP,EuropeLDAP,AsiaLDAP 14 | 15 | .NOTES 16 | 17 | #> 18 | [CmdletBinding(HelpUri='https://nexushell.dev/Security/LDAP/Switch-NexusLdapOrder/')] 19 | Param( 20 | [Parameter(Mandatory)] 21 | [Array] 22 | $NewOrder 23 | ) 24 | 25 | begin { 26 | if (-not $header) { 27 | throw "Not connected to Nexus server! Run Connect-NexusServer first." 28 | } 29 | 30 | } 31 | 32 | process { 33 | $urislug = '/service/rest/v1/security/ldap/change-order' 34 | Invoke-Nexus -Urislug $urislug -BodyAsArray $NewOrder -Method POST 35 | } 36 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Stephen Valdinger 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/public/Component/Remove-NexusComponent.ps1: -------------------------------------------------------------------------------- 1 | function Remove-NexusComponent { 2 | <# 3 | .SYNOPSIS 4 | Removes a component from a Nexus Repository 5 | 6 | .DESCRIPTION 7 | Removes a component from a Nexus Repository 8 | 9 | .PARAMETER Id 10 | The ID of the component to remove 11 | 12 | .EXAMPLE 13 | Remove-NexusComponent -Id RGV2OmM2MGJjNmI5NjEyZjQ3ZDM5ZTc2ZmMwNTI1ODg0M2Rj 14 | 15 | .EXAMPLE 16 | Get-NexusComponent -Repository dev | Where-Object {$_.Name -eq "somePackage" -and $_.Version "1.2.3"} | Remove-NexusComponent -Confirm:$false 17 | #> 18 | [CmdletBinding(HelpUri='https://nexushell.dev/Assets/Remove-NexusComponent/', SupportsShouldProcess, ConfirmImpact='High')] 19 | Param( 20 | [Parameter(Mandatory, ValueFromPipelineByPropertyName)] 21 | [String[]] 22 | $Id 23 | ) 24 | process { 25 | $Id | ForEach-Object { 26 | $urislug = "/service/rest/v1/components/$($_)" 27 | 28 | if ($PSCmdlet.ShouldProcess("$($_)", "Remove Component")) { 29 | $null = Invoke-Nexus -UriSlug $urislug -Method DELETE 30 | } 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /src/private/Send-PreAuthenticate.ps1: -------------------------------------------------------------------------------- 1 | function Send-PreAuthenticate 2 | { 3 | param( 4 | [Parameter(Mandatory=$true)] 5 | [ValidateNotNullOrEmpty()] 6 | [string]$Url, 7 | 8 | [Parameter(Mandatory=$true)] 9 | [ValidateNotNullOrEmpty()] 10 | [pscredential]$Credential 11 | ) 12 | 13 | $response = $null; 14 | try 15 | { 16 | [System.Uri]$uri = $Url; 17 | $repositoryAuthority = (($uri.GetLeftPart([System.UriPartial]::Authority)).TrimEnd('/') + '/'); 18 | Write-Verbose "Send-PreAuthenticate - Sending HEAD to $repositoryAuthority"; 19 | $wr = [System.Net.WebRequest]::Create($repositoryAuthority); 20 | $wr.Method = "HEAD"; 21 | $wr.PreAuthenticate = $true; 22 | $auth = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($Credential.UserName + ":" + $Credential.GetNetworkCredential().Password)); 23 | $wr.Headers["Authorization"] = "Basic $auth" 24 | $response = $wr.GetResponse(); 25 | } 26 | finally 27 | { 28 | if ($response) 29 | { 30 | $response.Close(); 31 | $response.Dispose(); 32 | $response = $null; 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /src/nuget/tools/chocolateyUninstall.ps1: -------------------------------------------------------------------------------- 1 | $ErrorActionPreference = 'Stop' 2 | 3 | $toolsDir = Split-Path -Parent $MyInvocation.MyCommand.Definition 4 | $moduleName = $env:ChocolateyPackageName # this may be different from the package name and different case 5 | $savedParamsPath = Join-Path $toolsDir -ChildPath 'parameters.saved' 6 | 7 | if (Test-Path -Path $savedParamsPath) { 8 | $removePath = Get-Content -Path $savedParamsPath 9 | } else { 10 | $removePath = Join-Path -Path $env:ProgramFiles -ChildPath "WindowsPowerShell\Modules\$moduleName" 11 | } 12 | 13 | ForEach ($path in $removePath) { 14 | Write-Verbose "Removing all version of '$moduleName' from '$path'." 15 | Remove-Item -Path $path -Recurse -Force -ErrorAction SilentlyContinue 16 | } 17 | 18 | # remove path of module from $env:PSModulePath 19 | if ($PSVersionTable.PSVersion.Major -lt 4) { 20 | $modulePaths = [Environment]::GetEnvironmentVariable('PSModulePath', 'Machine') -split ';' 21 | 22 | Write-Verbose "Removing '$sourcePath' from PSModulePath." 23 | $newModulePath = $modulePaths | Where-Object { $_ -ne $sourcePath } 24 | 25 | [Environment]::SetEnvironmentVariable('PSModulePath', $newModulePath, 'Machine') 26 | $env:PSModulePath = $newModulePath 27 | } -------------------------------------------------------------------------------- /src/public/Task/Start-NexusTask.ps1: -------------------------------------------------------------------------------- 1 | function Start-NexusTask { 2 | <# 3 | .SYNOPSIS 4 | Starts a Nexus Task 5 | 6 | .DESCRIPTION 7 | Starts a Nexus Task 8 | 9 | .PARAMETER Task 10 | The task to start 11 | 12 | .EXAMPLE 13 | Stop-NexusTask -Task 'Cleanup Service' 14 | 15 | .NOTES 16 | 17 | #> 18 | [CmdletBinding(HelpUri = 'https://nexushell.dev/Tasks/Start-NexusTask/')] 19 | Param( 20 | [Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)] 21 | [ArgumentCompleter( { 22 | param($Command, $Parameter, $WordToComplete, $CommandAst, $FakeBoundParams) 23 | 24 | $r = (Get-NexusTask).Name 25 | 26 | if ($WordToComplete) { 27 | $r.Where($_ -match "^$WordToComplete") 28 | } 29 | 30 | else { 31 | $r 32 | } 33 | })] 34 | [Alias('Name')] 35 | [String] 36 | $Task 37 | ) 38 | 39 | process { 40 | 41 | $id = (Get-NexusTask | Where-Object { $_.Name -eq $Task }).Id 42 | $urislug = "/service/rest/v1/tasks/$id/run" 43 | Invoke-Nexus -Urislug $urislug -Method POST 44 | } 45 | } -------------------------------------------------------------------------------- /src/public/Task/Stop-NexusTask.ps1: -------------------------------------------------------------------------------- 1 | function Stop-NexusTask { 2 | <# 3 | .SYNOPSIS 4 | Stops a running Nexus Task 5 | 6 | .DESCRIPTION 7 | Stops a running Nexus Task 8 | 9 | .PARAMETER Task 10 | The task to stop 11 | 12 | .EXAMPLE 13 | Stop-NexusTask -Task 'Cleanup Service' 14 | 15 | .NOTES 16 | 17 | #> 18 | [CmdletBinding(HelpUri = 'https://nexushell.dev/Tasks/Stop-NexusTask/')] 19 | Param( 20 | [Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)] 21 | [ArgumentCompleter( { 22 | param($Command, $Parameter, $WordToComplete, $CommandAst, $FakeBoundParams) 23 | 24 | $r = (Get-NexusTask).Name 25 | 26 | if ($WordToComplete) { 27 | $r.Where($_ -match "^$WordToComplete") 28 | } 29 | 30 | else { 31 | $r 32 | } 33 | })] 34 | [Alias('Name')] 35 | [String] 36 | $Task 37 | ) 38 | 39 | process { 40 | $id = (Get-NexusTask | Where-Object { $_.Name -eq $Task }).Id 41 | 42 | $urislug = "/service/rest/v1/tasks/$id/stop" 43 | Invoke-Nexus -Urislug $urislug -Method POST 44 | } 45 | } -------------------------------------------------------------------------------- /src/public/Repository/Cleanup Policy/Get-NexusCleanupPolicy.ps1: -------------------------------------------------------------------------------- 1 | function Get-NexusCleanupPolicy { 2 | <# 3 | .SYNOPSIS 4 | Gets Nexus Cleanup Policy information 5 | 6 | .DESCRIPTION 7 | Gets Nexus Cleanup Policy information 8 | 9 | .PARAMETER Name 10 | The specific policy to retrieve 11 | 12 | .EXAMPLE 13 | Get-NexusCleanupPolicy 14 | 15 | .EXAMPLE 16 | Get-NexusCleanupPolicy -Name TestPol 17 | 18 | .EXAMPLE 19 | Get-NexusCleanupPolicy -Name TestPol,ProdPol 20 | 21 | .NOTES 22 | 23 | #> 24 | [CmdletBinding(HelpUri='https://nexushell.dev/Repository/Cleanup%20Policy/Get-NexusCleanupPolicy/')] 25 | Param( 26 | [Parameter()] 27 | [Alias('Policy','CleanupPolicy')] 28 | [String[]] 29 | $Name 30 | ) 31 | 32 | process { 33 | 34 | $urislug = "/service/rest/internal/cleanup-policies?_dc=$(([DateTime]::ParseExact("01/02/0001 21:08:29", "MM/dd/yyyy HH:mm:ss",$null)).Ticks)" 35 | 36 | if(-not $CleanupPolicy){ 37 | Invoke-Nexus -Urislug $urislug -Method GET 38 | } else { 39 | $result = Invoke-Nexus -Urislug $urislug -Method GET 40 | 41 | $result | Where-Object { $_.name -in $CleanupPolicy} 42 | } 43 | } 44 | 45 | } -------------------------------------------------------------------------------- /src/public/Tag/Set-NexusTag.ps1: -------------------------------------------------------------------------------- 1 | function Set-NexusTag { 2 | <# 3 | .SYNOPSIS 4 | Sets tag metadata for an existing tag 5 | 6 | .DESCRIPTION 7 | This command provides a mechanism to update tag metadata for existing tags within a Sonatype Nexus installation 8 | 9 | .PARAMETER Tag 10 | The tag to update 11 | 12 | .PARAMETER Attributes 13 | A hashtable of attributes to apply to the tag 14 | 15 | .EXAMPLE 16 | Set-NexusTag -Name 'Example' -Attributes @{ foo = 'bar' ; bazz = 'bizz'} 17 | 18 | .LINK 19 | https://help.sonatype.com/en/tagging.html 20 | #> 21 | [CmdletBinding(HelpUri='https://nexushell.dev/Tags/Set-NexusTag/')] 22 | Param( 23 | [Parameter(Mandatory)] 24 | [String] 25 | $Tag, 26 | 27 | [Parameter(Mandatory)] 28 | [hashtable] 29 | $Attributes 30 | ) 31 | 32 | begin { 33 | if (-not $header) { 34 | throw "Not connected to Nexus server! Run Connect-NexusServer first." 35 | } 36 | 37 | $urislug = '/service/rest/v1/tags/{0}' -f $Tag 38 | } 39 | 40 | process { 41 | $Body = @{ 42 | attributes = $Attributes 43 | } 44 | Invoke-Nexus -UriSlug $urislug -Method PUT -Body $Body 45 | } 46 | } -------------------------------------------------------------------------------- /src/private/Get-BufferSize.ps1: -------------------------------------------------------------------------------- 1 | function Get-BufferSize 2 | { 3 | <# 4 | .SYNOPSIS 5 | Returns a buffer size that is 1% of ByteLength, rounded in whole MB's or at least AtLeast size. 6 | 7 | .DESCRIPTION 8 | Returns a buffer size that is 1% of ByteLength, rounded to whole MB's or if 1% is smaller than AtLeast, then AtLeast size is returned which is 1MB by default. 9 | 10 | .PARAMETER ByteLength 11 | Length of the bytes for which to calculate a valid buffer size. 12 | 13 | .PARAMETER AtLeast 14 | The minimum required buffer size, default 1MB. 15 | 16 | .EXAMPLE 17 | Get-BufferSize 4283304773 18 | 19 | Returns 42991616 which is 41MB. 20 | 21 | .EXAMPLE 22 | Get-BufferSize 4283304 23 | 24 | Returns 1048576 which is 1MB. 25 | 26 | .EXAMPLE 27 | Get-BufferSize 4283304 5MB 28 | 29 | Returns 5242880 which is 5MB. 30 | 31 | .NOTES 32 | Taken from: https://stackoverflow.com/a/48323495 33 | #> 34 | param( 35 | [Parameter(Mandatory=$true)] 36 | [long]$ByteLength, 37 | 38 | [long]$AtLeast = 1MB 39 | ) 40 | 41 | [long]$size = $ByteLength / 100; 42 | if ($size -lt $AtLeast) 43 | { 44 | $size = $AtLeast; 45 | } 46 | else 47 | { 48 | $size = [Math]::Round($size / 1MB) * 1MB; 49 | } 50 | 51 | return $size; 52 | } -------------------------------------------------------------------------------- /src/public/Script/New-NexusScript.ps1: -------------------------------------------------------------------------------- 1 | function New-NexusScript { 2 | <# 3 | .SYNOPSIS 4 | Stores a new script in Nexus 5 | 6 | .DESCRIPTION 7 | Stores a new script in Nexus 8 | 9 | .PARAMETER Name 10 | The name of the script 11 | 12 | .PARAMETER Content 13 | The contents of the script 14 | 15 | .PARAMETER Type 16 | The language of the script 17 | 18 | .EXAMPLE 19 | New-NexusScript -Name TestScript -Content 'Get-ComputerInfo' -Type powershell 20 | 21 | .NOTES 22 | 23 | #> 24 | [CmdletBinding()] 25 | Param( 26 | [Parameter(Mandatory)] 27 | [String] 28 | $Name, 29 | 30 | [Parameter(Mandatory)] 31 | [String] 32 | $Content, 33 | 34 | [Parameter(Mandatory)] 35 | [String] 36 | $Type 37 | ) 38 | 39 | begin { 40 | if (-not $header) { 41 | throw "Not connected to Nexus server! Run Connect-NexusServer first." 42 | } 43 | } 44 | 45 | process { 46 | 47 | $urislug = "/service/rest/v1/script" 48 | 49 | $body = @{ 50 | name = $Name 51 | content = $Content 52 | type = $Type 53 | } 54 | 55 | Write-Verbose ($body | ConvertTo-Json) 56 | Invoke-Nexus -UriSlug $urislug -Body $Body -Method POST 57 | 58 | } 59 | } -------------------------------------------------------------------------------- /src/public/Script/Set-NexusScript.ps1: -------------------------------------------------------------------------------- 1 | function Set-NexusScript { 2 | <# 3 | .SYNOPSIS 4 | Updates a script saved in Nexus 5 | 6 | .DESCRIPTION 7 | Updates a script saved in Nexus 8 | 9 | .PARAMETER Name 10 | The script to update 11 | 12 | .PARAMETER Content 13 | The new content of the script 14 | 15 | .PARAMETER Type 16 | The new type, if different 17 | 18 | .EXAMPLE 19 | Set-NexusScript -Name SuperAwesomeScript -Content "some awesome groovy code" -Type groovy 20 | 21 | .NOTES 22 | 23 | #> 24 | [CmdletBinding()] 25 | Param( 26 | [Parameter(Mandatory)] 27 | [String] 28 | $Name, 29 | 30 | [Parameter(Mandatory)] 31 | [String] 32 | $Content, 33 | 34 | [Parameter(Mandatory)] 35 | [String] 36 | $Type 37 | ) 38 | 39 | begin { 40 | if (-not $header) { 41 | throw "Not connected to Nexus server! Run Connect-NexusServer first." 42 | } 43 | } 44 | 45 | process { 46 | 47 | $urislug = "/service/rest/v1/script/$Name" 48 | 49 | $body = @{ 50 | name = $Name 51 | content = $Content 52 | type = $Type 53 | } 54 | 55 | Write-Verbose ($body | ConvertTo-Json) 56 | Invoke-Nexus -UriSlug $urislug -Body $Body -Method PUT 57 | 58 | } 59 | 60 | } -------------------------------------------------------------------------------- /src/public/Format/Get-NexusFormat.ps1: -------------------------------------------------------------------------------- 1 | function Get-NexusFormat { 2 | <# 3 | .SYNOPSIS 4 | Returns detailed format information 5 | 6 | .DESCRIPTION 7 | Returns detailed information about the upload specifications for each format supported 8 | 9 | .PARAMETER RepositoryFormat 10 | Retrieve information about a specific format 11 | 12 | .EXAMPLE 13 | Get-NexusFormat 14 | 15 | .EXAMPLE 16 | Get-NexusFormat -RepositoryFormat nuget 17 | #> 18 | [Cmdletbinding(HelpUri='https://nexushell.dev/Formats/Get-NexusFormat/')] 19 | Param( 20 | [Parameter()] 21 | [Alias('Format')] 22 | [ValidateSet('helm', 23 | 'r', 24 | 'pypi', 25 | 'docker', 26 | 'yum', 27 | 'rubygems', 28 | 'nuget', 29 | 'npm', 30 | 'raw', 31 | 'apt', 32 | 'maven2' 33 | )] 34 | [String] 35 | $RepositoryFormat 36 | ) 37 | begin { 38 | if (-not $header) { 39 | throw "Not connected to Nexus server! Run Connect-NexusServer first." 40 | } 41 | 42 | $urislug = if (-not $RepositoryFormat) { 43 | "/service/rest/v1/formats/upload-specs" 44 | } 45 | else { 46 | "/service/rest/v1/formats/$RepositoryFormat/upload-specs" 47 | } 48 | } 49 | process { 50 | Invoke-Nexus -UriSlug $urislug -Method 'GET' 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/public/Realm/Get-NexusRealm.ps1: -------------------------------------------------------------------------------- 1 | function Get-NexusRealm { 2 | <# 3 | .SYNOPSIS 4 | Gets Nexus Realm information 5 | 6 | .DESCRIPTION 7 | Gets Nexus Realm information 8 | 9 | .PARAMETER Active 10 | Returns only active realms 11 | 12 | .EXAMPLE 13 | Get-NexusRealm 14 | 15 | .EXAMPLE 16 | Get-NexusRealm -Active 17 | #> 18 | [CmdletBinding(HelpUri = 'https://nexushell.dev/Get-NexusRealm/')] 19 | Param( 20 | [Parameter()] 21 | [Switch] 22 | $Active 23 | ) 24 | 25 | begin { 26 | 27 | if (-not $header) { 28 | throw "Not connected to Nexus server! Run Connect-NexusServer first." 29 | } 30 | 31 | 32 | $urislug = "/service/rest/v1/security/realms/available" 33 | 34 | 35 | } 36 | 37 | process { 38 | 39 | if ($Active) { 40 | $current = Invoke-Nexus -UriSlug $urislug -Method 'GET' 41 | $urislug = '/service/rest/v1/security/realms/active' 42 | $Activated = Invoke-Nexus -UriSlug $urislug -Method 'GET' 43 | $current | Where-Object { $_.Id -in $Activated } 44 | } 45 | else { 46 | $result = Invoke-Nexus -UriSlug $urislug -Method 'GET' 47 | 48 | $result | Foreach-Object { 49 | [pscustomobject]@{ 50 | Id = $_.id 51 | Name = $_.name 52 | } 53 | } 54 | } 55 | } 56 | } -------------------------------------------------------------------------------- /src/public/Certificate/Get-NexusCertificate.ps1: -------------------------------------------------------------------------------- 1 | function Get-NexusCertificate { 2 | <# 3 | .SYNOPSIS 4 | Retrieve a list of certificates added to the trust store 5 | 6 | .DESCRIPTION 7 | Retrieve a list of certificates added to the trust store 8 | 9 | .EXAMPLE 10 | Get-Nexuscertificate 11 | 12 | .NOTES 13 | 14 | #> 15 | [CmdletBinding(HelpUri='https://nexushell.dev/Get-NexusCertificate/')] 16 | Param() 17 | 18 | begin { 19 | if (-not $header) { 20 | throw "Not connected to Nexus server! Run Connect-NexusServer first." 21 | } 22 | } 23 | 24 | process { 25 | $urislug = '/service/rest/v1/security/ssl/truststore' 26 | $result = Invoke-Nexus -Urislug $urislug -Method GET 27 | 28 | $result | Foreach-Object { 29 | [pscustomobject]@{ 30 | ExpiresOn = $_.expiresOn 31 | Fingerprint = $_.fingerprint 32 | Id = $_.id 33 | IssuedOn = $_.issuedOn 34 | IssuerCommonName = $_.issuerCommonName 35 | IssuerOrganization = $_.issuerOrganization 36 | IssuerOrganizationalUnit = $_.issueOrganizationalUnit 37 | Pem = $_.pem 38 | SerialNumber = $_.serialNumber 39 | SubjectCommonName = $_.subjectCommonName 40 | SubjectOrganization = $_.subjectOrganization 41 | SubjectOrganizationalUnit = $_.subjectOrganizationalUnit 42 | } 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /src/public/Asset/Remove-NexusAsset.ps1: -------------------------------------------------------------------------------- 1 | function Remove-NexusAsset { 2 | <# 3 | .SYNOPSIS 4 | Removes an asset from a Nexus Repository 5 | 6 | .DESCRIPTION 7 | Removes an asset from a Nexus Repository 8 | 9 | .PARAMETER Id 10 | The id of the asset for removal 11 | 12 | .PARAMETER Force 13 | Don't prompt for confirmation before deleting 14 | 15 | .EXAMPLE 16 | Remove-NexusAsset -Id RGV2OmM2MGJjNmI5NjEyZjQ3ZDM5ZTc2ZmMwNTI1ODg0M2Rj 17 | 18 | .EXAMPLE 19 | Remove-NexusAsset -Id RGV2OmM2MGJjNmI5NjEyZjQ3ZDM5ZTc2ZmMwNTI1ODg0M2Rj -Force 20 | 21 | .NOTES 22 | #> 23 | [CmdletBinding(HelpUri='https://nexushell.dev/Assets/Remove-NexusAsset/',SupportsShouldProcess,ConfirmImpact='High')] 24 | Param( 25 | [Parameter(Mandatory)] 26 | [String[]] 27 | $Id, 28 | 29 | [Parameter()] 30 | [Switch] 31 | $Force 32 | ) 33 | 34 | process { 35 | $Id | Foreach-Object { 36 | $urislug = "/service/rest/v1/assets/$($_)" 37 | if ($Force -and -not $Confirm) { 38 | $ConfirmPreference = 'None' 39 | if ($PSCmdlet.ShouldProcess("$($_)", "Remove Asset")) { 40 | Invoke-Nexus -UriSlug $urislug -Method DELETE 41 | } 42 | } 43 | else { 44 | if ($PSCmdlet.ShouldProcess("$($_)", "Remove Asset")) { 45 | Invoke-Nexus -UriSlug $urislug -Method DELETE 46 | } 47 | } 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /src/public/Email/Get-NexusEmailConfig.ps1: -------------------------------------------------------------------------------- 1 | function Get-NexusEmailConfig { 2 | <# 3 | .SYNOPSIS 4 | Gets current Nexus email configuration 5 | 6 | .DESCRIPTION 7 | Gets current Nexus email configuration 8 | 9 | .EXAMPLE 10 | Get-NexusEmailConfig 11 | 12 | .NOTES 13 | 14 | #> 15 | [CmdletBinding()] 16 | Param() 17 | 18 | begin { 19 | if (-not $header) { 20 | throw "Not connected to Nexus server! Run Connect-NexusServer first." 21 | } 22 | } 23 | 24 | process { 25 | $urislug = '/service/rest/v1/email' 26 | 27 | $result = Invoke-Nexus -Urislug $urislug -Method GET 28 | 29 | [pscustomobject]@{ 30 | Enabled = $result.enabled 31 | Host = $result.host 32 | Port = $result.port 33 | Username = $result.username 34 | Password = $result.password 35 | FromAddress = $result.fromaddress 36 | SubjectPrefix = $result.subjectprefix 37 | StartTlsEnabled = $result.starttlsenabled 38 | StartTlsRequired = $result.starttlsrequired 39 | SslOnConnectEnabled = $result.sslonconnectenabled 40 | SslServerIdentityCheckEnabled = $result.sslserveridentitycheckenabled 41 | NexusTrustStoreEnabled = $result.nexustruststoreenabled 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /src/public/ContentSelector/New-NexusContentSelector.ps1: -------------------------------------------------------------------------------- 1 | function New-NexusContentSelector { 2 | <# 3 | .SYNOPSIS 4 | Creates a new Content Selector in Nexus 5 | 6 | .DESCRIPTION 7 | Creates a new Content Selector in Nexus 8 | 9 | .PARAMETER Name 10 | The content selector name cannot be changed after creation 11 | 12 | .PARAMETER Description 13 | A human-readable description 14 | 15 | .PARAMETER Expression 16 | The expression used to identify content 17 | 18 | .EXAMPLE 19 | New-NexusContentSelector -Name MavenContent -Expression 'format == "maven2" and path =^ "/org/sonatype/nexus"' 20 | 21 | .NOTES 22 | 23 | #> 24 | [CmdletBinding(HelpUri='https://nexushell.dev/Security/Content%20Selectors/New-NexusContentSelector/')] 25 | Param( 26 | [Parameter(Mandatory)] 27 | [String] 28 | $Name, 29 | 30 | [Parameter()] 31 | [String] 32 | $Description, 33 | 34 | [Parameter(Mandatory)] 35 | [String] 36 | $Expression 37 | ) 38 | 39 | begin { 40 | if (-not $header) { 41 | throw "Not connected to Nexus server! Run Connect-NexusServer first." 42 | } 43 | } 44 | 45 | process { 46 | 47 | $urislug = '/service/rest/v1/security/content-selectors' 48 | $Body = @{ 49 | name = $Name 50 | description = $Description 51 | expression = $Expression 52 | } 53 | 54 | Invoke-Nexus -Urislug $urislug -Body $Body -Method POST 55 | } 56 | } -------------------------------------------------------------------------------- /src/public/Email/Clear-NexusEmailConfig.ps1: -------------------------------------------------------------------------------- 1 | function Clear-NexusEmailConfig { 2 | <# 3 | .SYNOPSIS 4 | Clears and disables the Smtp configuration in Nexus 5 | 6 | .DESCRIPTION 7 | Clears and disables the Smtp configuration in Nexus 8 | 9 | .PARAMETER Force 10 | Don't prompt before clearing settings 11 | 12 | .EXAMPLE 13 | Clear-NexusEmailConfig 14 | 15 | .EXAMPLE 16 | Clear-NexusEmailConfig -Force 17 | 18 | .NOTES 19 | 20 | #> 21 | [CmdletBinding(SupportsShouldProcess,ConfirmImpact='High')] 22 | Param( 23 | [Parameter()] 24 | [Switch] 25 | $Force 26 | ) 27 | 28 | begin { 29 | if (-not $header) { 30 | throw "Not connected to Nexus server! Run Connect-NexusServer first." 31 | } 32 | } 33 | 34 | process { 35 | $urislug = '/service/rest/v1/email' 36 | 37 | try { 38 | if ($Force -and -not $Confirm) { 39 | $ConfirmPreference = 'None' 40 | if ($PSCmdlet.ShouldProcess("$Hostname", "Remove SMTP Connection")) { 41 | Invoke-Nexus -UriSlug $urislug -Method DELETE -ErrorAction Stop 42 | 43 | } 44 | } 45 | else { 46 | if ($PSCmdlet.ShouldProcess("$Hostname", "Remove SMTP Connection")) { 47 | Invoke-Nexus -UriSlug $urislug -Method DELETE -ErrorAction Stop 48 | } 49 | } 50 | } 51 | 52 | catch { 53 | $_.exception.message 54 | } 55 | } 56 | } -------------------------------------------------------------------------------- /src/public/APIKey/Get-NexusNuGetApiKey.ps1: -------------------------------------------------------------------------------- 1 | function Get-NexusNuGetApiKey { 2 | <# 3 | .SYNOPSIS 4 | Retrieves the NuGet API key of the given user credential 5 | 6 | .DESCRIPTION 7 | Retrieves the NuGet API key of the given user credential 8 | 9 | .PARAMETER Credential 10 | The Nexus User whose API key you wish to retrieve 11 | 12 | .EXAMPLE 13 | Get-NexusNugetApiKey -Credential (Get-Credential) 14 | 15 | .NOTES 16 | 17 | #> 18 | [CmdletBinding(HelpUri='https://nexushell.dev/Security/API%20Key/Get-NexusNuGetApiKey/')] 19 | Param( 20 | [Parameter(Mandatory)] 21 | [PSCredential] 22 | $Credential 23 | ) 24 | 25 | process { 26 | $token = Get-NexusUserToken -Credential $Credential 27 | $base64Token = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($token)) 28 | $UriBase = "$($protocol)://$($Hostname):$($port)$($ContextPath)" 29 | 30 | $slug = "/service/rest/internal/nuget-api-key?authToken=$base64Token&_dc=$(([DateTime]::ParseExact("01/02/0001 21:08:29", "MM/dd/yyyy HH:mm:ss",$null)).Ticks)" 31 | 32 | $uri = $UriBase + $slug 33 | 34 | 35 | $credPair = "{0}:{1}" -f $Credential.UserName,$Credential.GetNetworkCredential().Password 36 | $encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($credPair)) 37 | $ApiKeyHeader = @{ Authorization = "Basic $encodedCreds"} 38 | 39 | Invoke-RestMethod -Uri $uri -Headers $ApiKeyHeader -Method GET -ContentType 'application/json' -UseBasicParsing 40 | 41 | } 42 | } -------------------------------------------------------------------------------- /src/public/Asset/Remove-NexusRepositoryFolder.ps1: -------------------------------------------------------------------------------- 1 | function Remove-NexusRepositoryFolder { 2 | <# 3 | .SYNOPSIS 4 | Removes a given folder from a repository from the Nexus instance 5 | 6 | .PARAMETER RepositoryName 7 | The repository to remove from 8 | 9 | .PARAMETER Name 10 | The name of the folder to remove 11 | 12 | .EXAMPLE 13 | Remove-NexusRepositoryFolder -RepositoryName MyNuGetRepo -Name 'v3' 14 | # Removes the v3 folder in the MyNuGetRepo repository 15 | #> 16 | [CmdletBinding()] 17 | param( 18 | [Parameter(Mandatory)] 19 | [string]$RepositoryName, 20 | 21 | [Parameter(Mandatory)] 22 | [string]$Name 23 | ) 24 | end { 25 | if (-not $header) { 26 | throw "Not connected to Nexus server! Run Connect-NexusServer first." 27 | } 28 | 29 | $ApiParameters = @{ 30 | UriSlug = "/service/extdirect" 31 | Method = "POST" 32 | Body = @{ 33 | action = "coreui_Component" 34 | method = "deleteFolder" 35 | data = @( 36 | $Name, 37 | $RepositoryName 38 | ) 39 | type = "rpc" 40 | tid = Get-Random -Minimum 1 -Maximum 100 41 | } 42 | Headers = @{ 43 | "X-Nexus-UI" = "true" 44 | } 45 | } 46 | 47 | $Result = Invoke-Nexus @ApiParameters 48 | 49 | if (-not $Result.result.success) { 50 | throw "Failed to delete folder: $($Result.result.message)" 51 | } 52 | } 53 | } -------------------------------------------------------------------------------- /src/public/User/Remove-NexusUser.ps1: -------------------------------------------------------------------------------- 1 | function Remove-NexusUser { 2 | <# 3 | .SYNOPSIS 4 | Delete a Nexus user. 5 | 6 | .DESCRIPTION 7 | Delete a Nexus user. 8 | 9 | .PARAMETER Username 10 | The userid the request should apply to. 11 | 12 | .PARAMETER Force 13 | Don't prompt for confirmation before deleting 14 | 15 | .EXAMPLE 16 | Remove-NexusUser -Username jimmy 17 | 18 | .EXAMPLE 19 | Remove-NexusUser -Username jimmy -Force 20 | 21 | .EXAMPLE 22 | Get-NexusUser -User jimmy | Remove-NexusUser -Force 23 | 24 | .NOTES 25 | #> 26 | [CmdletBinding(HelpUri='https://nexushell.dev/Security/User/Remove-NexusUser/',SupportsShouldProcess, ConfirmImpact = 'High')] 27 | Param( 28 | [Parameter(Mandatory,ValueFromPipeline,ValueFromPipelineByPropertyName)] 29 | [Alias('userId')] 30 | [String[]] 31 | $Username, 32 | 33 | [Parameter()] 34 | [Switch] 35 | $Force 36 | ) 37 | 38 | process { 39 | 40 | $Username | Foreach-Object { 41 | $urislug = "/service/rest/v1/security/users/$_" 42 | if ($Force -and -not $Confirm) { 43 | $ConfirmPreference = 'None' 44 | if ($PSCmdlet.ShouldProcess("$($_)", "Remove User")) { 45 | Invoke-Nexus -UriSlug $urislug -Method DELETE 46 | } 47 | } 48 | else { 49 | if ($PSCmdlet.ShouldProcess("$($_)", "Remove User")) { 50 | Invoke-Nexus -UriSlug $urislug -Method DELETE 51 | } 52 | } 53 | } 54 | } 55 | } -------------------------------------------------------------------------------- /src/public/Asset/Get-NexusAsset.ps1: -------------------------------------------------------------------------------- 1 | function Get-NexusAsset { 2 | <# 3 | .SYNOPSIS 4 | Retrieve asset information from Nexus 5 | 6 | .DESCRIPTION 7 | Retrieve asset informatino from Nexus 8 | 9 | .PARAMETER RepositoryName 10 | The repository to query for assets 11 | 12 | .PARAMETER Id 13 | A specific asset to retrieve 14 | 15 | .EXAMPLE 16 | Get-NexusAsset -RepositoryName Dev 17 | 18 | .EXAMPLE 19 | Get-NexusAsset -Id RGV2OmM2MGJjNmI5NjEyZjQ3ZDM5ZTc2ZmMwNTI1ODg0M2Rj 20 | 21 | .NOTES 22 | #> 23 | [CmdletBinding(HelpUri='https://nexushell.dev/Assets/Get-NexusAsset/',DefaultParameterSetName="repo")] 24 | Param( 25 | [Parameter(ParameterSetName="repo",Mandatory)] 26 | [String] 27 | $RepositoryName, 28 | 29 | [Parameter(ParameterSetName="Id",Mandatory)] 30 | [String] 31 | $Id 32 | ) 33 | 34 | process { 35 | 36 | if ($Id) { 37 | $urislug = "/service/rest/v1/assets/$($Id)" 38 | Invoke-Nexus -Urislug $urislug -Method GET 39 | } 40 | 41 | else { 42 | $urislug = "/service/rest/v1/assets?repository=$($RepositoryName)" 43 | 44 | $result = Invoke-Nexus -Urislug $urislug -Method GET 45 | 46 | $result.items 47 | 48 | while ($($result.continuationToken)) { 49 | $urislug = "/service/rest/v1/assets?continuationToken=$($result.continuationToken)&repository=$($RepositoryName)" 50 | $result = Invoke-Nexus -Urislug $urislug -Method GET 51 | $result.items 52 | } 53 | } 54 | } 55 | } -------------------------------------------------------------------------------- /src/public/Anonymous/Set-NexusAnonymousAuth.ps1: -------------------------------------------------------------------------------- 1 | function Set-NexusAnonymousAuth { 2 | <# 3 | .SYNOPSIS 4 | Turns Anonymous Authentication on or off in Nexus 5 | 6 | .DESCRIPTION 7 | Turns Anonymous Authentication on or off in Nexus 8 | 9 | .PARAMETER Enabled 10 | Turns on Anonymous Auth 11 | 12 | .PARAMETER Disabled 13 | Turns off Anonymous Auth 14 | 15 | .EXAMPLE 16 | Set-NexusAnonymousAuth -Enabled 17 | #> 18 | [CmdletBinding(HelpUri='https://nexushell.dev/Set-NexusAnonymousAuth/')] 19 | Param( 20 | [Parameter()] 21 | [Switch] 22 | $Enabled, 23 | 24 | [Parameter()] 25 | [Switch] 26 | $Disabled 27 | ) 28 | 29 | begin { 30 | 31 | if (-not $header) { 32 | throw "Not connected to Nexus server! Run Connect-NexusServer first." 33 | } 34 | 35 | $urislug = "/service/rest/v1/security/anonymous" 36 | } 37 | 38 | process { 39 | 40 | Switch($true){ 41 | 42 | $Enabled { 43 | $Body = @{ 44 | enabled = $true 45 | userId = 'anonymous' 46 | realmName = 'NexusAuthorizingRealm' 47 | } 48 | 49 | Invoke-Nexus -UriSlug $urislug -Body $Body -Method 'PUT' 50 | } 51 | 52 | $Disabled { 53 | $Body = @{ 54 | enabled = $false 55 | userId = 'anonymous' 56 | realmName = 'NexusAuthorizingRealm' 57 | } 58 | 59 | Invoke-Nexus -UriSlug $urislug -Body $Body -Method 'PUT' 60 | 61 | } 62 | } 63 | } 64 | } -------------------------------------------------------------------------------- /src/public/Script/Get-NexusScript.ps1: -------------------------------------------------------------------------------- 1 | function Get-NexusScript { 2 | <# 3 | .SYNOPSIS 4 | Returns scripts stored for execution in Nexus 5 | 6 | .DESCRIPTION 7 | Returns scripts stored for execution in Nexus 8 | 9 | .PARAMETER Name 10 | Return a specific script's details 11 | 12 | .EXAMPLE 13 | Get-NexusScript 14 | 15 | .EXAMPLE 16 | Get-NexusScript -Name SuperAwesomeScript 17 | 18 | .NOTES 19 | 20 | #> 21 | [CmdletBinding()] 22 | Param( 23 | [Parameter()] 24 | [String[]] 25 | $Name 26 | ) 27 | begin { 28 | if (-not $header) { 29 | throw "Not connected to Nexus server! Run Connect-NexusServer first." 30 | } 31 | } 32 | 33 | process { 34 | 35 | if (-not $Name) { 36 | $urislug = "/service/rest/v1/script" 37 | $result = Invoke-Nexus -UriSlug $urislug -Method GET 38 | $result | ForEach-Object { 39 | [pscustomobject]@{ 40 | Name = $_.name 41 | Content = $_.content 42 | Type = $_.type 43 | } 44 | } 45 | 46 | } 47 | else { 48 | 49 | $Name | Foreach-Object { 50 | $urislug = "/service/rest/v1/script/$_" 51 | $result = Invoke-Nexus -UriSlug $urislug -Method GET 52 | $result | ForEach-Object { 53 | [pscustomobject]@{ 54 | Name = $_.name 55 | Content = $_.content 56 | Type = $_.type 57 | } 58 | } 59 | } 60 | } 61 | 62 | } 63 | } -------------------------------------------------------------------------------- /src/public/Tag/Add-NexusTagAssociation.ps1: -------------------------------------------------------------------------------- 1 | function Add-NexusTagAssociation { 2 | <# 3 | .SYNOPSIS 4 | Tags a component with the provided tag name based on the search query parameters 5 | 6 | .DESCRIPTION 7 | Tags a component based on the Query terms based via hashtable to the API endpoint. 8 | 9 | .PARAMETER Tag 10 | The tag to apply to the component(s) 11 | 12 | .PARAMETER SearchQuery 13 | A hashtable of search parameters by which to tag components 14 | 15 | .EXAMPLE 16 | Add-NexusTag -Tag SampleTag -SearchQuery @{ format = 'nuget' ; repository = 'ChocolateyPackages'} 17 | 18 | .LINK 19 | https://help.sonatype.com/en/tagging.html 20 | #> 21 | [CmdletBinding(HelpUri='https://nexushell.dev/Tags/Add-NexusTagAssociation/')] 22 | Param( 23 | [Parameter(Mandatory)] 24 | [String] 25 | $Tag, 26 | 27 | [Parameter()] 28 | [hashtable] 29 | $SearchQuery 30 | ) 31 | 32 | begin { 33 | if (-not $header) { 34 | throw "Not connected to Nexus server! Run Connect-NexusServer first." 35 | } 36 | 37 | $urislug = '/service/rest/v1/tags/associate/{0}' -f $Tag 38 | } 39 | 40 | process { 41 | $UriBase = "$($protocol)://$($Hostname):$($port)$($ContextPath)" 42 | $Uri = $UriBase + $UriSlug 43 | 44 | $tagUrl = New-HttpQueryString -Uri $uri -QueryParameter $SearchQuery 45 | 46 | $Params = @{ 47 | Headers = $header 48 | ContentType = 'application/json' 49 | Uri = $tagUrl 50 | Method = 'POST' 51 | UseBasicParsing = $true 52 | } 53 | 54 | Invoke-RestMethod @Params 55 | } 56 | } -------------------------------------------------------------------------------- /src/public/RoutingRule/New-NexusRoutingRule.ps1: -------------------------------------------------------------------------------- 1 | function New-NexusRoutingRule { 2 | <# 3 | .SYNOPSIS 4 | Create a new Nexus routing rule 5 | 6 | .DESCRIPTION 7 | Create a new Nexus routing rule 8 | 9 | .PARAMETER Name 10 | The name of the rule 11 | 12 | .PARAMETER Description 13 | A brief explanation of the routing rule 14 | 15 | .PARAMETER Mode 16 | Allow the connection, or block the connection 17 | 18 | .PARAMETER Matchers 19 | Regex strings to match for the route 20 | 21 | .EXAMPLE 22 | New-NexusRoutingRule -Name BlockNuGet -Mode Block -Matchers 'NuGet','[\w]Nuget.+' 23 | 24 | .NOTES 25 | General notes 26 | #> 27 | [CmdletBinding(HelpUri = 'https://nexushell.dev/New-NexusRoutingRule/')] 28 | Param( 29 | [Parameter(Mandatory)] 30 | [String] 31 | $Name, 32 | 33 | [Parameter()] 34 | [String] 35 | $Description, 36 | 37 | [Parameter(Mandatory)] 38 | [ValidateSet('Allow','Block')] 39 | [String] 40 | $Mode, 41 | 42 | [Parameter(Mandatory)] 43 | [String[]] 44 | $Matchers 45 | ) 46 | 47 | begin { 48 | 49 | if (-not $header) { 50 | throw "Not connected to Nexus server! Run Connect-NexusServer first." 51 | } 52 | 53 | $urislug = "/service/rest/v1/routing-rules" 54 | } 55 | 56 | process { 57 | 58 | $Body = @{ 59 | name = $Name 60 | description = $Description 61 | mode = $Mode.ToUpper() 62 | matchers = @($Matchers) 63 | } 64 | 65 | Write-Verbose $($Body | ConvertTo-Json) 66 | Invoke-Nexus -UriSlug $urislug -Body $Body -Method POST 67 | 68 | } 69 | } -------------------------------------------------------------------------------- /src/public/Tag/New-NexusTag.ps1: -------------------------------------------------------------------------------- 1 | function New-NexusTag { 2 | <# 3 | .SYNOPSIS 4 | Create a tag 5 | 6 | .DESCRIPTION 7 | Create a tag in Nexus Repository. Useful with CI/CD platforms, similar to git tags. 8 | 9 | .PARAMETER Tag 10 | The friendly name of the tag 11 | 12 | .PARAMETER Attributes 13 | Any additional metadata you wish to tag a component with 14 | 15 | .EXAMPLE 16 | $tag = @{ 17 | name = 'SampleTag' 18 | attributes = @{ 19 | jvm = '9' 20 | builtby = 'Jenkins' 21 | } 22 | } 23 | 24 | New-NexusTag @tag 25 | 26 | .LINK 27 | https://help.sonatype.com/en/tagging.html 28 | #> 29 | [CmdletBinding(HelpUri='https://nexushell.dev/Tags/New-NexusTag/')] 30 | Param( 31 | [Parameter(Mandatory)] 32 | [ValidateLength(1,256)] 33 | [String] 34 | $Tag, 35 | 36 | [Parameter()] 37 | [hashtable] 38 | $Attributes 39 | ) 40 | begin{ 41 | if (-not $header) { 42 | throw "Not connected to Nexus server! Run Connect-NexusServer first." 43 | } 44 | 45 | $urislug = '/service/rest/v1/tags' 46 | 47 | if ($Tag.Length -gt 256) { 48 | throw "Name cannot exceed 256 characters." 49 | } 50 | 51 | if ($Tag -notmatch '^[a-zA-Z0-9_.-]+$') { 52 | throw "Name can only contain letters, numbers, underscores, hyphens, and dots." 53 | } 54 | 55 | if ($Tag -match '^[_\.]') { 56 | throw "Name cannot start with an underscore or dot." 57 | } 58 | } 59 | 60 | process { 61 | 62 | $body = @{ 63 | name = $Tag 64 | attributes = $Attributes 65 | } 66 | 67 | Invoke-Nexus -Urislug $urislug -Body $body -Method POST 68 | } 69 | 70 | } -------------------------------------------------------------------------------- /src/private/Get-NexusUserToken.ps1: -------------------------------------------------------------------------------- 1 | function Get-NexusUserToken { 2 | <# 3 | .SYNOPSIS 4 | Fetches a User Token for the provided credential 5 | 6 | .DESCRIPTION 7 | Fetches a User Token for the provided credential 8 | 9 | .PARAMETER Credential 10 | The Nexus user for which to receive a token 11 | 12 | .NOTES 13 | This is a private function not exposed to the end user. 14 | #> 15 | [CmdletBinding()] 16 | Param( 17 | [Parameter(Mandatory)] 18 | [PSCredential] 19 | $Credential 20 | ) 21 | 22 | process { 23 | $UriBase = "$($protocol)://$($Hostname):$($port)$($ContextPath)" 24 | 25 | $slug = '/service/extdirect' 26 | 27 | $uri = $UriBase + $slug 28 | 29 | $credPair = "{0}:{1}" -f $Credential.UserName,$Credential.GetNetworkCredential().Password 30 | $encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($credPair)) 31 | $ApiKeyHeader = @{ Authorization = "Basic $encodedCreds"} 32 | 33 | 34 | $data = @{ 35 | action = 'rapture_Security' 36 | method = 'authenticationToken' 37 | data = @("$([System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($($Credential.Username))))", "$([System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($($Credential.GetNetworkCredential().Password))))") 38 | type = 'rpc' 39 | tid = 16 40 | } 41 | 42 | Write-Verbose ($data | ConvertTo-Json) 43 | $result = Invoke-RestMethod -Uri $uri -Headers $ApiKeyHeader -Method POST -Body ($data | ConvertTo-Json) -ContentType 'application/json' -UseBasicParsing 44 | $token = $result.result.data 45 | $token 46 | } 47 | 48 | } -------------------------------------------------------------------------------- /src/public/Certificate/New-NexusCertificate.ps1: -------------------------------------------------------------------------------- 1 | function New-NexusCertificate { 2 | <# 3 | .SYNOPSIS 4 | Add a certificate to the trust store. 5 | 6 | .DESCRIPTION 7 | Add a certificate to the trust store. 8 | 9 | .PARAMETER PemFile 10 | The certificate to add encoded in PEM format 11 | 12 | .EXAMPLE 13 | New-NexusCertificate -PemFile C:\cert\prod.pem 14 | 15 | .NOTES 16 | 17 | #> 18 | [CmdletBinding()] 19 | Param( 20 | [Parameter(Mandatory)] 21 | [ValidateScript({ 22 | Test-Path $_ 23 | })] 24 | [String] 25 | $PemFile 26 | ) 27 | 28 | begin { 29 | if (-not $header) { 30 | throw "Not connected to Nexus server! Run Connect-NexusServer first." 31 | } 32 | } 33 | 34 | process { 35 | $urislug = '/service/rest/v1/security/ssl/truststore' 36 | $Cert = Get-Content $PemFile -Raw 37 | $result = Invoke-Nexus -Urislug $urislug -BodyAsString $Cert -Method POST 38 | 39 | $result | Foreach-Object { 40 | [pscustomobject]@{ 41 | ExpiresOn = $_.expiresOn 42 | Fingerprint = $_.fingerprint 43 | Id = $_.id 44 | IssuedOn = $_.issuedOn 45 | IssuerCommonName = $_.issuerCommonName 46 | IssuerOrganization = $_.issuerOrganization 47 | IssuerOrganizationalUnit = $_.issueOrganizationalUnit 48 | Pem = $_.pem 49 | SerialNumber = $_.serialNumber 50 | SubjectCommonName = $_.subjectCommonName 51 | SubjectOrganization = $_.subjectOrganization 52 | SubjectOrganizationalUnit = $_.subjectOrganizationalUnit 53 | } 54 | } 55 | 56 | } 57 | } -------------------------------------------------------------------------------- /src/public/Tag/Remove-NexusTag.ps1: -------------------------------------------------------------------------------- 1 | function Remove-NexusTag { 2 | <# 3 | .SYNOPSIS 4 | Removes a tag from Sonatype Nexus 5 | 6 | .DESCRIPTION 7 | Removes a tag from Nexus. Completely disassociates all tagged components. Use Remove-NexusTagAssociation to modify tags on individual components. 8 | 9 | .PARAMETER Tag 10 | The tag to remove 11 | 12 | .PARAMETER Force 13 | Don't prompt for confirmation. 14 | 15 | .EXAMPLE 16 | Remove-NexusTag -Tag SampleTag 17 | 18 | This will prompt you to confirm the deletion 19 | 20 | .EXAMPLE 21 | Remove-NexusTag -Tag SampleTag -Force 22 | 23 | No prompts for confirmation. Potentially dangerous. Use -Whatif if not sure of results 24 | 25 | .LINK 26 | https://help.sonatype.com/en/tagging.html 27 | #> 28 | [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High', HelpUri = 'https://nexushell.dev/Tags/Remove-NexusTag/')] 29 | Param( 30 | [Parameter(Mandatory)] 31 | [String] 32 | $Tag, 33 | 34 | [Parameter()] 35 | [Switch] 36 | $Force 37 | ) 38 | begin { 39 | if (-not $header) { 40 | throw "Not connected to Nexus server! Run Connect-NexusServer first." 41 | } 42 | 43 | $urislug = '/service/rest/v1/tags/{0}' -f $Tag 44 | } 45 | process { 46 | if ($Force -and -not $Confirm) { 47 | $ConfirmPreference = 'None' 48 | if ($PSCmdlet.ShouldProcess("$($_)", "Remove Tag")) { 49 | Invoke-Nexus -Urislug $urislug -Method 'DELETE' 50 | } 51 | } 52 | else { 53 | if ($PSCmdlet.ShouldProcess("$($_)", "Remove Tag")) { 54 | Invoke-Nexus -Urislug $urislug -Method 'DELETE' 55 | } 56 | } 57 | } 58 | } -------------------------------------------------------------------------------- /src/public/Certificate/Remove-NexusCertificate.ps1: -------------------------------------------------------------------------------- 1 | function Remove-NexusCertificate { 2 | <# 3 | .SYNOPSIS 4 | Remove a certificate in the trust store. 5 | 6 | .DESCRIPTION 7 | Remove a certificate in the trust store. 8 | 9 | .PARAMETER Thumbprint 10 | The id of the certificate that should be removed. 11 | 12 | .PARAMETER Force 13 | Don't prompt before removing 14 | 15 | .EXAMPLE 16 | Remove-NexusCertificate -Thumbprint 1a:25:25:25:93:85:94 17 | 18 | .EXAMPLE 19 | Remove-NexusCertificate -Thumbprint 1a:25:25:25:93:85:94 -Force 20 | 21 | .EXAMPLE 22 | Get-NexusCertificate | Remove-NexusCertificate 23 | .NOTES 24 | 25 | #> 26 | [CmdletBinding(HelpUri='https://nexushell.dev/Remove-NexusCertificate/',SupportsShouldProcess,ConfirmImpact='High')] 27 | Param( 28 | [Alias('Id')] 29 | [Parameter(Mandatory,ValueFromPipeline,ValueFromPipelineByPropertyName)] 30 | [String] 31 | $Thumbprint, 32 | 33 | [Parameter()] 34 | [Switch] 35 | $Force 36 | ) 37 | 38 | begin { 39 | if (-not $header) { 40 | throw "Not connected to Nexus server! Run Connect-NexusServer first." 41 | } 42 | } 43 | 44 | process { 45 | $urislug = "/service/rest/v1/security/ssl/truststore/$Thumbprint" 46 | if ($Force -and -not $Confirm) { 47 | $ConfirmPreference = 'None' 48 | if ($PSCmdlet.ShouldProcess("$Thumbprint", "Remove certificate")) { 49 | Invoke-Nexus -UriSlug $urislug -Method DELETE 50 | } 51 | } 52 | else { 53 | if ($PSCmdlet.ShouldProcess("$Thumbprint", "Remove certificate")) { 54 | Invoke-Nexus -UriSlug $urislug -Method DELETE 55 | } 56 | } 57 | } 58 | } -------------------------------------------------------------------------------- /src/public/License/Remove-NexusLicense.ps1: -------------------------------------------------------------------------------- 1 | function Remove-NexusLicense { 2 | <# 3 | .SYNOPSIS 4 | Removes the license from a Nexus instance 5 | 6 | .DESCRIPTION 7 | Removes the license from a Nexus instance 8 | 9 | .PARAMETER Force 10 | Don't prompt for confirmation before removing the license 11 | 12 | .EXAMPLE 13 | Remove-NexusLicense 14 | 15 | .EXAMPLE 16 | Remove-NexusLicense -Force 17 | .NOTES 18 | 19 | #> 20 | [CmdletBinding(HelpUri='https://nexushell.dev/Remove-NexusLicense/',SupportsShouldProcess,ConfirmImpact='High')] 21 | Param( 22 | [Parameter()] 23 | [Switch] 24 | $Force 25 | ) 26 | 27 | begin { 28 | 29 | if (-not $header) { 30 | throw "Not connected to Nexus server! Run Connect-NexusServer first." 31 | } 32 | 33 | $urislug = "/service/rest/v1/system/license" 34 | } 35 | 36 | 37 | process { 38 | 39 | try { 40 | 41 | if ($Force -and -not $Confirm) { 42 | $ConfirmPreference = 'None' 43 | if ($PSCmdlet.ShouldProcess("$Hostname", "Remove Nexus license")) { 44 | Invoke-Nexus -UriSlug $urislug -Method DELETE -ErrorAction Stop 45 | Write-Warning "License has been removed. Nexus service restart necessary" 46 | } 47 | } 48 | else { 49 | if ($PSCmdlet.ShouldProcess("$Hostname", "Remove Nexus license")) { 50 | Invoke-Nexus -UriSlug $urislug -Method DELETE -ErrorAction Stop 51 | Write-Warning "License has been removed. Nexus service restart necessary" 52 | } 53 | } 54 | } 55 | 56 | catch { 57 | $_.exception.message 58 | } 59 | } 60 | } -------------------------------------------------------------------------------- /src/public/Security/Roles/Get-NexusRole.ps1: -------------------------------------------------------------------------------- 1 | function Get-NexusRole { 2 | <# 3 | .SYNOPSIS 4 | Retrieve Nexus Role information 5 | 6 | .DESCRIPTION 7 | Retrieve Nexus Role information 8 | 9 | .PARAMETER Role 10 | The role to retrieve 11 | 12 | .PARAMETER Source 13 | The source to retrieve from 14 | 15 | .EXAMPLE 16 | Get-NexusRole 17 | 18 | .EXAMPLE 19 | Get-NexusRole -Role ExampleRole 20 | 21 | .NOTES 22 | 23 | #> 24 | [CmdletBinding(HelpUri='https://nexushell.dev/Security/Roles/Get-NexusRole/')] 25 | Param( 26 | [Parameter()] 27 | [Alias('id')] 28 | [String] 29 | $Role, 30 | 31 | [Parameter()] 32 | [String] 33 | $Source 34 | ) 35 | begin { if (-not $header) { throw 'Not connected to Nexus server! Run Connect-NexusServer first.' } } 36 | process { 37 | 38 | $urislug = '/service/rest/v1/security/roles' 39 | 40 | if ($Role) { 41 | $urislug = "/service/rest/v1/security/roles/$Role" 42 | } 43 | 44 | if ($Source) { 45 | $urislug = "/service/rest/v1/security/roles?source=$Source" 46 | } 47 | 48 | if ($Role -and $Source) { 49 | $urislug = "/service/rest/v1/security/roles/$($Role)?source=$Source" 50 | } 51 | 52 | Write-verbose $urislug 53 | $result = Invoke-Nexus -Urislug $urislug -Method GET 54 | 55 | $result | ForEach-Object { 56 | [PSCustomObject]@{ 57 | Id = $_.id 58 | Source = $_.source 59 | Name = $_.name 60 | Description = $_.description 61 | Privileges = $_.privileges 62 | Roles = $_.roles 63 | } 64 | } 65 | } 66 | } -------------------------------------------------------------------------------- /src/public/RoutingRule/Get-NexusRoutingRule.ps1: -------------------------------------------------------------------------------- 1 | function Get-NexusRoutingRule { 2 | <# 3 | .SYNOPSIS 4 | Get Nexus Routing rule information 5 | 6 | .DESCRIPTION 7 | Get Nexus Routing rule information 8 | 9 | .PARAMETER Name 10 | Specific routing rule to return 11 | 12 | .EXAMPLE 13 | Get-NexusRoutingRule 14 | 15 | .EXAMPLE 16 | Get-NexusRoutingRule -Name NugetRule 17 | 18 | .NOTES 19 | #> 20 | [CmdletBinding(HelpUri='https://nexushell.dev/Get-NexusRoutingRule/')] 21 | Param( 22 | [Parameter()] 23 | [String[]] 24 | $Name 25 | ) 26 | 27 | begin { 28 | if (-not $header) { 29 | throw "Not connected to Nexus server! Run Connect-NexusServer first." 30 | } 31 | 32 | } 33 | process { 34 | if(-not $Name){ 35 | $urislug = "/service/rest/v1/routing-rules" 36 | 37 | $result = Invoke-Nexus -UriSlug $urislug -Method GET 38 | $result | ForEach-Object { 39 | [pscustomobject]@{ 40 | Name = $_.name 41 | Description = $_.description 42 | Mode = $_.mode 43 | Matchers = $_.matchers 44 | } 45 | } 46 | } else { 47 | $name | ForEach-Object { 48 | $urislug = "/service/rest/v1/routing-rules/$_" 49 | 50 | $result = Invoke-Nexus -Urislug $urislug -Method GET 51 | $result | ForEach-Object { 52 | [pscustomobject]@{ 53 | Name = $_.name 54 | Description = $_.description 55 | Mode = $_.mode 56 | Matchers = $_.matchers 57 | } 58 | } 59 | } 60 | } 61 | } 62 | } -------------------------------------------------------------------------------- /src/public/ContentSelector/Get-NexusContentSelector.ps1: -------------------------------------------------------------------------------- 1 | function Get-NexusContentSelector { 2 | <# 3 | .SYNOPSIS 4 | List Nexus Content Selectors 5 | 6 | .DESCRIPTION 7 | List Nexus Content Selectors 8 | 9 | .PARAMETER Name 10 | The content selector name 11 | 12 | .EXAMPLE 13 | Get-NexusContentSelector 14 | 15 | .EXAMPLE 16 | Get-NexusContentSelector -Name 'MavenSelector' 17 | 18 | .NOTES 19 | 20 | #> 21 | [CmdletBinding(HelpUri='https://nexushell.dev/Security/Content%20Selectors/Get-NexusContentSelector/')] 22 | Param( 23 | [Parameter()] 24 | [String[]] 25 | $Name 26 | ) 27 | 28 | begin { 29 | if (-not $header) { 30 | throw "Not connected to Nexus server! Run Connect-NexusServer first." 31 | } 32 | } 33 | 34 | process { 35 | 36 | if($Name){ 37 | $Name | Foreach-Object { 38 | $urislug = "/service/rest/v1/security/content-selectors/$_" 39 | 40 | $result = Invoke-Nexus -Urislug $urislug -Method GET 41 | 42 | if($result){ 43 | [pscustomobject]@{ 44 | Name = $result.name 45 | Description = $result.Description 46 | Expression = $result.expression 47 | } 48 | } 49 | 50 | } 51 | } else { 52 | $urislug = '/service/rest/v1/security/content-selectors' 53 | 54 | $result = Invoke-Nexus -Urislug $urislug -Method GET 55 | if($result){ 56 | [pscustomobject]@{ 57 | Name = $result.name 58 | Description = $result.Description 59 | Expression = $result.expression 60 | } 61 | } 62 | } 63 | } 64 | } -------------------------------------------------------------------------------- /src/public/Component/New-NexusRawComponent.ps1: -------------------------------------------------------------------------------- 1 | function New-NexusRawComponent { 2 | <# 3 | .SYNOPSIS 4 | Uploads a file to a Raw repository 5 | 6 | .DESCRIPTION 7 | Uploads a file to a Raw repository 8 | 9 | .PARAMETER RepositoryName 10 | The Raw repository to upload too 11 | 12 | .PARAMETER File 13 | The file to upload 14 | 15 | .PARAMETER Directory 16 | The directory to store the file on the repo 17 | 18 | .PARAMETER Name 19 | The name of the file stored into the repo. Can be different than the file name being uploaded. 20 | 21 | .EXAMPLE 22 | New-NexusRawComponent -RepositoryName GeneralFiles -File C:\temp\service.1234.log 23 | 24 | .EXAMPLE 25 | New-NexusRawComponent -RepositoryName GeneralFiles -File C:\temp\service.log -Directory logs 26 | 27 | .EXAMPLE 28 | New-NexusRawComponent -RepositoryName GeneralFile -File C:\temp\service.log -Directory logs -Name service.99999.log 29 | 30 | .NOTES 31 | #> 32 | [CmdletBinding()] 33 | Param( 34 | [Parameter(Mandatory)] 35 | [String] 36 | $RepositoryName, 37 | 38 | [Parameter(Mandatory)] 39 | [String] 40 | $File, 41 | 42 | [Parameter()] 43 | [String] 44 | $Directory, 45 | 46 | [Parameter()] 47 | [String] 48 | $Name = (Split-Path -Leaf $File) 49 | ) 50 | 51 | process { 52 | 53 | if(-not $Directory){ 54 | $urislug = "/repository/$($RepositoryName)/$($Name)" 55 | } 56 | else { 57 | $urislug = "/repository/$($RepositoryName)/$($Directory)/$($Name)" 58 | 59 | } 60 | $UriBase = "$($protocol)://$($Hostname):$($port)$($ContextPath)" 61 | $Uri = $UriBase + $UriSlug 62 | 63 | 64 | $params = @{ 65 | Url = $Uri 66 | File = $File 67 | Credential = $Credential 68 | } 69 | 70 | Upload-File @params 71 | } 72 | } -------------------------------------------------------------------------------- /src/private/Get-NexusCertificateDomain.ps1: -------------------------------------------------------------------------------- 1 | function Get-NexusCertificateDomain { 2 | <# 3 | .SYNOPSIS 4 | Returns the Certificate domain for the specified Nexus configuration, if present. 5 | 6 | .DESCRIPTION 7 | Uses the KeyTool to open the currently used KeyStore and grab the domain. 8 | 9 | .PARAMETER DataDir 10 | The path to the Sonatype Nexus data directory, e.g. C:\ProgramData\sonatype-work\nexus3. 11 | 12 | .PARAMETER ProgramDir 13 | The path to the Sonatype Nexus program files, e.g. C:\ProgramData\nexus. 14 | 15 | .EXAMPLE 16 | Get-NexusCertificateDomain -DataDir C:\ProgramData\sonatype-work\nexus3 -ProgramDir C:\ProgramData\nexus 17 | #> 18 | param( 19 | [string]$DataDir = $script:InstalledNexusService.DataFolder, 20 | 21 | [string]$ProgramDir = $script:InstalledNexusService.ProgramFolder 22 | ) 23 | $Config = Get-NexusConfiguration -Path $DataDir\etc\nexus.properties 24 | if ($Config.'nexus-args'.Split(',') -contains '${jetty.etc}/jetty-https.xml') { 25 | [xml]$HttpsConfig = Get-Content $ProgramDir\etc\jetty\jetty-https.xml 26 | $KeyToolPath = Join-Path $ProgramDir "jre/bin/keytool.exe" 27 | $KeyStorePath = Join-Path (Join-Path $ProgramDir "etc/ssl") $HttpsConfig.SelectSingleNode("//Set[@name='KeyStorePath']").'#text' 28 | $KeyStorePassword = $HttpsConfig.SelectSingleNode("//Set[@name='KeyStorePassword']").'#text' 29 | 30 | if ((Test-Path $KeyToolPath) -and (Test-Path $KeyStorePath)) { 31 | # Running in a job, as otherwise KeyTool fails when run without input 32 | Start-Job { 33 | $KeyToolOutput = $using:KeyStorePassword | & "$using:KeyToolPath" -list -v -keystore "$using:KeyStorePath" -J"-Duser.language=en" 2>$null 34 | if ($KeyToolOutput -join "`n" -match "(?smi)Certificate\[1\]:\nOwner: CN=(?.+?)(\n|,)") { 35 | $Matches.Domain 36 | } 37 | } | Receive-Job -Wait 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /src/private/Get-NexusRepositoryServiceInstall.ps1: -------------------------------------------------------------------------------- 1 | function Get-NexusRepositoryServiceInstall { 2 | <# 3 | .SYNOPSIS 4 | If found, returns the name of the Nexus service and the install and data directories it uses. 5 | 6 | .DESCRIPTION 7 | Checks all current services for services that run "nexus.exe", then returns the program and data directories for one/each. 8 | 9 | .PARAMETER AllResults 10 | To speed up execution, by default we check services until we find the first one running nexus.exe. 11 | If you have more than one instance installed, you can use this switch to check all services. 12 | 13 | .EXAMPLE 14 | Get-NexusRepositoryInstallValues 15 | #> 16 | [CmdletBinding()] 17 | param( 18 | # By default, we assume there is only one service. This searches for all installed services. 19 | [switch]$AllResults 20 | ) 21 | # If you have a lot of services, searching them all may take longer - 22 | # so we can stop searching when we find the first service matching nexus.exe. 23 | $ResultCount = @{} 24 | if (-not $AllResults) { $ResultCount.First = 1 } 25 | 26 | $NexusService = Get-ChildItem HKLM:\System\CurrentControlSet\Services\ | Where-Object { 27 | ($ImagePath = Get-ItemProperty -Path $_.PSPath -Name ImagePath -ErrorAction SilentlyContinue) -and 28 | $ImagePath.ImagePath.Trim('"''').EndsWith('\nexus.exe') 29 | } | Select-Object @ResultCount 30 | 31 | foreach ($Service in $NexusService) { 32 | $ServiceName = $Service.PSChildName 33 | $TargetFolder = (Get-ItemProperty -Path $Service.PSPath).ImagePath.Trim('"''') | Split-Path | Split-Path 34 | $DataFolder = Convert-Path (Join-Path $TargetFolder "$((Get-Content $TargetFolder\bin\nexus.vmoptions) -match '^-Dkaraf.data=(?.+)$' -replace '^-Dkaraf.data=')") 35 | [PSCustomObject]@{ 36 | ServiceName = $ServiceName 37 | ProgramFolder = $TargetFolder 38 | DataFolder = $DataFolder 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /src/public/Security/LDAP/Remove-NexusLDAPServer.ps1: -------------------------------------------------------------------------------- 1 | function Remove-NexusLDAPServerConnection { 2 | <# 3 | .SYNOPSIS 4 | Renove LDAP Connection from Nexus 5 | 6 | .DESCRIPTION 7 | Renove LDAP Connection from Nexus 8 | 9 | .PARAMETER Name 10 | The LDAP Connection you wish to remove 11 | 12 | .PARAMETER Force 13 | Don't prompt for confirmation 14 | 15 | .EXAMPLE 16 | Remove-NexusLDAPServerConnection -Name DevLDAP 17 | 18 | .EXAMPLE 19 | Remove-NexusLDAPServerConnection -Name DevLDAP -Force 20 | 21 | .NOTES 22 | #> 23 | [CmdletBinding(HelpUri = 'https://nexushell.dev/Security/LDAP/Remove-NexusLDAPServerConnection/',SupportsShouldProcess,ConfirmImpact = 'High')] 24 | Param( 25 | [Parameter(Mandatory,ValueFromPipeline,ValueFromPipelineByPropertyName)] 26 | [String[]] 27 | $Name, 28 | 29 | [Parameter()] 30 | [Switch] 31 | $Force 32 | ) 33 | 34 | begin { 35 | 36 | if (-not $header) { 37 | throw "Not connected to Nexus server! Run Connect-NexusServer first." 38 | } 39 | 40 | 41 | } 42 | 43 | process { 44 | 45 | $Name | ForEach-Object { 46 | $urislug = "/service/rest/v1/security/ldap/$_" 47 | 48 | try { 49 | 50 | if ($Force -and -not $Confirm) { 51 | $ConfirmPreference = 'None' 52 | if ($PSCmdlet.ShouldProcess("$_", "Remove LDAP Connection")) { 53 | Invoke-Nexus -UriSlug $urislug -Method DELETE -ErrorAction Stop 54 | 55 | } 56 | } 57 | else { 58 | if ($PSCmdlet.ShouldProcess("$_", "Remove LDAP Connection")) { 59 | Invoke-Nexus -UriSlug $urislug -Method DELETE -ErrorAction Stop 60 | } 61 | } 62 | } 63 | 64 | catch { 65 | $_.exception.message 66 | } 67 | 68 | 69 | } 70 | 71 | } 72 | } -------------------------------------------------------------------------------- /src/public/Security/Roles/Remove-NexusRole.ps1: -------------------------------------------------------------------------------- 1 | function Remove-NexusRole { 2 | <# 3 | .SYNOPSIS 4 | Remove a Nexus Role 5 | 6 | .DESCRIPTION 7 | Remove a Nexus Role 8 | 9 | .PARAMETER Role 10 | The role to remove 11 | 12 | .PARAMETER Force 13 | Don't prompt for confirmation prior to removal 14 | 15 | .EXAMPLE 16 | Remove-NexusRole -Role SampleRole 17 | 18 | .EXAMPLE 19 | Remove-NexusRole -Role SampleRole -Force 20 | 21 | .EXAMPLE 22 | Get-NexusRole -Role SampleRole | Remove-Nexus Role 23 | 24 | .NOTES 25 | #> 26 | [CmdletBinding(HelpUri='https://nexushell.dev/Security/Roles/Remove-NexusRole/',SupportsShouldProcess,ConfirmImpact='High')] 27 | Param( 28 | [Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)] 29 | [ArgumentCompleter( { 30 | param($Command, $Parameter, $WordToComplete, $CommandAst, $FakeBoundParams) 31 | 32 | $r = (Get-NexusRole).id 33 | 34 | if ($WordToComplete) { 35 | $r.Where($_ -match "^$WordToComplete") 36 | } 37 | 38 | else { 39 | $r 40 | } 41 | })] 42 | [Alias('Id', 'Name')] 43 | [String[]] 44 | $Role, 45 | 46 | [Parameter()] 47 | [Switch] 48 | $Force 49 | ) 50 | 51 | process { 52 | $Role | Foreach-Object { 53 | $urislug = "/service/rest/v1/security/roles/$($_)" 54 | 55 | if ($Force -and -not $Confirm) { 56 | $ConfirmPreference = 'None' 57 | if ($PSCmdlet.ShouldProcess("$($_)", "Remove Role")) { 58 | Invoke-Nexus -UriSlug $urislug -Method DELETE -ErrorAction Stop 59 | } 60 | } 61 | else { 62 | if ($PSCmdlet.ShouldProcess("$($_)", "Remove Role")) { 63 | Invoke-Nexus -UriSlug $urislug -Method DELETE -ErrorAction Stop 64 | } 65 | } 66 | } 67 | } 68 | 69 | } -------------------------------------------------------------------------------- /src/NexuShell.psd1: -------------------------------------------------------------------------------- 1 | # 2 | # Module manifest for module 'NexuShell' 3 | # 4 | # Generated by: steviecoaster 5 | # 6 | # Generated on: 2/26/2021 7 | # 8 | 9 | @{ 10 | RootModule = 'NexuShell.psm1' 11 | Description = 'Allows for the administration of Sonatype Nexus via its robust REST api' 12 | GUID = '7e720347-1e77-4ba3-a848-1295093940c1' 13 | ModuleVersion = '1.0' 14 | 15 | Author = 'steviecoaster' 16 | CompanyName = '' 17 | Copyright = '(c) 2021 steviecoaster. All rights reserved.' 18 | 19 | # Minimum version of the Windows PowerShell engine required by this module 20 | # PowerShellVersion = '' 21 | 22 | # For best performance, do not use wildcards and do not delete the entries, use an empty array. 23 | FunctionsToExport = @() 24 | CmdletsToExport = @() 25 | VariablesToExport = @() 26 | AliasesToExport = @('Get-NexusLifecycle','New-NexusLifecycle','Get-NexusUri') 27 | 28 | # Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell. 29 | PrivateData = @{ 30 | PSData = @{ 31 | # Tags applied to this module. These help with module discovery in online galleries. 32 | Tags = @("nexus", "repository", "REST", "API", "sonatype") 33 | 34 | # A URL to the license for this module. 35 | LicenseUri = 'https://raw.githubusercontent.com/steviecoaster/NexuShell/main/LICENSE' 36 | 37 | # A URL to the main website for this project. 38 | ProjectUri = 'https://github.com/steviecoaster/NexuShell' 39 | 40 | # A URL to an icon representing this module. 41 | # IconUri = '' 42 | 43 | # ReleaseNotes of this module 44 | ReleaseNotes = '' 45 | 46 | # Prerelease string of this module 47 | Prerelease = '' 48 | 49 | } # End of PSData hashtable 50 | } # End of PrivateData hashtable 51 | 52 | # HelpInfo URI of this module 53 | HelpInfoURI = 'https://nexushell.dev/' 54 | } 55 | -------------------------------------------------------------------------------- /src/nuget/NexuShell.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | NexuShell 6 | 1.0.0 7 | steviecoaster 8 | https://github.com/steviecoaster/NexuShell/tree/develop/src/public/nuget 9 | NexuShell 10 | Stephen Valdinger 11 | https://github.com/steviecoaster/NexuShell 12 | https://github.com/steviecoaster/NexuShell 13 | https://cdn.jsdelivr.net/gh/steviecoaster/NexuShell@develop/logo/nexushell.svg 14 | (c) 2021 steviecoaster. All rights reserved. 15 | https://nexushell.dev/ 16 | https://github.com/steviecoaster/NexuShell/issues 17 | https://raw.githubusercontent.com/steviecoaster/NexuShell/main/LICENSE 18 | false 19 | sonatype nexus repository powershell module 20 | A PowerShell module for Sonatype Nexus repository server administration. 21 | A PowerShell module for Sonatype Nexus repository server administration. 22 | 23 | You can pass the following parameters: 24 | 25 | * `/Core` - Installs the module to the PowerShell Modules directory 26 | * `/Windows` - Installs the module to the WindowsPowerShell Modules directory 27 | * `/CurrentUser` - Installs the module to the CurrentUser scope 28 | * `/AllUsers` - Installs the module to the AllUsers scope 29 | 30 | https://github.com/steviecoaster/NexuShell/releases 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /src/public/User/Get-NexusUser.ps1: -------------------------------------------------------------------------------- 1 | function Get-NexusUser { 2 | <# 3 | .SYNOPSIS 4 | Retrieve a list of users. Note if the source is not 'default' the response is limited to 100 users. 5 | 6 | .DESCRIPTION 7 | Retrieve a list of users. Note if the source is not 'default' the response is limited to 100 users. 8 | 9 | .PARAMETER User 10 | The username to fetch 11 | 12 | .PARAMETER Source 13 | The source to fetch from 14 | 15 | .EXAMPLE 16 | Get-NexusUser 17 | 18 | .EXAMPLE 19 | Get-NexusUser -User bob 20 | 21 | .EXAMPLE 22 | Get-NexusUser -Source default 23 | 24 | .NOTES 25 | 26 | #> 27 | [CmdletBinding(HelpUri='https://nexushell.dev/Security/User/Get-NexusUser/')] 28 | Param( 29 | [Parameter()] 30 | [String] 31 | $User, 32 | 33 | [Parameter()] 34 | [String] 35 | $Source 36 | ) 37 | 38 | begin { 39 | if (-not $header) { 40 | throw "Not connected to Nexus server! Run Connect-NexusServer first." 41 | } 42 | } 43 | 44 | process { 45 | $urislug = '/service/rest/v1/security/users' 46 | 47 | if($User){ 48 | $urislug = "/service/rest/v1/security/users?userId=$User" 49 | } 50 | 51 | if($Source){ 52 | $urislug = "/service/rest/v1/security/users?source=$Source" 53 | } 54 | 55 | if($User -and $Source){ 56 | $urislug = "/service/rest/v1/security/users?userId=$User&source=$Source" 57 | } 58 | 59 | $result = Invoke-Nexus -Urislug $urislug -Method GET 60 | 61 | $result | Foreach-Object { 62 | [pscustomobject]@{ 63 | Username = $_.userId 64 | FirstName = $_.firstName 65 | LastName = $_.lastName 66 | EmailAddress = $_.emailAddress 67 | Source = $_.source 68 | Status = $_.status 69 | ReadOnly = $_.readOnly 70 | Roles = $_.roles 71 | ExternalRoles = $_.externalRoles 72 | } 73 | } 74 | } 75 | } -------------------------------------------------------------------------------- /src/public/RoutingRule/Set-NexusRoutingRule.ps1: -------------------------------------------------------------------------------- 1 | function Set-NexusRoutingRule { 2 | <# 3 | .SYNOPSIS 4 | Updates a Nexus routing rule 5 | 6 | .DESCRIPTION 7 | Updates a Nexus routing rule 8 | 9 | .PARAMETER Name 10 | The name of the rule 11 | 12 | .PARAMETER Description 13 | A brief explanation of the routing rule 14 | 15 | .PARAMETER Mode 16 | Allow the connection, or block the connection 17 | 18 | .PARAMETER Matchers 19 | Regex strings to match for the route 20 | 21 | .EXAMPLE 22 | Set-NexusRoutingRule -Name BlockNuGet -Mode Block -Matchers 'NuGet','[\w]Nuget.+' 23 | 24 | .NOTES 25 | #> 26 | [CmdletBinding(HelpUri = 'https://nexushell.dev/Set-NexusRoutingRule/')] 27 | Param( 28 | [Parameter(Mandatory)] 29 | [ArgumentCompleter( { 30 | param($Command, $Parameter, $WordToComplete, $CommandAst, $FakeBoundParams) 31 | 32 | $r = (Get-NexusRoutingRule).name 33 | 34 | if ($WordToComplete) { 35 | $r.Where($_ -match "^$WordToComplete") 36 | } 37 | else { 38 | $r 39 | } 40 | } 41 | )] 42 | [String] 43 | $Name, 44 | 45 | [Parameter()] 46 | [String] 47 | $Description, 48 | 49 | [Parameter(Mandatory)] 50 | [ValidateSet('Allow','Block')] 51 | [String] 52 | $Mode, 53 | 54 | [Parameter(Mandatory)] 55 | [String[]] 56 | $Matchers 57 | ) 58 | 59 | begin { 60 | 61 | if (-not $header) { 62 | throw "Not connected to Nexus server! Run Connect-NexusServer first." 63 | } 64 | 65 | $urislug = "/service/rest/v1/routing-rules/$Name" 66 | } 67 | 68 | process { 69 | 70 | $Body = @{ 71 | name = $Name 72 | description = $Description 73 | mode = $Mode.ToUpper() 74 | matchers = @($Matchers) 75 | } 76 | 77 | Write-Verbose $($Body | ConvertTo-Json) 78 | Invoke-Nexus -UriSlug $urislug -Body $Body -Method PUT 79 | 80 | } 81 | } -------------------------------------------------------------------------------- /src/public/Security/Roles/New-NexusRole.ps1: -------------------------------------------------------------------------------- 1 | function New-NexusRole { 2 | <# 3 | .SYNOPSIS 4 | Creates a new Nexus Role 5 | 6 | .DESCRIPTION 7 | Creates a new Nexus Role 8 | 9 | .PARAMETER Id 10 | The ID of the role 11 | 12 | .PARAMETER Name 13 | The friendly name of the role 14 | 15 | .PARAMETER Description 16 | A description of the role 17 | 18 | .PARAMETER Privileges 19 | Included privileges for the role 20 | 21 | .PARAMETER Roles 22 | Included nested roles 23 | 24 | .EXAMPLE 25 | New-NexusRole -Id SamepleRole 26 | 27 | .EXAMPLE 28 | New-NexusRole -Id SampleRole -Description "A sample role" -Privileges nx-all 29 | 30 | .NOTES 31 | 32 | #> 33 | [CmdletBinding(HelpUri='https://nexushell.dev/Security/Roles/New-NexusRole/')] 34 | Param( 35 | [Parameter(Mandatory)] 36 | [String] 37 | $Id, 38 | 39 | [Parameter(Mandatory)] 40 | [String] 41 | $Name, 42 | 43 | [Parameter()] 44 | [String] 45 | $Description, 46 | 47 | [Parameter(Mandatory)] 48 | [String[]] 49 | $Privileges, 50 | 51 | [Parameter()] 52 | [String[]] 53 | $Roles 54 | ) 55 | 56 | begin { 57 | if (-not $header) { 58 | throw 'Not connected to Nexus server! Run Connect-NexusServer first.' 59 | } 60 | } 61 | 62 | process { 63 | 64 | $urislug = '/service/rest/v1/security/roles' 65 | $Body = @{ 66 | 67 | id = $Id 68 | name = $Name 69 | description = $Description 70 | privileges = @($Privileges) 71 | roles = $Roles 72 | 73 | } 74 | 75 | Invoke-Nexus -Urislug $urislug -Body $Body -Method POST | Foreach-Object { 76 | [PSCustomobject]@{ 77 | Id = $_.id 78 | Name = $_.name 79 | Description = $_.description 80 | Privileges = $_.privileges 81 | Roles = $_.roles 82 | } 83 | } 84 | 85 | } 86 | } -------------------------------------------------------------------------------- /src/public/Security/Privileges/Get-NexusPrivilege.ps1: -------------------------------------------------------------------------------- 1 | function Get-NexusPrivilege { 2 | <# 3 | .SYNOPSIS 4 | Retrieve Privilege information from Nexus 5 | 6 | .DESCRIPTION 7 | Retrieve Privilege information from Nexus 8 | 9 | .PARAMETER PrivilegeId 10 | The id of the privilege to retrieve. 11 | 12 | .EXAMPLE 13 | Get-NexusPrivilege 14 | 15 | .EXAMPLE 16 | Get-NexusPrivilege -PrivilegeId NuGetProdAdmin 17 | 18 | .NOTES 19 | 20 | #> 21 | [CmdletBinding(HelpUri='https://nexushell.dev/Security/Privileges/Get-NexusPrivilege/')] 22 | Param( 23 | [Parameter()] 24 | [String] 25 | $PrivilegeId 26 | ) 27 | 28 | begin { 29 | if (-not $header) { 30 | throw "Not connected to Nexus server! Run Connect-NexusServer first." 31 | } 32 | } 33 | 34 | process { 35 | 36 | 37 | if ($PrivilegeId) { 38 | $urislug = "/service/rest/v1/security/privileges/$PrivilegeId" 39 | 40 | try { 41 | $result = Invoke-Nexus -Urislug $urislug -Method GET 42 | 43 | [pscustomobject]@{ 44 | Name = $result.name 45 | Type = $result.type 46 | Description = $result.description 47 | ReadOnly = $result.readonly 48 | Actions = $result.actions 49 | Domain = $result.domain 50 | } 51 | } 52 | catch { 53 | $_.Exception.Message 54 | } 55 | } 56 | else { 57 | $urislug = '/service/rest/v1/security/privileges' 58 | 59 | $result = Invoke-Nexus -Urislug $urislug -Method GET 60 | 61 | $result | Foreach-Object { 62 | [pscustomobject]@{ 63 | Name = $_.name 64 | Type = $_.type 65 | Description = $_.description 66 | ReadOnly = $_.readOnly 67 | Pattern = $_.pattern 68 | } 69 | } 70 | 71 | } 72 | 73 | } 74 | } -------------------------------------------------------------------------------- /src/public/Security/Privileges/Remove-NexusPrivilege.ps1: -------------------------------------------------------------------------------- 1 | function Remove-NexusPrivilege { 2 | <# 3 | .SYNOPSIS 4 | Remove a Nexus Privilege 5 | 6 | .DESCRIPTION 7 | Remove a Nexus Privilege 8 | 9 | .PARAMETER PrivilegeId 10 | The id of the privilege to delete. 11 | 12 | .PARAMETER Force 13 | Don't prompt for confirmation before removal 14 | 15 | .EXAMPLE 16 | Remove-NexusPrivilege -PrivilegeId NuGetSuperAdmin 17 | 18 | .EXAMPLE 19 | Get-NexusPrivilege -PrivilegeId NuGetSuperAdmin | Remove-NexusPrivilege 20 | 21 | .EXAMPLE 22 | Remove-NexusPrivilege -PrivilegeId NuGetSuperAdmin -Force 23 | 24 | .NOTES 25 | General notes 26 | #> 27 | [CmdletBinding(HelpUri='https://nexushell.dev/Security/Privileges/Remove-NexusPrivilege/',SupportsShouldProcess,ConfirmImpact="High")] 28 | Param( 29 | [Parameter(Mandatory,ValueFromPipeline,ValueFromPipelineByPropertyName)] 30 | [ArgumentCompleter({ 31 | param($Command, $Parameter, $WordToComplete, $CommandAst, $FakeBoundParams) 32 | 33 | $r = (Get-NexusPrivilege).Name 34 | 35 | if($WordToComplete){ 36 | $r.Where($_ -match "^$WordToComplete") 37 | } 38 | else { 39 | $r 40 | } 41 | })] 42 | [String[]] 43 | [Alias('Name')] 44 | $PrivilegeId, 45 | 46 | [Parameter()] 47 | [Switch] 48 | $Force 49 | ) 50 | 51 | process { 52 | $PrivilegeId | Foreach-Object { 53 | $urislug = "/service/rest/v1/security/privileges/$($_)" 54 | 55 | if ($Force -and -not $Confirm) { 56 | $ConfirmPreference = 'None' 57 | if ($PSCmdlet.ShouldProcess("$($_)", "Remove Privilege")) { 58 | Invoke-Nexus -UriSlug $urislug -Method DELETE -ErrorAction Stop 59 | } 60 | } 61 | else { 62 | if ($PSCmdlet.ShouldProcess("$($_)", "Remove Privilege")) { 63 | Invoke-Nexus -UriSlug $urislug -Method DELETE -ErrorAction Stop 64 | } 65 | } 66 | } 67 | } 68 | } -------------------------------------------------------------------------------- /src/public/Script/Remove-NexusScript.ps1: -------------------------------------------------------------------------------- 1 | function Remove-NexusScript { 2 | <# 3 | .SYNOPSIS 4 | Deletes a stored script from Nexus 5 | 6 | .DESCRIPTION 7 | Deletes a stored script from Nexus 8 | 9 | .PARAMETER Name 10 | The script to remove 11 | 12 | .PARAMETER Force 13 | Don't prompt for confirmation before removing 14 | 15 | .EXAMPLE 16 | Remove-NexusScript -Name TestScript 17 | 18 | .EXAMPLE 19 | Remove-NexusScript -Name TestScript -Force 20 | 21 | .EXAMPLE 22 | GetNexusScript | Remove-NexusScript -Force 23 | 24 | .NOTES 25 | 26 | #> 27 | [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High')] 28 | Param( 29 | [Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)] 30 | [ArgumentCompleter( { 31 | param($Command, $Parameter, $WordToComplete, $CommandAst, $FakeBoundParams) 32 | 33 | $r = (Get-NexusScript).name 34 | 35 | if ($WordToComplete) { 36 | $r.Where{ $_ -match "^$WordToComplete" } 37 | } 38 | else { 39 | $r 40 | } 41 | } 42 | )] 43 | [String[]] 44 | $Name, 45 | 46 | [Parameter()] 47 | [Switch] 48 | $Force 49 | ) 50 | 51 | begin { 52 | if (-not $header) { 53 | throw "Not connected to Nexus server! Run Connect-NexusServer first." 54 | } 55 | } 56 | 57 | process { 58 | 59 | $Name | Foreach-Object { 60 | 61 | $urislug = "/service/rest/v1/script/$_" 62 | 63 | if ($Force -and -not $Confirm) { 64 | $ConfirmPreference = 'None' 65 | if ($PSCmdlet.ShouldProcess("$_", "Remove Script")) { 66 | Invoke-Nexus -UriSlug $urislug -Method DELETE -ErrorAction Stop 67 | } 68 | } 69 | else { 70 | if ($PSCmdlet.ShouldProcess("$_", "Remove Script")) { 71 | Invoke-Nexus -UriSlug $urislug -Method DELETE -ErrorAction Stop 72 | } 73 | } 74 | 75 | } 76 | } 77 | } -------------------------------------------------------------------------------- /src/public/ContentSelector/Set-NexusContentSelector.ps1: -------------------------------------------------------------------------------- 1 | function Set-NexusContentSelector { 2 | <# 3 | .SYNOPSIS 4 | Updates a Content Selector in Nexus 5 | 6 | .DESCRIPTION 7 | Updates a Content Selector in Nexus 8 | 9 | .PARAMETER Name 10 | The content selector to update 11 | 12 | .PARAMETER Description 13 | A human-readable description 14 | 15 | .PARAMETER Expression 16 | The expression used to identify content 17 | 18 | .EXAMPLE 19 | Set-NexusContentSelector -Name MavenContent -Expression 'format == "maven2" and path =^ "/org/sonatype/nexus"' 20 | 21 | .NOTES 22 | 23 | #> 24 | [CmdletBinding(HelpUri='https://nexushell.dev/Security/Content%20Selectors/Set-NexusContentSelector/')] 25 | Param( 26 | [Parameter(Mandatory)] 27 | [ArgumentCompleter({ 28 | param($Command, $Parameter, $WordToComplete, $CommandAst, $FakeBoundParams) 29 | 30 | $r = (Get-NexusContentSelector).Name 31 | 32 | if($WordToComplete){ 33 | $r.Where($_ -match "^$WordToComplete") 34 | } 35 | else { 36 | $r 37 | } 38 | })] 39 | [String] 40 | $Name, 41 | 42 | [Parameter()] 43 | [String] 44 | $Description, 45 | 46 | [Parameter()] 47 | [String] 48 | $Expression 49 | ) 50 | 51 | begin { 52 | if (-not $header) { 53 | throw "Not connected to Nexus server! Run Connect-NexusServer first." 54 | } 55 | } 56 | 57 | process { 58 | 59 | $CurrentSettings = Get-NexusContentSelector -Name $Name 60 | 61 | if(-not $Description){ 62 | $Description = $CurrentSettings.Description 63 | } 64 | if(-not $Expression){ 65 | $Expression = $CurrentSettings.Expression 66 | } 67 | 68 | $urislug = "/service/rest/v1/security/content-selectors/$Name" 69 | $Body = @{ 70 | name = $Name 71 | description = $Description 72 | expression = $Expression 73 | } 74 | 75 | Invoke-Nexus -Urislug $urislug -Body $Body -Method PUT 76 | } 77 | } -------------------------------------------------------------------------------- /src/public/BlobStore/Remove-NexusBlobStore.ps1: -------------------------------------------------------------------------------- 1 | function Remove-NexusBlobStore { 2 | <# 3 | .SYNOPSIS 4 | Deletes a Nexus blob store 5 | 6 | .DESCRIPTION 7 | Deletes a Nexus blob store 8 | 9 | .PARAMETER Name 10 | The blob store to remove 11 | 12 | .PARAMETER Force 13 | Disable confirmation of the delete action. 14 | 15 | .EXAMPLE 16 | Remove-NexusBlobStore -Name TreasureBlob 17 | 18 | .EXAMPLE 19 | Remove-NexusBlobStore -Name TreasureBlob -Force 20 | #> 21 | [CmdletBinding(HelpUri='https://nexushell.dev/Remove-NexusBlobStore/',SupportsShouldProcess, ConfirmImpact = 'High')] 22 | Param( 23 | [Parameter(Mandatory)] 24 | [String] 25 | $Name, 26 | 27 | [Parameter()] 28 | [Switch] 29 | $Force 30 | ) 31 | begin { 32 | 33 | if (-not $header) { 34 | throw "Not connected to Nexus server! Run Connect-NexusServer first." 35 | } 36 | 37 | $urislug = "/service/rest/v1/blobstores" 38 | } 39 | 40 | process { 41 | $Uri = $urislug + "/$Name" 42 | 43 | try { 44 | 45 | 46 | if ($Force -and -not $Confirm) { 47 | $ConfirmPreference = 'None' 48 | if ($PSCmdlet.ShouldProcess("$name", "Remove Blob Store")) { 49 | $result = Invoke-Nexus -UriSlug $Uri -Method 'DELETE' -ErrorAction Stop 50 | [pscustomobject]@{ 51 | Status = 'Success' 52 | Blob = $Name 53 | } 54 | } 55 | } 56 | 57 | else { 58 | if ($PSCmdlet.ShouldProcess("$name", "Remove Blob Store")) { 59 | $result = Invoke-Nexus -UriSlug $Uri -Method 'DELETE' -ErrorAction Stop 60 | [pscustomobject]@{ 61 | Status = 'Success' 62 | Blob = $Name 63 | Timestamp = $result.date 64 | 65 | } 66 | } 67 | 68 | } 69 | 70 | 71 | } 72 | 73 | catch { 74 | $_.exception.message 75 | } 76 | } 77 | } -------------------------------------------------------------------------------- /src/public/Repository/Cleanup Policy/Remove-NexusCleanupPolicy.ps1: -------------------------------------------------------------------------------- 1 | function Remove-NexusCleanupPolicy { 2 | <# 3 | .SYNOPSIS 4 | Removes a Nexus Cleanup Policy 5 | 6 | .DESCRIPTION 7 | Removes a Nexus Cleanup Policy 8 | 9 | .PARAMETER Name 10 | The policy to remove 11 | 12 | .PARAMETER Force 13 | Don't prompt for confirmation before removal 14 | 15 | .EXAMPLE 16 | Remove-NexusCleanupPolicy -Name TestPolicy 17 | 18 | .EXAMPLE 19 | Remove-NexusCleanupPolicy -Name TestPolicy -Force 20 | 21 | .EXAMPLE 22 | Get-NexusCleanupPolicy -Name TestPol | Remove-NexusCleanupPolicy -Force 23 | 24 | .NOTES 25 | 26 | #> 27 | [CmdletBinding(HelpUri='https://nexushell.dev/Repository/Cleanup%20Policy/Remove-NexusCleanupPolicy/',SupportsShouldProcess, ConfirmImpact = 'High')] 28 | Param( 29 | [Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)] 30 | [ArgumentCompleter( { 31 | param($Command, $Parameters, $WordToComplete, $CommandAst, $FakeBoundParams) 32 | 33 | $r = (Get-NexusCleanupPolicy).Name 34 | 35 | if ($WordToComplete) { 36 | $r.Where($_ -match "^$WordToComplete") 37 | } 38 | 39 | else { 40 | $r 41 | } 42 | })] 43 | [String] 44 | $Name, 45 | 46 | [Parameter()] 47 | [Switch] 48 | $Force 49 | ) 50 | 51 | process { 52 | 53 | $Name | Foreach-Object { 54 | $urislug = "/service/rest/internal/cleanup-policies/$($_)?_dc=$(([DateTime]::ParseExact("01/02/0001 21=08=29", "MM/dd/yyyy HH=mm=ss",$null)).Ticks)" 55 | if ($Force -and -not $Confirm) { 56 | $ConfirmPreference = 'None' 57 | if ($PSCmdlet.ShouldProcess("$($_)", "Remove Cleanup Policy")) { 58 | Invoke-Nexus -UriSlug $urislug -Method DELETE 59 | } 60 | } 61 | else { 62 | if ($PSCmdlet.ShouldProcess("$($_)", "Remove Cleanup Policy")) { 63 | Invoke-Nexus -UriSlug $urislug -Method DELETE 64 | } 65 | } 66 | } } 67 | } -------------------------------------------------------------------------------- /src/public/Repository/New-NexusGoGroupRepository.ps1: -------------------------------------------------------------------------------- 1 | function New-NexusGoGroupRepository { 2 | <# 3 | .SYNOPSIS 4 | Creates a new Go Group repository 5 | 6 | .DESCRIPTION 7 | Creates a new Go Group repository 8 | 9 | .PARAMETER Name 10 | The name of the repository 11 | 12 | .PARAMETER Online 13 | Marks the repository to accept incoming requests 14 | 15 | .PARAMETER BlobStoreName 16 | Blob store to use to store Go packages 17 | 18 | .PARAMETER StrictContentValidation 19 | Validate that all content uploaded to this repository is of a MIME type appropriate for the repository format 20 | 21 | .PARAMETER GroupMembers 22 | Member repositories' names 23 | 24 | .EXAMPLE 25 | New-NexusGoGroupRepository -Name GoGroup -GroupMembers GoHostedLinux,GoProd -Online 26 | 27 | .NOTES 28 | #> 29 | [CmdletBinding(HelpUri = 'https://nexushell.dev/New-NexusGoGroupRepository/')] 30 | Param( 31 | [Parameter(Mandatory)] 32 | [String] 33 | $Name, 34 | 35 | [Parameter(Mandatory)] 36 | [String[]] 37 | $GroupMembers, 38 | 39 | [Parameter()] 40 | [Switch] 41 | $Online, 42 | 43 | [Parameter()] 44 | [String] 45 | $BlobStoreName = 'default', 46 | 47 | [Parameter()] 48 | [Switch] 49 | $UseStrictContentTypeValidation 50 | ) 51 | 52 | begin { 53 | 54 | if (-not $header) { 55 | throw "Not connected to Nexus server! Run Connect-NexusServer first." 56 | } 57 | 58 | $urislug = "/service/rest/v1/repositories/go/group" 59 | 60 | } 61 | 62 | process { 63 | 64 | $body = @{ 65 | name = $Name 66 | online = [bool]$Online 67 | storage = @{ 68 | blobStoreName = $BlobStoreName 69 | strictContentTypeValidation = [bool]$UseStrictContentValidation 70 | } 71 | group = @{ 72 | memberNames = $GroupMembers 73 | writableMember = $WritableMember 74 | } 75 | } 76 | 77 | Write-Verbose $($Body | ConvertTo-Json) 78 | $null = Invoke-Nexus -UriSlug $urislug -Body $Body -Method POST 79 | } 80 | 81 | } -------------------------------------------------------------------------------- /src/public/Task/Get-NexusTask.ps1: -------------------------------------------------------------------------------- 1 | function Get-NexusTask { 2 | <# 3 | .SYNOPSIS 4 | Gets a list of Nexus tasks 5 | 6 | .DESCRIPTION 7 | Gets a list of Nexus tasks 8 | 9 | .PARAMETER Type 10 | The type of task to return 11 | 12 | .EXAMPLE 13 | Get-NexusTask 14 | 15 | .EXAMPLE 16 | Get-NexusTask -Type repository.cleanup 17 | 18 | .NOTES 19 | 20 | #> 21 | [CmdletBinding(HelpUri = 'https://nexushell.dev/Tasks/Get-NexusTask/')] 22 | Param( 23 | [Parameter()] 24 | [String[]] 25 | $Type 26 | ) 27 | 28 | begin { 29 | if (-not $header) { 30 | throw "Not connected to Nexus server! Run Connect-NexusServer first." 31 | } 32 | } 33 | 34 | process { 35 | $urislug = '/service/rest/v1/tasks' 36 | if ($Type) { 37 | $Type | Foreach-Object { 38 | $urislug = '/service/rest/v1/tasks' 39 | $result = Invoke-Nexus -Urislug $urislug -BodyAsString $_ -Method Get 40 | 41 | $result.items | Foreach-Object { 42 | [pscustomobject]@{ 43 | Id = $_.id 44 | Name = $_.name 45 | Type = $_.type 46 | Message = $_.message 47 | CurrentState = $_.currentState 48 | LastRunResult = $_.lastRunResult 49 | NextRun = $_.nextRun 50 | LastRun = $_.lastRun 51 | } 52 | } 53 | } 54 | } 55 | 56 | else { 57 | $result = Invoke-Nexus -Urislug $urislug -Method Get 58 | $result.items | Foreach-Object { 59 | [pscustomobject]@{ 60 | Id = $_.id 61 | Name = $_.name 62 | Type = $_.type 63 | Message = $_.message 64 | CurrentState = $_.currentState 65 | LastRunResult = $_.lastRunResult 66 | NextRun = $_.nextRun 67 | LastRun = $_.lastRun 68 | } 69 | } 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/public/Tag/Remove-NexusTagAssociation.ps1: -------------------------------------------------------------------------------- 1 | function Remove-NexusTagAssociation { 2 | <# 3 | .SYNOPSIS 4 | Removes a tag from a component 5 | 6 | .DESCRIPTION 7 | Disassociates a tag from a component within Nexus. Does not remove the tag itself from the system. 8 | 9 | .PARAMETER Tag 10 | The tag to disassociate 11 | 12 | .PARAMETER SearchQuery 13 | The search parameters to find components with the tag to remove 14 | 15 | .PARAMETER Force 16 | Don't prompt to remove the tag 17 | 18 | .EXAMPLE 19 | Remove-NexusTagAssociation -Tag SampleTag -SearchQuery @{ format = 'nuget' ; repository = 'ChocolateyInternal'} 20 | 21 | .LINK 22 | https://help.sonatype.com/en/tagging.html 23 | #> 24 | [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High', HelpUri = 'https://nexushell.dev/Tags/Remove-NexusTagAssociation/')] 25 | Param( 26 | [Parameter(Mandatory)] 27 | [String] 28 | $Tag, 29 | 30 | [Parameter(Mandatory)] 31 | [hashtable] 32 | $SearchQuery, 33 | 34 | [Parameter()] 35 | [Switch] 36 | $Force 37 | ) 38 | 39 | begin { 40 | if (-not $header) { 41 | throw "Not connected to Nexus server! Run Connect-NexusServer first." 42 | } 43 | 44 | $urislug = '/service/rest/v1/tags/associate/{0}' -f $Tag 45 | } 46 | 47 | process { 48 | $UriBase = "$($protocol)://$($Hostname):$($port)$($ContextPath)" 49 | $Uri = $UriBase + $UriSlug 50 | 51 | $tagUrl = New-HttpQueryString -Uri $uri -QueryParameter $SearchQuery 52 | 53 | $Params = @{ 54 | Headers = $header 55 | ContentType = 'application/json' 56 | Uri = $tagUrl 57 | Method = 'DELETE' 58 | UseBasicParsing = $true 59 | } 60 | 61 | if ($Force -and -not $Confirm) { 62 | $ConfirmPreference = 'None' 63 | if ($PSCmdlet.ShouldProcess("$($_)", "Remove Tag Association")) { 64 | Invoke-RestMethod @Params 65 | } 66 | } 67 | else { 68 | if ($PSCmdlet.ShouldProcess("$($_)", "Remove Tag Association")) { 69 | Invoke-RestMethod @Params 70 | } 71 | } 72 | } 73 | } -------------------------------------------------------------------------------- /src/public/ContentSelector/Remove-NexusContentSelector.ps1: -------------------------------------------------------------------------------- 1 | function Remove-NexusContentSelector { 2 | <# 3 | .SYNOPSIS 4 | Removes a Nexus Content Selector 5 | 6 | .DESCRIPTION 7 | Removes a Nexus Content Selector 8 | 9 | .PARAMETER Name 10 | The Content Selector to remove 11 | 12 | .PARAMETER Force 13 | Don't prompt for confirmation before removing 14 | 15 | .EXAMPLE 16 | Remove-NexusContentSelector -Name MavenContent 17 | 18 | .EXAMPLE 19 | Remove-NexusContentSelect -Name MavenContent -Force 20 | 21 | .EXAMPLE 22 | Get-NexusContentSelector | Remove-NexusContentSelector -Force 23 | 24 | .NOTES 25 | 26 | #> 27 | [CmdletBinding(HelpUri = 'https://nexushell.dev/Security/Content%20Selectors/Remove-NexusContentSelector/',SupportsShouldProcess,ConfirmImpact='High')] 28 | Param( 29 | [Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)] 30 | [ArgumentCompleter( { 31 | param($Command, $Parameter, $WordToComplete, $CommandAst, $FakeBoundParams) 32 | 33 | $r = (Get-NexusContentSelector).Name 34 | 35 | if ($WordToComplete) { 36 | $r.Where($_ -match "^$WordToComplete") 37 | } 38 | else { 39 | $r 40 | } 41 | })] 42 | [String[]] 43 | $Name, 44 | 45 | [Parameter()] 46 | [Switch] 47 | $Force 48 | ) 49 | 50 | begin { 51 | if (-not $header) { 52 | throw "Not connected to Nexus server! Run Connect-NexusServer first." 53 | } 54 | } 55 | 56 | process { 57 | 58 | $Name | Foreach-Object { 59 | 60 | $urislug = "/service/rest/v1/security/content-selectors/$_" 61 | if ($Force -and -not $Confirm) { 62 | $ConfirmPreference = 'None' 63 | if ($PSCmdlet.ShouldProcess("$($_)", "Remove Content Selector")) { 64 | Invoke-Nexus -UriSlug $urislug -Method DELETE -ErrorAction Stop 65 | } 66 | } 67 | else { 68 | if ($PSCmdlet.ShouldProcess("$($_)", "Remove Content Selector")) { 69 | Invoke-Nexus -UriSlug $urislug -Method DELETE -ErrorAction Stop 70 | } 71 | } 72 | } 73 | } 74 | } -------------------------------------------------------------------------------- /src/public/ReadOnly/Set-NexusReadOnlyMode.ps1: -------------------------------------------------------------------------------- 1 | function Set-NexusReadOnlyMode { 2 | <# 3 | .SYNOPSIS 4 | Sets the nexus instance Read-Only mode 5 | 6 | .DESCRIPTION 7 | Either Disable or Enable Read-Only mode of your nexus instance 8 | 9 | .PARAMETER Enable 10 | Sets the nexus instance to Read-Only mode 11 | 12 | .PARAMETER Disable 13 | Sets the nexus instance to write-enabled mode 14 | 15 | .EXAMPLE 16 | Set-NexusReadOnlyMode -Enable 17 | 18 | .EXAMPLE 19 | Set-NexusReadOnlyMode -Disable 20 | #> 21 | [CmdletBinding(HelpUri='https://nexushell.dev/Set-NexusReadOnlyMode/',SupportsShouldProcess, DefaultParameterSetName = "Enable", ConfirmImpact = 'High')] 22 | Param( 23 | [Parameter(Mandatory, ParameterSetName = "Enable")] 24 | [Switch] 25 | $Enable, 26 | 27 | [Parameter(Mandatory, ParameterSetName = "Disable")] 28 | [Switch] 29 | $Disable, 30 | 31 | [Parameter(ParameterSetName = "Disable")] 32 | [Switch] 33 | $Force 34 | 35 | ) 36 | 37 | begin { 38 | 39 | if (-not $header) { 40 | throw "Not connected to Nexus server! Run Connect-NexusServer first." 41 | } 42 | 43 | $urislug = "/service/rest/v1/read-only" 44 | } 45 | 46 | process { 47 | 48 | switch ($PSCmdlet.ParameterSetName) { 49 | 'Enable' { 50 | $Uri = $urislug + "/freeze" 51 | Invoke-Nexus -UriSlug $Uri -Method 'POST' 52 | } 53 | 'Disable' { 54 | if ($Force -and -not $Confirm) { 55 | $ConfirmPreference = 'None' 56 | if ($PSCmdlet.ShouldProcess("Read-Only", "Forcibly release mode")) { 57 | $Uri = $urislug + "/force-release" 58 | Invoke-Nexus -UriSlug $Uri -Method 'POST' 59 | 60 | } 61 | } 62 | 63 | else { 64 | Write-Warning "Caution! This operation could result in data loss" 65 | if ($PSCmdlet.ShouldProcess("Read-Only", "Forcibly release mode")) { 66 | $Uri = $urislug + "/release" 67 | Invoke-Nexus -UriSlug $Uri -Method 'POST' 68 | } 69 | } 70 | } 71 | } 72 | } 73 | } -------------------------------------------------------------------------------- /src/public/Realm/Enable-NexusRealm.ps1: -------------------------------------------------------------------------------- 1 | function Enable-NexusRealm { 2 | <# 3 | .SYNOPSIS 4 | Enable realms in Nexus 5 | 6 | .DESCRIPTION 7 | Enable realms in Nexus 8 | 9 | .PARAMETER Realm 10 | The realms you wish to activate 11 | 12 | .EXAMPLE 13 | Enable-NexusRealm -Realm 'NuGet Api-Key Realm', 'Rut Auth Realm' 14 | 15 | .EXAMPLE 16 | Enable-NexusRealm -Realm 'LDAP Realm' 17 | 18 | .NOTES 19 | #> 20 | [CmdletBinding(HelpUri = 'https://nexushell.dev/Enable-NexusRealm/')] 21 | Param( 22 | [Parameter(Mandatory)] 23 | [ArgumentCompleter({ 24 | param($Command,$Parameter,$WordToComplete,$CommandAst,$FakeBoundParams) 25 | 26 | $r = (Get-NexusRealm).name 27 | 28 | if($WordToComplete){ 29 | $r.Where($_ -match "^$WordToComplete") 30 | } else { 31 | $r 32 | } 33 | } 34 | )] 35 | [String[]] 36 | $Realm 37 | ) 38 | 39 | begin { 40 | 41 | if (-not $header) { 42 | throw "Not connected to Nexus server! Run Connect-NexusServer first." 43 | } 44 | 45 | $urislug = "/service/rest/v1/security/realms/active" 46 | 47 | } 48 | 49 | process { 50 | 51 | $collection = @() 52 | 53 | Get-NexusRealm -Active | ForEach-Object { $collection += $_.id } 54 | 55 | $Realm | Foreach-Object { 56 | 57 | switch($_){ 58 | 'Conan Bearer Token Realm' { $id = 'org.sonatype.repository.conan.internal.security.token.ConanTokenRealm' } 59 | 'Default Role Realm' { $id = 'DefaultRole' } 60 | 'Docker Bearer Token Realm' { $id = 'DockerToken' } 61 | 'LDAP Realm' { $id = 'LdapRealm' } 62 | 'Local Authentication Realm' { $id = 'NexusAuthenticatingRealm'} 63 | 'Local Authorizing Realm' {$id = 'NexusAuthorizingRealm'} 64 | 'npm Bearer Token Realm' {$id = 'NpmToken'} 65 | 'NuGet API-Key Realm' { $id = 'NuGetApiKey'} 66 | 'Rut Auth Realm' { $id = 'rutauth-realm'} 67 | } 68 | 69 | $collection += $id 70 | 71 | } 72 | 73 | $body = $collection 74 | 75 | Write-Verbose $($Body | ConvertTo-Json) 76 | $null = Invoke-Nexus -UriSlug $urislug -BodyAsArray $Body -Method PUT 77 | 78 | } 79 | } -------------------------------------------------------------------------------- /src/public/RoutingRule/Remove-NexusRoutingRule.ps1: -------------------------------------------------------------------------------- 1 | function Remove-NexusRoutingRule { 2 | <# 3 | .SYNOPSIS 4 | Disable realms in Nexus 5 | 6 | .DESCRIPTION 7 | Disable realms in Nexus 8 | 9 | .PARAMETER Rule 10 | The realms you wish to activate 11 | 12 | .PARAMETER Force 13 | Don't prompt for confirmation 14 | 15 | .EXAMPLE 16 | Remove-NexusRoutingRule -Rule NugetRule 17 | 18 | .EXAMPLE 19 | Remove-NexusRoutingRule -Rule NugetRule -Force 20 | 21 | .NOTES 22 | #> 23 | [CmdletBinding(HelpUri = 'https://github.com/steviecoaster/NexuShell/blob/develop/docs/Remove-NexusRoutingRule.md',SupportsShouldProcess,ConfirmImpact = 'High')] 24 | Param( 25 | [Parameter(Mandatory,ValueFromPipeline,ValueFromPipelineByPropertyName)] 26 | [ArgumentCompleter( { 27 | param($Command, $Parameter, $WordToComplete, $CommandAst, $FakeBoundParams) 28 | 29 | $r = (Get-NexusRoutingRule).name 30 | 31 | if ($WordToComplete) { 32 | $r.Where($_ -match "^$WordToComplete") 33 | } 34 | else { 35 | $r 36 | } 37 | } 38 | )] 39 | [Alias('Name')] 40 | [String[]] 41 | $Rule, 42 | 43 | [Parameter()] 44 | [Switch] 45 | $Force 46 | ) 47 | 48 | begin { 49 | 50 | if (-not $header) { 51 | throw "Not connected to Nexus server! Run Connect-NexusServer first." 52 | } 53 | } 54 | 55 | process { 56 | $Rule | ForEach-Object { 57 | $urislug = "/service/rest/v1/routing-rules/$_" 58 | 59 | try { 60 | 61 | if ($Force -and -not $Confirm) { 62 | $ConfirmPreference = 'None' 63 | if ($PSCmdlet.ShouldProcess("$_", "Remove Routing rule")) { 64 | Invoke-Nexus -UriSlug $urislug -Method DELETE -ErrorAction Stop 65 | 66 | } 67 | } 68 | else { 69 | if ($PSCmdlet.ShouldProcess("$_", "Remove Routing rule")) { 70 | Invoke-Nexus -UriSlug $urislug -Method DELETE -ErrorAction Stop 71 | } 72 | } 73 | } 74 | 75 | catch { 76 | $_.exception.message 77 | } 78 | 79 | } 80 | 81 | } 82 | } -------------------------------------------------------------------------------- /src/public/Realm/Disable-NexusRealm.ps1: -------------------------------------------------------------------------------- 1 | function Disable-NexusRealm { 2 | <# 3 | .SYNOPSIS 4 | Disable realms in Nexus 5 | 6 | .DESCRIPTION 7 | Disable realms in Nexus 8 | 9 | .PARAMETER Realm 10 | The realms you wish to activate 11 | 12 | .EXAMPLE 13 | Disable-NexusRealm -Realm 'NuGet Api-Key Realm', 'Rut Auth Realm' 14 | 15 | .EXAMPLE 16 | Disable-NexusRealm -Realm 'LDAP Realm' 17 | 18 | .NOTES 19 | #> 20 | [CmdletBinding(HelpUri = 'https://nexushell.dev/Disable-NexusRealm/',SupportsShouldProcess,ConfirmImpact = 'High')] 21 | Param( 22 | [Parameter(Mandatory,ValueFromPipeline,ValueFromPipelineByPropertyName)] 23 | [ArgumentCompleter( { 24 | param($Command, $Parameter, $WordToComplete, $CommandAst, $FakeBoundParams) 25 | 26 | $r = (Get-NexusRealm).name 27 | 28 | if ($WordToComplete) { 29 | $r.Where($_ -match "^$WordToComplete") 30 | } 31 | else { 32 | $r 33 | } 34 | } 35 | )] 36 | [Alias('Name')] 37 | [String[]] 38 | $Realm, 39 | 40 | [Parameter()] 41 | [Switch] 42 | $Force 43 | ) 44 | 45 | begin { 46 | 47 | if (-not $header) { 48 | throw "Not connected to Nexus server! Run Connect-NexusServer first." 49 | } 50 | 51 | $urislug = "/service/rest/v1/security/realms/active" 52 | 53 | } 54 | 55 | process { 56 | 57 | $body = @((Get-NexusRealm -Active| Where-Object { $_.Name -notin $Realm }).id) 58 | 59 | try { 60 | 61 | if ($Force -and -not $Confirm) { 62 | $ConfirmPreference = 'None' 63 | if ($PSCmdlet.ShouldProcess("$_", "Remove Repository")) { 64 | Write-Verbose $($Body | ConvertTo-Json) 65 | Invoke-Nexus -UriSlug $urislug -BodyAsArray $Body -Method PUT -ErrorAction Stop 66 | 67 | } 68 | } 69 | else { 70 | if ($PSCmdlet.ShouldProcess("$_", "Remove Repository")) { 71 | Write-Verbose $($Body | ConvertTo-Json) 72 | Invoke-Nexus -UriSlug $urislug -BodyAsArray $Body -Method PUT -ErrorAction Stop 73 | } 74 | } 75 | } 76 | 77 | catch { 78 | $_.exception.message 79 | } 80 | 81 | } 82 | } -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Build NexuShell 2 | 3 | on: 4 | push: 5 | branches-ignore: 6 | - gh-pages 7 | pull_request: 8 | branches: 9 | - main 10 | - develop 11 | 12 | workflow_dispatch: 13 | 14 | jobs: 15 | build: 16 | runs-on: windows-latest 17 | env: 18 | NugetApiKey: ${{ secrets.NugetApiKey }} 19 | ChocoApiKey: ${{ secrets.ChocoApiKey }} 20 | 21 | steps: 22 | - uses: actions/checkout@v4 23 | with: 24 | fetch-depth: 0 # Required for GitVersion to behave 25 | 26 | - name: GitVersion 27 | id: gitversion 28 | uses: PoshCode/Actions/gitversion@v1.0.1 29 | 30 | - name: Install-RequiredModules 31 | uses: PoshCode/Actions/install-requiredmodules@v1 32 | 33 | - name: Build Module 34 | run: .\build.ps1 -Build -SemVer "${{ steps.gitversion.outputs.SemVer }}" 35 | shell: pwsh 36 | 37 | - name: Upload Built Module 38 | uses: actions/upload-artifact@v4 39 | with: 40 | name: NexuShell.${{ steps.gitversion.outputs.SemVer }} 41 | path: .\Output 42 | 43 | - name: Test Module 44 | run: .\build.ps1 -TestPrePublish -SemVer "${{ steps.gitversion.outputs.SemVer }}" 45 | shell: pwsh 46 | 47 | - name: Upload Test Results 48 | uses: EnricoMi/publish-unit-test-result-action/composite@v1 49 | if: always() 50 | with: 51 | files: TestResults.xml 52 | 53 | - name: Create Release 54 | if: ${{ github.ref == 'refs/heads/main' }} 55 | continue-on-error: true 56 | id: create_release 57 | uses: actions/create-release@v1 58 | env: 59 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 60 | with: 61 | release_name: NexuShell v${{ steps.gitversion.outputs.MajorMinorPatch }} 62 | tag_name: ${{ steps.gitversion.outputs.MajorMinorPatch }} 63 | body: | 64 | PowerShellGallery: [NexuShell ](https://www.powershellgallery.com/packages/NexuShell/${{ steps.gitversion.outputs.MajorMinorPatch }}) 65 | Chocolatey Community Repository: [NexuShell ](https://community.chocolatey.org/packages/NexuShell/${{ steps.gitversion.outputs.MajorMinorPatch }}) 66 | draft: false 67 | prerelease: ${{ github.ref != 'refs/heads/main' }} 68 | 69 | - name: Publish Module 70 | if: ${{ github.ref == 'refs/heads/main' }} 71 | run: .\build.ps1 -DeployToGallery -SemVer "${{ steps.gitversion.outputs.SemVer }}" -------------------------------------------------------------------------------- /tests/public/BlobStore/Update-NexusFileBlobStore.Tests.ps1: -------------------------------------------------------------------------------- 1 | #requires -Modules NexuShell 2 | 3 | Describe "Update-NexusFileBlobStore" { 4 | BeforeAll { 5 | $InModule = @{ 6 | ModuleName = "NexuShell" 7 | } 8 | 9 | InModuleScope @InModule { 10 | $script:header = @{ 11 | Authentication = "fake auth" 12 | } 13 | } 14 | 15 | Mock Invoke-Nexus @InModule 16 | Mock Get-NexusBlobStore @InModule -MockWith { 17 | if ($script:BlobStoreObject) { 18 | $script:BlobStoreObject 19 | } else { 20 | [PSCustomObject]@{ 21 | path = "default" 22 | softQuota = @{ 23 | type = "" 24 | limit = "" 25 | } 26 | } 27 | } 28 | } 29 | } 30 | 31 | Context "Updating a BlobStore Path from 'default'" { 32 | BeforeAll { 33 | Update-NexusFileBlobStore -Name "Test" -Path "D:\Repository\" -Confirm:$false 34 | } 35 | 36 | It "Sets the specified path for the specified BlobStore" { 37 | Assert-MockCalled Invoke-Nexus @InModule -ParameterFilter { 38 | $UriSlug -eq "/service/rest/v1/blobstores/file/Test" -and 39 | $Method -eq "Put" -and 40 | $Body.path -eq "D:\Repository\" 41 | } -Scope Context 42 | } 43 | } 44 | 45 | Context "Updating a BlobStore Path that is already correct" { 46 | BeforeAll { 47 | Update-NexusFileBlobStore -Name "Test" -Path "default" -Confirm:$false 48 | } 49 | 50 | It "Does not attempt to modify the BlobStore" { 51 | Assert-MockCalled Invoke-Nexus @InModule -Times 0 -Scope Context 52 | } 53 | } 54 | 55 | Context "Updating a BlobStore Quota" { 56 | BeforeAll { 57 | Update-NexusFileBlobStore -Name "QuotaTest" -SoftQuotaType Remaining -SoftQuotaLimit 203 -Confirm:$false 58 | } 59 | 60 | It "Sets the specified quota limit for the specified BlobStore" { 61 | Assert-MockCalled Invoke-Nexus @InModule -ParameterFilter { 62 | $UriSlug -eq "/service/rest/v1/blobstores/file/QuotaTest" -and 63 | $Method -eq "Put" -and 64 | $Body.softQuota.type -eq "spaceRemainingQuota" -and 65 | $Body.softQuota.limit -eq 203MB 66 | } -Scope Context 67 | } 68 | } 69 | } -------------------------------------------------------------------------------- /src/private/New-HttpWebRequest.ps1: -------------------------------------------------------------------------------- 1 | function New-HttpWebRequest 2 | { 3 | <# 4 | .SYNOPSIS 5 | Creates a new [System.Net.HttpWebRequest] ready for file transmission. 6 | 7 | .DESCRIPTION 8 | Creates a new [System.Net.HttpWebRequest] ready for file transmission. 9 | The method will be Put. If the filesize is larger than the buffersize, 10 | the HttpWebRequest will be configured for chunked transfer. 11 | 12 | .PARAMETER Url 13 | Url to connect to. 14 | 15 | .PARAMETER Credential 16 | Credential for authentication at the Url resource. 17 | 18 | .EXAMPLE 19 | An example 20 | 21 | .NOTES 22 | Taken from: https://stackoverflow.com/a/48323495 23 | #> 24 | param( 25 | [Parameter(Mandatory=$true)] 26 | [ValidateNotNullOrEmpty()] 27 | [string]$Url, 28 | 29 | [Parameter(Mandatory=$true)] 30 | [ValidateNotNullOrEmpty()] 31 | [pscredential]$Credential, 32 | 33 | [Parameter(Mandatory=$true)] 34 | [long]$FileSize, 35 | 36 | [Parameter(Mandatory=$true)] 37 | [long]$BufferSize 38 | ) 39 | 40 | $webRequest = [System.Net.HttpWebRequest]::Create($Url) 41 | $webRequest.Timeout = 600 * 1000; 42 | $webRequest.ReadWriteTimeout = 600 * 1000; 43 | $webRequest.ProtocolVersion = [System.Net.HttpVersion]::Version11; 44 | $webRequest.Method = "PUT"; 45 | $webRequest.ContentType = "application/octet-stream"; 46 | $webRequest.KeepAlive = $true; 47 | $webRequest.UserAgent = ""; 48 | #$webRequest.UserAgent = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)'; 49 | $webRequest.PreAuthenticate = $true; 50 | $auth = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($Credential.UserName + ":" + $Credential.GetNetworkCredential().Password)); 51 | $webRequest.Headers["Authorization"] = "Basic $auth" 52 | 53 | if (Get-UseChunkedUpload -FileSize $FileSize -BufferSize $BufferSize) 54 | { 55 | Write-Verbose "FileSize is greater than BufferSize, using chunked transfer."; 56 | $webRequest.AllowWriteStreamBuffering = $false; 57 | $webRequest.SendChunked = $true; 58 | } 59 | else 60 | { 61 | # Filesize is equal to or smaller than the BufferSize. The file will be transferred in one write. 62 | # Chunked cannot be used in this case. 63 | $webRequest.AllowWriteStreamBuffering = $true; 64 | $webRequest.SendChunked = $false; 65 | $webRequest.ContentLength = $FileSize; 66 | } 67 | 68 | return $webRequest; 69 | } -------------------------------------------------------------------------------- /src/public/Component/New-NexusNugetComponent.ps1: -------------------------------------------------------------------------------- 1 | function New-NexusNugetComponent { 2 | <# 3 | .SYNOPSIS 4 | Uploads a NuGet package to Nexus through the Components API 5 | 6 | .DESCRIPTION 7 | Uploads a NuGet package to Nexus through the Components API 8 | 9 | .PARAMETER RepositoryName 10 | The repository to upload to 11 | 12 | .PARAMETER NuGetComponent 13 | The NuGet package to upload 14 | 15 | .EXAMPLE 16 | New-NexusNugetComponent -RepositoryName ProdNuGet -NuGetComponent C:\temp\awesomepackage.0.1.0.nupkg 17 | 18 | .EXAMPLE 19 | Get-ChildItem ~\Downloads\ -Filter *.nupkg | New-NexusNugetComponent -RepositoryName ChocolateyTest 20 | #> 21 | [CmdletBinding()] 22 | Param( 23 | [Parameter(Mandatory)] 24 | [String] 25 | $RepositoryName, 26 | 27 | [Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)] 28 | [Alias("PSPath")] 29 | [ValidateScript( { 30 | Test-Path $_ 31 | })] 32 | [String] 33 | $NuGetComponent 34 | ) 35 | begin { 36 | if (-not ('System.Net.Http.HttpClient' -as [type])) { 37 | Add-Type -AssemblyName 'System.Net.Http' 38 | } 39 | 40 | $Uri = "$($protocol)://$($Hostname):$($port)$($ContextPath.TrimEnd('/'))/service/rest/v1/components?repository=$($RepositoryName)" 41 | 42 | $Client = [System.Net.Http.HttpClient]::new() 43 | $Client.DefaultRequestHeaders.Authorization = $header.Authorization 44 | } 45 | process { 46 | try { 47 | $Content = [System.Net.Http.MultipartFormDataContent]::new() 48 | $FileName = [System.IO.Path]::GetFileName($NuGetComponent) 49 | $FileStream = [System.IO.File]::OpenRead((Convert-Path $NuGetComponent)) 50 | $FileContent = [System.Net.Http.StreamContent]::new($FileStream) 51 | $Content.Add($FileContent, 'nuget.asset', $FileName) 52 | 53 | $Result = $Client.PostAsync($Uri, $Content).Result 54 | if ($Result.EnsureSuccessStatusCode()) { 55 | Write-Verbose "'$($FileName)' was successfully uploaded to '$($RepositoryName)'" 56 | } 57 | } catch { 58 | Write-Error "'$($FileName)' failed to upload to '$($RepositoryName)': $($Result.ReasonPhrase)`n$_" 59 | } finally { 60 | if ($Content) {$Content.Dispose()} 61 | if ($FileStream) {$FileStream.Dispose()} 62 | if ($FileContent) {$FileContent.Dispose()} 63 | } 64 | } 65 | end { 66 | if ($Client) {$Client.Dispose()} 67 | } 68 | } -------------------------------------------------------------------------------- /specifications/apt.md: -------------------------------------------------------------------------------- 1 | # Repository Format: Apt 2 | 3 | ## Format: Hosted 4 | 5 | ### Spec 6 | 7 | #### Section: General 8 | 9 | | Name | Definition | Required | Type | Example | 10 | | ---- | ----| ---- | ---- | ---- | 11 | | name | A unique identifier for this repository| yes | String | internal | 12 | | online| Whether this repository accepts incoming requests | yes | Boolean | true 13 | 14 | #### Section : Storage 15 | 16 | | Name | Definition | Required | Type | Example 17 | | ---- | ---- | ---- | ---- | ---- | 18 | | blobStoreName | Blob store used to store repository contents | yes | string | default | 19 | | strictContentTypeValidation | Whether to validate uploaded content's MIME type appropriate for the repository format | yes | Boolean | true | 20 | | writePolicy | Controls if deployments of and updates to assets are allowed | yes | string | "allow" | 21 | 22 | #### Section : Cleanup 23 | 24 | | Name | Definition | Required | Type | Example | 25 | | ---- | ---- | ---- | ---- | ---- | 26 | | policyNames | Components that match any of the applied policies will be deleted | no | String | null | 27 | 28 | #### Section : Component 29 | 30 | | Name | Definition | Required | Type | Example | 31 | | ---- | ---- | ---- | ---- | ---- | 32 | | proprietaryComponents | Components in this repository count as proprietary for namespace conflict attacks (requires Sonatype Nexus Firewall) | no | Boolean | false | 33 | 34 | #### Section : Apt 35 | 36 | | Name | Definition | Required | Type | Example | 37 | | ---- | ---- | ---- | ---- | ---- | 38 | | distribution | Distribution to fetch | yes | String | bionic | 39 | 40 | #### Section : AptSigning 41 | 42 | | Name | Definition | Required | Type | Example | 43 | | ---- | ---- | ---- | ---- | ---- | 44 | | keypair | PGP signing key pair (armored private key e.g. gpg --export-secret-key --armor) | yes | string | 1h2332 | 45 | | passphrase | Passphrase to access PGP signing key | no | string | null | 46 | 47 | ### Example 48 | 49 | ```json 50 | { 51 | "name": "internal", 52 | "online": true, 53 | "storage": { 54 | "blobStoreName": "default", 55 | "strictContentTypeValidation": true, 56 | "writePolicy": "allow_once" 57 | }, 58 | "cleanup": { 59 | "policyNames": [ 60 | "string" 61 | ] 62 | }, 63 | "component": { 64 | "proprietaryComponents": true 65 | }, 66 | "apt": { 67 | "distribution": "bionic" 68 | }, 69 | "aptSigning": { 70 | "keypair": "string", 71 | "passphrase": "string" 72 | } 73 | } 74 | ``` 75 | 76 | ## Format: Proxy 77 | 78 | ### Spec 79 | 80 | ### Example 81 | 82 | ## Format: Group 83 | 84 | ### Spec 85 | 86 | ### Example 87 | 88 | ## NOTES 89 | -------------------------------------------------------------------------------- /src/public/BlobStore/Get-NexusBlobStore.ps1: -------------------------------------------------------------------------------- 1 | function Get-NexusBlobStore { 2 | <# 3 | .SYNOPSIS 4 | Get information about a blob store 5 | 6 | .DESCRIPTION 7 | Get basic or detailed blob store configuration information 8 | 9 | .PARAMETER Name 10 | The blob store to get information from 11 | 12 | .PARAMETER Type 13 | The type of the blob store 14 | 15 | .PARAMETER Detailed 16 | Return detailed information about the blob store 17 | 18 | .EXAMPLE 19 | Get-NexusBlobStore 20 | 21 | .EXAMPLE 22 | Get-NexusBlobStore -Name default -Type file 23 | 24 | .EXAMPLE 25 | Get-NexusBlobStore -Name TreasureBlob -Type file -Detailed 26 | #> 27 | [CmdletBinding(HelpUri='https://nexushell.dev/Get-NexusBlobStore/',DefaultParameterSetName = "Default")] 28 | Param( 29 | [Parameter(Mandatory, ParameterSetName = "Name")] 30 | [String] 31 | $Name, 32 | 33 | [Parameter(Mandatory, ParameterSetName = "Type")] 34 | [Parameter(Mandatory, ParameterSetName = "Name")] 35 | [ValidateSet('File', 'S3')] 36 | [String] 37 | $Type, 38 | 39 | [Parameter(ParameterSetName = "Name")] 40 | [Parameter(ParameterSetName = "Type")] 41 | [Switch] 42 | $Detailed 43 | ) 44 | 45 | begin { 46 | 47 | if (-not $header) { 48 | throw "Not connected to Nexus server! Run Connect-NexusServer first." 49 | } 50 | 51 | $urislug = "/service/rest/v1/blobstores" 52 | } 53 | 54 | process { 55 | 56 | switch ($PSCmdlet.ParameterSetName) { 57 | 58 | { $Name } { 59 | if (-not $Detailed) { 60 | switch ($Type) { 61 | 'File' { 62 | $urlType = '/file' 63 | $Uri = $urislug + $urlType + "/$Name" 64 | 65 | Invoke-Nexus -UriSlug $Uri -Method 'GET' 66 | } 67 | 68 | 'S3' { 69 | $urlType = '/s3' 70 | $Uri = $urislug + $urlType + "/$Name" 71 | 72 | Invoke-Nexus -UriSlug $Uri -Method 'GET' 73 | } 74 | } 75 | 76 | } 77 | 78 | else { 79 | $result = Invoke-Nexus -UriSlug $urislug -Method 'GET' 80 | $result | Where-Object { $_.name -eq $Name } 81 | } 82 | 83 | } 84 | 85 | default { 86 | Invoke-Nexus -UriSlug $urislug -Method 'GET' 87 | 88 | } 89 | } 90 | 91 | } 92 | } -------------------------------------------------------------------------------- /src/private/Invoke-Nexus.ps1: -------------------------------------------------------------------------------- 1 | function Invoke-Nexus { 2 | [CmdletBinding()] 3 | param( 4 | [Parameter(Mandatory)] 5 | [String] 6 | $UriSlug, 7 | 8 | [Parameter()] 9 | [Hashtable] 10 | $Body, 11 | 12 | [Parameter()] 13 | [Array] 14 | $BodyAsArray, 15 | 16 | [Parameter()] 17 | [String] 18 | $BodyAsString, 19 | 20 | [Parameter()] 21 | [SecureString] 22 | $BodyAsSecureString, 23 | 24 | [Parameter()] 25 | [String] 26 | $File, 27 | 28 | [Parameter()] 29 | [String] 30 | $ContentType = 'application/json', 31 | 32 | [Parameter(Mandatory)] 33 | [String] 34 | $Method, 35 | 36 | [Parameter()] 37 | [hashtable] 38 | $Headers 39 | ) 40 | process { 41 | $UriBase = "$($protocol)://$($Hostname):$($port)$($ContextPath)" 42 | $Uri = $UriBase + $UriSlug 43 | if ($Headers) { 44 | $local:header = $script:header.Clone() 45 | $Headers.Keys.ForEach{ 46 | $header[$_] = $Headers[$_] 47 | } 48 | } 49 | $Params = @{ 50 | Headers = $header 51 | ContentType = $ContentType 52 | Uri = $Uri 53 | Method = $Method 54 | UseBasicParsing = $true 55 | } 56 | 57 | if($Body){ 58 | $Params.Add('Body',$($Body | ConvertTo-Json -Depth 3)) 59 | } 60 | 61 | if($BodyAsArray){ 62 | $Params.Add('Body',$($BodyAsArray | ConvertTo-Json -Depth 3)) 63 | } 64 | 65 | if($BodyAsString){ 66 | $Params.Add('Body',$BodyAsString) 67 | } 68 | 69 | if($BodyAsSecureString){ 70 | $Params.Add( 71 | 'Body', 72 | [Runtime.InteropServices.Marshal]::PtrToStringBSTR( 73 | [Runtime.InteropServices.Marshal]::SecureStringToBSTR($BodyAsSecureString) 74 | ) 75 | ) 76 | } 77 | 78 | if($File){ 79 | $Params.Remove('ContentType') 80 | $Params.Add('InFile',$File) 81 | } 82 | 83 | try { 84 | Invoke-RestMethod @Params -ErrorAction Stop 85 | } catch { 86 | try { 87 | $JsonMessage = $_.ErrorDetails.Message | ConvertFrom-Json -ErrorAction Stop 88 | } catch {<# Not a Json message #>} 89 | if ($JsonMessage) { 90 | # If there's a message from the server, display it appropriately 91 | Write-Error -Message $Message -Exception $_.Exception 92 | } else { 93 | # Otherwise, rethrow 94 | throw 95 | } 96 | } 97 | } 98 | } -------------------------------------------------------------------------------- /src/public/Repository/New-NexusBowerGroupRepository.ps1: -------------------------------------------------------------------------------- 1 | function New-NexusBowerGroupRepository { 2 | <# 3 | .SYNOPSIS 4 | Creates a Bower Group repository 5 | 6 | .DESCRIPTION 7 | Creates a Bower Group repository 8 | 9 | .PARAMETER Name 10 | The name of the repository 11 | 12 | .PARAMETER GroupMembers 13 | The Bower Repositories to add as group members 14 | 15 | .PARAMETER Online 16 | Marks the repository as online 17 | 18 | .PARAMETER BlobStore 19 | The blob store to attach to the repository 20 | 21 | .PARAMETER UseStrictContentTypeValidation 22 | Validate that all content uploaded to this repository is of a MIME type appropriate for the repository format 23 | 24 | .PARAMETER ContentDisposition 25 | Add Content-Disposition header as 'Attachment' to disable some content from being inline in a browser 26 | 27 | .PARAMETER DeploymentPolicy 28 | Required by the API, but thrown away by the underlying system. Use whatever you want here from the set 29 | 30 | .EXAMPLE 31 | New-NexusBowerGroupRepository -Name AllArtifacts -GroupMembers BinaryArtifacts,Documentation -DeploymentPolicy Allow 32 | 33 | .NOTES 34 | #> 35 | [CmdletBinding(HelpUri = 'https://nexushell.dev/New-NexusBowerGroupRepository/')] 36 | Param( 37 | [Parameter(Mandatory)] 38 | [String] 39 | $Name, 40 | 41 | [Parameter(Mandatory)] 42 | [String[]] 43 | $GroupMembers, 44 | 45 | [Parameter()] 46 | [Switch] 47 | $Online = $true, 48 | 49 | [Parameter()] 50 | [String] 51 | $BlobStore = 'default', 52 | 53 | [Parameter()] 54 | [Switch] 55 | $UseStrictContentTypeValidation, 56 | 57 | [Parameter(Mandatory)] 58 | [ValidateSet('Allow', 'Deny', 'Allow_Once')] 59 | [String] 60 | $DeploymentPolicy = 'Allow_Once' 61 | ) 62 | begin { 63 | 64 | if (-not $header) { 65 | throw "Not connected to Nexus server! Run Connect-NexusServer first." 66 | } 67 | 68 | $urislug = "/service/rest/v1/repositories/bower/group" 69 | 70 | } 71 | 72 | process { 73 | 74 | $body = @{ 75 | name = $Name 76 | online = [bool]$Online 77 | storage = @{ 78 | blobStoreName = $BlobStore 79 | strictContentTypeValidation = [bool]$UseStrictContentTypeValidation 80 | writePolicy = $DeploymentPolicy.ToLower() 81 | } 82 | group = @{ 83 | memberNames = $GroupMembers 84 | } 85 | } 86 | 87 | Write-Verbose $($Body | ConvertTo-Json) 88 | $null = Invoke-Nexus -UriSlug $urislug -Body $Body -Method POST 89 | 90 | } 91 | 92 | } -------------------------------------------------------------------------------- /src/public/Repository/Get-NexusRepository.ps1: -------------------------------------------------------------------------------- 1 | function Get-NexusRepository { 2 | <# 3 | .SYNOPSIS 4 | Returns info about configured Nexus repository 5 | 6 | .DESCRIPTION 7 | Returns details for currently configured repositories on your Nexus server 8 | 9 | .PARAMETER Format 10 | Query for only a specific repository format. E.g. nuget, maven2, or docker 11 | 12 | .PARAMETER Name 13 | Query for a specific repository by name 14 | 15 | .EXAMPLE 16 | Get-NexusRepository 17 | 18 | .EXAMPLE 19 | Get-NexusRepository -Format nuget 20 | 21 | .EXAMPLE 22 | Get-NexusRepository -Name CompanyNugetPkgs 23 | #> 24 | [cmdletBinding(HelpUri='https://nexushell.dev/Get-NexusRepository/',DefaultParameterSetName="default")] 25 | param( 26 | [Parameter(ParameterSetName="Format",Mandatory)] 27 | [String] 28 | [ValidateSet('apt','bower','cocoapods','conan','conda','docker','gitlfs','go','helm','maven2','npm','nuget','p2','pypi','r','raw','rubygems','yum')] 29 | $Format, 30 | 31 | [Parameter(ParameterSetName="Type",Mandatory)] 32 | [String] 33 | [ValidateSet('hosted','group','proxy')] 34 | $Type, 35 | 36 | [Parameter(ParameterSetName="Name",Mandatory)] 37 | [String] 38 | $Name 39 | ) 40 | 41 | 42 | begin { 43 | 44 | if(-not $header){ 45 | throw "Not connected to Nexus server! Run Connect-NexusServer first." 46 | } 47 | 48 | $urislug = "/service/rest/v1/repositories" 49 | } 50 | process { 51 | 52 | switch($PSCmdlet.ParameterSetName){ 53 | {$Format} { 54 | $filter = { $_.format -eq $Format} 55 | 56 | $result = Invoke-Nexus -UriSlug $urislug -Method Get 57 | $result | Where-Object $filter 58 | 59 | } 60 | 61 | {$Name} { 62 | $filter = { $_.name -eq $Name } 63 | 64 | $result = Invoke-Nexus -UriSlug $urislug -Method Get 65 | $result | Where-Object $filter 66 | 67 | } 68 | 69 | {$Type} { 70 | $filter = { $_.type -eq $Type } 71 | $result = Invoke-Nexus -UriSlug $urislug -Method Get 72 | $result | Where-Object $filter 73 | } 74 | 75 | default { 76 | Invoke-Nexus -UriSlug $urislug -Method Get| ForEach-Object { 77 | [pscustomobject]@{ 78 | Name = $_.SyncRoot.name 79 | Format = $_.SyncRoot.format 80 | Type = $_.SyncRoot.type 81 | Url = $_.SyncRoot.url 82 | Attributes = $_.SyncRoot.attributes 83 | } 84 | } 85 | } 86 | } 87 | } 88 | } -------------------------------------------------------------------------------- /src/public/Component/Get-NexusComponent.ps1: -------------------------------------------------------------------------------- 1 | function Get-NexusComponent { 2 | <# 3 | .SYNOPSIS 4 | Retrieve component information from Nexus 5 | 6 | .DESCRIPTION 7 | Retrieve component information from Nexus 8 | 9 | .PARAMETER RepositoryName 10 | The repository to query for components 11 | 12 | .PARAMETER Id 13 | A specific component to retrieve 14 | 15 | .EXAMPLE 16 | Get-NexusComponent -RepositoryName Dev 17 | 18 | .EXAMPLE 19 | Get-NexusComponent -Id RGV2OmM2MGJjNmI5NjEyZjQ3ZDM5ZTc2ZmMwNTI1ODg0M2Rj 20 | #> 21 | [CmdletBinding(HelpUri = 'https://nexushell.dev/Components/Get-NexusComponent/', DefaultParameterSetName = "repo")] 22 | Param( 23 | [Parameter(ParameterSetName = "repo", Mandatory)] 24 | [String] 25 | $RepositoryName, 26 | 27 | [Parameter(ParameterSetName = "Id", Mandatory)] 28 | [String] 29 | $Id 30 | ) 31 | 32 | process { 33 | 34 | if ($Id) { 35 | $urislug = "/service/rest/v1/components/$($Id)" 36 | Invoke-Nexus -Urislug $urislug -Method GET 37 | } 38 | 39 | else { 40 | 41 | $resultCollection = [System.Collections.Generic.List[psobject]]::new() 42 | $urislug = "/service/rest/v1/components?repository=$($RepositoryName)" 43 | 44 | $result = Invoke-Nexus -Urislug $urislug -Method GET 45 | 46 | $result.items | Foreach-Object { 47 | $temp = [PsCustomObject]@{ 48 | Id = $_.id 49 | Repository = $_.repository 50 | Format = $_.format 51 | Group = $_.group 52 | Name = $_.name 53 | Version = $_.version 54 | Assets = $_.assets 55 | } 56 | $resultCollection.Add($temp) 57 | } 58 | 59 | do { 60 | $urislug = "/service/rest/v1/components?repository=$($RepositoryName)&continuationToken=$($result.continuationToken)" 61 | $result = Invoke-Nexus -Urislug $urislug -Method GET 62 | 63 | $result.items | Foreach-Object { 64 | $temp = [PsCustomObject]@{ 65 | Id = $_.id 66 | Repository = $_.repository 67 | Format = $_.format 68 | Group = $_.group 69 | Name = $_.name 70 | Version = $_.version 71 | Assets = $_.assets 72 | } 73 | $resultCollection.Add($temp) 74 | } 75 | } 76 | 77 | while ($null -ne $result.continuationToken) 78 | $resultCollection 79 | 80 | } 81 | } 82 | } -------------------------------------------------------------------------------- /src/public/Security/Roles/Set-NexusRole.ps1: -------------------------------------------------------------------------------- 1 | function Set-NexusRole { 2 | <# 3 | .SYNOPSIS 4 | Modifies an existing Nexus Role 5 | 6 | .DESCRIPTION 7 | Modifies an existing Nexus Role 8 | 9 | .PARAMETER Role 10 | The role to modify 11 | 12 | .PARAMETER Name 13 | The new name of the role 14 | 15 | .PARAMETER Description 16 | Update the description 17 | 18 | .PARAMETER Privileges 19 | Update privileges 20 | 21 | .PARAMETER Roles 22 | Update nested roles 23 | 24 | .EXAMPLE 25 | Set-NexusRole -Role Example -Description "This is an updated description" 26 | 27 | .NOTES 28 | 29 | #> 30 | [CmdletBinding(HelpUri='https://nexushell.dev/Security/Roles/Set-NexusRole/')] 31 | Param( 32 | [Parameter(Mandatory)] 33 | [ArgumentCompleter( { 34 | param($Command, $Parameter, $WordToComplete, $CommandAst, $FakeBoundParams) 35 | 36 | $r = (Get-NexusRole).id 37 | 38 | if ($WordToComplete) { 39 | $r.Where($_ -match "^$WordToComplete") 40 | } 41 | 42 | else { 43 | $r 44 | } 45 | })] 46 | [String] 47 | $Role, 48 | 49 | [Parameter()] 50 | [String] 51 | $Name = $Role, 52 | 53 | [Parameter()] 54 | [String] 55 | $Description, 56 | 57 | [Parameter()] 58 | [String[]] 59 | $Privileges, 60 | 61 | [Parameter()] 62 | [String[]] 63 | $Roles 64 | ) 65 | 66 | begin { 67 | if (-not $header) { 68 | throw 'Not connected to Nexus server! Run Connect-NexusServer first.' 69 | } 70 | } 71 | 72 | process { 73 | 74 | $Id = $Role 75 | 76 | $urislug = "/service/rest/v1/security/roles/$Id" 77 | 78 | $CurrentSetting = Get-NexusRole -Role $Role 79 | 80 | 81 | if (-not $Name) { 82 | $Name = $Role 83 | } 84 | 85 | $Privileges = if (-not $Privileges) { 86 | @($($CurrentSetting.privileges)) 87 | } 88 | else { @($Privileges) } 89 | 90 | $Roles = if (-not $Roles -eq $null) { 91 | if ($null -ne $($CurrentSetting.roles)) { 92 | $null 93 | } 94 | } 95 | else { @($Roles) } 96 | 97 | $Body = @{ 98 | 99 | id = $Id 100 | name = $Name 101 | description = $Description 102 | privileges = $Privileges 103 | roles = $Roles 104 | 105 | } 106 | 107 | Write-Verbose ($Body | ConvertTo-Json) 108 | 109 | Invoke-Nexus -Urislug $urislug -Body $Body -Method PUT 110 | 111 | } 112 | } -------------------------------------------------------------------------------- /docs/index.md: -------------------------------------------------------------------------------- 1 | # NexuShell Documentation 2 | 3 | ![NexuShell logo](https://cdn.jsdelivr.net/gh/steviecoaster/NexuShell@develop/logo/nexushell.svg) 4 | 5 | You've found the online documentation for [NexuShell](https://github.com/steviecoaster/NexuShell)! 6 | 7 | NexuShell is a PowerShell module for the [Sonatype Nexus Repository Server](https://www.sonatype.com/products/repository-oss) API. Each function inside of the module links back to its corresponding page here on the docs site. 8 | 9 | ## What is Sonatype Nexus 10 | 11 | Sonatype Nexus is a Repository Server that exists in two flavors. Open Source (Sonatype Nexus OSS), and Pro (Sonatype Nexus Pro). The open-source version of Sonatype Nexus is extremely feature rich, providing you _almost_ all of the functionality of the Pro edition. It only lacks things like Azure Blob Storage availability for use in Blob Stores, High Availability, and Blob Store migrations, and a Support contract. 12 | 13 | ## Functionality 14 | 15 | - Manage Repositories 🚧 WIP, partially implemented 16 | - Manage Assets 17 | - Manage Components 18 | - Manage Anonymous Access 19 | - Manage Licensing 20 | - Manage Email configuration 21 | - Manage Blob Stores 22 | - Manage Routing Rules 23 | - Manage Cleanup Policies 24 | - Manage Scripts 25 | - Manage Roles 26 | - Manage Privileges 27 | - Manage Users 28 | - Manage Tasks 29 | - Search Nexus 🚧 Coming Soon! 30 | - Collect Support information 31 | 32 | ## Building 33 | 34 | To build this project from source, follow these steps: 35 | 36 | 1. Clone this repo and run `.\build.ps1 -Build` from the cloned folder 37 | 2. Import the module with `Import-Module .\Output\NexuShell\NexuShell.psd1` from the cloned folder 38 | 3. Discover the available commands with `Get-Command -Module NexuShell` 39 | 4. Explore the available commands with `Get-Help` 40 | 5. Start having fun! 41 | 42 | Once I have complete API coverage I'll publish this to the Gallery, and from there you'll be able to do `Install-Module NexuShell`, `Update-Module NexuShell` etc 43 | 44 | ## Installation 45 | 46 | You can install this module a couple of ways: 47 | 48 | - PowerShell Gallery: `Install-Module NexuShell -Force` 49 | - Chocolatey: `choco install nexushell -y -s https://community.chocolatey.org/api/v2` 50 | ## Contributing 51 | 52 | This is an Open Source project. If you spot a bug, or a feature that is missing file an [issue](https://github.com/steviecoaster/NexuShell/issues/new)! You're also welcome to file a Pull Request with your changes. When filing issues please ensure to include as much information as possible to make troubleshooting easier. Things like Operating System, PowerShell Version, Nexus Version, and any error output you receive while running a command are extremely helpful. 53 | 54 | Also, this is an open repository in which you encounter folks from many walks of life. Language is hard, but please try to keep conversations civil and inclusive. Foul language and extreme anger in comments will not be tolerated. -------------------------------------------------------------------------------- /src/public/BlobStore/Update-NexusFileBlobStore.ps1: -------------------------------------------------------------------------------- 1 | function Update-NexusFileBlobStore { 2 | <# 3 | .SYNOPSIS 4 | Updates some properties of a given file blobstore 5 | 6 | .PARAMETER Name 7 | The Name of the file blobstore to update 8 | 9 | .PARAMETER Path 10 | The path for the blob store to use 11 | 12 | .PARAMETER SoftQuotaType 13 | The type of soft quota limit to enforce 14 | 15 | .PARAMETER SoftQuotaLimit 16 | The size of the soft quota limit, in MB 17 | 18 | .NOTES 19 | This does not automatically migrate blobs from the previous location. 20 | There may be some time where the store is inaccessible. 21 | 22 | .EXAMPLE 23 | Update-NexusFileBlobStore -Name default -Path D:\NexusStore 24 | 25 | # Sets the default blobstore to the location listed 26 | #> 27 | [CmdletBinding(HelpUri = 'https://nexushell.dev/Update-NexusFileBlobStore/', SupportsShouldProcess, ConfirmImpact = 'High')] 28 | param( 29 | [Parameter(Mandatory)] 30 | [string] 31 | $Name, 32 | 33 | [string] 34 | $Path, 35 | 36 | [ValidateSet("Remaining", "Used")] 37 | [string] 38 | $SoftQuotaType, 39 | 40 | [ValidateRange(1, [int]::MaxValue)] 41 | [int] 42 | $SoftQuotaLimit 43 | ) 44 | begin { 45 | if (-not $header) { 46 | throw "Not connected to Nexus server! Run Connect-NexusServer first." 47 | } 48 | } 49 | end { 50 | $urislug = "/service/rest/v1/blobstores/file/$Name" 51 | 52 | $Body = Get-NexusBlobStore -Name $Name -Type File | Convert-ObjectToHashtable 53 | 54 | $Modified = $false 55 | switch -Wildcard ($PSBoundParameters.Keys) { 56 | "Path" { 57 | if ($Body.path -ne $Path) { 58 | $Body.path = $Path 59 | $Modified = $true 60 | } 61 | } 62 | "SoftQuota*" { 63 | if (-not $Body.softQuota) { 64 | $Body.softQuota = @{} 65 | } 66 | } 67 | "SoftQuotaType" { 68 | if ($Body.softQuota.type -ne "space$($SoftQuotaType)Quota") { 69 | $Body.softQuota.type = "space$($SoftQuotaType)Quota" 70 | $Modified = $true 71 | } 72 | } 73 | "SoftQuotaLimit" { 74 | if ($Body.softQuota.limit -ne $SoftQuotaLimit) { 75 | $Body.softQuota.limit = $SoftQuotaLimit * 1MB 76 | $Modified = $true 77 | } 78 | } 79 | } 80 | 81 | if ($Modified) { 82 | if ($PSCmdlet.ShouldProcess($Name, "Update File Blob Store")) { 83 | Invoke-Nexus -UriSlug $urislug -Method Put -Body $Body 84 | } 85 | } else { 86 | Write-Verbose "No change to '$($Name)' was required." 87 | } 88 | } 89 | } -------------------------------------------------------------------------------- /src/public/Repository/Remove-NexusRepository.ps1: -------------------------------------------------------------------------------- 1 | function Remove-NexusRepository { 2 | <# 3 | .SYNOPSIS 4 | Removes a given repository from the Nexus instance 5 | 6 | .DESCRIPTION 7 | Removes a given repository from the Nexus instance 8 | 9 | .PARAMETER Repository 10 | The repository to remove 11 | 12 | .PARAMETER Force 13 | Disable prompt for confirmation before removal 14 | 15 | .EXAMPLE 16 | Remove-NexusRepository -Repository ProdNuGet 17 | 18 | .EXAMPLE 19 | Remove-NexusRepository -Repository MavenReleases -Force() 20 | #> 21 | [CmdletBinding(HelpUri = 'https://nexushell.dev/Remove-NexusRepository/', SupportsShouldProcess, ConfirmImpact = 'High')] 22 | Param( 23 | [Parameter(Mandatory,ValueFromPipeline,ValueFromPipelineByPropertyName)] 24 | [Alias('Name')] 25 | [ArgumentCompleter( { 26 | param($CommandName, $ParameterName, $WordToComplete, $CommandAst, $FakeBoundParameters) 27 | $repositories = (Get-NexusRepository).Name 28 | 29 | if ($WordToComplete) { 30 | $repositories.Where{ $_ -match "^$WordToComplete" } 31 | } 32 | else { 33 | $repositories 34 | } 35 | })] 36 | [String[]] 37 | $Repository, 38 | 39 | [Parameter()] 40 | [Switch] 41 | $Force 42 | ) 43 | begin { 44 | 45 | if (-not $header) { 46 | throw "Not connected to Nexus server! Run Connect-NexusServer first." 47 | } 48 | 49 | $urislug = "/service/rest/v1/repositories" 50 | } 51 | process { 52 | 53 | $Repository | Foreach-Object { 54 | $Uri = $urislug + "/$_" 55 | 56 | try { 57 | 58 | if ($Force -and -not $Confirm) { 59 | $ConfirmPreference = 'None' 60 | if ($PSCmdlet.ShouldProcess("$_", "Remove Repository")) { 61 | $result = Invoke-Nexus -UriSlug $Uri -Method 'DELETE' -ErrorAction Stop 62 | [pscustomobject]@{ 63 | Status = 'Success' 64 | Repository = $_ 65 | } 66 | } 67 | } 68 | else { 69 | if ($PSCmdlet.ShouldProcess("$_", "Remove Repository")) { 70 | $result = Invoke-Nexus -UriSlug $Uri -Method 'DELETE' -ErrorAction Stop 71 | [pscustomobject]@{ 72 | Status = 'Success' 73 | Repository = $_ 74 | Timestamp = $result.date 75 | } 76 | } 77 | } 78 | } 79 | 80 | catch { 81 | $_.exception.message 82 | } 83 | } 84 | } 85 | } -------------------------------------------------------------------------------- /src/nuget/tools/chocolateyInstall.ps1: -------------------------------------------------------------------------------- 1 | $ErrorActionPreference = 'Stop' 2 | 3 | $toolsDir = Split-Path -Parent $MyInvocation.MyCommand.Definition 4 | $ModuleName = $env:ChocolateyPackageName # this may be different from the package name and different case 5 | $ModuleVersion = $env:ChocolateyPackageVersion # this may change so keep this here 6 | $SavedParamsPath = Join-Path $toolsDir -ChildPath 'parameters.saved' 7 | 8 | if ($PSVersionTable.PSVersion.Major -lt 5) { 9 | Write-Warning "$ModuleName has not been tested on this version of PowerShell" 10 | } 11 | 12 | # Module may already be installed outside of Chocolatey 13 | Remove-Module -Name $ModuleName -Force -ErrorAction SilentlyContinue 14 | 15 | # remove the saved parameters file if it exists 16 | if (Test-Path -Path $savedParamsPath) { 17 | Remove-Item -Path $savedParamsPath -Force 18 | } 19 | 20 | $sourcePath = Join-Path $toolsDir -ChildPath "$($ModuleName).zip" 21 | $destinationPath = @() 22 | 23 | $PathSegment = @{ 24 | Windows = "WindowsPowerShell\Modules\" 25 | Core = "PowerShell\Modules\" 26 | 27 | AllUsers = $env:ProgramFiles 28 | CurrentUser = try { 29 | $PROFILE | Split-Path | Split-Path 30 | } catch { 31 | Write-Warning "Profile is set to '$($PROFILE)'. Current user '$($env:USERNAME)' may not be able to install at user level." 32 | } 33 | } 34 | 35 | $Parameters = Get-PackageParameters 36 | 37 | if (-not $Parameters.ContainsKey('Windows') -and -not $Parameters.ContainsKey('Core')) { 38 | $Parameters += @{ 39 | Windows = $PSVersionTable.PSVersion.Major -le 5 40 | Core = $PSVersionTable.PSVersion.Major -gt 5 41 | } 42 | } 43 | 44 | if (-not $Parameters.ContainsKey('AllUsers') -and -not $Parameters.ContainsKey('CurrentUser')) { 45 | $Parameters += @{ 46 | AllUsers = Test-ProcessAdminRights 47 | CurrentUser = -not (Test-ProcessAdminRights) 48 | } 49 | } 50 | 51 | foreach ($Scope in $Parameters.Keys.Where{$Parameters[$_] -and $_ -in @("AllUsers", "CurrentUser")}) { 52 | if ($Parameters.Windows) { 53 | $destinationPath += Join-Path -Path $PathSegment.$Scope -ChildPath $PathSegment.Windows 54 | } 55 | 56 | if ($Parameters.Core) { 57 | $destinationPath += Join-Path -Path $PathSegment.$Scope -ChildPath $PathSegment.Core 58 | } 59 | } 60 | 61 | foreach ($destPath in $destinationPath) { 62 | Write-Verbose "Installing '$($modulename)' to '$($destPath)'." 63 | 64 | # Check if the destination path exists and create if not 65 | if (Test-Path -Path $destPath) { 66 | $null = New-Item -Path $destPath -ItemType Directory -Force 67 | } 68 | Get-ChocolateyUnzip -FileFullPath $sourcePath -Destination $destPath -PackageName $moduleName 69 | 70 | # save the locations where the module was installed so we can uninstall it 71 | Add-Content -Path $savedParamsPath -Value $destPath 72 | } 73 | 74 | # cleanup the module from the Chocolatey $toolsDir folder 75 | Remove-Item -Path $sourcePath -Force -Recurse -------------------------------------------------------------------------------- /src/public/Repository/New-NexusRawGroupRepository.ps1: -------------------------------------------------------------------------------- 1 | function New-NexusRawGroupRepository { 2 | <# 3 | .SYNOPSIS 4 | Creates a Raw Group repository 5 | 6 | .DESCRIPTION 7 | Creates a Raw Group repository 8 | 9 | .PARAMETER Name 10 | The name of the repository 11 | 12 | .PARAMETER GroupMembers 13 | The Raw Repositories to add as group members 14 | 15 | .PARAMETER Online 16 | Marks the repository as online 17 | 18 | .PARAMETER BlobStore 19 | The blob store to attach to the repository 20 | 21 | .PARAMETER UseStrictContentTypeValidation 22 | Validate that all content uploaded to this repository is of a MIME type appropriate for the repository format 23 | 24 | .PARAMETER ContentDisposition 25 | Add Content-Disposition header as 'Attachment' to disable some content from being inline in a browser 26 | 27 | .PARAMETER DeploymentPolicy 28 | Required by the API, but thrown away by the underlying system. Use whatever you want here from the set 29 | 30 | .EXAMPLE 31 | New-NexusRawGroupRepository -Name AllArtifacts -GroupMembers BinaryArtifacts,Documentation -DeploymentPolicy Allow 32 | 33 | .NOTES 34 | #> 35 | [CmdletBinding(HelpUri='https://nexushell.dev/New-NexusRawGroupRepository/')] 36 | Param( 37 | [Parameter(Mandatory)] 38 | [String] 39 | $Name, 40 | 41 | [Parameter(Mandatory)] 42 | [String[]] 43 | $GroupMembers, 44 | 45 | [Parameter()] 46 | [Switch] 47 | $Online = $true, 48 | 49 | [Parameter()] 50 | [String] 51 | $BlobStore = 'default', 52 | 53 | [Parameter()] 54 | [Switch] 55 | $UseStrictContentTypeValidation, 56 | 57 | [Parameter(Mandatory)] 58 | [ValidateSet('Inline', 'Attachment')] 59 | [String] 60 | $ContentDisposition, 61 | 62 | [Parameter(Mandatory)] 63 | [ValidateSet('Allow', 'Deny', 'Allow_Once')] 64 | [String] 65 | $DeploymentPolicy = 'Allow_Once' 66 | ) 67 | begin { 68 | 69 | if (-not $header) { 70 | throw "Not connected to Nexus server! Run Connect-NexusServer first." 71 | } 72 | 73 | $urislug = "/service/rest/v1/repositories/raw/group" 74 | 75 | } 76 | 77 | process { 78 | 79 | $body = @{ 80 | name = $Name 81 | online = [bool]$Online 82 | storage = @{ 83 | blobStoreName = $BlobStore 84 | strictContentTypeValidation = [bool]$UseStrictContentTypeValidation 85 | writePolicy = $DeploymentPolicy.ToLower() 86 | } 87 | group = @{ 88 | memberNames = $GroupMembers 89 | } 90 | raw = @{ 91 | contentDisposition = $ContentDisposition 92 | } 93 | } 94 | 95 | Write-Verbose $($Body | ConvertTo-Json) 96 | $null = Invoke-Nexus -UriSlug $urislug -Body $Body -Method POST 97 | 98 | } 99 | 100 | } -------------------------------------------------------------------------------- /src/public/User/New-NexusUser.ps1: -------------------------------------------------------------------------------- 1 | function New-NexusUser { 2 | <# 3 | .SYNOPSIS 4 | Create a new user in the default source. 5 | 6 | .DESCRIPTION 7 | Create a new user in the default source. 8 | 9 | .PARAMETER Username 10 | The userid which is required for login. This value cannot be changed. 11 | 12 | .PARAMETER Password 13 | The password for the new user. 14 | 15 | .PARAMETER FirstName 16 | The first name of the user. 17 | 18 | .PARAMETER LastName 19 | The last name of the user. 20 | 21 | .PARAMETER EmailAddress 22 | The email address associated with the user. 23 | 24 | .PARAMETER Status 25 | The user's status, e.g. active or disabled. 26 | 27 | .PARAMETER Roles 28 | The roles which the user has been assigned within Nexus. 29 | 30 | .EXAMPLE 31 | $params = @{ 32 | Username = 'jimmy' 33 | Password = ("sausage" | ConvertTo-SecureString -AsPlainText -Force) 34 | FirstName = 'Jimmy' 35 | LastName = 'Dean' 36 | EmailAddress = 'sausageking@jimmydean.com' 37 | Status = Active 38 | Roles = 'nx-admin' 39 | } 40 | 41 | New-NexusUser @params 42 | 43 | .NOTES 44 | 45 | #> 46 | [CmdletBinding(HelpUri='https://nexushell.dev/Security/User/New-NexusUser/')] 47 | Param( 48 | [Parameter(Mandatory)] 49 | [String] 50 | $Username, 51 | 52 | [Parameter(Mandatory)] 53 | [SecureString] 54 | $Password, 55 | 56 | [Parameter(Mandatory)] 57 | [String] 58 | $FirstName, 59 | 60 | [Parameter(Mandatory)] 61 | [String] 62 | $LastName, 63 | 64 | [Parameter(Mandatory)] 65 | [String] 66 | $EmailAddress, 67 | 68 | [Parameter(Mandatory)] 69 | [ValidateSet('Active', 'Locked', 'Disabled', 'ChangePassword')] 70 | [String] 71 | $Status, 72 | 73 | [Parameter(Mandatory)] 74 | [ArgumentCompleter({ 75 | param($Command, $Parameter, $WordToComplete, $CommandAst, $FakeBoundParams) 76 | (Get-NexusRole).Id.Where{$_ -like "*$WordToComplete*"} 77 | })] 78 | [String[]] 79 | $Roles 80 | ) 81 | 82 | process { 83 | $urislug = '/service/rest/v1/security/users' 84 | 85 | $Body = @{ 86 | userId = $Username 87 | firstName = $FirstName 88 | lastName = $LastName 89 | emailAddress = $EmailAddress 90 | password = [System.Net.NetworkCredential]::new($Username, $Password).Password 91 | status = $Status 92 | roles = $Roles 93 | } 94 | 95 | Write-Verbose ($Body | ConvertTo-Json) 96 | $result = Invoke-Nexus -Urislug $urislug -Body $Body -Method POST 97 | 98 | [pscustomObject]@{ 99 | Username = $result.userId 100 | FirstName = $result.firstName 101 | LastName = $result.lastName 102 | EmailAddress = $result.emailAddress 103 | Source = $result.source 104 | Status = $result.status 105 | Roles = $result.roles 106 | ExternalRoles = $result.externalRoles 107 | } 108 | } 109 | } -------------------------------------------------------------------------------- /src/public/Repository/New-NexusGitLfsHostedRepository.ps1: -------------------------------------------------------------------------------- 1 | function New-NexusGitlfsHostedRepository { 2 | <# 3 | .SYNOPSIS 4 | Creates a new GitLfs Hosted repository 5 | 6 | .DESCRIPTION 7 | Creates a new GitLfs Hosted repository 8 | 9 | .PARAMETER Name 10 | The name of the repository 11 | 12 | .PARAMETER CleanupPolicy 13 | The Cleanup Policies to apply to the repository 14 | 15 | .PARAMETER Online 16 | Marks the repository to accept incoming requests 17 | 18 | .PARAMETER BlobStoreName 19 | Blob store to use to store GitLfs packages 20 | 21 | .PARAMETER StrictContentValidation 22 | Validate that all content uploaded to this repository is of a MIME type appropriate for the repository format 23 | 24 | .PARAMETER DeploymentPolicy 25 | Controls if deployments of and updates to artifacts are allowed 26 | 27 | .PARAMETER HasProprietaryComponents 28 | Components in this repository count as proprietary for namespace conflict attacks (requires Sonatype Nexus Firewall) 29 | 30 | .EXAMPLE 31 | New-NexusGitLfsHostedRepository -Name GitLfsHostedTest -DeploymentPolicy Allow 32 | 33 | .EXAMPLE 34 | 35 | $RepoParams = @{ 36 | Name = 'MyGitLfsRepo' 37 | CleanupPolicy = '90 Days' 38 | DeploymentPolicy = 'Allow' 39 | UseStrictContentValidation = $true 40 | } 41 | 42 | New-NexusGitLfsHostedRepository @RepoParams 43 | 44 | .NOTES 45 | #> 46 | [CmdletBinding(HelpUri = 'https://nexushell.dev/New-NexusGitlfsHostedRepository/')] 47 | Param( 48 | [Parameter(Mandatory)] 49 | [String] 50 | $Name, 51 | 52 | [Parameter()] 53 | [String] 54 | $CleanupPolicy, 55 | 56 | [Parameter()] 57 | [Switch] 58 | $Online, 59 | 60 | [Parameter()] 61 | [String] 62 | $BlobStoreName = 'default', 63 | 64 | [Parameter()] 65 | [Switch] 66 | $UseStrictContentValidation, 67 | 68 | [Parameter()] 69 | [ValidateSet('Allow', 'Deny', 'Allow_Once')] 70 | [String] 71 | $DeploymentPolicy, 72 | 73 | [Parameter()] 74 | [Switch] 75 | $HasProprietaryComponents 76 | ) 77 | 78 | begin { 79 | 80 | if (-not $header) { 81 | throw "Not connected to Nexus server! Run Connect-NexusServer first." 82 | } 83 | 84 | $urislug = "/service/rest/v1/repositories/gitlfs/hosted" 85 | 86 | } 87 | 88 | process { 89 | $body = @{ 90 | name = $Name 91 | online = [bool]$Online 92 | storage = @{ 93 | blobStoreName = $BlobStoreName 94 | strictContentTypeValidation = [bool]$UseStrictContentValidation 95 | writePolicy = $DeploymentPolicy 96 | } 97 | cleanup = @{ 98 | policyNames = @($CleanupPolicy) 99 | } 100 | } 101 | 102 | if ($HasProprietaryComponents) { 103 | $Prop = @{ 104 | proprietaryComponents = 'True' 105 | } 106 | 107 | $Body.Add('component', $Prop) 108 | } 109 | 110 | Write-Verbose $($Body | ConvertTo-Json) 111 | $null = Invoke-Nexus -UriSlug $urislug -Body $Body -Method POST 112 | } 113 | } -------------------------------------------------------------------------------- /src/public/Repository/New-NexusBowerHostedRepository.ps1: -------------------------------------------------------------------------------- 1 | function New-NexusBowerHostedRepository { 2 | <# 3 | .SYNOPSIS 4 | Creates a new Bower Hosted repository 5 | 6 | .DESCRIPTION 7 | Creates a new Bower Hosted repository 8 | 9 | .PARAMETER Name 10 | The name of the repository 11 | 12 | .PARAMETER CleanupPolicy 13 | The Cleanup Policies to apply to the repository 14 | 15 | .PARAMETER Online 16 | Marks the repository to accept incoming requests 17 | 18 | .PARAMETER BlobStoreName 19 | Blob store to use to store Bower packages 20 | 21 | .PARAMETER StrictContentValidation 22 | Validate that all content uploaded to this repository is of a MIME type appropriate for the repository format 23 | 24 | .PARAMETER DeploymentPolicy 25 | Controls if deployments of and updates to artifacts are allowed 26 | 27 | .PARAMETER HasProprietaryComponents 28 | Components in this repository count as proprietary for namespace conflict attacks (requires Sonatype Nexus Firewall) 29 | 30 | .EXAMPLE 31 | New-NexusBowerHostedRepository -Name BowerHostedTest -DeploymentPolicy Allow 32 | 33 | .EXAMPLE 34 | 35 | $RepoParams = @{ 36 | Name = 'MyBowerRepo' 37 | CleanupPolicy = '90 Days' 38 | DeploymentPolicy = 'Allow' 39 | UseStrictContentValidation = $true 40 | } 41 | 42 | New-NexusBowerHostedRepository @RepoParams 43 | 44 | .NOTES 45 | General notes 46 | #> 47 | [CmdletBinding(HelpUri = 'https://nexushell.dev/New-NexusBowerHostedRepository/')] 48 | Param( 49 | [Parameter(Mandatory)] 50 | [String] 51 | $Name, 52 | 53 | [Parameter()] 54 | [String] 55 | $CleanupPolicy, 56 | 57 | [Parameter()] 58 | [ValidateSet('True', 'False')] 59 | [String] 60 | $Online = 'True', 61 | 62 | [Parameter()] 63 | [String] 64 | $BlobStoreName = 'default', 65 | 66 | [Parameter()] 67 | [ValidateSet('True', 'False')] 68 | [String] 69 | $UseStrictContentValidation = 'True', 70 | 71 | [Parameter()] 72 | [ValidateSet('Allow', 'Deny', 'Allow_Once')] 73 | [String] 74 | $DeploymentPolicy, 75 | 76 | [Parameter()] 77 | [Switch] 78 | $HasProprietaryComponents 79 | ) 80 | 81 | begin { 82 | 83 | if (-not $header) { 84 | throw "Not connected to Nexus server! Run Connect-NexusServer first." 85 | } 86 | 87 | $urislug = "/service/rest/v1/repositories/bower/hosted" 88 | 89 | } 90 | 91 | process { 92 | $body = @{ 93 | name = $Name 94 | online = $Online 95 | storage = @{ 96 | blobStoreName = $BlobStoreName 97 | strictContentTypeValidation = $UseStrictContentValidation 98 | writePolicy = $DeploymentPolicy 99 | } 100 | cleanup = @{ 101 | policyNames = @($CleanupPolicy) 102 | } 103 | } 104 | 105 | if ($HasProprietaryComponents) { 106 | $Prop = @{ 107 | proprietaryComponents = 'True' 108 | } 109 | 110 | $Body.Add('component', $Prop) 111 | } 112 | 113 | Write-Verbose $($Body | ConvertTo-Json) 114 | $null = Invoke-Nexus -UriSlug $urislug -Body $Body -Method POST 115 | 116 | } 117 | } -------------------------------------------------------------------------------- /src/public/Repository/New-NexusNugetHostedRepository.ps1: -------------------------------------------------------------------------------- 1 | function New-NexusNugetHostedRepository { 2 | <# 3 | .SYNOPSIS 4 | Creates a new NuGet Hosted repository 5 | 6 | .DESCRIPTION 7 | Creates a new NuGet Hosted repository 8 | 9 | .PARAMETER Name 10 | The name of the repository 11 | 12 | .PARAMETER CleanupPolicy 13 | The Cleanup Policies to apply to the repository 14 | 15 | 16 | 17 | .PARAMETER Online 18 | Marks the repository to accept incoming requests 19 | 20 | .PARAMETER BlobStoreName 21 | Blob store to use to store NuGet packages 22 | 23 | .PARAMETER StrictContentValidation 24 | Validate that all content uploaded to this repository is of a MIME type appropriate for the repository format 25 | 26 | .PARAMETER DeploymentPolicy 27 | Controls if deployments of and updates to artifacts are allowed 28 | 29 | .PARAMETER HasProprietaryComponents 30 | Components in this repository count as proprietary for namespace conflict attacks (requires Sonatype Nexus Firewall) 31 | 32 | .EXAMPLE 33 | New-NexusNugetHostedRepository -Name NugetHostedTest -DeploymentPolicy Allow 34 | 35 | .EXAMPLE 36 | 37 | $RepoParams = @{ 38 | Name = MyNuGetRepo 39 | CleanupPolicy = '90 Days' 40 | DeploymentPolicy = 'Allow' 41 | UseStrictContentValidation = $true 42 | } 43 | 44 | New-NexusNugetHostedRepository @RepoParams 45 | 46 | .NOTES 47 | General notes 48 | #> 49 | [CmdletBinding(HelpUri = 'https://nexushell.dev/New-NexusNugetHostedRepository/')] 50 | Param( 51 | [Parameter(Mandatory)] 52 | [String] 53 | $Name, 54 | 55 | [Parameter()] 56 | [String] 57 | $CleanupPolicy, 58 | 59 | [Parameter()] 60 | [Switch] 61 | $Online = $true, 62 | 63 | [Parameter()] 64 | [String] 65 | $BlobStoreName = 'default', 66 | 67 | [Parameter()] 68 | [ValidateSet('True', 'False')] 69 | [String] 70 | $UseStrictContentValidation = 'True', 71 | 72 | [Parameter()] 73 | [ValidateSet('Allow', 'Deny', 'Allow_Once')] 74 | [String] 75 | $DeploymentPolicy, 76 | 77 | [Parameter()] 78 | [Switch] 79 | $HasProprietaryComponents 80 | ) 81 | 82 | begin { 83 | 84 | if (-not $header) { 85 | throw "Not connected to Nexus server! Run Connect-NexusServer first." 86 | } 87 | 88 | $urislug = "/service/rest/v1/repositories" 89 | 90 | } 91 | 92 | process { 93 | $formatUrl = $urislug + '/nuget' 94 | 95 | $FullUrlSlug = $formatUrl + '/hosted' 96 | 97 | 98 | $body = @{ 99 | name = $Name 100 | online = [bool]$Online 101 | storage = @{ 102 | blobStoreName = $BlobStoreName 103 | strictContentTypeValidation = $UseStrictContentValidation 104 | writePolicy = $DeploymentPolicy 105 | } 106 | cleanup = @{ 107 | policyNames = @($CleanupPolicy) 108 | } 109 | } 110 | 111 | if ($HasProprietaryComponents) { 112 | $Prop = @{ 113 | proprietaryComponents = 'True' 114 | } 115 | 116 | $Body.Add('component', $Prop) 117 | } 118 | 119 | Write-Verbose $($Body | ConvertTo-Json) 120 | $null = Invoke-Nexus -UriSlug $FullUrlSlug -Body $Body -Method POST 121 | 122 | } 123 | } -------------------------------------------------------------------------------- /src/public/Repository/Cleanup Policy/Set-NexusCleanupPolicy.ps1: -------------------------------------------------------------------------------- 1 | function Set-NexusCleanupPolicy { 2 | <# 3 | .SYNOPSIS 4 | Updates a Nexus Cleanup Policy 5 | 6 | .DESCRIPTION 7 | Updates a Nexus Cleanup Policy 8 | 9 | .PARAMETER Name 10 | The cleanup policy to update 11 | 12 | .PARAMETER Format 13 | The format that this cleanup policy can be applied to 14 | 15 | .PARAMETER Notes 16 | Additional details about the policy 17 | 18 | .PARAMETER ComponentAge 19 | Remove components that were published over this many days 20 | 21 | .PARAMETER ComponentUsage 22 | Remove components that haven't been downloaded in this many days 23 | 24 | .PARAMETER AssetMatcher 25 | Remove components that have at least one asset name matching the following regular expression pattern 26 | 27 | .EXAMPLE 28 | Set-NexusCleanupPolicy -Name TestPol -Notes "New notes here" -ComponentAge 60 29 | 30 | .NOTES 31 | 32 | #> 33 | [CmdletBinding(HelpUri='https://nexushell.dev/Repository/Cleanup%20Policy/Set-NexusCleanupPolicy/')] 34 | Param( 35 | [Parameter(Mandatory)] 36 | [ArgumentCompleter( { 37 | param($Command, $Parameter, $WordToComplete, $CommandAst, $FakeBoundParams) 38 | 39 | $r = (Get-NexusCleanupPolicy).Name 40 | 41 | if ($WordToComplete) { 42 | $r.Where($_ -match "^$WordToComplete") 43 | } 44 | 45 | else { 46 | $r 47 | } 48 | })] 49 | [String] 50 | $Name, 51 | 52 | [ValidateSet('All', 'Apt', 'Bower', 'CocoaPods', 'Conan', 'Conda', 'Docker', 'GitLFS', 'Go', 'Helm', 'Maven2', 'Npm', 'Nuget', 'P2', 'PyPi', 'R', 'Raw', 'RubyGems', 'Yum')] 53 | [String] 54 | $Format, 55 | 56 | [Parameter()] 57 | [String] 58 | $Notes, 59 | 60 | [Int] 61 | $ComponentAge, 62 | 63 | [Int] 64 | $ComponentUsage, 65 | 66 | [String] 67 | $AssetMatcher 68 | ) 69 | 70 | $currentSettings = Get-NexusCleanupPolicy -CleanupPolicy $Name 71 | 72 | $currentSettings = [pscustomobject]@{ 73 | Name = $Name 74 | Format = $currentSettings.format 75 | Notes = $currentSettings.notes 76 | CriteriaLastBlobUpdated = $currentSettings.criteriaLastBlobUpdated 77 | CriteriaLastDownloaded = $currentSettings.criteriaLastDownloaded 78 | CriteriaReleaseType = $currentSettings.criteriaReleaseType 79 | CriteriaAssetRegex = $currentSettings.criteriaAssetRegex 80 | InUseCount = $currentSettings.inUseCount 81 | } 82 | 83 | $urislug = "/service/rest/internal/cleanup-policies/$($Name)?_dc=$(([DateTime]::ParseExact("01/02/0001 21=08=29", "MM/dd/yyyy HH=mm=ss",$null)).Ticks)" 84 | 85 | $Body = @{ 86 | name = $Name 87 | notes = if($Notes){ $Notes } else { $currentSettings.Notes} 88 | criteriaLastDownloaded = if($ComponentUsage) { $ComponentUsage} else {$currentSettings.CriteriaLastDownloaded} 89 | criteriaLastBlobUpdated = if($ComponentAge) { $ComponentAge} else {$currentSettings.CriteriaLastBlobUpdated} 90 | criteriaAssetRegex = if($AssetMatcher) {$AssetMatcher} else { $currentSettings.CriteriaAssetRegex} 91 | format = if($Format) { $Format.ToLower()} else {$currentSettings.Format} 92 | } 93 | 94 | Write-Verbose ($Body | ConvertTo-Json) 95 | Invoke-Nexus -Urislug $urislug -Body $Body -Method PUT 96 | } -------------------------------------------------------------------------------- /src/public/Repository/New-NexusDockerGroupRepository.ps1: -------------------------------------------------------------------------------- 1 | function New-NexusDockerGroupRepository { 2 | <# 3 | .SYNOPSIS 4 | Creates a new Docker Group repository 5 | 6 | .DESCRIPTION 7 | Creates a new Docker Group repository 8 | 9 | .PARAMETER Name 10 | The name of the repository 11 | 12 | .PARAMETER Online 13 | Marks the repository to accept incoming requests 14 | 15 | .PARAMETER BlobStoreName 16 | Blob store to use to store Docker packages 17 | 18 | .PARAMETER StrictContentValidation 19 | Validate that all content uploaded to this repository is of a MIME type appropriate for the repository format 20 | 21 | .PARAMETER EnableV1 22 | Whether to allow clients to use the V1 API to interact with this repository 23 | 24 | .PARAMETER ForceBasicAuth 25 | Whether to force authentication (Docker Bearer Token Realm required if false) 26 | 27 | .PARAMETER HttpPort 28 | Create an HTTP connector at specified port 29 | 30 | .PARAMETER HttpsPort 31 | Create an HTTPS connector at specified port 32 | 33 | .EXAMPLE 34 | New-NexusDockerGroupRepository -Name DockerGroup -GroupMembers DockerHostedLinux,DockerProd -Online 35 | 36 | .NOTES 37 | #> 38 | [CmdletBinding(HelpUri = 'https://nexushell.dev/New-NexusDockerGroupRepository/')] 39 | Param( 40 | [Parameter(Mandatory)] 41 | [String] 42 | $Name, 43 | 44 | [Parameter(Mandatory)] 45 | [String[]] 46 | $GroupMembers, 47 | 48 | [Parameter()] 49 | [String] 50 | $WritableMember, 51 | 52 | [Parameter()] 53 | [Switch] 54 | $Online = $true, 55 | 56 | [Parameter()] 57 | [String] 58 | $BlobStoreName = 'default', 59 | 60 | [Parameter()] 61 | [Switch] 62 | $UseStrictContentTypeValidation, 63 | 64 | [Parameter()] 65 | [Switch] 66 | $EnableV1, 67 | 68 | [Parameter()] 69 | [Switch] 70 | $ForceBasicAuth, 71 | 72 | [Parameter()] 73 | [String] 74 | $HttpPort, 75 | 76 | [Parameter()] 77 | [String] 78 | $HttpsPort 79 | ) 80 | 81 | begin { 82 | 83 | if (-not $header) { 84 | throw "Not connected to Nexus server! Run Connect-NexusServer first." 85 | } 86 | 87 | $urislug = "/service/rest/v1/repositories/docker/group" 88 | 89 | } 90 | 91 | process { 92 | 93 | $body = @{ 94 | name = $Name 95 | online = [bool]$Online 96 | storage = @{ 97 | blobStoreName = $BlobStoreName 98 | strictContentTypeValidation = [bool]$UseStrictContentValidation 99 | } 100 | group = @{ 101 | memberNames = $GroupMembers 102 | writableMember = $WritableMember 103 | } 104 | docker = @{ 105 | v1Enabled = [bool]$EnableV1 106 | forceBasicAuth = [bool]$ForceBasicAuth 107 | httpPort = $HttpPort 108 | httpsPort = $HttpsPort 109 | } 110 | } 111 | 112 | Write-Verbose $($Body | ConvertTo-Json) 113 | $null = Invoke-Nexus -UriSlug $urislug -Body $Body -Method POST 114 | 115 | if($ForceBasicAuth -eq $false){ 116 | Write-Warning "Docker Bearer Token Realm required since -ForceBasicAuth was not passed." 117 | Write-Warning "Use Add-NexusRealm to enable if desired." 118 | } 119 | 120 | 121 | } 122 | 123 | } -------------------------------------------------------------------------------- /src/public/Email/Set-NexusEmailConfig.ps1: -------------------------------------------------------------------------------- 1 | function Set-NexusEmailConfig { 2 | <# 3 | .SYNOPSIS 4 | Sets the email settings for Nexus 5 | 6 | .DESCRIPTION 7 | Sets the email settings for Nexus 8 | 9 | .PARAMETER SmtpServer 10 | The hostname or IP address of your mail server 11 | 12 | .PARAMETER SmtpPort 13 | The SMTP port of your mail server 14 | 15 | .PARAMETER Enabled 16 | Enable sending mail from Nexus 17 | 18 | .PARAMETER Credential 19 | Credentials to connect to your SMTP server if required 20 | 21 | .PARAMETER FromAddress 22 | Messages from Nexus with be sent from this email address 23 | 24 | .PARAMETER SubjectPrefix 25 | Append a prefix to messages from Nexus if desired 26 | 27 | .PARAMETER StartTlsEnabled 28 | Enable StartTLS 29 | 30 | .PARAMETER StartTlsRequired 31 | Require TLS on the smtp connection 32 | 33 | .PARAMETER SSLOnConnect 34 | Require SSL on the smtp connection 35 | 36 | .PARAMETER VerifyServerIdentity 37 | Verify mail server identity before sending messages 38 | 39 | .PARAMETER UseNexusTrustStore 40 | Use Nexus Trust Store for email certificates 41 | 42 | .EXAMPLE 43 | Set-NexusEmailConfig -SmtpSerer mail.foo.org -Port 25 -Enabled 44 | 45 | .EXAMPLE 46 | Set-NexusEmailConfig -SmtpServer mail.foo.org -Port 427 -Enabled -StartTlsEnabled -StartTlsrequired 47 | 48 | .NOTES 49 | 50 | #> 51 | [CmdletBinding()] 52 | Param( 53 | [Parameter()] 54 | [String] 55 | $SmtpServer, 56 | 57 | [Parameter(Mandatory)] 58 | [Int32] 59 | $SmtpPort, 60 | 61 | [Parameter()] 62 | [Switch] 63 | $Enabled, 64 | 65 | [Parameter()] 66 | [PSCredential] 67 | $Credential, 68 | 69 | [Parameter()] 70 | [String] 71 | $FromAddress, 72 | 73 | [Parameter()] 74 | [String] 75 | $SubjectPrefix, 76 | 77 | [Parameter()] 78 | [Switch] 79 | $StartTlsEnabled, 80 | 81 | [Parameter()] 82 | [Switch] 83 | $StartTlsRequired, 84 | 85 | [Parameter()] 86 | [Switch] 87 | $SSLOnConnect, 88 | 89 | [Parameter()] 90 | [Switch] 91 | $VerifyServerIdentity, 92 | 93 | [Parameter()] 94 | [Switch] 95 | $UseNexusTrustStore 96 | ) 97 | 98 | begin { 99 | if (-not $header) { 100 | throw "Not connected to Nexus server! Run Connect-NexusServer first." 101 | } 102 | } 103 | 104 | process { 105 | $urislug = '/service/rest/v1/email' 106 | 107 | if($Credential){ 108 | $username = $Credential.UserName 109 | $password = $Credential.GetNetworkCredential().Password 110 | } 111 | 112 | $Body = @{ 113 | enabled= [bool]$Enabled 114 | host= $SmtpServer 115 | port= $SmtpPort 116 | username= $username 117 | password= $password 118 | fromAddress= $FromAddress 119 | subjectPrefix= $SubjectPrefix 120 | startTlsEnabled= [bool]$StartTlsEnabled 121 | startTlsRequired= [bool]$StartTlsRequired 122 | sslOnConnectEnabled= [bool]$SSLOnConnect 123 | sslServerIdentityCheckEnabled= [bool]$VerifyServerIdentity 124 | nexusTrustStoreEnabled= [bool]$UseNexusTrustStore 125 | } 126 | 127 | Write-verbose ($Body | ConvertTo-Json) 128 | Invoke-Nexus -Urislug $urislug -Body $Body -Method PUT 129 | } 130 | } -------------------------------------------------------------------------------- /src/public/User/Set-NexusUser.ps1: -------------------------------------------------------------------------------- 1 | function Set-NexusUser { 2 | <# 3 | .SYNOPSIS 4 | Update an existing user. 5 | 6 | .DESCRIPTION 7 | Update an existing user. 8 | 9 | .PARAMETER Username 10 | The userid the request should apply to. 11 | 12 | .PARAMETER FirstName 13 | The first name of the user. 14 | 15 | .PARAMETER LastName 16 | The last name of the user. 17 | 18 | .PARAMETER EmailAddress 19 | The email address associated with the user. 20 | 21 | .PARAMETER Source 22 | The user source which is the origin of this user. This value cannot be changed. 23 | 24 | .PARAMETER Status 25 | The user's status, e.g. active or disabled. 26 | 27 | .PARAMETER ReadOnly 28 | Indicates whether the user's properties could be modified by the Nexus Repository Manager. When false only roles are considered during update. 29 | 30 | .PARAMETER Roles 31 | The roles which the user has been assigned within Nexus. 32 | 33 | .PARAMETER ExternalRoles 34 | The roles which the user has been assigned in an external source, e.g. LDAP group. These cannot be changed within the Nexus Repository Manager. 35 | 36 | .EXAMPLE 37 | An example 38 | 39 | .NOTES 40 | General notes 41 | #> 42 | [CmdletBinding(HelpUri='https://nexushell.dev/Security/User/Set-NexusUser/')] 43 | Param( 44 | [Parameter(Mandatory)] 45 | [ArgumentCompleter( { 46 | param($Command, $Parameter, $WordToComplete, $CommandAst, $FakeBoundParams) 47 | 48 | $r = (Get-NexusUser).UserName 49 | 50 | if ($WordToComplete) { 51 | $r.Where($_ -match "^$WordToComplete") 52 | } 53 | else { 54 | $r 55 | } 56 | })] 57 | [String] 58 | $Username, 59 | 60 | [Parameter()] 61 | [String] 62 | $FirstName, 63 | 64 | [Parameter()] 65 | [String] 66 | $LastName, 67 | 68 | [Parameter()] 69 | [String] 70 | $EmailAddress, 71 | 72 | [Parameter()] 73 | [ValidateSet('Active', 'Locked', 'Disabled', 'ChangePassword')] 74 | [String] 75 | $Status, 76 | 77 | [Parameter()] 78 | [Switch] 79 | $ReadOnly, 80 | 81 | [Parameter()] 82 | [String[]] 83 | $Roles 84 | ) 85 | 86 | process { 87 | 88 | $user = Get-NexusUser -User $Username 89 | $urislug = "/service/rest/v1/security/users/$Username" 90 | 91 | if($Username -notin $((Get-nexusUser).Username)){ 92 | throw "Username cannot be changed or not found in list of existing users" 93 | } 94 | 95 | switch($null){ 96 | $FirstName { $FirstName = $user.FirstName} 97 | $LastName { $LastName = $user.LastName } 98 | $EmailAddress { $EmailAddress = $user.EmailAddress } 99 | $Status { $Status = $user.Status } 100 | $ReadOnly {[bool]$ReadOnly = $user.ReadOnly } 101 | $Roles { $Roles = $user.Roles} 102 | } 103 | 104 | $Body = @{ 105 | userId = $Username 106 | firstName = $FirstName 107 | lastName = $LastName 108 | emailAddress = $EmailAddress 109 | status = $Status.ToLower() 110 | readOnly = [bool]$ReadOnly 111 | roles = $Roles 112 | source = $($user.Source) 113 | } 114 | 115 | Write-Verbose ($Body | ConvertTo-Json) 116 | Invoke-Nexus -Urislug $urislug -Body $Body -Method PUT 117 | } 118 | } -------------------------------------------------------------------------------- /src/public/Repository/Cleanup Policy/New-NexusCleanupPolicy.ps1: -------------------------------------------------------------------------------- 1 | function New-NexusCleanupPolicy { 2 | <# 3 | .SYNOPSIS 4 | Create a new Nexus Cleanup Policy 5 | 6 | .DESCRIPTION 7 | Create a new Nexus Cleanup Policy 8 | 9 | .PARAMETER Name 10 | Unique name for the cleanup policy 11 | 12 | .PARAMETER Format 13 | The format that this cleanup policy can be applied to 14 | 15 | .PARAMETER Notes 16 | Additional details about the policy 17 | 18 | .PARAMETER ComponentAge 19 | Remove components that were published over this many days 20 | 21 | .PARAMETER ComponentUsage 22 | Remove components that haven't been downloaded in this many days 23 | 24 | .PARAMETER AssetMatcher 25 | Remove components that have at least one asset name matching the following regular expression pattern 26 | 27 | 28 | .EXAMPLE 29 | New-NexusCleanupPolicy -Name SamplePol -Format nuget -ComponentAge 180 30 | 31 | .EXAMPLE 32 | New-NexusCleanupPolicy -Name SamplePol -Format Go -ComponentUsage 90 -AssetMatcher '*.+' 33 | 34 | .NOTES 35 | #> 36 | [CmdletBinding(HelpUri='https://nexushell.dev/Repository/Cleanup%20Policy/New-NexusCleanupPolicy/',DefaultParameterSetName = "Default")] 37 | Param( 38 | [Parameter(Mandatory)] 39 | [Parameter(ParameterSetName = 'Age', Mandatory)] 40 | [Parameter(ParameterSetName = 'Usage', Mandatory)] 41 | 42 | [String] 43 | $Name, 44 | 45 | [Parameter(Mandatory)] 46 | [Parameter(ParameterSetName = 'Age', Mandatory)] 47 | [Parameter(ParameterSetName = 'Usage', Mandatory)] 48 | [ValidateSet('All', 'Apt', 'Bower', 'CocoaPods', 'Conan', 'Conda', 'Docker', 'GitLFS', 'Go', 'Helm', 'Maven2', 'Npm', 'Nuget', 'P2', 'PyPi', 'R', 'Raw', 'RubyGems', 'Yum')] 49 | [String] 50 | $Format, 51 | 52 | [Parameter()] 53 | [String] 54 | $Notes, 55 | 56 | [Parameter(ParameterSetName = 'Age', Mandatory)] 57 | [Int] 58 | $ComponentAge, 59 | 60 | [Parameter(ParameterSetName = 'Usage', Mandatory)] 61 | [Int] 62 | $ComponentUsage, 63 | 64 | [Parameter(ParameterSetName = 'Age')] 65 | [Parameter(ParameterSetName = 'Usage')] 66 | [String] 67 | $AssetMatcher 68 | ) 69 | 70 | process { 71 | 72 | $urislug = "/service/rest/internal/cleanup-policies?_dc=$(([DateTime]::ParseExact("01/02/0001 21:08:29", "MM/dd/yyyy HH:mm:ss",$null)).Ticks)" 73 | 74 | switch ($PSCmdlet.ParameterSetName) { 75 | 'Age' { 76 | $Body = @{ 77 | name = $Name 78 | notes = $Notes 79 | criteriaLastBlobUpdated = $ComponentAge 80 | format = $Format.ToLower() 81 | } 82 | } 83 | 'Usage' { 84 | $Body = @{ 85 | name = $Name 86 | notes = $Notes 87 | criteriaLastDownloaded = $ComponentUsage 88 | format = $Format.ToLower() 89 | } 90 | } 91 | } 92 | 93 | if ($AssetMatcher) { 94 | if ($Format -ne 'All') { 95 | $Body.Add('criteriaAssetRegex', $AssetMatcher) 96 | } else { 97 | Write-Warning "Asset matcher will be thrown out as it doesn't apply to All formats" 98 | } 99 | } 100 | 101 | Invoke-Nexus -UriSlug $urislug -Body $Body -Method POST 102 | } 103 | } -------------------------------------------------------------------------------- /src/public/Support/New-NexusSupportZip.ps1: -------------------------------------------------------------------------------- 1 | function New-NexusSupportZip { 2 | <# 3 | .SYNOPSIS 4 | Prepares a support zip file on your Nexus Server 5 | 6 | .DESCRIPTION 7 | Prepares a support zip file on your Nexus Server 8 | 9 | .PARAMETER IncludeSystemInfo 10 | Includes system info in the zip 11 | 12 | .PARAMETER IncludeThreadDump 13 | Includes a thread dump in the zip 14 | 15 | .PARAMETER IncludeMetrics 16 | Includes metrics in the zip 17 | 18 | .PARAMETER IncludeConfiguration 19 | Includes server configuration in the zip 20 | 21 | .PARAMETER IncludeSecurity 22 | Include security information in the zip 23 | 24 | .PARAMETER IncludeNexusLog 25 | Include the nexus log in the zip 26 | 27 | .PARAMETER IncludeTaskLog 28 | Include the task log in the zip 29 | 30 | .PARAMETER IncludeAuditLog 31 | Include the audit log in the zip 32 | 33 | .PARAMETER IncludeJmx 34 | Include the jmx configuration in the zip 35 | 36 | .PARAMETER LimitFileSize 37 | Limit the output size of files in the zip 38 | 39 | .PARAMETER LimitZipSizes 40 | Limit the overall size of the zip 41 | 42 | .EXAMPLE 43 | New-NexusSupportZip -IncludeNexusLog -IncludeConfiguration 44 | 45 | .NOTES 46 | 47 | #> 48 | [CmdletBinding(HelpUri='https://nexushell.dev/Support/New-NexusSupportZip/')] 49 | Param( 50 | [Parameter()] 51 | [Switch] 52 | $IncludeSystemInfo, 53 | 54 | [Parameter()] 55 | [Switch] 56 | $IncludeThreadDump, 57 | 58 | [Parameter()] 59 | [Switch] 60 | $IncludeMetrics, 61 | 62 | [Parameter()] 63 | [Switch] 64 | $IncludeConfiguration, 65 | 66 | [Parameter()] 67 | [Switch] 68 | $IncludeSecurity, 69 | 70 | [Parameter()] 71 | [Switch] 72 | $IncludeNexusLog, 73 | 74 | [Parameter()] 75 | [Switch] 76 | $IncludeTaskLog, 77 | 78 | [Parameter()] 79 | [Switch] 80 | $IncludeAuditLog, 81 | 82 | [Parameter()] 83 | [Switch] 84 | $IncludeJmx, 85 | 86 | [Parameter()] 87 | [Switch] 88 | $LimitFileSize, 89 | 90 | [Parameter()] 91 | [Switch] 92 | $LimitZipSizes 93 | ) 94 | 95 | begin { 96 | if (-not $header) { 97 | throw "Not connected to Nexus server! Run Connect-NexusServer first." 98 | } 99 | 100 | } 101 | 102 | process { 103 | $Body = @{ 104 | systemInformation = [bool]$IncludeSystemInfo 105 | threadDump = [bool]$IncludeThreadDump 106 | metrics = [bool]$IncludeMetrics 107 | configuration = [bool]$IncludeConfiguration 108 | security = [bool]$IncludeSecurity 109 | log = [bool]$IncludeNexusLog 110 | taskLog = [bool]$IncludeTaskLog 111 | auditLog = [bool]$IncludeAuditLog 112 | jmx = [bool]$IncludeJmx 113 | limitFileSizes = [bool]$LimitFileSize 114 | limitZipSize = [bool]$LimitZipSizes 115 | } 116 | 117 | $urislug = '/service/rest/v1/support/supportzippath' 118 | Write-Verbose ($Body | ConvertTo-Json) 119 | $result = Invoke-Nexus -Urislug $urislug -Body $Body -Method POST 120 | 121 | [pscustomobject]@{ 122 | File = $result.file 123 | Name = $result.name 124 | Size = "$([Math]::Round($result.size,2)) MB" 125 | Truncated = $result.truncated 126 | } 127 | 128 | } 129 | } -------------------------------------------------------------------------------- /src/public/Get-NexusLocalServiceUri.ps1: -------------------------------------------------------------------------------- 1 | function Get-NexusLocalServiceUri { 2 | <# 3 | .SYNOPSIS 4 | Returns the base URI used to access Sonatype Nexus (and it's API) 5 | 6 | .DESCRIPTION 7 | Checks configuration files in order to find which schema, FQDN, port, and path Nexus is being run on, so that we can connect to it. 8 | 9 | .PARAMETER DataDir 10 | The path to the Sonatype Nexus data directory, e.g. C:\ProgramData\sonatype-work\nexus3. 11 | 12 | .PARAMETER ProgramDir 13 | The path to the Sonatype Nexus program files, e.g. C:\ProgramData\nexus. 14 | 15 | .PARAMETER ConfigPath 16 | The path to the in-use config file. Checks for the existance of nexus.properties, and falls back to nexus-default.properties if not present. 17 | 18 | .PARAMETER HostnameOverride 19 | If a wildcard certificate is used, or you want to specify a particular FQDN to access Nexus, you can override the attempted lookup with this parameter. 20 | 21 | .EXAMPLE 22 | Get-NexusLocalServiceUri 23 | 24 | .EXAMPLE 25 | Get-NexusLocalServiceUri -HostnameOverride nexus.fabrikam.com 26 | #> 27 | [CmdletBinding()] 28 | [Alias("Get-NexusUri")] 29 | param( 30 | [Parameter()] 31 | [string]$DataDir = $script:InstalledNexusService.DataFolder, 32 | 33 | [Parameter()] 34 | [string]$ProgramDir = $script:InstalledNexusService.ProgramFolder, 35 | 36 | [Parameter()] 37 | [string]$ConfigPath = $( 38 | if (Test-Path $DataDir/etc/nexus.properties) { 39 | "$DataDir/etc/nexus.properties" 40 | } elseif (Test-Path $ProgramDir/etc/nexus-default.properties) { 41 | "$ProgramDir/etc/nexus-default.properties" 42 | } 43 | ), 44 | 45 | [string]$HostnameOverride 46 | ) 47 | $Scheme, $Hostname, $Port, $Path = if (Test-Path $ConfigPath) { 48 | $Config = Get-NexusConfiguration -Path $ConfigPath -ErrorAction SilentlyContinue 49 | 50 | if ($Config.'application-port-ssl' -gt 0) { 51 | 'https' 52 | if ($CertDomain = Get-NexusCertificateDomain -ConfigPath $ConfigPath) { 53 | if (-not $script:OverriddenDomains) { $script:OverriddenDomains = @{} } 54 | if ($CertDomain -notmatch '^\*') { 55 | $CertDomain 56 | } elseif ($CertDomain -match '^\*' -and $HostnameOverride -like $CertDomain) { 57 | ($script:OverriddenDomains[$CertDomain] = $HostnameOverride) 58 | } elseif ($CertDomain -match '^\*') { 59 | while ($script:OverriddenDomains[$CertDomain] -notlike $CertDomain) { 60 | $script:OverriddenDomains[$CertDomain] = Read-Host "Please provide the FQDN for Nexus matching the '$($CertDomain)' certificate" 61 | } 62 | $script:OverriddenDomains[$CertDomain] 63 | } 64 | } else { 65 | Write-Warning "Could not figure out SSL configuration for $($env:ComputerName) - using 'localhost', specify -HostnameOverride if required." 66 | "localhost" 67 | } 68 | $Config.'application-port-ssl' 69 | } elseif ($Config.'application-port' -gt 0) { 70 | 'http' 71 | if ($HostnameOverride) { 72 | $HostnameOverride 73 | } else { 74 | "localhost" 75 | } 76 | $Config.'application-port' 77 | } else { 78 | "http" 79 | "localhost" 80 | "8081" 81 | } 82 | 83 | $Config.'nexus-context-path' 84 | } 85 | 86 | # Set defaults if still not present 87 | if (-not $Hostname) { $Hostname = "localhost" } 88 | if (-not $Scheme) { $Scheme = 'http' } 89 | if (-not $Port) { $Port = '8081' } 90 | 91 | "$($Scheme)://$($Hostname):$($Port)$($Path)" 92 | } -------------------------------------------------------------------------------- /src/public/Repository/New-NexusRawHostedRepository.ps1: -------------------------------------------------------------------------------- 1 | function New-NexusRawHostedRepository { 2 | <# 3 | .SYNOPSIS 4 | Creates a new Raw Hosted repository 5 | 6 | .DESCRIPTION 7 | Creates a new Raw Hosted repository 8 | 9 | .PARAMETER Name 10 | The Name of the repository to create 11 | 12 | .PARAMETER Online 13 | Mark the repository as Online. Defaults to True 14 | 15 | .PARAMETER BlobStore 16 | The blob store to attach the repository too. Defaults to 'default' 17 | 18 | .PARAMETER UseStrictContentTypeValidation 19 | Validate that all content uploaded to this repository is of a MIME type appropriate for the repository format 20 | 21 | .PARAMETER DeploymentPolicy 22 | Controls if deployments of and updates to artifacts are allowed 23 | 24 | .PARAMETER CleanupPolicy 25 | Components that match any of the Applied policies will be deleted 26 | 27 | .PARAMETER HasProprietaryComponents 28 | Components in this repository count as proprietary for namespace conflict attacks (requires Sonatype Nexus Firewall) 29 | 30 | .PARAMETER ContentDisposition 31 | Add Content-Disposition header as 'Attachment' to disable some content from being inline in a browser. 32 | 33 | .EXAMPLE 34 | New-NexusRawHostedRepository -Name BinaryArtifacts -ContentDisposition Attachment 35 | 36 | .EXAMPLE 37 | $RepoParams = @{ 38 | Name = 'BinaryArtifacts' 39 | Online = $true 40 | UseStrictContentTypeValidation = $true 41 | DeploymentPolicy = 'Allow' 42 | CleanupPolicy = '90Days', 43 | BlobStore = 'AmazonS3Bucket' 44 | } 45 | 46 | New-NexusRawHostedRepository @RepoParams 47 | 48 | .NOTES 49 | #> 50 | [CmdletBinding(HelpUri = 'https://nexushell.dev/New-NexusRawHostedRepository/', DefaultParameterSetname = "Default")] 51 | Param( 52 | [Parameter(Mandatory)] 53 | [String] 54 | $Name, 55 | 56 | [Parameter()] 57 | [Switch] 58 | $Online = $true, 59 | 60 | [Parameter()] 61 | [String] 62 | $BlobStore = 'default', 63 | 64 | [Parameter()] 65 | [Switch] 66 | $UseStrictContentTypeValidation, 67 | 68 | [Parameter()] 69 | [ValidateSet('Allow', 'Deny', 'Allow_Once')] 70 | [String] 71 | $DeploymentPolicy = 'Allow_Once', 72 | 73 | [Parameter()] 74 | [String] 75 | $CleanupPolicy, 76 | 77 | [Parameter()] 78 | [Switch] 79 | $HasProprietaryComponents, 80 | 81 | [Parameter(Mandatory)] 82 | [ValidateSet('Inline','Attachment')] 83 | [String] 84 | $ContentDisposition 85 | ) 86 | 87 | begin { 88 | 89 | if (-not $header) { 90 | throw "Not connected to Nexus server! Run Connect-NexusServer first." 91 | } 92 | 93 | $urislug = "/service/rest/v1/repositories/raw/hosted" 94 | 95 | } 96 | 97 | process { 98 | 99 | $Body = @{ 100 | name = $Name 101 | online = [bool]$Online 102 | storage = @{ 103 | blobStoreName = $BlobStore 104 | strictContentTypeValidation = [bool]$UseStrictContentTypeValidation 105 | writePolicy = $DeploymentPolicy.ToLower() 106 | } 107 | cleanup = @{ 108 | policyNames = @($CleanupPolicy) 109 | } 110 | component = @{ 111 | proprietaryComponents = [bool]$HasProprietaryComponents 112 | } 113 | raw = @{ 114 | contentDisposition = $ContentDisposition.ToUpper() 115 | } 116 | } 117 | 118 | Write-Verbose $($Body | ConvertTo-Json) 119 | $null = Invoke-Nexus -UriSlug $urislug -Body $Body -Method POST 120 | 121 | 122 | } 123 | } --------------------------------------------------------------------------------