Last active
February 17, 2018 23:24
-
-
Save torgro/ed63aeb38cd74c5b9104edf9b5d187d3 to your computer and use it in GitHub Desktop.
This file contains 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
$CreateFileEndpoint = New-UDEndpoint -Url "/file/" -Method "Post" -Endpoint { | |
Param( | |
$Authorization | |
, | |
$FileName | |
, | |
$Content | |
) | |
$secretBytes = [System.Convert]::FromBase64String(($Authorization -replace "Basic ")) | |
[string]$Secret = [System.Text.Encoding]::UTF8.GetString($secretBytes) | |
$path = Join-Path -Path c: -ChildPath temp | Join-Path -ChildPath Api | |
if ([string]::IsNullOrEmpty($Authorization)) | |
{ | |
throw "You shall not pass" | |
} | |
if ($Secret -eq 'foo:bar') | |
{ | |
$fullPath = Join-Path -Path $path -ChildPath $FileName | |
Set-Content -Path $fullPath -Value $Content | |
$file = Get-ChildItem -Path $fullPath | |
[pscustomobject]@{ | |
Name = $file.Name | |
Size = $file.Length | |
BaseName = $file.BaseName | |
Extension = $file.Extension | |
} | ConvertTo-Json | |
} | |
else | |
{ | |
throw "You shall not pass" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment