This is an automated email from the ASF dual-hosted git repository.
dmeden pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/master by this push:
new 383b754534 records.yaml - Move common code to a single place. (#9603)
383b754534 is described below
commit 383b754534146eeb6042fd56ce00f0a61edea3d8
Author: Damian Meden <[email protected]>
AuthorDate: Mon Apr 17 12:15:31 2023 +0100
records.yaml - Move common code to a single place. (#9603)
Just a clean up around the YAML tag definitions used in several places,
better have them in a single place and also available for plugins.
---
include/tscpp/util/YamlCfg.h | 6 ++++++
src/records/RecYAMLDecoder.cc | 21 +++++++--------------
src/traffic_ctl/CtrlCommands.cc | 1 -
src/traffic_ctl/FileConfigCommand.cc | 8 ++++----
src/traffic_ctl/utils/yaml_utils.h | 32 --------------------------------
5 files changed, 17 insertions(+), 51 deletions(-)
diff --git a/include/tscpp/util/YamlCfg.h b/include/tscpp/util/YamlCfg.h
index 51ca003afc..8d528d4d68 100644
--- a/include/tscpp/util/YamlCfg.h
+++ b/include/tscpp/util/YamlCfg.h
@@ -32,6 +32,12 @@ namespace ts
{
namespace Yaml
{
+ constexpr std::string_view YAML_FLOAT_TAG_URI{"tag:yaml.org,2002:float"};
+ constexpr std::string_view YAML_INT_TAG_URI{"tag:yaml.org,2002:int"};
+ constexpr std::string_view YAML_STR_TAG_URI{"tag:yaml.org,2002:str"};
+ constexpr std::string_view YAML_BOOL_TAG_URI{"tag:yaml.org,2002:bool"};
+ constexpr std::string_view YAML_NULL_TAG_URI{"tag:yaml.org,2002:null"};
+
// A class that is a wrapper for a YAML::Node that corresponds to a map in a
YAML input file.
// It's purpose is to make sure all keys in the map are processed.
//
diff --git a/src/records/RecYAMLDecoder.cc b/src/records/RecYAMLDecoder.cc
index 002361c85f..7be727ee6a 100644
--- a/src/records/RecYAMLDecoder.cc
+++ b/src/records/RecYAMLDecoder.cc
@@ -26,7 +26,7 @@
#include "records/RecYAMLDefs.h"
#include "tscore/Diags.h"
-
+#include "tscpp/util/YamlCfg.h"
#include "records/I_RecordsConfig.h"
#include <string_view>
@@ -42,13 +42,6 @@ namespace
constexpr std::string_view CONFIG_RECORD_PREFIX{"proxy.config"};
const inline std::string RECORD_YAML_ROOT_STR{"ts"};
-// I will move this to a common place.
-constexpr std::string_view YAML_FLOAT_TAG_URI{"tag:yaml.org,2002:float"};
-constexpr std::string_view YAML_INT_TAG_URI{"tag:yaml.org,2002:int"};
-constexpr std::string_view YAML_STR_TAG_URI{"tag:yaml.org,2002:str"};
-constexpr std::string_view YAML_BOOL_TAG_URI{"tag:yaml.org,2002:bool"};
-constexpr std::string_view YAML_NULL_TAG_URI{"tag:yaml.org,2002:null"};
-
} // namespace
namespace detail
@@ -163,17 +156,17 @@ try_deduce_type(YAML::Node const &node)
{
// Using the tag.
std::string_view tag = node.Tag();
- if (tag == YAML_FLOAT_TAG_URI) {
+ if (tag == ts::Yaml::YAML_FLOAT_TAG_URI) {
return {RecDataT::RECD_FLOAT, {}};
- } else if (tag == YAML_INT_TAG_URI) {
+ } else if (tag == ts::Yaml::YAML_INT_TAG_URI) {
return {RecDataT::RECD_INT, {}};
- } else if (tag == YAML_STR_TAG_URI) {
+ } else if (tag == ts::Yaml::YAML_STR_TAG_URI) {
return {RecDataT::RECD_STRING, {}};
- } else if (tag == YAML_INT_TAG_URI) {
+ } else if (tag == ts::Yaml::YAML_INT_TAG_URI) {
return {RecDataT::RECD_INT, {}};
- } else if (tag == YAML_BOOL_TAG_URI) {
+ } else if (tag == ts::Yaml::YAML_BOOL_TAG_URI) {
return {RecDataT::RECD_INT, {}};
- } else if (tag == YAML_NULL_TAG_URI) {
+ } else if (tag == ts::Yaml::YAML_NULL_TAG_URI) {
return {RecDataT::RECD_NULL, {}};
}
std::string text;
diff --git a/src/traffic_ctl/CtrlCommands.cc b/src/traffic_ctl/CtrlCommands.cc
index 85d98f92f9..f786e29ede 100644
--- a/src/traffic_ctl/CtrlCommands.cc
+++ b/src/traffic_ctl/CtrlCommands.cc
@@ -26,7 +26,6 @@
#include "CtrlCommands.h"
#include "jsonrpc/CtrlRPCRequests.h"
#include "jsonrpc/ctrl_yaml_codecs.h"
-#include "utils/yaml_utils.h"
#include "swoc/TextView.h"
#include "swoc/BufferWriter.h"
#include "swoc/bwf_base.h"
diff --git a/src/traffic_ctl/FileConfigCommand.cc
b/src/traffic_ctl/FileConfigCommand.cc
index 742bc103c0..0d5428a237 100644
--- a/src/traffic_ctl/FileConfigCommand.cc
+++ b/src/traffic_ctl/FileConfigCommand.cc
@@ -22,7 +22,7 @@
#include <unordered_map>
#include "FileConfigCommand.h"
-#include "utils/yaml_utils.h"
+#include "tscpp/util/YamlCfg.h"
#include "swoc/TextView.h"
#include "swoc/BufferWriter.h"
#include "swoc/bwf_base.h"
@@ -97,9 +97,9 @@ std::string
get_tag(swoc::TextView tag)
{
static std::vector<std::pair<std::string_view,
std::vector<std::string_view>>> const Str_to_Tag{
- {yaml_utils::YAML_INT_TAG_URI, {"int", "i", "I", "INT", "integer"}
},
- {yaml_utils::YAML_FLOAT_TAG_URI, {"float", "f", "F", "FLOAT"}
},
- {yaml_utils::YAML_STR_TAG_URI, {"str", "s", "S", "STR", "string",
"STRING"}}
+ {ts::Yaml::YAML_INT_TAG_URI, {"int", "i", "I", "INT", "integer"}
},
+ {ts::Yaml::YAML_FLOAT_TAG_URI, {"float", "f", "F", "FLOAT"}
},
+ {ts::Yaml::YAML_STR_TAG_URI, {"str", "s", "S", "STR", "string",
"STRING"}}
};
for (auto const &[yaml_tag, strs] : Str_to_Tag) {
diff --git a/src/traffic_ctl/utils/yaml_utils.h
b/src/traffic_ctl/utils/yaml_utils.h
deleted file mode 100644
index 348b81fb0c..0000000000
--- a/src/traffic_ctl/utils/yaml_utils.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/** @file
-
- @section license License
-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- */
-#pragma once
-#include <string_view>
-#include <swoc/Lexicon.h>
-
-namespace yaml_utils
-{
-// TODO: This should be sourced from another place
-constexpr std::string_view YAML_FLOAT_TAG_URI{"tag:yaml.org,2002:float"};
-constexpr std::string_view YAML_INT_TAG_URI{"tag:yaml.org,2002:int"};
-constexpr std::string_view YAML_STR_TAG_URI{"tag:yaml.org,2002:str"};
-
-} // namespace yaml_utils