Skip to content

Commit

Permalink
Refactor PathMatcher to an independent BUILD target (envoyproxy#251)
Browse files Browse the repository at this point in the history
* Templatize PathMatcher

* make path_matcher.cc ready to move to header

* Move path_matcher to independent build target

* Remove utils from dep
  • Loading branch information
lizan authored Apr 20, 2017
1 parent 54158a2 commit 2ed5d6c
Show file tree
Hide file tree
Showing 7 changed files with 416 additions and 419 deletions.
19 changes: 15 additions & 4 deletions contrib/endpoints/src/api_manager/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ cc_library(
"config.h",
"gce_metadata.h",
"method_impl.h",
"path_matcher.h",
"path_matcher_node.h",
"request_handler.h",
],
deps = [
Expand All @@ -77,8 +75,6 @@ cc_library(
"gce_metadata.cc",
"http_template.h",
"method_impl.cc",
"path_matcher.cc",
"path_matcher_node.cc",
"quota_control.cc",
"quota_control.h",
"request_handler.cc",
Expand All @@ -96,6 +92,7 @@ cc_library(
deps = [
":auth_headers",
":http_template",
":path_matcher",
":impl_headers",
":server_config_proto",
"//contrib/endpoints/src/api_manager/auth",
Expand All @@ -114,6 +111,20 @@ cc_library(
],
)

cc_library(
name = "path_matcher",
srcs = [
"path_matcher_node.cc",
"path_matcher_node.h",
],
hdrs = [
"path_matcher.h",
],
deps = [
":http_template",
],
)

cc_library(
name = "http_template",
srcs = [
Expand Down
8 changes: 4 additions & 4 deletions contrib/endpoints/src/api_manager/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ bool Config::LoadQuotaRule(ApiManagerEnvInterface *env) {
}

bool Config::LoadHttpMethods(ApiManagerEnvInterface *env,
PathMatcherBuilder *pmb) {
PathMatcherBuilder<MethodInfo *> *pmb) {
std::set<std::string> all_urls, urls_with_options;
// By default, allow_cors is false. This means that the default behavior
// of ESP is to reject all "OPTIONS" requests. If customers want to enable
Expand Down Expand Up @@ -210,7 +210,7 @@ bool Config::LoadHttpMethods(ApiManagerEnvInterface *env,
}

bool Config::AddOptionsMethodForAllUrls(ApiManagerEnvInterface *env,
PathMatcherBuilder *pmb,
PathMatcherBuilder<MethodInfo *> *pmb,
const std::set<std::string> &all_urls) {
// In order to support CORS. Http method OPTIONS needs to be added to
// the path_matcher for all urls except the ones already with options.
Expand Down Expand Up @@ -242,7 +242,7 @@ bool Config::AddOptionsMethodForAllUrls(ApiManagerEnvInterface *env,
}

bool Config::LoadRpcMethods(ApiManagerEnvInterface *env,
PathMatcherBuilder *pmb) {
PathMatcherBuilder<MethodInfo *> *pmb) {
for (const auto &api : service_.apis()) {
if (api.name().empty()) {
continue;
Expand Down Expand Up @@ -439,7 +439,7 @@ std::unique_ptr<Config> Config::Create(ApiManagerEnvInterface *env,
return nullptr;
}
config->LoadServerConfig(env, server_config);
PathMatcherBuilder pmb;
PathMatcherBuilder<MethodInfo *> pmb;
// Load apis before http rules to store API versions
if (!config->LoadRpcMethods(env, &pmb)) {
return nullptr;
Expand Down
10 changes: 6 additions & 4 deletions contrib/endpoints/src/api_manager/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,17 @@ class Config {
const std::string &server_config);

// Create MethodInfo for HTTP methods, register them to PathMatcher.
bool LoadHttpMethods(ApiManagerEnvInterface *env, PathMatcherBuilder *pmb);
bool LoadHttpMethods(ApiManagerEnvInterface *env,
PathMatcherBuilder<MethodInfo *> *pmb);

// Add a special option method info for all URLs to support CORS.
bool AddOptionsMethodForAllUrls(ApiManagerEnvInterface *env,
PathMatcherBuilder *pmb,
PathMatcherBuilder<MethodInfo *> *pmb,
const std::set<std::string> &all_urls);

// Create MethodInfo for RPC methods, register them to PathMatcher.
bool LoadRpcMethods(ApiManagerEnvInterface *env, PathMatcherBuilder *pmb);
bool LoadRpcMethods(ApiManagerEnvInterface *env,
PathMatcherBuilder<MethodInfo *> *pmb);

// Load Authentication info to MethodInfo.
bool LoadAuthentication(ApiManagerEnvInterface *env);
Expand All @@ -124,7 +126,7 @@ class Config {

::google::api::Service service_;
std::unique_ptr<proto::ServerConfig> server_config_;
PathMatcherPtr path_matcher_;
PathMatcherPtr<MethodInfo *> path_matcher_;
std::map<std::string, MethodInfoImplPtr> method_map_;
// Maps issuer to {jwksUri, openIdValid} pair.
// jwksUri is populated either from service config, or by openId discovery.
Expand Down
1 change: 1 addition & 0 deletions contrib/endpoints/src/api_manager/context/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ cc_library(
}),
deps = [
"//contrib/endpoints/src/api_manager:http_template",
"//contrib/endpoints/src/api_manager:path_matcher",
"//contrib/endpoints/src/api_manager:impl_headers",
"//contrib/endpoints/src/api_manager:server_config_proto",
"//contrib/endpoints/src/api_manager/auth",
Expand Down
Loading

0 comments on commit 2ed5d6c

Please sign in to comment.