Skip to content

Instantly share code, notes, and snippets.

Tore Groneng torgro

View GitHub Profile
View log.ps1
function Test-Command
{
[cmdletbinding()]
Param()
write-verbose -Message "Start"
}
function Write-Verbose
{
[cmdletbinding()]
View CreateManifest.ps1
$exportFunctions = (Get-ChildItem -Path .\Functions -Filter "*.ps1").BaseName
$manifestPath = Join-Path -Path .\ -ChildPath FilesAPI.psd1
$newManifest = @{
Path = $manifestPath
Guid = ([guid]::NewGuid())
Author = "SomeDude"
CompanyName = "Contoso"
RootModule = "FilesAPI.psm1"
Description = "Awsome files module"
View NewSet-FileApi.ps1
function Set-FileApi
{
[cmdletbinding(
SupportsShouldProcess
)]
Param(
[Parameter(Mandatory)]
[hashtable]
$Authorization
,
View NewCreateFileEndpoint.ps1
$CreateFileEndpoint = New-UDEndpoint -Url "/file/" -Method "Post" -Endpoint {
Param(
$Authorization
,
$FileName
,
$Content
)
$secretBytes = [System.Convert]::FromBase64String(($Authorization -replace "Basic "))
View Set-FileApi.ps1
function Set-FileApi
{
[cmdletbinding(
SupportsShouldProcess
)]
Param(
[Parameter(Mandatory)]
[hashtable]
$Authorization
,
View newGet-FileApi.ps1
function Get-FileApi
{
[cmdletbinding()]
Param(
[Parameter(Mandatory)]
[hashtable]
$Authorization
,
[string]
$Name
View NewGetFileEndpoint.ps1
$GetFileEndpoint = New-UDEndpoint -Url "/file/" -Method "GET" -Endpoint {
Param(
$Authorization
,
$Name
)
if ($request.headers.ContainsKey("Authorization"))
{
$Authorization = $request.headers["Authorization"].ToString()
View Get-FileApi.ps1
function Get-FileApi
{
[cmdletbinding()]
Param(
[Parameter(Mandatory)]
[hashtable]
$Authorization
,
[string]
$Name
View CreateModule.ps1
$ModuleScript = {
$folders = @('functions', 'private', 'classes')
ForEach ($folder in $folders)
{
$currentPath = $PSScriptRoot | Join-Path -ChildPath $folder
If (Test-Path -Path $currentPath -PathType Container)
{
$functions = Get-ChildItem -Path $currentPath -Filter '*.ps1'
View RegisterEndpoint.ps1
Start-UDRestApi -Port 11000 -Endpoint @($CreateFileEndpoint, $GetFileEndpoint)
$securePwd = ConvertTo-SecureString -String bar -AsPlainText -Force
$authKey = [PSCredential]::New("foo", $securePwd) | Get-AuthorizationHeader
$invokeSplat = @{
Uri = "http://localhost:11000/api/file"
Method = 'Get'
Headers = $authKey
}
You can’t perform that action at this time.