-
Notifications
You must be signed in to change notification settings - Fork 297
Feature/permissions are checked in sql executors #1605
Conversation
@@ -82,6 +82,7 @@ namespace iroha { | |||
std::function<void(std::vector<std::string> &result)> callback( | |||
const rxcpp::subscriber<wTransaction> &s, uint64_t block_id); | |||
|
|||
std::unique_ptr<soci::session> sql_ptr_; |
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.
is this needed?
|
||
std::vector<std::function<std::string()>> message_gen = { | ||
[&] { | ||
return std::string( |
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.
do we need std::string constructor here?
@@ -87,6 +87,7 @@ namespace iroha { | |||
shared_model::interface::permissions::Grantable permission) override; | |||
|
|||
private: | |||
std::unique_ptr<soci::session> sql_ptr_; |
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.
Is this needed?
Signed-off-by: Victor Drobny <vdrobny@yandex.ru>
Signed-off-by: Victor Drobny <vdrobny@yandex.ru>
Signed-off-by: Victor Drobny <vdrobny@yandex.ru>
Signed-off-by: Victor Drobny <vdrobny@yandex.ru>
Signed-off-by: Victor Drobny <vdrobny@yandex.ru>
Signed-off-by: Victor Drobny <vdrobny@yandex.ru>
Signed-off-by: Victor Drobny <vdrobny@yandex.ru>
cc58ac5
to
25780ce
Compare
Signed-off-by: Victor Drobny <vdrobny@yandex.ru>
Signed-off-by: Victor Drobny <vdrobny@yandex.ru>
Signed-off-by: Victor Drobny <vdrobny@yandex.ru>
const auto bits = shared_model::interface::GrantablePermissionSet::size(); | ||
std::string query = R"( | ||
SELECT COALESCE(bit_or(permission), '0'::bit()" | ||
+ std::to_string(bits) + R"()) & ')" + std::string(perm_str) |
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.
Can we use boost::format here?
@@ -18,7 +18,6 @@ namespace iroha { | |||
wsv_(std::make_shared<PostgresWsvQuery>(*sql_, factory)), | |||
executor_(std::make_shared<PostgresWsvCommand>(*sql_)), | |||
command_executor_(std::make_shared<PostgresCommandExecutor>(*sql_)), |
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.
Maybe make unique?
} | ||
|
||
/** | ||
* @given command ] |
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.
command ]?
ASSERT_TRUE(val(execute(buildCommand(TestTransactionBuilder().createAsset( | ||
"coin", domain->domainId(), 1))))); | ||
auto ass = query->getAsset(asset->assetId()); | ||
ASSERT_TRUE(ass); | ||
ASSERT_EQ(*asset.get(), *ass.get()); | ||
} | ||
|
||
/** | ||
* @given command ] |
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.
sab
Signed-off-by: Victor Drobny <vdrobny@yandex.ru>
& '%s' = '%s' FROM role_has_permissions AS rp | ||
JOIN account_has_roles AS ar on ar.role_id = rp.role_id | ||
WHERE ar.account_id = :%s)") | ||
% bits % perm_str % perm_str % account_alias) |
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.
%1%
, %2%
can be used for positional arguments, so that there is no need to write perm_str
twice.
std::string checkAccountHasRoleOrGrantablePerm( | ||
shared_model::interface::permissions::Role role, | ||
shared_model::interface::permissions::Grantable grantable) { | ||
return R"(WITH |
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.
This also looks like a candidate for boost::format
, to reduce the number of raw strings.
@@ -122,7 +151,12 @@ namespace iroha { | |||
WHERE account_id = :account_id LIMIT 1), | |||
has_asset AS (SELECT asset_id FROM asset | |||
WHERE asset_id = :asset_id AND | |||
precision >= :precision LIMIT 1), | |||
precision >= :precision LIMIT 1),)" + | |||
(do_validation_ ? R"(has_perm AS ()" |
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.
How about introducing boost::format
to all commands, and doing something like:
boost::format cmd("...");
if (do_validation_)
cmd % "has_perm_...";
else
cmd % "";
It might be easier to read without ternary operators.
@@ -124,6 +124,9 @@ namespace iroha { | |||
processSoci(st, ind, row, [&set](std::string &row) { | |||
set = shared_model::interface::RolePermissionSet(row); | |||
}); | |||
if (set.none()) { |
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.
This does not look valid, because empty roles are allowed, and boost::none
means db error here. Consider refactoring.
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.
Isn't it IR-1480?
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.
It looks like the task is outdated 😔 Since roles with no permissions are allowed at the moment, boost::none
can be returned only as a result of database error.
@@ -53,8 +53,10 @@ namespace iroha { | |||
|
|||
CommandResult execute( | |||
const std::unique_ptr<shared_model::interface::Command> &command, | |||
bool is_genesis = false, |
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.
Not sure if genesis block should be mentioned here. Maybe use do_validation
?
% peer.pubkey().hex() % peer.address()) | ||
.str(); | ||
soci::statement st = sql_.prepare << R"( | ||
WITH |
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.
Please use boost::format
Signed-off-by: Victor Drobny <vdrobny@yandex.ru>
Signed-off-by: Victor Drobny <vdrobny@yandex.ru>
SonarQube analysis reported 2 issues
|
Validation and permissions checks are done in sql executors Signed-off-by: Victor Drobny <vdrobny@yandex.ru>
Description of the Change
Validation and permissions checks are done in sql executors
Benefits
Less db communication, better performance