Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-1.6] cherry-pick of https://github.com/envoyproxy/envoy-wasm/pull/486 #197

Merged
merged 1 commit into from
Apr 21, 2020
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
20 changes: 13 additions & 7 deletions source/extensions/common/wasm/context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ static absl::flat_hash_map<std::string, PropertyToken> property_tokens = {PROPER
#undef _PARI

absl::optional<google::api::expr::runtime::CelValue>
Context::FindValue(absl::string_view name, Protobuf::Arena* arena) const {
Context::findValue(absl::string_view name, Protobuf::Arena* arena, bool last) const {
using google::api::expr::runtime::CelValue;

const StreamInfo::StreamInfo* info = getConstRequestStreamInfo();
Expand All @@ -411,11 +411,15 @@ Context::FindValue(absl::string_view name, Protobuf::Arena* arena) const {
const WasmState* state;
if (info->filterState().hasData<WasmState>(key)) {
state = &info->filterState().getDataReadOnly<WasmState>(key);
} else if (info->upstreamFilterState()->hasData<WasmState>(key)) {
} else if (info->upstreamFilterState() &&
info->upstreamFilterState()->hasData<WasmState>(key)) {
state = &info->upstreamFilterState()->getDataReadOnly<WasmState>(key);
} else {
return {};
}
if (last) {
return CelValue::CreateBytes(&state->value());
}
return state->exprValue(arena);
}
return {};
Expand Down Expand Up @@ -542,7 +546,7 @@ WasmResult Context::getProperty(absl::string_view path, std::string* result) {
if (first) {
// top-level ident
first = false;
auto top_value = FindValue(part, &arena);
auto top_value = findValue(part, &arena, start >= path.size());
if (!top_value.has_value()) {
return WasmResult::NotFound;
}
Expand Down Expand Up @@ -1066,12 +1070,14 @@ WasmResult Context::setProperty(absl::string_view path, absl::string_view value)
state = &stream_info->filterState()->getDataMutable<WasmState>(key);
} else {
const auto& it = rootContext()->state_prototypes_.find(path);
auto state_ptr = std::make_unique<WasmState>(it == rootContext()->state_prototypes_.end()
? DefaultWasmStatePrototype::get()
: *it->second.get());
const WasmStatePrototype& prototype = it == rootContext()->state_prototypes_.end()
? DefaultWasmStatePrototype::get()
: *it->second.get();
auto state_ptr = std::make_unique<WasmState>(prototype);
state = state_ptr.get();
stream_info->filterState()->setData(key, std::move(state_ptr),
StreamInfo::FilterState::StateType::ReadOnly);
StreamInfo::FilterState::StateType::Mutable,
prototype.life_span_);
}
if (!state->setValue(value)) {
return WasmResult::BadArgument;
Expand Down
12 changes: 8 additions & 4 deletions source/extensions/common/wasm/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,13 +306,17 @@ class Context : public Logger::Loggable<Logger::Id::wasm>,
bool end_stream); // stream only

// CEL evaluation
virtual std::vector<const google::api::expr::runtime::CelFunction*>
std::vector<const google::api::expr::runtime::CelFunction*>
FindFunctionOverloads(absl::string_view) const override {
return {};
}
virtual absl::optional<google::api::expr::runtime::CelValue>
FindValue(absl::string_view name, Protobuf::Arena* arena) const override;
virtual bool IsPathUnknown(absl::string_view) const override { return false; }
absl::optional<google::api::expr::runtime::CelValue>
findValue(absl::string_view name, Protobuf::Arena* arena, bool last) const;
absl::optional<google::api::expr::runtime::CelValue>
FindValue(absl::string_view name, Protobuf::Arena* arena) const override {
return findValue(name, arena, false);
}
bool IsPathUnknown(absl::string_view) const override { return false; }
const std::vector<google::api::expr::runtime::CelAttributePattern>&
unknown_attribute_patterns() const override {
static const std::vector<google::api::expr::runtime::CelAttributePattern> empty;
Expand Down