This repository has been archived by the owner on Jul 12, 2022. It is now read-only.
forked from envoyproxy/envoy-filter-example
-
Notifications
You must be signed in to change notification settings - Fork 7
/
extauth_config.cc
49 lines (41 loc) · 1.64 KB
/
extauth_config.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "extauth_config.h"
#include "extauth.h"
namespace Envoy {
namespace Server {
namespace Configuration {
const std::string EXTAUTH_HTTP_FILTER_SCHEMA(R"EOF(
{
"$schema": "http://json-schema.org/schema#",
"type" : "object",
"properties" : {
"cluster" : {"type" : "string"},
"timeout_ms": {"type" : "integer"}
},
"required" : ["cluster", "timeout_ms"],
"additionalProperties" : false
}
)EOF");
HttpFilterFactoryCb ExtAuthConfig::tryCreateFilterFactory(HttpFilterType type,
const std::string& name,
const Json::Object& json_config,
const std::string& stats_prefix,
Server::Instance& server) {
if (type != HttpFilterType::Decoder || name != "extauth") {
return nullptr;
}
json_config.validateSchema(EXTAUTH_HTTP_FILTER_SCHEMA);
Http::ExtAuthConfigConstSharedPtr config(new Http::ExtAuthConfig{
server.clusterManager(), Http::ExtAuth::generateStats(stats_prefix, server.stats()),
json_config.getString("cluster"),
std::chrono::milliseconds(json_config.getInteger("timeout_ms"))});
return [config](Http::FilterChainFactoryCallbacks& callbacks) -> void {
callbacks.addStreamDecoderFilter(Http::StreamDecoderFilterSharedPtr{new Http::ExtAuth(config)});
};
}
/**
* Static registration for the extauth filter. @see RegisterHttpFilterConfigFactory.
*/
static RegisterHttpFilterConfigFactory<ExtAuthConfig> register_;
} // Configuration
} // Server
} // Envoy