<commit_before>/* Copyright 2017 Istio Authors. All Rights Reserved.
 *
 * Licensed 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 "src/istio/control/tcp/attributes_builder.h"

#include "include/istio/utils/attribute_names.h"
#include "include/istio/utils/attributes_builder.h"

namespace istio {
namespace control {
namespace tcp {
namespace {
// Connection events for TCP connection.
const std::string kConnectionOpen("open");
const std::string kConnectionContinue("continue");
const std::string kConnectionClose("close");
}  // namespace

void AttributesBuilder::ExtractCheckAttributes(CheckData* check_data) {
  utils::AttributesBuilder builder(&request_->attributes);

  std::string source_ip;
  int source_port;
  // TODO(kuat): there is no way to propagate source IP in TCP, so we auto-set
  // it
  if (check_data->GetSourceIpPort(&source_ip, &source_port)) {
    builder.AddBytes(utils::AttributeName::kSourceIp, source_ip);
  }

  // TODO(diemtvu): add TCP authn filter similar to http case, and use authn
  // result output here instead.
  std::string source_user;
  if (check_data->GetSourceUser(&source_user)) {
    // TODO(diemtvu): remove kSourceUser once migration to source.principal is
    // over. https://github.com/istio/istio/issues/4689
    builder.AddString(utils::AttributeName::kSourceUser, source_user);
    builder.AddString(utils::AttributeName::kSourcePrincipal, source_user);
  }
  builder.AddBool(utils::AttributeName::kConnectionMtls,
                  check_data->IsMutualTLS());

  builder.AddString(utils::AttributeName::kConnectionRequestedServerName,
                    check_data->GetRequestedServerName());
<commit_msg>check that the requested server name is not emtpy in attributes builder<commit_after>/* Copyright 2017 Istio Authors. All Rights Reserved.
 *
 * Licensed 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 "src/istio/control/tcp/attributes_builder.h"

#include "include/istio/utils/attribute_names.h"
#include "include/istio/utils/attributes_builder.h"

namespace istio {
namespace control {
namespace tcp {
namespace {
// Connection events for TCP connection.
const std::string kConnectionOpen("open");
const std::string kConnectionContinue("continue");
const std::string kConnectionClose("close");
}  // namespace

void AttributesBuilder::ExtractCheckAttributes(CheckData* check_data) {
  utils::AttributesBuilder builder(&request_->attributes);

  std::string source_ip;
  int source_port;
  // TODO(kuat): there is no way to propagate source IP in TCP, so we auto-set
  // it
  if (check_data->GetSourceIpPort(&source_ip, &source_port)) {
    builder.AddBytes(utils::AttributeName::kSourceIp, source_ip);
  }

  // TODO(diemtvu): add TCP authn filter similar to http case, and use authn
  // result output here instead.
  std::string source_user;
  if (check_data->GetSourceUser(&source_user)) {
    // TODO(diemtvu): remove kSourceUser once migration to source.principal is
    // over. https://github.com/istio/istio/issues/4689
    builder.AddString(utils::AttributeName::kSourceUser, source_user);
    builder.AddString(utils::AttributeName::kSourcePrincipal, source_user);
  }
  builder.AddBool(utils::AttributeName::kConnectionMtls,
                  check_data->IsMutualTLS());

  std::string requested_server_name = check_data->GetRequestedServerName());
  if (!requested_server_name.empty()) {
    builder.AddString(utils::AttributeName::kConnectionRequestedServerName,
                      requested_server_name);
  }

{'fraction_non_alphanumeric': 0.10363959165557035, 'fraction_numerical': 0.005326231691078562, 'mean_word_length': 4.571075401730532, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7649243', 'n_tokens_mistral': 1268, 'n_tokens_neox': 1242, 'n_words': 378}