Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,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
49 changes: 49 additions & 0 deletions script/check-style
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/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)"

CLANG_FORMAT="$(which clang-format)" || CLANG_FORMAT="${HOME}/clang/bin/clang-format"

CLANG_VERSION="$(${CLANG_FORMAT} -version | cut -d ' ' -f 3)"
CLANG_VERSION_REQUIRED="3.8.0"
if [[ "${CLANG_VERSION}" != "${CLANG_VERSION_REQUIRED}" ]]; then
echo "Current version: ${CLANG_VERSION}"
CLANG_DIRECTORY=$(mktemp -d /tmp/clang_XXXXX)
echo "Installing required clang-format ${CLANG_VERSION_REQUIRED} to ${CLANG_DIRECTORY}"
curl --silent --show-error --retry 10 \

Copy link
Copy Markdown
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-debian8.tar.xz" \

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

our Travis uses Ubuntu Xenial (16.04), so this should be: http://releases.llvm.org/3.8.0/clang+llvm-3.8.0-x86_64-linux-gnu-ubuntu-16.04.tar.xz

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

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

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