Lesson 35 - Get Compute Auth Token Working
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
#include "AwsAccountCredentials.h"
|
||||
|
||||
#include <future>
|
||||
|
||||
#include "aws/gamelift/core/exports.h"
|
||||
|
||||
#include "GameLiftCoreLog.h"
|
||||
#include "GameLiftCoreConstants.h"
|
||||
#include "Utils/NativeLogPrinter.h"
|
||||
#include "AwsErrors/Converter.h"
|
||||
|
||||
namespace AwsAccountCredentialsInternal
|
||||
{
|
||||
void LogCallback(unsigned int InLevel, const char* InMessage, int InSize)
|
||||
{
|
||||
auto Level = Logs::PrintAwsLog(InLevel, InMessage, InSize, Credentials::Logs::kLogReceived);
|
||||
}
|
||||
} // namespace AwsAccountCredentialsInternal
|
||||
|
||||
inline AwsAccountCredentials::AwsAccountCredentials(const FString& ProfileName, TSharedRef<IAWSConfigFileProfile> ProfileReader)
|
||||
{
|
||||
StdRegion = Convertors::FSToStdS(ProfileReader->GetRegion(ProfileName));
|
||||
StdAccessKey = Convertors::FSToStdS(ProfileReader->GetAccessKey(ProfileName));
|
||||
StdSecretKey = Convertors::FSToStdS(ProfileReader->GetSecretAccessKey(ProfileName));
|
||||
}
|
||||
|
||||
int AwsAccountCredentials::BuildCredentials()
|
||||
{
|
||||
std::promise<std::string> Promise;
|
||||
|
||||
CharPtrCallback DispatchReceiver = [](DISPATCH_RECEIVER_HANDLE InPromise, const char* CharPtr)
|
||||
{
|
||||
((std::promise<std::string>*) InPromise)->set_value(CharPtr);
|
||||
};
|
||||
|
||||
unsigned int Status = GameLiftGetAwsAccountId(&Promise, DispatchReceiver, StdAccessKey.c_str(),
|
||||
StdSecretKey.c_str(), &AwsAccountCredentialsInternal::LogCallback);
|
||||
|
||||
if (Status != GameLift::GAMELIFT_SUCCESS)
|
||||
{
|
||||
UE_LOG(GameLiftCoreLog, Error, TEXT("%s %s"), Credentials::Logs::kUnableToGetAccountId, *GameLiftErrorAsString::Convert(Status));
|
||||
return Status;
|
||||
}
|
||||
|
||||
StdAccountId = Promise.get_future().get();
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
GameLift::AccountCredentials AwsAccountCredentials::GetCredentials() const
|
||||
{
|
||||
GameLift::AccountCredentials GameLiftCredentials;
|
||||
|
||||
GameLiftCredentials.region = StdRegion.c_str();
|
||||
GameLiftCredentials.accessKey = StdAccessKey.c_str();
|
||||
GameLiftCredentials.accessSecret = StdSecretKey.c_str();
|
||||
GameLiftCredentials.accountId = StdAccountId.c_str();
|
||||
|
||||
return GameLiftCredentials;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "IAWSConfigFileProfile.h"
|
||||
#include "Utils/StringConvertors.h"
|
||||
|
||||
#include "aws/gamelift/core/model/account_credentials.h"
|
||||
|
||||
class AwsAccountCredentials
|
||||
{
|
||||
public:
|
||||
AwsAccountCredentials(const FString& ProfileName, TSharedRef<IAWSConfigFileProfile> ProfileReader);
|
||||
|
||||
GameLift::AccountCredentials GetCredentials() const;
|
||||
int BuildCredentials();
|
||||
|
||||
private:
|
||||
std::string StdRegion;
|
||||
std::string StdAccessKey;
|
||||
std::string StdSecretKey;
|
||||
std::string StdAccountId;
|
||||
};
|
||||
@@ -0,0 +1,85 @@
|
||||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
#include "AwsAccountInfo.h"
|
||||
|
||||
#include "GameLiftCoreLog.h"
|
||||
#include "GameLiftCoreConstants.h"
|
||||
|
||||
#include <Misc/App.h>
|
||||
#include <Interfaces/IPluginManager.h>
|
||||
#include <Runtime/EngineSettings/Classes/GeneralProjectSettings.h>
|
||||
|
||||
#include "aws/gamelift/core/exports.h"
|
||||
|
||||
namespace AwsAccountInfoInternal
|
||||
{
|
||||
void LogCallback(unsigned int InLevel, const char* InMessage, int InSize)
|
||||
{
|
||||
UE_LOG(GameLiftCoreLog, Log, TEXT("AwsAccountInfo: %s"), *FString(InMessage));
|
||||
}
|
||||
} // namespace AwsAccountInfoInternal
|
||||
|
||||
int AwsAccountInfo::BuildAccountInfo(std::string BootstrapBucketName)
|
||||
{
|
||||
StdGameName = Convertors::FSToStdS(FApp::GetName());
|
||||
StdBuildConfiguration = "dev";
|
||||
StdBucketName = BootstrapBucketName;
|
||||
|
||||
UGeneralProjectSettings* ProjectSettings = GetMutableDefault<UGeneralProjectSettings>();
|
||||
StdCompanyName = Convertors::FSToStdS(ProjectSettings->CompanyName);
|
||||
|
||||
return GameLift::GAMELIFT_SUCCESS;
|
||||
}
|
||||
|
||||
void AwsAccountInfo::SetGameName(std::string NewGameName)
|
||||
{
|
||||
StdGameName = NewGameName;
|
||||
}
|
||||
|
||||
void AwsAccountInfo::SetBucketName(std::string BucketName)
|
||||
{
|
||||
StdBucketName = BucketName;
|
||||
}
|
||||
|
||||
GameLift::AccountInfo AwsAccountInfo::GetAccountInfo() const
|
||||
{
|
||||
auto GetCString = [&](const std::string& StdString) -> const char*
|
||||
{
|
||||
return StdString.length() > 1 ? StdString.c_str() : "";
|
||||
};
|
||||
|
||||
GameLift::AccountInfo GameLiftAccountInfo;
|
||||
GameLiftAccountInfo.environment = GetCString(StdBuildConfiguration);
|
||||
GameLiftAccountInfo.accountId = GetCString(StdAccountId);
|
||||
GameLiftAccountInfo.companyName = GetCString(StdCompanyName);
|
||||
GameLiftAccountInfo.gameName = GetCString(StdGameName);
|
||||
GameLiftAccountInfo.bucketName = GetCString(StdBucketName);
|
||||
|
||||
return GameLiftAccountInfo;
|
||||
}
|
||||
|
||||
const std::string& AwsAccountInfo::GetAccountId() const
|
||||
{
|
||||
return StdAccountId;
|
||||
}
|
||||
|
||||
const std::string& AwsAccountInfo::GetBucketName() const
|
||||
{
|
||||
return StdBucketName;
|
||||
}
|
||||
|
||||
const std::string& AwsAccountInfo::GetBuildConfiguration() const
|
||||
{
|
||||
return StdBuildConfiguration;
|
||||
}
|
||||
|
||||
const std::string& AwsAccountInfo::GetCompanyName() const
|
||||
{
|
||||
return StdCompanyName;
|
||||
}
|
||||
|
||||
const std::string& AwsAccountInfo::GetGameName() const
|
||||
{
|
||||
return StdGameName;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "IAWSConfigFileProfile.h"
|
||||
#include "Utils/StringConvertors.h"
|
||||
|
||||
#include "aws/gamelift/core/model/account_info.h"
|
||||
|
||||
class AwsAccountInfo
|
||||
{
|
||||
public:
|
||||
AwsAccountInfo(const char* AccountId = "") : StdAccountId(AccountId) {}
|
||||
|
||||
GameLift::AccountInfo GetAccountInfo() const;
|
||||
|
||||
int BuildAccountInfo(std::string BootstrapBucketName = "");
|
||||
|
||||
void SetGameName(std::string NewGameName);
|
||||
void SetBucketName(std::string NewBucketName);
|
||||
|
||||
const std::string& GetAccountId() const;
|
||||
const std::string& GetBucketName() const;
|
||||
const std::string& GetBuildConfiguration() const;
|
||||
const std::string& GetCompanyName() const;
|
||||
const std::string& GetGameName() const;
|
||||
|
||||
private:
|
||||
std::string StdAccountId;
|
||||
std::string StdBucketName;
|
||||
std::string StdBuildConfiguration;
|
||||
std::string StdCompanyName;
|
||||
std::string StdGameName;
|
||||
};
|
||||
@@ -0,0 +1,133 @@
|
||||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
#include "AwsAccountInstanceManager.h"
|
||||
|
||||
#include "GameLiftCoreLog.h"
|
||||
#include "GameLiftCoreConstants.h"
|
||||
|
||||
#include "aws/gamelift/core/errors.h"
|
||||
#include "aws/gamelift/core/exports.h"
|
||||
|
||||
#include "AwsAccount/AwsAccountCredentials.h"
|
||||
#include "AwsAccount/AwsAccountInfo.h"
|
||||
|
||||
#include "Utils/StringPaths.h"
|
||||
#include "Utils/NativeLogPrinter.h"
|
||||
#include "Utils/LogMessageStorage.h"
|
||||
|
||||
namespace AwsAccountInstanceInternal
|
||||
{
|
||||
static Logs::MessageStorage sLatestAccountConfigurationLogErrorMessage = {};
|
||||
|
||||
void LogCallback(unsigned int InLevel, const char* InMessage, int InSize)
|
||||
{
|
||||
auto Level = Logs::PrintAwsLog(InLevel, InMessage, InSize, Account::Logs::kLogReceived);
|
||||
|
||||
if (Level == ELogVerbosity::Error)
|
||||
{
|
||||
sLatestAccountConfigurationLogErrorMessage.Set(InMessage);
|
||||
}
|
||||
}
|
||||
} // namespace AwsAccountInstanceInternal
|
||||
|
||||
AwsAccountInstanceManager::AwsAccountInstanceManager()
|
||||
: AccountInstance(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
AwsAccountInstanceManager::~AwsAccountInstanceManager()
|
||||
{
|
||||
ReleaseInstance();
|
||||
}
|
||||
|
||||
bool AwsAccountInstanceManager::IsValid() const
|
||||
{
|
||||
return GameLiftAccountHasValidCredentials(static_cast<GAMELIFT_ACCOUNT_INSTANCE_HANDLE>(AccountInstance));
|
||||
}
|
||||
|
||||
FString AwsAccountInstanceManager::GetBucketName() const
|
||||
{
|
||||
return BucketName;
|
||||
}
|
||||
|
||||
int AwsAccountInstanceManager::BuildInstance(const FString& InProfile, TSharedRef<IAWSConfigFileProfile> InProfileReader, const FString& InExistingBucketName, const FString& InRootPath, const FString& InPluginRootPath)
|
||||
{
|
||||
ReleaseInstance();
|
||||
|
||||
std::string StdBucketName = Convertors::FSToStdS(InExistingBucketName);
|
||||
auto result = AccountInfo.BuildAccountInfo(StdBucketName);
|
||||
|
||||
if (result != GameLift::GAMELIFT_SUCCESS)
|
||||
{
|
||||
UE_LOG(GameLiftCoreLog, Warning, TEXT("%s"), Account::Logs::kUnableToBuildAccountInfo);
|
||||
return result;
|
||||
}
|
||||
|
||||
GameLift::AccountInfo AccountInfoData = AccountInfo.GetAccountInfo();
|
||||
std::string StdRootPath = Convertors::FSToStdS(InRootPath);
|
||||
std::string StdPluginRootPath = Convertors::FSToStdS(InPluginRootPath);
|
||||
std::string ProfileName = Convertors::FSToStdS(InProfile);
|
||||
|
||||
AccountInstance = GameLiftAccountInstanceCreateWithRootPathsAndProfile(
|
||||
AccountInfoData,
|
||||
ProfileName.c_str(),
|
||||
StdRootPath.c_str(),
|
||||
StdPluginRootPath.c_str(),
|
||||
&AwsAccountInstanceInternal::LogCallback
|
||||
);
|
||||
|
||||
if (AccountInstance == nullptr)
|
||||
{
|
||||
UE_LOG(GameLiftCoreLog, Warning, TEXT("%s"), Account::Logs::kAccountIsNotCreated);
|
||||
return GameLift::GAMELIFT_ERROR_GENERAL;
|
||||
}
|
||||
|
||||
if (!IsValid())
|
||||
{
|
||||
UE_LOG(GameLiftCoreLog, Warning, TEXT("%s"), Account::Logs::kAccountIsInvalid);
|
||||
return GameLift::GAMELIFT_ERROR_GENERAL;
|
||||
}
|
||||
|
||||
return GameLift::GAMELIFT_SUCCESS;
|
||||
}
|
||||
|
||||
void AwsAccountInstanceManager::ReleaseInstance()
|
||||
{
|
||||
AwsAccountInstanceInternal::sLatestAccountConfigurationLogErrorMessage.Clear();
|
||||
|
||||
if (AccountInstance != nullptr)
|
||||
{
|
||||
GameLiftAccountInstanceRelease(AccountInstance);
|
||||
}
|
||||
}
|
||||
|
||||
void AwsAccountInstanceManager::SetBucketName(const FString& NewBucketName)
|
||||
{
|
||||
BucketName = NewBucketName;
|
||||
}
|
||||
|
||||
void* AwsAccountInstanceManager::GetInstance() const
|
||||
{
|
||||
return AccountInstance;
|
||||
}
|
||||
|
||||
const char* AwsAccountInstanceManager::GetGameName() const
|
||||
{
|
||||
return AccountInfo.GetGameName().c_str();
|
||||
}
|
||||
|
||||
const char* AwsAccountInstanceManager::GetAccountId() const
|
||||
{
|
||||
return AccountInfo.GetAccountId().c_str();
|
||||
}
|
||||
|
||||
const char* AwsAccountInstanceManager::GetBuildConfiguration() const
|
||||
{
|
||||
return AccountInfo.GetBuildConfiguration().c_str();
|
||||
}
|
||||
|
||||
FString AwsAccountInstanceManager::GetLastErrorMessage() const
|
||||
{
|
||||
return AwsAccountInstanceInternal::sLatestAccountConfigurationLogErrorMessage.Get();
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "IAWSAccountInstance.h"
|
||||
#include "AwsAccount/AwsAccountInfo.h"
|
||||
|
||||
class AwsAccountInstanceManager : public IAWSAccountInstance
|
||||
{
|
||||
public:
|
||||
AwsAccountInstanceManager();
|
||||
virtual ~AwsAccountInstanceManager();
|
||||
|
||||
int BuildInstance(const FString& Profile, TSharedRef<IAWSConfigFileProfile> ProfileReader, const FString& ExistingBucketName, const FString& RootPath, const FString& PluginRootPath);
|
||||
void ReleaseInstance();
|
||||
|
||||
void SetBucketName(const FString& NewBucketName);
|
||||
|
||||
virtual void* GetInstance() const override;
|
||||
virtual bool IsValid() const override;
|
||||
virtual FString GetBucketName() const override;
|
||||
virtual const char* GetGameName() const override;
|
||||
virtual const char* GetAccountId() const override;
|
||||
virtual const char* GetBuildConfiguration() const override;
|
||||
virtual FString GetLastErrorMessage() const override;
|
||||
|
||||
private:
|
||||
AwsAccountInfo AccountInfo;
|
||||
void* AccountInstance;
|
||||
FString BucketName;
|
||||
};
|
||||
Reference in New Issue
Block a user