Skip to content

Commit 392b448

Browse files
Merge pull request #33 from steviecoaster/develop
Prep 1.1.0 release
2 parents 08d8896 + bac23e7 commit 392b448

13 files changed

+436
-10
lines changed

README.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,20 @@
44

55
A PowerShell module for Sonatype Nexus repository server administration
66

7-
## Try it out!
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+
```
820

9-
1. Clone this repo and run `.\build.ps1 -Build` from the cloned folder
10-
2. Import the module with `Import-Module .\Output\NexuShell\NexuShell.psd1` from the cloned folder
11-
3. Discover the available commands with `Get-Command -Module NexuShell`
12-
4. Explore the available commands with `Get-Help`
13-
5. Start having fun!
1421

1522
### Documentation
1623

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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://steviecoaster.github.io/NexuShell/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+
}

src/public/Security/ContentSelector/Get-NexusContentSelector.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function Get-NexusContentSelector {
1818
.NOTES
1919
2020
#>
21-
[CmdletBinding(HelpUri='')]
21+
[CmdletBinding(HelpUri='https://steviecoaster.github.io/NexuShell/Security/Content%20Selectors/Get-NexusContentSelector/')]
2222
Param(
2323
[Parameter()]
2424
[String[]]

src/public/Security/ContentSelector/New-NexusContentSelector.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function New-NexusContentSelector {
2121
.NOTES
2222
2323
#>
24-
[CmdletBinding(HelpUri='')]
24+
[CmdletBinding(HelpUri='https://steviecoaster.github.io/NexuShell/Security/Content%20Selectors/New-NexusContentSelector/')]
2525
Param(
2626
[Parameter(Mandatory)]
2727
[String]

src/public/Security/ContentSelector/Remove-NexusContentSelector.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function Remove-NexusContentSelector {
2424
.NOTES
2525
2626
#>
27-
[CmdletBinding(HelpUri = '',SupportsShouldProcess,ConfirmImpact='High')]
27+
[CmdletBinding(HelpUri = 'https://steviecoaster.github.io/NexuShell/Security/Content%20Selectors/Remove-NexusContentSelector/',SupportsShouldProcess,ConfirmImpact='High')]
2828
Param(
2929
[Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)]
3030
[ArgumentCompleter( {

src/public/Security/ContentSelector/Set-NexusContentSelector.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function Set-NexusContentSelector {
2121
.NOTES
2222
2323
#>
24-
[CmdletBinding(HelpUri='')]
24+
[CmdletBinding(HelpUri='https://steviecoaster.github.io/NexuShell/Security/Content%20Selectors/Set-NexusContentSelector/')]
2525
Param(
2626
[Parameter(Mandatory)]
2727
[ArgumentCompleter({
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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://steviecoaster.github.io/NexuShell/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/Tags/Get-NexusTag.ps1

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
function Get-NexusTag {
2+
[Cmdletbinding(HelpUri = 'https://steviecoaster.github.io/NexuShell/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/Tags/New-NexusTag.ps1

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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://steviecoaster.github.io/NexuShell/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+
}

0 commit comments

Comments
 (0)