From fa3f672be9153a4a10c956f29eb7a1b953cc26f7 Mon Sep 17 00:00:00 2001 From: Kamil Pro Date: Sun, 24 Mar 2024 21:15:44 +0000 Subject: [PATCH 1/7] Add URL push --- src/public/URL/New-PwpushUrl.ps1 | 61 ++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 src/public/URL/New-PwpushUrl.ps1 diff --git a/src/public/URL/New-PwpushUrl.ps1 b/src/public/URL/New-PwpushUrl.ps1 new file mode 100644 index 0000000..4d058b2 --- /dev/null +++ b/src/public/URL/New-PwpushUrl.ps1 @@ -0,0 +1,61 @@ +function New-PwpushUrl +{ + <# + .SYNOPSIS + Create a new URL push. + .DESCRIPTION + Create a new URL push. + .LINK + https://pwpush.com/api/1.0/urls/create.en.html + .EXAMPLE + New-KpPwpushFile -Payload mySecret + Creates a new push with payload of mySecret + #> + + [cmdletbinding()] + param ( + [Parameter(Mandatory)] + [string]$Payload, + + [string]$Passphrase, + + [string]$Note = "", + + [ValidateRange(1, 90)] + [int]$ExpireAfterDays = 7, + + [ValidateRange(1, 100)] + [int]$ExpireAfterViews = 5, + + [bool]$DeletableByViewer = $true, + + [bool]$RetrievalStep = $false + ) + + $endpoint = "r.json" + + $data = @{ + url = @{ + "payload" = $Payload + "expire_after_days" = $ExpireAfterDays + "expire_after_views" = $ExpireAfterViews + "deletable_by_viewer" = $DeletableByViewer + "retrieval_step" = $RetrievalStep + } + } + + switch ($PSBoundParameters.GetEnumerator() ) + { + { $_.Key -eq "Note" } { $data.url[$_.Key.ToLower()] = $_.Value } + { $_.Key -eq "Passphrase" } { $data.url[$_.Key.ToLower()] = $_.Value } + } + + $body = $data | ConvertTo-Json + + $params = @{ + Endpoint = $endpoint + Method = "Post" + Body = $body + } + Invoke-PwpushRequest @params +} \ No newline at end of file From c871edfe9b75a0a7db0fa23840652b8e28e4c38a Mon Sep 17 00:00:00 2001 From: Kamil Pro Date: Mon, 6 May 2024 17:50:15 +0100 Subject: [PATCH 2/7] Add URL expired function --- src/public/URL/Get-PwpushUrlExpired.ps1 | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/public/URL/Get-PwpushUrlExpired.ps1 diff --git a/src/public/URL/Get-PwpushUrlExpired.ps1 b/src/public/URL/Get-PwpushUrlExpired.ps1 new file mode 100644 index 0000000..ef1f950 --- /dev/null +++ b/src/public/URL/Get-PwpushUrlExpired.ps1 @@ -0,0 +1,18 @@ +function Get-PwpushUrlExpired +{ + <# + .SYNOPSIS + Retrieves a push including it’s payload and details. If the push is still active, this will burn a view and the transaction will be logged in the push audit log. + #> + [cmdletbinding()] + param ( + ) + + $endpoint = "r/expired.json" + + $params = @{ + Endpoint = $endpoint + Method = "Get" + } + Invoke-PwpushRequest @params +} \ No newline at end of file From b803d197262d167338a68a212799942bed668076 Mon Sep 17 00:00:00 2001 From: Kamil Pro Date: Mon, 6 May 2024 17:52:01 +0100 Subject: [PATCH 3/7] Add URL active --- src/public/URL/Get-PwpushUrlActive.ps1 | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/public/URL/Get-PwpushUrlActive.ps1 diff --git a/src/public/URL/Get-PwpushUrlActive.ps1 b/src/public/URL/Get-PwpushUrlActive.ps1 new file mode 100644 index 0000000..d5bc5af --- /dev/null +++ b/src/public/URL/Get-PwpushUrlActive.ps1 @@ -0,0 +1,18 @@ +function Get-PwpushUrlActive +{ + <# + .SYNOPSIS + Returns the list of URL pushes that you previously pushed which are still active. + #> + [cmdletbinding()] + param ( + ) + + $endpoint = "r/active.json" + + $params = @{ + Endpoint = $endpoint + Method = "Get" + } + Invoke-PwpushRequest @params +} \ No newline at end of file From e893c0b8bd50a0187a8c781fcb3d60effc4def4b Mon Sep 17 00:00:00 2001 From: Kamil Pro Date: Mon, 6 May 2024 18:07:36 +0100 Subject: [PATCH 4/7] add retrieve URL --- src/public/URL/Get-PwpushUrl.ps1 | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/public/URL/Get-PwpushUrl.ps1 diff --git a/src/public/URL/Get-PwpushUrl.ps1 b/src/public/URL/Get-PwpushUrl.ps1 new file mode 100644 index 0000000..501c54d --- /dev/null +++ b/src/public/URL/Get-PwpushUrl.ps1 @@ -0,0 +1,29 @@ +function Get-PwpushUrl +{ + <# + .SYNOPSIS + Retrieves a URL push. + .DESCRIPTION + Retrieves a push including it’s payload and details. If the push is still active, this will burn a view and the transaction will be logged in the push audit log. + .PARAMETER UrlToken + Token of the push + .LINK + https://pwpush.com/api/1.0/urls/show.en.html + .EXAMPLE + Get-KpPwpushUrl -UrlToken abc123 + Retrieves push with token abc123 + #> + [cmdletbinding()] + param ( + [Parameter(Mandatory)] + [string]$UrlToken + ) + + $endpoint = "r/$($UrlToken).json" + + $params = @{ + Endpoint = $endpoint + Method = "Get" + } + Invoke-PwpushRequest @params +} \ No newline at end of file From 808bdfddcaf5c621b50b3082ceb8dd47cfa6812d Mon Sep 17 00:00:00 2001 From: Kamil Pro Date: Mon, 6 May 2024 18:07:53 +0100 Subject: [PATCH 5/7] Add ability to keep module loaded --- build-scripts/Start-ModuleBuild.ps1 | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/build-scripts/Start-ModuleBuild.ps1 b/build-scripts/Start-ModuleBuild.ps1 index 4d34440..7091907 100644 --- a/build-scripts/Start-ModuleBuild.ps1 +++ b/build-scripts/Start-ModuleBuild.ps1 @@ -1,7 +1,9 @@ param ( [string]$Version = "1.0.0", - [string]$Name = "KpPwpush" + [string]$Name = "KpPwpush", + + [switch]$KeepLoaded ) #Requires -Module "ModuleBuilder" @@ -14,12 +16,12 @@ $root = Resolve-Path -Path "$PSScriptRoot/../" Write-Host "root: [$($root)]" $params = @{ - SourcePath = "$PSScriptRoot/../src/KpPwpush.psd1" + SourcePath = "$PSScriptRoot/../src/KpPwpush.psd1" UnversionedOutputDirectory = $true - Version = $Version - Passthru = $true - Verbose = $true - OutputDirectory = "$root/build" + Version = $Version + Passthru = $true + Verbose = $true + OutputDirectory = "$root/build" } $result = Build-Module @params @@ -37,4 +39,10 @@ finally { Write-Host "Unloading module" Remove-Module -Name $result.Name -ErrorAction SilentlyContinue +} + +if ($KeepLoaded) +{ + Write-Host "Keeping loaded module" + Import-Module -Name $result.Path -Verbose:$false -Force } \ No newline at end of file From 41b9fc7e6df94ee687d4c4beb14801cdc5cdfbac Mon Sep 17 00:00:00 2001 From: Kamil Pro Date: Mon, 6 May 2024 18:40:32 +0100 Subject: [PATCH 6/7] add url preview --- src/public/URL/Get-PwpushUrlPreview.ps1 | 29 +++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/public/URL/Get-PwpushUrlPreview.ps1 diff --git a/src/public/URL/Get-PwpushUrlPreview.ps1 b/src/public/URL/Get-PwpushUrlPreview.ps1 new file mode 100644 index 0000000..37a0332 --- /dev/null +++ b/src/public/URL/Get-PwpushUrlPreview.ps1 @@ -0,0 +1,29 @@ +function Get-PwpushUrlPreview +{ + <# + .SYNOPSIS + Helper endpoint to retrieve the fully qualified secret URL of a push. + .DESCRIPTION + Helper endpoint to retrieve the fully qualified secret URL of a push. + .PARAMETER UrlToken + Secret URL token of a previously created push + .LINK + https://pwpush.com/api/1.0/urls/preview.en.html + .EXAMPLE + Get-KpPwpushPreviewUrl -UrlToken 123abc + Retrieves URL for token 123abc + #> + [cmdletbinding()] + param ( + [Parameter(Mandatory)] + [string]$UrlToken + ) + + $endpoint = "r/$($UrlToken)/preview.json" + + $params = @{ + Endpoint = $endpoint + Method = "Get" + } + Invoke-PwpushRequest @params +} \ No newline at end of file From eece71ea0277bcbed21b574fd7983cbc78b18dc2 Mon Sep 17 00:00:00 2001 From: Kamil Pro Date: Mon, 6 May 2024 18:42:37 +0100 Subject: [PATCH 7/7] add url removal --- src/public/URL/Remove-PwpushUrl.ps1 | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/public/URL/Remove-PwpushUrl.ps1 diff --git a/src/public/URL/Remove-PwpushUrl.ps1 b/src/public/URL/Remove-PwpushUrl.ps1 new file mode 100644 index 0000000..28f5ee0 --- /dev/null +++ b/src/public/URL/Remove-PwpushUrl.ps1 @@ -0,0 +1,29 @@ +function Remove-PwpushUrl +{ + <# + .SYNOPSIS + Expires a push + .DESCRIPTION + Expires a push immediately. Must be authenticated & owner of the push or the push must have been created with deleteable_by_viewer + .LINK + https://pwpush.com/api/1.0/passwords/destroy.en.html + .PARAMETER UrlToken + Token of a push + .EXAMPLE + Remove-KpPwPush -UrlToken abc123 + Expires token abc123 + #> + [cmdletbinding()] + param ( + [Parameter(Mandatory)] + [string]$UrlToken + ) + + $endpoint = "r/$($UrlToken).json" + + $params = @{ + Endpoint = $endpoint + Method = "Delete" + } + Invoke-PwpushRequest @params +} \ No newline at end of file