From f3ef3e01acd183eefb864f2adcffe65fed783e3f Mon Sep 17 00:00:00 2001 From: ben marsh Date: Sat, 2 Dec 2023 21:19:55 -0500 Subject: [PATCH] [Backout] - CL30069106 [FYI] Ben.Marsh Original CL Desc ----------------------------------------------------------------- Horde: Add a typed HTTP client for communicating with the Horde server. Removes boilerplate code for getting an access token, configuring request objects, and parsing responses. Synchronous for now. [CL 30069215 by ben marsh in ue5-main branch] --- .../Private/DesktopPlatformBase.cpp | 5 +- Engine/Source/Developer/Horde/Horde.Build.cs | 2 +- .../Horde/Private/HordeHttpClient.cpp | 70 ------------------- .../Horde/Private/Server/ServerMessages.cpp | 37 ---------- .../Developer/Horde/Public/HordeHttpClient.h | 34 --------- .../Horde/Public/Server/ServerMessages.h | 44 ------------ 6 files changed, 2 insertions(+), 190 deletions(-) delete mode 100644 Engine/Source/Developer/Horde/Private/HordeHttpClient.cpp delete mode 100644 Engine/Source/Developer/Horde/Private/Server/ServerMessages.cpp delete mode 100644 Engine/Source/Developer/Horde/Public/HordeHttpClient.h delete mode 100644 Engine/Source/Developer/Horde/Public/Server/ServerMessages.h diff --git a/Engine/Source/Developer/DesktopPlatform/Private/DesktopPlatformBase.cpp b/Engine/Source/Developer/DesktopPlatform/Private/DesktopPlatformBase.cpp index d95cd07bcc37..73e1e428f3ae 100644 --- a/Engine/Source/Developer/DesktopPlatform/Private/DesktopPlatformBase.cpp +++ b/Engine/Source/Developer/DesktopPlatform/Private/DesktopPlatformBase.cpp @@ -820,10 +820,7 @@ bool FDesktopPlatformBase::GetOidcAccessToken(const FString& RootDir, const FStr FString Arguments = TEXT(" "); Arguments += FString::Printf(TEXT(" --Service=\"%s\""), *ProviderIdentifier); Arguments += FString::Printf(TEXT(" --OutFile=\"%s\""), *ResultFilePath); - if (ProjectFileName.Len() > 0) - { - Arguments += FString::Printf(TEXT(" --project=\"%s\""), *IFileManager::Get().ConvertToAbsolutePathForExternalAppForRead(*FPaths::GetPath(*ProjectFileName))); - } + Arguments += FString::Printf(TEXT(" --project=\"%s\""), *IFileManager::Get().ConvertToAbsolutePathForExternalAppForRead(*FPaths::ProjectDir())); FString UnattendedArguments = Arguments; UnattendedArguments += TEXT(" --Unattended=true"); diff --git a/Engine/Source/Developer/Horde/Horde.Build.cs b/Engine/Source/Developer/Horde/Horde.Build.cs index 7cf564c1c972..543017071810 100644 --- a/Engine/Source/Developer/Horde/Horde.Build.cs +++ b/Engine/Source/Developer/Horde/Horde.Build.cs @@ -7,6 +7,6 @@ public class Horde : ModuleRules { public Horde(ReadOnlyTargetRules Target) : base(Target) { - PrivateDependencyModuleNames.AddRange(new string[] { "Core", "HTTP", "Json", "DesktopPlatform" }); + PrivateDependencyModuleNames.AddRange(new string[] { "Core" }); } } diff --git a/Engine/Source/Developer/Horde/Private/HordeHttpClient.cpp b/Engine/Source/Developer/Horde/Private/HordeHttpClient.cpp deleted file mode 100644 index 1476a24fb841..000000000000 --- a/Engine/Source/Developer/Horde/Private/HordeHttpClient.cpp +++ /dev/null @@ -1,70 +0,0 @@ -// 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" - -FHordeHttpClient::FHordeHttpClient(FString InServerUrl) - : ServerUrl(InServerUrl) -{ -} - -FHordeHttpClient::~FHordeHttpClient() -{ -} - -bool FHordeHttpClient::LoginWithOidc(const TCHAR* Profile, bool bUnattended, FFeedbackContext* Warn) -{ - IDesktopPlatform* DesktopPlatform = FDesktopPlatformModule::Get(); - - FString NewToken; - FDateTime ExpiresAt; - bool bWasInteractive = false; - - if (!DesktopPlatform->GetOidcAccessToken(FPaths::RootDir(), FString(), Profile, bUnattended, Warn, NewToken, ExpiresAt, bWasInteractive)) - { - return false; - } - - Token = NewToken; - return true; -} - -TSharedRef FHordeHttpClient::CreateRequest(const TCHAR* Verb, const TCHAR* Path) -{ - FHttpModule& Module = FHttpModule::Get(); - - TSharedRef 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 FHordeHttpClient::Get(const TCHAR* Path) -{ - return ExecuteRequest(CreateRequest(TEXT("GET"), Path)); -} - -TSharedRef FHordeHttpClient::ExecuteRequest(TSharedRef Request) -{ - verify(Request->ProcessRequest()); - - for (;;) - { - FHttpResponsePtr Response = Request->GetResponse(); - if (Response) - { - return Response.ToSharedRef(); - } - FPlatformProcess::Sleep(0.05f); - } -} diff --git a/Engine/Source/Developer/Horde/Private/Server/ServerMessages.cpp b/Engine/Source/Developer/Horde/Private/Server/ServerMessages.cpp deleted file mode 100644 index 3c8e2042500a..000000000000 --- a/Engine/Source/Developer/Horde/Private/Server/ServerMessages.cpp +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright Epic Games, Inc. All Rights Reserved. - -#include "Server/ServerMessages.h" - -FGetServerInfoResponse::FGetServerInfoResponse() -{ -} - -FGetServerInfoResponse::~FGetServerInfoResponse() -{ -} - -void FGetServerInfoResponse::Serialize(FJsonSerializerBase& Serializer, bool bFlatObject) -{ - JSON_SERIALIZE("ServerVersion", ServerVersion); - JSON_SERIALIZE("AgentVersion", AgentVersion); - JSON_SERIALIZE("OsDescription", OsDescription); -} - -// ------------------------------------- - -FGetAuthConfigResponse::FGetAuthConfigResponse() -{ -} - -FGetAuthConfigResponse::~FGetAuthConfigResponse() -{ -} - -void FGetAuthConfigResponse::Serialize(FJsonSerializerBase& Serializer, bool bFlatObject) -{ - JSON_SERIALIZE("Method", Method); - JSON_SERIALIZE("ServerUrl", ServerUrl); - JSON_SERIALIZE("ClientId", ClientId); - JSON_SERIALIZE_ARRAY("LocalRedirectUrls", LocalRedirectUrls); -} - diff --git a/Engine/Source/Developer/Horde/Public/HordeHttpClient.h b/Engine/Source/Developer/Horde/Public/HordeHttpClient.h deleted file mode 100644 index c94a8885fb72..000000000000 --- a/Engine/Source/Developer/Horde/Public/HordeHttpClient.h +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright Epic Games, Inc. All Rights Reserved. - -#pragma once - -#include "CoreMinimal.h" -#include "Containers/UnrealString.h" -#include "Interfaces/IHttpRequest.h" -#include "Interfaces/IHttpResponse.h" - -class HORDE_API FHordeHttpClient -{ -public: - FHordeHttpClient(FString InServerUrl); - ~FHordeHttpClient(); - - bool LoginWithOidc(const TCHAR* Profile, bool bUnattended, FFeedbackContext* Warn = nullptr); - - TSharedRef CreateRequest(const TCHAR* Verb, const TCHAR* Path); - TSharedRef Get(const TCHAR* Path); - - template - T Get(const TCHAR* Path) - { - T Result; - Result.FromJson(Get(Path)->GetContentAsString()); - return Result; - } - - static TSharedRef ExecuteRequest(TSharedRef Request); - -private: - FString ServerUrl; - FString Token; -}; diff --git a/Engine/Source/Developer/Horde/Public/Server/ServerMessages.h b/Engine/Source/Developer/Horde/Public/Server/ServerMessages.h deleted file mode 100644 index 7d02e10720fb..000000000000 --- a/Engine/Source/Developer/Horde/Public/Server/ServerMessages.h +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright Epic Games, Inc. All Rights Reserved. - -#pragma once - -#include "CoreMinimal.h" -#include "Serialization/JsonSerializerMacros.h" - -/** Server Info */ -struct FGetServerInfoResponse : FJsonSerializable -{ - /** Server version info */ - FString ServerVersion; - - /** The current agent version string */ - FString AgentVersion; - - /** The operating system server is hosted on */ - FString OsDescription; - - FGetServerInfoResponse(); - virtual ~FGetServerInfoResponse() override; - virtual void Serialize(FJsonSerializerBase& Serializer, bool bFlatObject) override; -}; - -/** Describes the auth config for this server */ -struct FGetAuthConfigResponse : FJsonSerializable -{ - /** Issuer for tokens from the auth provider */ - FString Method; - - /** Issuer for tokens from the auth provider */ - FString ServerUrl; - - /** Client id for the OIDC authority */ - FString ClientId; - - /** Optional redirect url provided to OIDC login for external tools (typically to a local server) */ - TArray LocalRedirectUrls; - - FGetAuthConfigResponse(); - virtual ~FGetAuthConfigResponse() override; - virtual void Serialize(FJsonSerializerBase& Serializer, bool bFlatObject) override; -}; -