Skip to content

Commit 5d71815

Browse files
authored
Merge pull request #30220 from pgellert/sr-types-acl
security/acl: move get_resource_type body to acl.cc
2 parents 7c4ad8b + 3127624 commit 5d71815

File tree

8 files changed

+41
-22
lines changed

8 files changed

+41
-22
lines changed

src/v/cloud_topics/frontend/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ redpanda_cc_library(
3131
"//src/v/cloud_topics/level_zero/stm:ctp_stm",
3232
"//src/v/cloud_topics/level_zero/stm:placeholder",
3333
"//src/v/cluster",
34+
"//src/v/kafka/protocol",
3435
"//src/v/kafka/server:write_at_offset_stm",
3536
"//src/v/ssx:future_util",
3637
"//src/v/storage:record_batch_builder",

src/v/cloud_topics/frontend/frontend.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "cluster/partition.h"
2727
#include "cluster/rm_stm_types.h"
2828
#include "cluster/types.h"
29+
#include "kafka/protocol/errors.h"
2930
#include "kafka/server/write_at_offset_stm.h"
3031
#include "model/fundamental.h"
3132
#include "model/offset_interval.h"

src/v/security/BUILD

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ redpanda_cc_library(
129129
"types.h",
130130
],
131131
implementation_deps = [
132+
"//src/v/kafka/protocol",
133+
"//src/v/pandaproxy/schema_registry:types",
132134
"//src/v/random:secure_random",
133135
"//src/v/thirdparty/krb5",
134136
"@abseil-cpp//absl/strings",
@@ -145,12 +147,10 @@ redpanda_cc_library(
145147
"//src/v/hashing:secure",
146148
"//src/v/http",
147149
"//src/v/json",
148-
"//src/v/kafka/protocol",
149150
"//src/v/metrics",
150151
"//src/v/model",
151152
"//src/v/net",
152153
"//src/v/net:types",
153-
"//src/v/pandaproxy/schema_registry:types",
154154
"//src/v/reflection:adl",
155155
"//src/v/security/audit:types",
156156
"//src/v/serde",

src/v/security/acl.cc

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
#include "absl/container/flat_hash_map.h"
1414
#include "absl/container/node_hash_map.h"
15+
#include "kafka/protocol/types.h"
16+
#include "pandaproxy/schema_registry/types.h"
1517
#include "security/acl_store.h"
1618
#include "serde/read_header.h"
1719
#include "serde/rw/rw.h"
@@ -707,6 +709,36 @@ void acl_binding_filter::testing_serde_full_read_v2(
707709
*this = acl_binding_filter{res._pattern, res._acl};
708710
}
709711

712+
template<typename T>
713+
resource_type get_resource_type() {
714+
if constexpr (std::is_same_v<T, model::topic>) {
715+
return resource_type::topic;
716+
} else if constexpr (std::is_same_v<T, kafka::group_id>) {
717+
return resource_type::group;
718+
} else if constexpr (std::is_same_v<T, acl_cluster_name>) {
719+
return resource_type::cluster;
720+
} else if constexpr (std::is_same_v<T, kafka::transactional_id>) {
721+
return resource_type::transactional_id;
722+
} else if constexpr (
723+
std::is_same_v<T, pandaproxy::schema_registry::context_subject>) {
724+
return resource_type::sr_subject;
725+
} else if constexpr (
726+
std::is_same_v<T, pandaproxy::schema_registry::registry_resource>) {
727+
return resource_type::sr_registry;
728+
} else {
729+
static_assert(base::unsupported_type<T>::value, "Unsupported type");
730+
}
731+
}
732+
733+
template resource_type get_resource_type<model::topic>();
734+
template resource_type get_resource_type<kafka::group_id>();
735+
template resource_type get_resource_type<acl_cluster_name>();
736+
template resource_type get_resource_type<kafka::transactional_id>();
737+
template resource_type
738+
get_resource_type<pandaproxy::schema_registry::context_subject>();
739+
template resource_type
740+
get_resource_type<pandaproxy::schema_registry::registry_resource>();
741+
710742
template<typename T>
711743
const std::vector<acl_operation>& get_allowed_operations() {
712744
static const std::vector<acl_operation> topic_resource_ops{

src/v/security/acl.h

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414
#include "base/format_to.h"
1515
#include "base/seastarx.h"
1616
#include "base/type_traits.h"
17-
#include "kafka/protocol/types.h"
1817
#include "model/fundamental.h"
19-
#include "pandaproxy/schema_registry/types.h"
2018
#include "security/audit/schemas/types.h"
2119
#include "serde/envelope.h"
2220
#include "serde/rw/enum.h"
@@ -105,24 +103,7 @@ std::optional<resource_type>
105103
from_string_view<resource_type>(std::string_view str);
106104

107105
template<typename T>
108-
consteval resource_type get_resource_type() {
109-
namespace ppsr = pandaproxy::schema_registry;
110-
if constexpr (std::is_same_v<T, model::topic>) {
111-
return resource_type::topic;
112-
} else if constexpr (std::is_same_v<T, kafka::group_id>) {
113-
return resource_type::group;
114-
} else if constexpr (std::is_same_v<T, security::acl_cluster_name>) {
115-
return resource_type::cluster;
116-
} else if constexpr (std::is_same_v<T, kafka::transactional_id>) {
117-
return resource_type::transactional_id;
118-
} else if constexpr (std::is_same_v<T, ppsr::context_subject>) {
119-
return resource_type::sr_subject;
120-
} else if constexpr (std::is_same_v<T, ppsr::registry_resource>) {
121-
return resource_type::sr_registry;
122-
} else {
123-
static_assert(base::unsupported_type<T>::value, "Unsupported type");
124-
}
125-
}
106+
resource_type get_resource_type();
126107

127108
/*
128109
* A pattern rule for matching ACL resource names.

src/v/security/authorizer.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313

1414
#include "acl_store.h"
1515
#include "config/configuration.h"
16+
#include "kafka/protocol/types.h"
1617
#include "metrics/metrics.h"
1718
#include "metrics/prometheus_sanitize.h"
19+
#include "pandaproxy/schema_registry/types.h"
1820
#include "security/role.h"
1921
#include "security/role_store.h"
2022

src/v/security/tests/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ redpanda_cc_gtest(
7575
],
7676
deps = [
7777
"//src/v/config",
78+
"//src/v/kafka/protocol",
7879
"//src/v/pandaproxy/schema_registry:types",
7980
"//src/v/random:generators",
8081
"//src/v/security",

src/v/security/tests/authorizer_test.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// by the Apache License, Version 2.0
99
#include "absl/container/flat_hash_set.h"
1010
#include "config/mock_property.h"
11+
#include "kafka/protocol/types.h"
1112
#include "pandaproxy/schema_registry/types.h"
1213
#include "random/generators.h"
1314
#include "security/acl.h"

0 commit comments

Comments
 (0)