Created
February 14, 2018 19:38
-
-
Save torgro/6b61228b7351909ef5185caecdf0da5d 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
$GetFileEndpoint = New-UDEndpoint -Url "/file/" -Method "GET" -Endpoint { | |
Param( | |
$Authorization | |
) | |
if ($request.headers.ContainsKey("Authorization")) | |
{ | |
$Authorization = $request.headers["Authorization"].ToString() | |
} | |
if ([string]::IsNullOrEmpty($Authorization)) | |
{ | |
throw "You shall not pass" | |
} | |
$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 ($Secret -eq 'foo:bar') | |
{ | |
$output = foreach ($f in (Get-ChildItem -Path $path)) | |
{ | |
$fileObj = [pscustomobject]@{ | |
Name = $f.Name | |
Size = $f.Length | |
BaseName = $f.BaseName | |
Extension = $f.Extension | |
} | |
$fileObj | |
} | |
$output | 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