Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ cache:
directories:
- $HOME/bazel/install
- $HOME/bazel/outbase
- $HOME/clang

before_install:
- mkdir -p ${HOME}/bazel/install
Expand All @@ -34,6 +35,7 @@ before_install:
- cat .bazelrc.travis .bazelrc.orig > .bazelrc

script:
- script/check-style
- bazel --output_base=${HOME}/bazel/outbase test //...

notifications:
Expand Down
10 changes: 5 additions & 5 deletions contrib/endpoints/src/api_manager/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ bool Config::LoadRpcMethods(ApiManagerEnvInterface *env,
bool Config::LoadAuthentication(ApiManagerEnvInterface *env) {
// Parsing auth config.
const ::google::api::Authentication &auth = service_.authentication();
map<string, const ::google::api::AuthProvider*> provider_id_provider_map;
map<string, const ::google::api::AuthProvider *> provider_id_provider_map;
for (const auto &provider : auth.providers()) {
if (provider.id().empty()) {
env->LogError("Missing id field in AuthProvider.");
Expand Down Expand Up @@ -296,15 +296,15 @@ bool Config::LoadAuthentication(ApiManagerEnvInterface *env) {
env->LogError(error.c_str());
continue;
}
auto provider = utils::FindPtrOrNull(provider_id_provider_map,
provider_id);
auto provider =
utils::FindPtrOrNull(provider_id_provider_map, provider_id);
if (provider == nullptr) {
std::string error = "Undefined provider_id: " + provider_id;
env->LogError(error.c_str());
} else {
const std::string &audiences = provider->audiences().empty()
? requirement.audiences()
: provider->audiences();
? requirement.audiences()
: provider->audiences();
(*method)->addAudiencesForIssuer(provider->issuer(), audiences);
}
}
Expand Down
52 changes: 52 additions & 0 deletions script/check-style
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/bash
#
# Copyright 2016 Google Inc. 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.
#
################################################################################
#
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"

# Install required clang version to a folder and cache it.
CLANG_VERSION_REQUIRED="3.8.0"
CLANG_DIRECTORY="${HOME}/clang"
CLANG_FORMAT="${CLANG_DIRECTORY}/bin/clang-format"

CLANG_VERSION="$(${CLANG_FORMAT} -version | cut -d ' ' -f 3)"
if [[ "${CLANG_VERSION}" != "${CLANG_VERSION_REQUIRED}" ]]; then
echo "Installing required clang-format ${CLANG_VERSION_REQUIRED} to ${CLANG_DIRECTORY}"
mkdir -p ${CLANG_DIRECTORY}
curl --silent --show-error --retry 10 \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"http://releases.llvm.org/${CLANG_VERSION_REQUIRED}/clang+llvm-${CLANG_VERSION_REQUIRED}-x86_64-linux-gnu-ubuntu-14.04.tar.xz" \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

16.04

| tar Jx -C "${CLANG_DIRECTORY}" --strip=1 \
|| { echo "Could not install required clang-format. Skip formating." ; exit 0 ; }
fi

echo "Checking file format ..."

pushd ${ROOT} > /dev/null

SOURCE_FILES=($(git ls-tree -r HEAD --name-only | grep -E '\.(h|c|cc|proto)$'))
"${CLANG_FORMAT}" -style=Google -i "${SOURCE_FILES[@]}" \
|| { echo "Could not run clang-format." ; exit 1 ; }

CHANGED_FILES=($(git diff HEAD --name-only | grep -E '\.(h|c|cc|proto)$'))

if [[ "${#CHANGED_FILES}" -ne 0 ]]; then
echo "Files not formatted: ${CHANGED_FILES[@]}"
exit 1
fi
echo "All files are properly formatted."

popd
11 changes: 5 additions & 6 deletions src/envoy/prototype/api_manager_env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ void Http::ApiManager::Env::Log(LogLevel level, const char *message) {
}
}


class PeriodicTimer : public google::api_manager::PeriodicTimer,
public Logger::Loggable<Logger::Id::http> {
private:
Expand Down Expand Up @@ -73,9 +72,8 @@ class HTTPRequest : public Http::Message {
header_map_.addStatic(Headers::get().Scheme, "http");
header_map_.addStatic(Headers::get().Host, "localhost");
header_map_.addStatic(Headers::get().ContentLength,
std::to_string(body_.length()));
header_map_.addStatic(LowerCaseString("x-api-manager-url"),
request->url());
std::to_string(body_.length()));
header_map_.addStatic(LowerCaseString("x-api-manager-url"), request->url());
for (auto header : request->request_headers()) {
LowerCaseString key(header.first);
header_map_.addStatic(key, header.second);
Expand All @@ -102,10 +100,11 @@ class RequestCallbacks : public AsyncClient::Callbacks {
std::stoi(response->headers().Status()->value().c_str()), "");
std::map<std::string, std::string> headers;
response->headers().iterate(
[&](const HeaderEntry& header, void*) -> void {
[&](const HeaderEntry &header, void *) -> void {
// TODO: fix it
// headers.emplace(header.key().c_str(), header.value().c_str());
}, nullptr);
},
nullptr);
request_->OnComplete(status, std::move(headers), response->bodyAsString());
delete this;
}
Expand Down
2 changes: 1 addition & 1 deletion src/envoy/prototype/api_manager_env.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#include "precompiled/precompiled.h"

#include "common/common/logger.h"
#include "envoy/upstream/cluster_manager.h"
#include "contrib/endpoints/include/api_manager/env_interface.h"
#include "envoy/upstream/cluster_manager.h"
#include "server/server.h"

namespace Http {
Expand Down
10 changes: 5 additions & 5 deletions src/envoy/prototype/api_manager_filter.cc
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#include "precompiled/precompiled.h"

#include "api_manager_env.h"
#include "common/grpc/common.h"
#include "common/common/logger.h"
#include "common/grpc/common.h"
#include "common/http/filter/ratelimit.h"
#include "common/http/headers.h"
#include "common/http/utility.h"
#include "envoy/server/instance.h"
#include "contrib/endpoints/include/api_manager/api_manager.h"
#include "server/config/network/http_connection_manager.h"
#include "contrib/endpoints/src/grpc/transcoding/transcoder.h"
#include "envoy/server/instance.h"
#include "server/config/network/http_connection_manager.h"

namespace Http {
namespace ApiManager {
Expand Down Expand Up @@ -157,7 +157,7 @@ class Instance : public Http::StreamFilter,
FilterDataStatus decodeData(Buffer::Instance& data,
bool end_stream) override {
log().debug("Called ApiManager::Instance : {} ({}, {})", __func__,
data.length(), end_stream);
data.length(), end_stream);
if (state_ == Calling) {
return FilterDataStatus::StopIterationAndBuffer;
}
Expand All @@ -180,7 +180,7 @@ class Instance : public Http::StreamFilter,
}
void completeCheck(const google::api_manager::utils::Status& status) {
log().debug("Called ApiManager::Instance : check complete {}",
status.ToJson());
status.ToJson());
if (!status.ok() && state_ != Responded) {
state_ = Responded;
Utility::sendLocalReply(*decoder_callbacks_, Code(status.HttpCode()),
Expand Down