Created
December 16, 2022 20:25
-
-
Save gmccoy/56b942d3876bee8ad66d16576970a07d to your computer and use it in GitHub Desktop.
PowerShell module for controlling FileLocker
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
# PowerShell Module for uploading files to FileLocker | |
# Greg McCoy gmccoy@purdue.edu | |
# 15 May 2020 | |
function Sign-In { | |
param( | |
[Parameter(Mandatory=$true)] [string]$Key, | |
[Parameter(Mandatory=$true)] [string]$User | |
) | |
$body = @{CLIkey=$Key; userId=$User} | |
$headers = @{Accept='text/xml'} | |
$junk = Invoke-WebRequest -Body $body -Method 'POST' -Headers $headers -Uri 'https://filelocker.purdue.edu/cli_interface/CLI_login' -SessionVariable 'Session' | |
return $Session | |
} | |
function Add-File { | |
param( | |
[Parameter(Mandatory=$true)] [string]$Key, | |
[Parameter(Mandatory=$true)] [string]$User, | |
[Parameter(Mandatory=$true)] [string]$FilePath | |
) | |
$body = @{format='cli'} | |
$headers = @{Accept='text/xml'} | |
$Session = Sign-In -Key $Key -User $User | |
$filename = Split-Path $FilePath -leaf | |
$result = Invoke-WebRequest -WebSession $Session -Infile $FilePath -Method 'POST' -Headers $headers -Uri "https://filelocker.purdue.edu/file_interface/upload?format=cli&fileName=$filename" -ContentType 'application/octet-stream' | |
([xml]$result.Content).cli_response.data.file.id | |
} | |
function Get-Files { | |
param( | |
[Parameter(Mandatory=$true)] [string]$Key, | |
[Parameter(Mandatory=$true)] [string]$User | |
) | |
$Session = Sign-In -Key $Key -User $User | |
$body = @{format='cli'} | |
$headers = @{Accept='text/xml'} | |
$result = Invoke-WebRequest -WebSession $Session -Body $body -Method 'POST' -Headers $headers -Uri 'https://filelocker.purdue.edu/file_interface/get_user_file_list' | |
([xml]$result.Content).cli_response.data.file | |
} | |
function Grant-Access { | |
param( | |
[Parameter(Mandatory=$true)] [string]$Key, | |
[Parameter(Mandatory=$true)] [string]$User, | |
[Parameter(Mandatory=$true)] [int]$FileId, | |
[Parameter(Mandatory=$true)] [string]$ShareWith | |
) | |
$Session = Sign-In -Key $Key -User $User | |
$body = @{format='cli'; fileIds=$FileId; targetId=$ShareWith} | |
$headers = @{Accept='text/xml'} | |
$result = Invoke-WebRequest -WebSession $Session -Body $body -Method 'POST' -Headers $headers -Uri 'https://filelocker.purdue.edu/share_interface/create_private_share' | |
} | |
Export-ModuleMember -Function Add-File | |
Export-ModuleMember -Function Get-Files | |
Export-ModuleMember -Function Grant-Access |
Sign in
to join this conversation on GitHub.