Last active
November 28, 2019 10:53
-
-
Save pcrockett-pathway/7e04f393546649fe06bd14334269919e to your computer and use it in GitHub Desktop.
patchbay.pub scripts (see https://patchbay.pub/)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <# | |
| .SYNOPSIS | |
| Receive PGP-encrypted messages from patchbay.pub | |
| .PARAMETER MyId | |
| Your personal PGP key fingerprint | |
| .PARAMETER PubSub | |
| "Publish / Subscribe" mode: Use this switch if multiple subscribers (you | |
| and perhaps other people) will all get the same messages from the | |
| publisher. If you don't specify this switch, one published message will go | |
| to only one subscriber. | |
| If the sender has specified this switch on their end, then you must specify | |
| this switch on your end. If the sender has NOT specified this switch, then | |
| you shouldn't either. | |
| .EXAMPLE | |
| .\Receive-PatchBay.ps1 "8FE971D61F31E38081BFBEC0D1F8F50F1C12EE80" | |
| Receive and decrypt a message from patchbay | |
| .EXAMPLE | |
| .\Receive-PatchBay.ps1 "8FE971D61F31E38081BFBEC0D1F8F50F1C12EE80" | ConvertFrom-Json | |
| Receive, decrypt, and parse a JSON message from patchbay | |
| #> | |
| [CmdletBinding()] | |
| param( | |
| [Parameter(Mandatory=$True)] | |
| [string]$MyId, | |
| [Parameter()] | |
| [switch]$PubSub | |
| ) | |
| $ErrorActionPreference = "Stop" | |
| Set-StrictMode -Version 5.0 | |
| $pubSubVal = ([bool]$PubSub).ToString().ToLowerInvariant() | |
| $uri = "https://patchbay.pub/$($MyId)?pubsub=$pubSubVal" | |
| Invoke-RestMethod -UseBasicParsing -Uri $uri ` | |
| | gpg --decrypt |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <# | |
| .SYNOPSIS | |
| Send signed and encrypted PGP messages via patchbay.pub. | |
| .PARAMETER Recipient | |
| The full PGP public key fingerprint of the recipient you want to send | |
| messages to. | |
| .PARAMETER InputObject | |
| The message(s) you want to send to your recipient | |
| .PARAMETER PubSub | |
| "Publish / Subscribe" mode: Use this switch if multiple subscribers will | |
| all get the same messages from the publisher (you). This will NOT be a | |
| blocking call. | |
| If you don't specify this switch, one published message will go to only one | |
| subscriber, and this WILL be a blocking call. | |
| If you specify this switch, all subscribers must specify it as well. And if | |
| you don't specify this switch, your subscriber also shouldn't. | |
| .EXAMPLE | |
| "Hello!" | .\Send-PatchBay.ps1 "8FE971D61F31E38081BFBEC0D1F8F50F1C12EE80" | |
| Send "Hello!" to the person with the given public key | |
| .EXAMPLE | |
| Get-Process | .\Send-PatchBay.ps1 "8FE971D61F31E38081BFBEC0D1F8F50F1C12EE80" | |
| Send a list of processes to the person with the given public key | |
| .EXAMPLE | |
| [pscustomobject]@{ Foo = "FOO!"; Bar = "BAR!"; } | ConvertTo-Json | .\Send-PatchBay.ps1 "8FE971D61F31E38081BFBEC0D1F8F50F1C12EE80" | |
| Send a JSON object via patchbay. | |
| #> | |
| [CmdletBinding()] | |
| param( | |
| [Parameter(Mandatory=$True)] | |
| [string]$Recipient, | |
| [Parameter(Mandatory=$True, ValueFromPipeline=$True)] | |
| [PSObject]$InputObject, | |
| [Parameter()] | |
| [switch]$PubSub | |
| ) | |
| begin { | |
| $ErrorActionPreference = "Stop" | |
| Set-StrictMode -Version 5.0 | |
| [PSObject[]]$fullMessage = @() | |
| } | |
| process { | |
| $ErrorActionPreference = "Stop" | |
| Set-StrictMode -Version 5.0 | |
| $fullMessage += $InputObject | |
| } | |
| end { | |
| $ErrorActionPreference = "Stop" | |
| Set-StrictMode -Version 5.0 | |
| $pubSubVal = ([bool]$PubSub).ToString().ToLowerInvariant() | |
| $uri = "https://patchbay.pub/$($Recipient)?pubsub=$pubSubVal" | |
| $fullMessage | Out-String ` | |
| | gpg --armor --sign --encrypt --recipient $Recipient ` | |
| | Out-String ` | |
| | Invoke-RestMethod -UseBasicParsing ` | |
| -Uri $uri ` | |
| -Method POST | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment