Renamed 'key' to 'base' to avoid future problems with secrets patterns, cleanup and improvements

Signed-off-by: lsemp3d <58790905+lsemp3d@users.noreply.github.com>
This commit is contained in:
lsemp3d
2021-11-23 08:50:41 -08:00
parent 9e6e83ff7f
commit 2da3ab42fd
21 changed files with 74 additions and 172 deletions
@@ -19,7 +19,6 @@
#include <GraphCanvas/Components/StyleBus.h>
#include <GraphCanvas/Components/VisualBus.h>
#include <GraphCanvas/Types/EntitySaveData.h>
#include <GraphCanvas/Types/TranslationTypes.h>
#include <Widgets/GraphCanvasLabel.h>
namespace GraphCanvas
@@ -58,7 +58,6 @@
#include <GraphCanvas/Types/ConstructPresets.h>
#include <GraphCanvas/Types/EntitySaveData.h>
#include <GraphCanvas/Types/TranslationTypes.h>
#include <GraphCanvas/Widgets/GraphCanvasEditor/GraphCanvasAssetEditorMainWindow.h>
#include <GraphCanvas/Widgets/GraphCanvasMimeEvent.h>
@@ -59,14 +59,14 @@ namespace GraphCanvas
//!
//! Requirements:
//! - Must have a top level array called "entries"
//! - Must provide a "key" element for any entry added
//! - Must provide a "base" element for any entry added
//!
//! Example:
//!
//! {
//! "entries": [
//! {
//! "key": "Globals",
//! "base": "Globals",
//! "details": {
//! "name": "My Name",
//! "tooltip": "My Tooltip"
@@ -90,21 +90,21 @@ namespace GraphCanvas
//! Globals.details.somearray.0.name
//! Globals.details.somearray.1.name
//!
//! There is one important aspect however, if an element in an array has a "key" value, the value of this key
//! There is one important aspect however, if an element in an array has a "base" value, the value of this key
//! will replace the index. This is useful when the index and/or ordering of an entry is not relevant or may
//! change.
//!
//! "somearray": [ {
//! "name": "First one"
//! "key": "a_key"
//! "base": "a_key"
//! }, {
//! "name": "Second one",
//! "key": "b_key"
//! "base": "b_key"
//! } ]
//!
//! Globals.details.somearray.0.key == "a_key"
//! Globals.details.somearray.0.base == "a_key"
//! Globals.details.somearray.0.name == "First one"
//! Globals.details.somearray.1.key == "b_key"
//! Globals.details.somearray.1.base == "b_key"
//! Globals.details.somearray.1.name == "Second one"
//!
class TranslationAssetHandler
@@ -11,17 +11,6 @@
namespace GraphCanvas
{
namespace Schema
{
namespace Field
{
static constexpr char key[] = "key";
static constexpr char context[] = "context";
static constexpr char variant[] = "variant";
static constexpr char entries[] = "entries";
}
}
AZ_CLASS_ALLOCATOR_IMPL(TranslationFormatSerializer, AZ::SystemAllocator, 0);
void AddEntryToDatabase(const AZStd::string& baseKey, const AZStd::string& name, const rapidjson::Value& it, TranslationFormat* translationFormat)
@@ -76,11 +65,15 @@ namespace GraphCanvas
const rapidjson::Value& array = it;
for (rapidjson::SizeType i = 0; i < array.Size(); ++i)
{
// so, here, I need to go in and if there is a "key" member within the object, then I need to use that,
// if there isn't, I can use the %d
// if there is a "base" member within the object, then use it, otherwise use the index
if (array[i].IsObject())
{
if (array[i].HasMember(Schema::Field::key))
if (array[i].HasMember(Schema::Field::deprecated_key))
{
AZStd::string innerKey = array[i].FindMember(Schema::Field::deprecated_key)->value.GetString();
itemKey.append(AZStd::string::format(".%s", innerKey.c_str()));
}
else if (array[i].HasMember(Schema::Field::key))
{
AZStd::string innerKey = array[i].FindMember(Schema::Field::key)->value.GetString();
itemKey.append(AZStd::string::format(".%s", innerKey.c_str()));
@@ -133,7 +126,12 @@ namespace GraphCanvas
AZStd::string keyStr;
rapidjson::Value::ConstMemberIterator keyValue;
if (entry.HasMember(Schema::Field::key))
if (entry.HasMember(Schema::Field::deprecated_key))
{
keyValue = entry.FindMember(Schema::Field::deprecated_key);
keyStr = keyValue->value.GetString();
}
else if (entry.HasMember(Schema::Field::key))
{
keyValue = entry.FindMember(Schema::Field::key);
keyStr = keyValue->value.GetString();
@@ -23,4 +23,17 @@ namespace GraphCanvas
AZ::JsonSerializationResult::Result Store(rapidjson::Value& outputValue, const void* inputValue,
const void* defaultValue, const AZ::Uuid& valueTypeId, AZ::JsonSerializerContext& context) override;
};
namespace Schema
{
namespace Field
{
// Moved away from "key" due to some strict filtering on secrets
static constexpr char deprecated_key[] = "key";
static constexpr char key[] = "base";
static constexpr char context[] = "context";
static constexpr char variant[] = "variant";
static constexpr char entries[] = "entries";
}
}
}
@@ -16,7 +16,6 @@ AZ_PUSH_DISABLE_WARNING(4251 4800, "-Wunknown-warning-option")
AZ_POP_DISABLE_WARNING
#include <GraphCanvas/Styling/StyleHelper.h>
#include <GraphCanvas/Types/TranslationTypes.h>
namespace GraphCanvas
{