Initial commit

This commit is contained in:
Laurence Horrocks-Barlow 2026-05-19 00:35:27 +01:00
commit 6bf433c9a9
20 changed files with 1162 additions and 0 deletions

View file

@ -0,0 +1,80 @@
function Connect-GpfsServer {
[CmdletBinding(DefaultParameterSetName = 'Credential')]
param(
[Parameter(Mandatory, Position = 0)]
[string]$Server,
[Parameter()]
[int]$Port = 443,
[Parameter()]
[ValidateSet('v2')]
[string]$ApiVersion = 'v2',
[Parameter(Mandatory, ParameterSetName = 'Credential')]
[PSCredential]$Credential,
[Parameter(Mandatory, ParameterSetName = 'UserPass')]
[string]$Username,
[Parameter(Mandatory, ParameterSetName = 'UserPass')]
[SecureString]$Password,
[Parameter()]
[switch]$UseSsl,
[Parameter()]
[switch]$SkipCertificateCheck,
[Parameter()]
[int]$TimeoutSeconds = 30,
[Parameter()]
[switch]$PassThru
)
if ($PSCmdlet.ParameterSetName -eq 'UserPass') {
$Credential = [PSCredential]::new($Username, $Password)
}
$protocol = if ($UseSsl) { 'https' } else { 'https' }
$baseUrl = '{0}://{1}:{2}' -f $protocol, $Server, $Port
$plainPass = $Credential.GetNetworkCredential().Password
$credBytes = [System.Text.Encoding]::UTF8.GetBytes('{0}:{1}' -f $Credential.UserName, $plainPass)
$encodedCred = [Convert]::ToBase64String($credBytes)
$script:GpfsSession = @{
Server = $Server
Port = $Port
BaseUrl = $baseUrl
ApiVersion = $ApiVersion
SkipCertificateCheck = $SkipCertificateCheck.IsPresent
TimeoutSeconds = $TimeoutSeconds
Headers = @{
Authorization = "Basic $encodedCred"
Accept = 'application/json'
}
}
try {
$cluster = Invoke-GpfsApiRequest -Method GET -Endpoint 'cluster'
Write-Verbose "Connected to GPFS cluster: $($cluster.cluster.clusterName)"
}
catch {
$script:GpfsSession = $null
throw "Failed to connect to GPFS server '$Server': $_"
}
if ($PassThru) {
[PSCustomObject]@{
Server = $Server
Port = $Port
ApiVersion = $ApiVersion
Connected = $true
}
}
else {
Write-Host "Connected to GPFS server: $Server ($ApiVersion)" -ForegroundColor Green
}
}