Skip to content

Commit

Permalink
Merge pull request #15 from JohnDuprey/main
Browse files Browse the repository at this point in the history
Big thanks to @JohnDuprey and the CIPP crew!
  • Loading branch information
adamburley authored Feb 6, 2025
2 parents 62edd5f + ce56697 commit eb4d595
Show file tree
Hide file tree
Showing 16 changed files with 367 additions and 216 deletions.
57 changes: 39 additions & 18 deletions Docs/Initialize-PassPushPosh.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,23 @@ Initialize the PassPushPosh module
## SYNTAX

### Anonymous (Default)
```powershell
```PowerShell
Initialize-PassPushPosh [[-BaseUrl] <String>] [-UserAgent <String>] [-Force]
[-ProgressAction <ActionPreference>] [<CommonParameters>]
```

### Authenticated
```powershell
Initialize-PassPushPosh [-EmailAddress] <String> [-ApiKey] <String> [[-BaseUrl] <String>] [-UserAgent <String>]
```PowerShell
Initialize-PassPushPosh [-EmailAddress] <String> -ApiKey <String> [[-BaseUrl] <String>] [-UserAgent <String>]
[-Force] [-ProgressAction <ActionPreference>] [<CommonParameters>]
```

### Pro
```PowerShell
Initialize-PassPushPosh [-AccountType <String>] -ApiKey <String> [-UserAgent <String>] [-Force]
[-ProgressAction <ActionPreference>] [<CommonParameters>]
```

## DESCRIPTION
Initialize-PassPushPosh sets variables for the module's use during the remainder of the session.
Server URL and User Agent values are set by default but may be overridden.
Expand All @@ -28,23 +34,23 @@ This function is called automatically if needed, defaulting to the public pwpush

## EXAMPLES

### EXAMPLE: Default settings
```powershell
### Default Settings
```PowerShell
PS > Initialize-PassPushPosh
```

Initializes with default settings - anonymous pushes and pwpush.com for the server.

### EXAMPLE: Authentication
```powershell
### Authenticated
```PowerShell
PS > Initialize-PassPushPosh -EmailAddress 'youremail@example.com' -ApiKey '239jf0jsdflskdjf' -Verbose
VERBOSE: Initializing PassPushPosh.
ApiKey: \[x-kdjf\], BaseUrl: https://pwpush.com
```
Initialize with authentication - free account or self-hosted instance.

### EXAMPLE: Private Server
```powershell
### Private Server
```PowerShell
PS > Initialize-PassPushPosh -BaseUrl https://myprivatepwpushinstance.com -EmailAddress 'youremail@example.com' -ApiKey '239jf0jsdflskdjf' -Verbose
VERBOSE: Initializing PassPushPosh.
Expand All @@ -53,15 +59,29 @@ ApiKey: \[x-kdjf\], BaseUrl: https://myprivatepwpushinstance.com

Initialize with another server with authentication

### EXAMPLE: Custom User-Agent
```
### Custom User-Agent
```PowerShell
PS > InitializePassPushPosh -UserAgent "My-CoolUserAgent/1.12.1"
```

User agent must meet [RFC9110](https://www.rfc-editor.org/rfc/rfc9110#name-user-agent) specifications or the Password Pusher API will reject the call.

## PARAMETERS

### -AccountType
For paid users, specify the account type as Premium or Pro.
Not required for free accounts and self-hosted.

```yaml
Type: String
Parameter Sets: Pro
Aliases:

Required: False
Position: Named
Default value: Pro
Accept pipeline input: False
Accept wildcard characters: False
```
### -EmailAddress
Email address for authenticated calls.
Expand All @@ -82,11 +102,11 @@ API key for authenticated calls.
```yaml
Type: String
Parameter Sets: Authenticated
Parameter Sets: Pro, Authenticated
Aliases:

Required: True
Position: 2
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
Expand All @@ -99,7 +119,7 @@ Default: https://pwpush.com
```yaml
Type: String
Parameter Sets: (All)
Parameter Sets: Anonymous, Authenticated
Aliases:

Required: False
Expand Down Expand Up @@ -165,4 +185,5 @@ function has not yet run.
## RELATED LINKS
[https://github.com/adamburley/PassPushPosh/blob/main/Docs/Initialize-PassPushPosh.md](https://github.com/adamburley/PassPushPosh/blob/main/Docs/Initialize-PassPushPosh.md)
[https://github.com/adamburley/PassPushPosh/blob/main/Docs/Initialize-PassPushPosh.md](https://github.com/adamburley/PassPushPosh/blob/main/Docs/Initialize-PassPushPosh.md)
51 changes: 33 additions & 18 deletions Docs/New-Push.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ Create a new Push
## SYNTAX

### Anonymous (Default)
```powershell
```PowerShell
New-Push [-Payload] <String> [-Passphrase <String>] [-ExpireAfterDays <Int32>] [-ExpireAfterViews <Int32>]
[-DeletableByViewer] [-RetrievalStep] [-ProgressAction <ActionPreference>] [-WhatIf] [-Confirm]
[<CommonParameters>]
[-DeletableByViewer] [-RetrievalStep] [-AccountId <Object>] [-ProgressAction <ActionPreference>] [-WhatIf]
[-Confirm] [<CommonParameters>]
```

### Authenticated
```powershell
```PowerShell
New-Push [-Payload] <String> [-Passphrase <String>] [-Note <String>] [-ExpireAfterDays <Int32>]
[-ExpireAfterViews <Int32>] [-DeletableByViewer] [-RetrievalStep] [-ProgressAction <ActionPreference>]
[-WhatIf] [-Confirm] [<CommonParameters>]
[-ExpireAfterViews <Int32>] [-DeletableByViewer] [-RetrievalStep] [-AccountId <Object>]
[-ProgressAction <ActionPreference>] [-WhatIf] [-Confirm] [<CommonParameters>]
```

## DESCRIPTION
Expand All @@ -30,8 +30,8 @@ are always provided at LinkRetrievalStep and LinkDirect properties.

## EXAMPLES

### EXAMPLE: Basic use
```powershell
### Basic Usage
```PowerShell
$myPush = New-Push "Here's my secret!"
PS > $myPush | Select-Object Link, LinkRetrievalStep, LinkDirect
Expand All @@ -40,15 +40,15 @@ LinkRetrievalStep : https://pwpush.com/p/gzv65wiiuciy/r # 1-step
LinkDirect : https://pwpush.com/p/gzv65wiiuciy # Direct
```

### EXAMPLE: Pipeline
```powershell
"Super secret secret" | New-Push -RetrievalStep | Select-Object -ExpandProperty Link
### PipeLine
```PowerShell
PS > "Super secret secret" | New-Push -RetrievalStep | Select-Object -ExpandProperty Link
https://pwpush.com/p/gzv65wiiuciy/r
```

### EXAMPLE: Burn after reading-style
```powershell
### "Burn after reading" style
```PowerShell
PS > New-Push -Payload "Still secret text!" -ExpireAfterViews 1 -RetrievalStep
```

Expand Down Expand Up @@ -166,6 +166,22 @@ Accept pipeline input: False
Accept wildcard characters: False
```
### -AccountId
Account ID to associate with this push.
Requires a Pro subscription.
```yaml
Type: Object
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -WhatIf
Shows what would happen if the cmdlet runs.
The cmdlet is not run.
Expand Down Expand Up @@ -203,11 +219,11 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable
## INPUTS
- [string] A password to send
-
## OUTPUTS
- [PasswordPush] Representation of the submitted push
-
## NOTES
Maximum for -ExpireAfterDays and -ExpireAfterViews is based on the default
values for Password Pusher and what's used on the public instance
Expand All @@ -217,8 +233,7 @@ override that value you'll need to fork this module.
## RELATED LINKS
[https://github.com/adamburley/PassPushPosh/blob/main/Docs/New-Push.md](https://github.com/adamburley/PassPushPosh/blob/main/Docs/New-Push.md)
[New-Push](https://github.com/adamburley/PassPushPosh/blob/main/Docs/New-Push.md)
[https://pwpush.com/api/1.0/passwords/create.en.html](https://pwpush.com/api/1.0/passwords/create.en.html)
[Get-Push](https://github.com/adamburley/PassPushPosh/blob/main/Docs/Get-Push.md)
[https://github.com/pglombardo/PasswordPusher/blob/c2909b2d5f1315f9b66939c9fbc7fd47b0cfeb03/app/controllers/passwords_controller.rb#L120](https://github.com/pglombardo/PasswordPusher/blob/c2909b2d5f1315f9b66939c9fbc7fd47b0cfeb03/app/controllers/passwords_controller.rb#L120)
5 changes: 4 additions & 1 deletion Docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
| --- | --- |
| [Get-Dashboard](./docs/Get-Dashboard.md) | Get a list of active or expired Pushes for an authenticated user |
| [Get-Push](./docs/Get-Push.md) | Retrieve the secret contents of a Push |
| [Get-PushAccount](./docs/Get-PushAccount.md) | Get a list of accounts for an authenticated user |
| [Get-PushAuditLog](./docs/Get-PushAuditLog.md) | Get the view log of an authenticated Push |
| [Get-SecretLink](./docs/Get-SecretLink.md) | Returns a fully qualified secret link to a push of given URL Token |
| [Initialize-PassPushPosh](./docs/Initialize-PassPushPosh.md) | Initialize the PassPushPosh module |
| [New-Push](./docs/New-Push.md) | Create a new Push |
| [Remove-Push](./docs/Remove-Push.md) | Remove a Push |
| [Get-PushPreview](./docs/Get-PushPreview.md) | Returns a fully qualified secret link to a push of given URL Token |
| [Get-PushPreview](./docs/Get-PushPreview.md) | Returns a fully qualified secret link to a push of given URL Token |

#
26 changes: 13 additions & 13 deletions PassPushPosh/Classes/PasswordPush.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@


$this | Add-Member -Name 'UrlToken' -MemberType ScriptProperty -Value {
return $this.__UrlToken
} -SecondValue {
$this.__UrlToken = $_
$this.__LinkBase = "$Script:PPPBaseUrl/p/$($this.__UrlToken)"
}
return $this.__UrlToken
} -SecondValue {
$this.__UrlToken = $_
$this.__LinkBase = $_j.html_url ?? "$Script:PPPBaseUrl/p/$($this.__UrlToken)"
}
$this.__UrlToken = $_j.url_token
$this.__LinkBase = "$Script:PPPBaseUrl/p/$($this.__UrlToken)"
$this.__LinkBase = $_j.html_url ?? "$Script:PPPBaseUrl/p/$($this.__UrlToken)"
$this | Add-Member -Name 'LinkDirect' -MemberType ScriptProperty -Value { return $this.__LinkBase } -SecondValue {
Write-Warning 'LinkDirect is a read-only calculated member.'
Write-Debug 'Link* members are calculated based on the Global BaseUrl and Push Retrieval Step values'
Expand All @@ -68,12 +68,12 @@
Write-Debug 'Link* members are calculated based on the Global BaseUrl and Push Retrieval Step values'
}
$this | Add-Member -Name 'Link' -MemberType ScriptProperty -Value {
$_Link = if ($this.RetrievalStep) { $this.LinkRetrievalStep } else { $this.LinkDirect }
Write-Debug "Presented Link: $_link"
$_Link
} -SecondValue {
Write-Warning 'Link is a read-only calculated member.'
Write-Debug 'Link* members are calculated based on the Global BaseUrl and Push Retrieval Step values'
}
$_Link = if ($this.RetrievalStep) { $this.LinkRetrievalStep } else { $this.LinkDirect }
Write-Debug "Presented Link: $_link"
$_Link
} -SecondValue {
Write-Warning 'Link is a read-only calculated member.'
Write-Debug 'Link* members are calculated based on the Global BaseUrl and Push Retrieval Step values'
}
}
}
9 changes: 5 additions & 4 deletions PassPushPosh/PassPushPosh.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# Generated by: Adam Burley
#
# Generated on: 9/3/2024
# Generated on: 2/6/2025
#

@{
Expand All @@ -12,10 +12,10 @@
RootModule = 'PassPushPosh.psm1'

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

# Supported PSEditions
CompatiblePSEditions = @('Core')
CompatiblePSEditions = 'Core'

# ID used to uniquely identify this module
GUID = '5d8a1afd-a912-440f-a9b9-e79f42a05f21'
Expand Down Expand Up @@ -104,10 +104,11 @@ PrivateData = @{
ProjectUri = 'https://github.com/adamburley/PassPushPosh'

# A URL to an icon representing this module.
# IconUri = 'https://github.com/adamburley/PassPushPosh/blob/main/pwplogo85x85.png?raw=true'
IconUri = 'https://github.com/adamburley/PassPushPosh/blob/main/pwplogo85x85.png?raw=true'

# ReleaseNotes of this module
ReleaseNotes = '
1.2.0 - Add compatibility with Premium and Pro API endpoints and branding.
1.0.0 - Major refactor, add capabilities and improve testing and build process.
0.3.0 - Remove route translations from URI segments for compatibility with PasswordPusher v1.42.0. See pglombardo/PasswordPusher/pull/2353'

Expand Down
1 change: 1 addition & 0 deletions PassPushPosh/Private/Format-PasswordPusherSecret.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
function Format-PasswordPusherSecret {
[CmdletBinding()]
[OutputType([string])]
param(
[Parameter(Mandatory)]
[AllowEmptyString()]
Expand Down
12 changes: 7 additions & 5 deletions PassPushPosh/Private/Invoke-PasswordPusherAPI.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ function Invoke-PasswordPusherAPI {
}
if ($Script:PPPHeaders.'X-User-Token') {
$iwrSplat['Headers'] = $Script:PPPHeaders
Write-Debug "Authentciated with API token $(Format-PasswordPusherSecret -Secret $Script:PPPHeaders.'X-User-Token' -ShowSample)"
Write-Debug "Authenticated with API token $(Format-PasswordPusherSecret -Secret $Script:PPPHeaders.'X-User-Token' -ShowSample)"
}
if ($Script:PPPHeaders.'Authorization') {
$iwrSplat['Headers'] = $Script:PPPHeaders
Write-Debug "Authenticated with API token $(Format-PasswordPusherSecret -Secret $Script:PPPHeaders.'Authorization' -ShowSample)"
}
$callInfo = "$Method $_uri"
Write-Verbose "Sending HTTP request: $callInfo"
Expand All @@ -32,12 +36,10 @@ function Invoke-PasswordPusherAPI {
$result = $call.Content | ConvertFrom-Json
if ($ReturnErrors -or $call.StatusCode -eq 200 -or $null -eq $result.error) {
$result
}
else {
} else {
Write-Error -Message "$callInfo : $($call.StatusCode) $($result.error)"
}
}
else {
} else {
Write-Error -Message "Parseable JSON not returned by API. $callInfo : $($call.StatusCode) $($call.Content)"
}
}
Expand Down
21 changes: 21 additions & 0 deletions PassPushPosh/Public/Get-PushAccount.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<#
.SYNOPSIS
Get a list of accounts for an authenticated user
.DESCRIPTION
Retrieves a list of accounts for an authenticated user.
.LINK
Get-PushAuditLog
#>
function Get-PushAccount {
[CmdletBinding()]
[OutputType([PasswordPush[]])]
param()
process {
if (-not $Script:PPPHeaders) { Write-Error 'Dashboard access requires authentication. Run Initialize-PassPushPosh and pass your email address and API key before retrying.' -ErrorAction Stop -Category AuthenticationError }
$uri = 'api/v1/accounts'
Invoke-PasswordPusherAPI -Endpoint $uri -Method Get
}
}
Loading

0 comments on commit eb4d595

Please sign in to comment.