-
Notifications
You must be signed in to change notification settings - Fork 735
sr/context: implement /contexts/{context}/... prefixed handlers #30189
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
Open
nguyen-andrew
wants to merge
10
commits into
redpanda-data:dev
Choose a base branch
from
nguyen-andrew:sr/context-prefix-handlers
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
735b11d
schema_registry: add URL-rewriting helpers for context-prefixed routes
nguyen-andrew f8e87d0
utils: add extend_variant_t type trait
nguyen-andrew 6cf12ea
sr/context: add auth resource type for context-prefixed routes
nguyen-andrew 7942863
sr/context: add context-prefixed routes for {subject} path param
nguyen-andrew cc96347
sr/context: add context-prefixed routes for ?subject query param
nguyen-andrew 6f0a4e7
sr/context: add context-prefixed routes for ?subjectPrefix query param
nguyen-andrew 466789c
sr/context: add context-prefixed routes for config, mode, and types
nguyen-andrew b079d4b
sr/context: fix context normalization in DELETE /contexts/{context}
nguyen-andrew ad32b18
tests/go: upgrade confluent-kafka-go from v2.0.2 to v2.3.0
nguyen-andrew a921cd1
sr/context: add serde client e2e test for context-prefixed URLs
nguyen-andrew File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| // Copyright 2026 Redpanda Data, Inc. | ||
| // | ||
| // Use of this software is governed by the Business Source License | ||
| // included in the file licenses/BSL.md | ||
| // | ||
| // As of the Change Date specified in that file, in accordance with | ||
| // the Business Source License, use of this software will be governed | ||
| // by the Apache License, Version 2.0 | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "base/seastarx.h" | ||
| #include "pandaproxy/schema_registry/errors.h" | ||
|
|
||
| #include <seastar/core/sstring.hh> | ||
| #include <seastar/http/request.hh> | ||
|
|
||
| #include <fmt/format.h> | ||
|
|
||
| #include <string_view> | ||
|
|
||
| namespace pandaproxy::schema_registry { | ||
|
|
||
| /// \brief Normalize a context name from a URL path parameter. | ||
| inline ss::sstring normalize_context(std::string_view ctx) { | ||
| if (ctx.starts_with(':')) { | ||
| ctx.remove_prefix(1); | ||
| } | ||
|
|
||
| if (ctx.ends_with(':')) { | ||
| ctx.remove_suffix(1); | ||
| } | ||
|
|
||
| if (ctx.find(':') != std::string_view::npos) { | ||
| throw as_exception(context_invalid(ctx)); | ||
| } | ||
|
|
||
| if (!ctx.starts_with('.')) { | ||
| return {fmt::format(".{}", ctx)}; | ||
| } | ||
| return ss::sstring(ctx); | ||
| } | ||
|
|
||
| /// \brief Check if a string already has a context prefix. | ||
| inline bool starts_with_context(std::string_view s) { | ||
| return s.starts_with(":.") || s.starts_with(":*:"); | ||
| } | ||
|
|
||
| } // namespace pandaproxy::schema_registry |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| // Copyright 2026 Redpanda Data, Inc. | ||
| // | ||
| // Use of this software is governed by the Business Source License | ||
| // included in the file licenses/BSL.md | ||
| // | ||
| // As of the Change Date specified in that file, in accordance with | ||
| // the Business Source License, use of this software will be governed | ||
| // by the Apache License, Version 2.0 | ||
|
|
||
| #include "pandaproxy/schema_registry/context_router.h" | ||
|
|
||
| #include "pandaproxy/schema_registry/exceptions.h" | ||
|
|
||
| #include <seastar/http/request.hh> | ||
|
|
||
| #include <gtest/gtest.h> | ||
|
|
||
| namespace pandaproxy::schema_registry { | ||
|
|
||
| TEST(ContextRouterTest, StartsWithContextDefault) { | ||
| EXPECT_FALSE(starts_with_context("")); | ||
| EXPECT_FALSE(starts_with_context("my-topic")); | ||
| EXPECT_FALSE(starts_with_context("plain-subject")); | ||
| } | ||
|
|
||
| TEST(ContextRouterTest, StartsWithContextQualified) { | ||
| EXPECT_TRUE(starts_with_context(":.staging:my-topic")); | ||
| EXPECT_TRUE(starts_with_context(":.prod:")); | ||
| EXPECT_TRUE(starts_with_context(":.:my-topic")); | ||
| } | ||
|
|
||
| TEST(ContextRouterTest, StartsWithContextWildcard) { | ||
| EXPECT_TRUE(starts_with_context(":*:")); | ||
| EXPECT_TRUE(starts_with_context(":*:my-topic")); | ||
| } | ||
|
|
||
| TEST(ContextRouterTest, StartsWithContextEdgeCases) { | ||
| EXPECT_FALSE(starts_with_context(":")); | ||
| EXPECT_FALSE(starts_with_context(":foo")); | ||
| EXPECT_FALSE(starts_with_context(":*")); | ||
| } | ||
|
|
||
| TEST(ContextRouterTest, NormalizeContextWithDot) { | ||
| EXPECT_EQ(normalize_context(".staging"), ".staging"); | ||
| EXPECT_EQ(normalize_context(".prod"), ".prod"); | ||
| EXPECT_EQ(normalize_context("."), "."); | ||
| } | ||
|
|
||
| TEST(ContextRouterTest, NormalizeContextWithoutDot) { | ||
| EXPECT_EQ(normalize_context("staging"), ".staging"); | ||
| EXPECT_EQ(normalize_context("prod"), ".prod"); | ||
| EXPECT_EQ(normalize_context(""), "."); | ||
| } | ||
|
|
||
| TEST(ContextRouterTest, NormalizeContextStripColons) { | ||
| EXPECT_EQ(normalize_context(":.staging"), ".staging"); | ||
| EXPECT_EQ(normalize_context(".staging:"), ".staging"); | ||
| EXPECT_EQ(normalize_context(":.staging:"), ".staging"); | ||
| EXPECT_EQ(normalize_context(":staging:"), ".staging"); | ||
| } | ||
|
|
||
| TEST(ContextRouterTest, NormalizeContextRejectsEmbeddedColons) { | ||
| EXPECT_THROW(normalize_context(".:."), exception); | ||
| EXPECT_THROW(normalize_context("a:b"), exception); | ||
| EXPECT_THROW(normalize_context(":.a:b:"), exception); | ||
| } | ||
|
|
||
| } // namespace pandaproxy::schema_registry |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| // Copyright 2026 Redpanda Data, Inc. | ||
| // | ||
| // Use of this software is governed by the Business Source License | ||
| // included in the file licenses/BSL.md | ||
| // | ||
| // As of the Change Date specified in that file, in accordance with | ||
| // the Business Source License, use of this software will be governed | ||
| // by the Apache License, Version 2.0 | ||
|
|
||
| #include "utils/variant.h" | ||
|
|
||
| #include <gtest/gtest.h> | ||
|
|
||
| #include <string> | ||
| #include <type_traits> | ||
| #include <variant> | ||
|
|
||
| static_assert(std::is_same_v< | ||
| extend_variant_t<std::variant<int, double>, bool>, | ||
| std::variant<int, double, bool>>); | ||
|
|
||
| static_assert(std::is_same_v< | ||
| extend_variant_t<std::variant<int>, double, std::string>, | ||
| std::variant<int, double, std::string>>); | ||
|
|
||
| static_assert(std::is_same_v< | ||
| extend_variant_t<std::variant<int, double>>, | ||
| std::variant<int, double>>); | ||
|
|
||
| TEST(VariantTest, CompileOnly) {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔥