cmcfarlen commented on code in PR #12755:
URL: https://github.com/apache/trafficserver/pull/12755#discussion_r2687124241


##########
src/config/ssl_multicert.cc:
##########
@@ -0,0 +1,457 @@
+/** @file
+
+  SSL Multi-Certificate configuration parsing and marshalling implementation.
+
+  @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.
+*/
+
+#include "config/ssl_multicert.h"
+
+#include <algorithm>
+#include <cctype>
+#include <exception>
+#include <fstream>
+#include <set>
+#include <sstream>
+
+#include <yaml-cpp/yaml.h>
+
+namespace
+{
+
+// YAML key names.
+constexpr char KEY_SSL_CERT_NAME[]      = "ssl_cert_name";
+constexpr char KEY_DEST_IP[]            = "dest_ip";
+constexpr char KEY_SSL_KEY_NAME[]       = "ssl_key_name";
+constexpr char KEY_SSL_CA_NAME[]        = "ssl_ca_name";
+constexpr char KEY_SSL_OCSP_NAME[]      = "ssl_ocsp_name";
+constexpr char KEY_SSL_KEY_DIALOG[]     = "ssl_key_dialog";
+constexpr char KEY_DEST_FQDN[]          = "dest_fqdn";
+constexpr char KEY_SSL_TICKET_ENABLED[] = "ssl_ticket_enabled";
+constexpr char KEY_SSL_TICKET_NUMBER[]  = "ssl_ticket_number";
+constexpr char KEY_ACTION[]             = "action";
+constexpr char KEY_SSL_MULTICERT[]      = "ssl_multicert";
+
+std::set<std::string> const valid_keys = {
+  KEY_SSL_CERT_NAME,  KEY_DEST_IP,   KEY_SSL_KEY_NAME,       KEY_SSL_CA_NAME,  
     KEY_SSL_OCSP_NAME,
+  KEY_SSL_KEY_DIALOG, KEY_DEST_FQDN, KEY_SSL_TICKET_ENABLED, 
KEY_SSL_TICKET_NUMBER, KEY_ACTION,
+};
+
+/// Trim whitespace from both ends of a string.
+std::string
+trim(std::string_view s)
+{
+  auto const start = s.find_first_not_of(" \t\r\n");
+  if (start == std::string_view::npos) {
+    return {};
+  }
+  auto const end = s.find_last_not_of(" \t\r\n");
+  return std::string(s.substr(start, end - start + 1));
+}
+
+/// Check if a string ends with a suffix.
+bool
+ends_with(std::string const &str, std::string_view suffix)
+{
+  if (suffix.size() > str.size()) {
+    return false;
+  }
+  return str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0;
+}

Review Comment:
   Perhaps these are AI generated, but we have existing utility for these 
helpers. If we want to keep these, maybe move them to a `ts::config` namespace 
so other config parsers don't also have to generate them.  Probably best to 
just use swoc:TextView



##########
src/iocore/net/YamlSSLMultiCertConfig.cc:
##########
@@ -0,0 +1,137 @@
+/** @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.
+ */
+
+#include "iocore/net/YamlSSLMultiCertConfig.h"
+
+#include <set>
+#include <string>
+#include <exception>
+
+#include <yaml-cpp/yaml.h>
+
+#include "tscore/Diags.h"
+
+namespace
+{
+// YAML key names matching the config file format.
+constexpr char YAML_SSL_CERT_NAME[]      = "ssl_cert_name";
+constexpr char YAML_DEST_IP[]            = "dest_ip";
+constexpr char YAML_SSL_KEY_NAME[]       = "ssl_key_name";
+constexpr char YAML_SSL_CA_NAME[]        = "ssl_ca_name";
+constexpr char YAML_SSL_OCSP_NAME[]      = "ssl_ocsp_name";
+constexpr char YAML_SSL_KEY_DIALOG[]     = "ssl_key_dialog";
+constexpr char YAML_DEST_FQDN[]          = "dest_fqdn";
+constexpr char YAML_SSL_TICKET_ENABLED[] = "ssl_ticket_enabled";
+constexpr char YAML_SSL_TICKET_NUMBER[]  = "ssl_ticket_number";
+constexpr char YAML_ACTION[]             = "action";

Review Comment:
   These are duplicated in src/config/ssl_multicert.cc.  A lot of this parser 
code below is also duplicated there. This code should just use the parser code 
in the config library so it doesn't have to change in multiple places later.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to