Skip to content

Commit

Permalink
compat: avoid setters when constructing acl types
Browse files Browse the repository at this point in the history
Signed-off-by: Noah Watkins <noahwatkins@gmail.com>
  • Loading branch information
dotnwat committed Aug 6, 2022
1 parent fed1435 commit 48cf023
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 41 deletions.
21 changes: 8 additions & 13 deletions src/v/compat/json.h
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ inline void read_value(
inline void read_value(json::Value const& rd, security::acl_host& host) {
ss::sstring address;
read_member(rd, "address", address);
host.set_address(ss::net::inet_address(address));
host = security::acl_host(address);
}

inline void rjson_serialize(
Expand All @@ -386,8 +386,7 @@ read_value(json::Value const& rd, security::acl_principal& principal) {
read_member_enum(rd, "type", security::principal_type{}));
ss::sstring name;
read_member(rd, "name", name);
principal.set_name(std::move(name));
principal.set_type(type);
principal = security::acl_principal(type, std::move(name));
}

inline void rjson_serialize(
Expand All @@ -410,10 +409,8 @@ inline void read_value(json::Value const& rd, security::acl_entry& entry) {
read_member_enum(rd, "operation", security::acl_operation{}));
auto permission = security::acl_permission(
read_member_enum(rd, "permission", security::acl_permission{}));
entry.set_principal(std::move(principal));
entry.set_host(std::move(host));
entry.set_operation(operation);
entry.set_permission(permission);
entry = security::acl_entry(
std::move(principal), host, operation, permission);
}

inline void rjson_serialize(
Expand All @@ -438,9 +435,8 @@ read_value(json::Value const& rd, security::resource_pattern& pattern) {
read_member(rd, "name", name);
auto pattern_type = security::pattern_type(
read_member_enum(rd, "pattern", security::pattern_type{}));
pattern.set_resource(resource);
pattern.set_name(std::move(name));
pattern.set_pattern(pattern_type);
pattern = security::resource_pattern(
resource, std::move(name), pattern_type);
}

inline void rjson_serialize(
Expand All @@ -461,8 +457,7 @@ inline void read_value(json::Value const& rd, security::acl_binding& binding) {
security::acl_entry entry;
read_member(rd, "pattern", pattern);
read_member(rd, "entry", entry);
binding.set_resource_pattern(std::move(pattern));
binding.set_acl_entry(std::move(entry));
binding = security::acl_binding(std::move(pattern), std::move(entry));
}

inline void rjson_serialize(
Expand Down Expand Up @@ -509,4 +504,4 @@ inline void rjson_serialize(
#define json_write(_fname) json::write_member(wr, #_fname, obj._fname)
#define json_read(_fname) json::read_member(rd, #_fname, obj._fname)

} // namespace json
} // namespace json
28 changes: 0 additions & 28 deletions src/v/security/acl.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,6 @@ class acl_principal : public serde::envelope<acl_principal, serde::version<0>> {
principal_type type() const { return _type; }
bool wildcard() const { return _name == "*"; }

void set_name(ss::sstring&& name) { _name = name; }

void set_type(principal_type type) { _type = type; }

auto serde_fields() { return std::tie(_type, _name); }

private:
Expand Down Expand Up @@ -289,12 +285,6 @@ class resource_pattern
const ss::sstring& name() const { return _name; }
pattern_type pattern() const { return _pattern; }

void set_resource(resource_type resource) { _resource = resource; }

void set_name(ss::sstring&& name) { _name = name; }

void set_pattern(pattern_type pattern) { _pattern = pattern; }

auto serde_fields() { return std::tie(_resource, _name, _pattern); }

private:
Expand All @@ -319,10 +309,6 @@ class acl_host : public serde::envelope<acl_host, serde::version<0>> {

friend bool operator==(const acl_host&, const acl_host&) = default;

void set_address(std::optional<ss::net::inet_address>&& addr) {
_addr = addr;
}

template<typename H>
friend H AbslHashValue(H h, const acl_host& host) {
if (host._addr) {
Expand Down Expand Up @@ -395,14 +381,6 @@ class acl_entry : public serde::envelope<acl_entry, serde::version<0>> {
acl_operation operation() const { return _operation; }
acl_permission permission() const { return _permission; }

void set_principal(acl_principal&& principal) { _principal = principal; }

void set_host(acl_host&& host) { _host = host; }

void set_operation(acl_operation op) { _operation = op; }

void set_permission(acl_permission permission) { _permission = permission; }

auto serde_fields() {
return std::tie(_principal, _host, _operation, _permission);
}
Expand All @@ -425,12 +403,6 @@ class acl_binding : public serde::envelope<acl_binding, serde::version<0>> {
: _pattern(std::move(pattern))
, _entry(std::move(entry)) {}

void set_resource_pattern(resource_pattern&& pattern) {
_pattern = pattern;
}

void set_acl_entry(acl_entry&& acl_entry) { _entry = acl_entry; }

friend bool operator==(const acl_binding&, const acl_binding&) = default;

template<typename H>
Expand Down

0 comments on commit 48cf023

Please sign in to comment.