' .NET 8+ console project: dotnet new console -lang VB; replace Program.vb.
Imports System
Imports System.Net.Http
Imports System.Net.Http.Headers
Imports System.Threading.Tasks
Module Program
 Sub Main()
  RunAsync().GetAwaiter().GetResult()
 End Sub
 Private Async Function RunAsync() As Task
  Dim baseUrl = Environment.GetEnvironmentVariable("REDROVER_URL")
  Dim apiKey = Environment.GetEnvironmentVariable("REDROVER_API_KEY")
  If String.IsNullOrWhiteSpace(baseUrl) OrElse String.IsNullOrWhiteSpace(apiKey) Then Throw New InvalidOperationException("Set REDROVER_URL and REDROVER_API_KEY.")
  Dim address As New Uri(baseUrl.TrimEnd("/"c) & "/api/v1/workspaces")
  If address.Scheme <> "https" AndAlso Not address.IsLoopback Then Throw New InvalidOperationException("Use HTTPS outside localhost.")
  Using handler As New HttpClientHandler With {.AllowAutoRedirect = False}
   Using client As New HttpClient(handler) With {.Timeout = TimeSpan.FromSeconds(30)}
    Using request As New HttpRequestMessage(HttpMethod.Get, address)
     request.Headers.Add("X-API-Key", apiKey)
     request.Headers.Accept.Add(New MediaTypeWithQualityHeaderValue("application/json"))
     Using response = Await client.SendAsync(request)
      response.EnsureSuccessStatusCode()
      Console.WriteLine("Workspace request succeeded (" & CInt(response.StatusCode) & ").")
     End Using
    End Using
   End Using
  End Using
 End Function
End Module
