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.h
74 lines (60 loc) · 2.21 KB
/
extauth.h
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#pragma once
#include "envoy/http/filter.h"
#include "envoy/upstream/cluster_manager.h"
#include "common/common/logger.h"
namespace Envoy {
namespace Http {
/**
* All stats for the extauth filter. @see stats_macros.h
*/
// clang-format off
#define ALL_EXTAUTH_STATS(COUNTER) \
COUNTER(rq_failed) \
COUNTER(rq_passed) \
COUNTER(rq_rejected) \
COUNTER(rq_redirected)
// clang-format on
/**
* Wrapper struct for extauth filter stats. @see stats_macros.h
*/
struct ExtAuthStats {
ALL_EXTAUTH_STATS(GENERATE_COUNTER_STRUCT)
};
/**
* Configuration for the extauth filter.
*/
struct ExtAuthConfig {
Upstream::ClusterManager& cm_;
ExtAuthStats stats_;
std::string cluster_;
std::chrono::milliseconds timeout_;
};
typedef std::shared_ptr<const ExtAuthConfig> ExtAuthConfigConstSharedPtr;
/**
* A pass-through filter that talks to an external authn/authz service (or will soon...)
*/
class ExtAuth : Logger::Loggable<Logger::Id::filter>,
public StreamDecoderFilter,
public Http::AsyncClient::Callbacks {
public:
ExtAuth(ExtAuthConfigConstSharedPtr config);
~ExtAuth();
static ExtAuthStats generateStats(const std::string& prefix, Stats::Store& store);
// Http::StreamFilterBase
void onDestroy() override;
// Http::StreamDecoderFilter
FilterHeadersStatus decodeHeaders(HeaderMap& headers, bool end_stream) override;
FilterDataStatus decodeData(Buffer::Instance& data, bool end_stream) override;
FilterTrailersStatus decodeTrailers(HeaderMap& trailers) override;
void setDecoderFilterCallbacks(StreamDecoderFilterCallbacks& callbacks) override;
// Http::AsyncClient::Callbacks
void onSuccess(Http::MessagePtr&& response) override;
void onFailure(Http::AsyncClient::FailureReason reason) override;
private:
ExtAuthConfigConstSharedPtr config_;
StreamDecoderFilterCallbacks* callbacks_{};
bool auth_complete_;
Http::AsyncClient::Request* auth_request_{};
};
} // Http
} // Envoy