Files
ben marsh 0a70a2d14e Horde: Add a setting for configuring the Horde server to the editor.
- Falls back to the UE_HORDE_URL environment variable or value configured in the registry from UGS if not set.
- Added support to OIDCToken for configuring using Horde settings using the --HordeUrl argument.
- Added overloads to HordeHttpClient to query auth settings from Horde itself.

#jira UE-211751

[CL 33009887 by ben marsh in ue5-main branch]
2024-04-16 14:55:33 -04:00

102 lines
2.4 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "HordeHttpClient.h"
#include "Server/ServerMessages.h"
#include "Interfaces/IHttpResponse.h"
#include "DesktopPlatformModule.h"
#include "IDesktopPlatform.h"
#include "HttpModule.h"
#include "Misc/Paths.h"
#include "HAL/PlatformMisc.h"
FHordeHttpClient::FHordeHttpClient(FString InServerUrl)
: ServerUrl(InServerUrl)
{
}
FHordeHttpClient::~FHordeHttpClient()
{
}
bool FHordeHttpClient::Login(bool bUnattended, FFeedbackContext* Warn)
{
IDesktopPlatform* DesktopPlatform = FDesktopPlatformModule::TryGet();
if (DesktopPlatform != nullptr)
{
FString NewToken;
FDateTime ExpiresAt;
bool bWasInteractive = false;
if (DesktopPlatform->GetHordeAccessToken(ServerUrl, bUnattended, Warn, NewToken, ExpiresAt, bWasInteractive))
{
Token = NewToken;
return true;
}
}
return false;
}
bool FHordeHttpClient::LoginWithOidc(const TCHAR* Profile, bool bUnattended, FFeedbackContext* Warn)
{
IDesktopPlatform* DesktopPlatform = FDesktopPlatformModule::TryGet();
if (DesktopPlatform != nullptr)
{
FString NewToken;
FDateTime ExpiresAt;
bool bWasInteractive = false;
if (DesktopPlatform->GetOidcAccessToken(FPaths::RootDir(), FString(), Profile, bUnattended, Warn, NewToken, ExpiresAt, bWasInteractive))
{
Token = NewToken;
return true;
}
}
return false;
}
bool FHordeHttpClient::LoginWithEnvironmentVariable()
{
FString EnvVarHordeToken = FPlatformMisc::GetEnvironmentVariable(TEXT("UE_HORDE_TOKEN"));
if (!EnvVarHordeToken.IsEmpty())
{
Token = MoveTemp(EnvVarHordeToken);
return true;
}
return false;
}
TSharedRef<IHttpRequest> FHordeHttpClient::CreateRequest(const TCHAR* Verb, const TCHAR* Path)
{
FHttpModule& Module = FHttpModule::Get();
TSharedRef<IHttpRequest> Request = Module.CreateRequest();
Request->SetVerb(Verb);
Request->SetURL(ServerUrl / Path);
if (Token.Len() > 0)
{
Request->SetHeader(TEXT("Authorization"), FString::Printf(TEXT("Bearer %s"), *Token));
}
return Request;
}
TSharedRef<IHttpResponse> FHordeHttpClient::Get(const TCHAR* Path)
{
return ExecuteRequest(CreateRequest(TEXT("GET"), Path));
}
TSharedRef<IHttpResponse> FHordeHttpClient::ExecuteRequest(TSharedRef<IHttpRequest> Request)
{
verify(Request->ProcessRequest());
for (;;)
{
FHttpResponsePtr Response = Request->GetResponse();
if (Response)
{
return Response.ToSharedRef();
}
FPlatformProcess::Sleep(0.05f);
}
}