Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add number of URL endpoints #5

Merged
merged 7 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions build-scripts/Start-ModuleBuild.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
param (
[string]$Version = "1.0.0",

[string]$Name = "KpPwpush"
[string]$Name = "KpPwpush",

[switch]$KeepLoaded
)

#Requires -Module "ModuleBuilder"
Expand All @@ -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
Expand All @@ -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
}
29 changes: 29 additions & 0 deletions src/public/URL/Get-PwpushUrl.ps1
Original file line number Diff line number Diff line change
@@ -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
}
18 changes: 18 additions & 0 deletions src/public/URL/Get-PwpushUrlActive.ps1
Original file line number Diff line number Diff line change
@@ -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
}
18 changes: 18 additions & 0 deletions src/public/URL/Get-PwpushUrlExpired.ps1
Original file line number Diff line number Diff line change
@@ -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
}
29 changes: 29 additions & 0 deletions src/public/URL/Get-PwpushUrlPreview.ps1
Original file line number Diff line number Diff line change
@@ -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
}
61 changes: 61 additions & 0 deletions src/public/URL/New-PwpushUrl.ps1
Original file line number Diff line number Diff line change
@@ -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
}
29 changes: 29 additions & 0 deletions src/public/URL/Remove-PwpushUrl.ps1
Original file line number Diff line number Diff line change
@@ -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
}