OmniSciDB  c0231cc57d
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ShowRolesCommand Class Reference

#include <DdlCommandExecutor.h>

+ Inheritance diagram for ShowRolesCommand:
+ Collaboration diagram for ShowRolesCommand:

Public Member Functions

 ShowRolesCommand (const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
 
ExecutionResult execute (bool read_only_mode) override
 
- Public Member Functions inherited from DdlCommand
 DdlCommand (const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
 

Additional Inherited Members

- Protected Attributes inherited from DdlCommand
const DdlCommandDataddl_data_
 
std::shared_ptr
< Catalog_Namespace::SessionInfo
const > 
session_ptr_
 

Detailed Description

Definition at line 240 of file DdlCommandExecutor.h.

Constructor & Destructor Documentation

ShowRolesCommand::ShowRolesCommand ( const DdlCommandData ddl_data,
std::shared_ptr< Catalog_Namespace::SessionInfo const >  session_ptr 
)

Definition at line 2313 of file DdlCommandExecutor.cpp.

References CHECK, and anonymous_namespace{DdlCommandExecutor.cpp}::extractPayload().

2316  : DdlCommand(ddl_data, session_ptr) {
2317  auto& ddl_payload = extractPayload(ddl_data);
2318  CHECK(ddl_payload["userName"].IsString());
2319  CHECK(ddl_payload["effective"].IsBool());
2320 }
const rapidjson::Value & extractPayload(const DdlCommandData &ddl_data)
DdlCommand(const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
#define CHECK(condition)
Definition: Logger.h:222

+ Here is the call graph for this function:

Member Function Documentation

ExecutionResult ShowRolesCommand::execute ( bool  read_only_mode)
overridevirtual

Executes the DDL command corresponding to provided JSON payload.

Parameters
_returnresult of DDL command execution (if applicable)

Implements DdlCommand.

Definition at line 2322 of file DdlCommandExecutor.cpp.

References ResultSetLogicalValuesBuilder::create(), DdlCommand::ddl_data_, anonymous_namespace{DdlCommandExecutor.cpp}::extractPayload(), genLiteralStr(), Catalog_Namespace::SysCatalog::instance(), Catalog_Namespace::UserMetadata::isSuper, kTEXT, DdlCommand::session_ptr_, and Catalog_Namespace::UserMetadata::userId.

Referenced by heavydb.cursor.Cursor::executemany().

2322  {
2323  // valid in read_only_mode
2324 
2325  auto& ddl_payload = extractPayload(ddl_data_);
2326  auto& sys_cat = Catalog_Namespace::SysCatalog::instance();
2327 
2328  // label_infos -> column labels
2329  std::vector<TargetMetaInfo> label_infos;
2330  std::vector<std::string> labels{"ROLES"};
2331  label_infos.emplace_back(labels[0], SQLTypeInfo(kTEXT, true));
2332 
2333  // logical_values -> table data
2334  std::vector<RelLogicalValues::RowValues> logical_values;
2335  std::vector<std::string> roles_list;
2336  Catalog_Namespace::UserMetadata self = session_ptr_->get_currentUser();
2337  std::string user_name = ddl_payload["userName"].GetString();
2338  bool effective = ddl_payload["effective"].GetBool();
2339  if (user_name.empty()) {
2340  user_name = self.userName;
2341  }
2343  bool is_user = sys_cat.getMetadataForUser(user_name, user);
2344  if (!self.isSuper) {
2345  if (is_user) {
2346  if (self.userId != user.userId) {
2347  throw std::runtime_error(
2348  "Only a superuser is authorized to request list of roles granted to another "
2349  "user.");
2350  }
2351  } else {
2352  if (!sys_cat.isRoleGrantedToGrantee(
2353  self.userName, user_name, /*only_direct=*/false)) {
2354  throw std::runtime_error(
2355  "Only a superuser is authorized to request list of roles granted to a role "
2356  "they don't have.");
2357  }
2358  }
2359  }
2360  if (user.isSuper) {
2361  auto s = sys_cat.getCreatedRoles();
2362  roles_list.insert(roles_list.end(), s.begin(), s.end());
2363  } else {
2364  roles_list = sys_cat.getRoles(user_name, effective);
2365  }
2366  for (const std::string& role_name : roles_list) {
2367  logical_values.emplace_back(RelLogicalValues::RowValues{});
2368  logical_values.back().emplace_back(genLiteralStr(role_name));
2369  }
2370 
2371  // Create ResultSet
2372  std::shared_ptr<ResultSet> rSet = std::shared_ptr<ResultSet>(
2373  ResultSetLogicalValuesBuilder::create(label_infos, logical_values));
2374 
2375  return ExecutionResult(rSet, label_infos);
2376 }
const DdlCommandData & ddl_data_
static SysCatalog & instance()
Definition: SysCatalog.h:341
const rapidjson::Value & extractPayload(const DdlCommandData &ddl_data)
static ResultSet * create(std::vector< TargetMetaInfo > &label_infos, std::vector< RelLogicalValues::RowValues > &logical_values)
Definition: sqltypes.h:66
static std::unique_ptr< RexLiteral > genLiteralStr(std::string val)
Definition: DBHandler.cpp:7263
std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr_
std::vector< std::unique_ptr< const RexScalar >> RowValues
Definition: RelAlgDag.h:2226
std::atomic< bool > isSuper
Definition: SysCatalog.h:107

+ Here is the call graph for this function:

+ Here is the caller graph for this function:


The documentation for this class was generated from the following files: