OmniSciDB  eb3a3d0a03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Parser::CreateUserStmt Class Reference

#include <ParserNode.h>

+ Inheritance diagram for Parser::CreateUserStmt:
+ Collaboration diagram for Parser::CreateUserStmt:

Public Member Functions

 CreateUserStmt (const rapidjson::Value &payload)
 
 CreateUserStmt (std::string *n, std::list< NameValueAssign * > *l)
 
void execute (const Catalog_Namespace::SessionInfo &session) override
 
- Public Member Functions inherited from Parser::DDLStmt
void setColumnDescriptor (ColumnDescriptor &cd, const ColumnDef *coldef)
 
- Public Member Functions inherited from Parser::Node
virtual ~Node ()
 

Private Attributes

std::unique_ptr< std::string > user_name_
 
std::list< std::unique_ptr
< NameValueAssign > > 
options_
 

Detailed Description

Definition at line 1972 of file ParserNode.h.

Constructor & Destructor Documentation

Parser::CreateUserStmt::CreateUserStmt ( const rapidjson::Value &  payload)

Definition at line 6075 of file ParserNode.cpp.

References CHECK, json_str(), and Parser::anonymous_namespace{ParserNode.cpp}::parse_options().

6075  {
6076  CHECK(payload.HasMember("name"));
6077  user_name_ = std::make_unique<std::string>(json_str(payload["name"]));
6078 
6079  parse_options(payload, options_);
6080 }
const std::string json_str(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:44
std::list< std::unique_ptr< NameValueAssign > > options_
Definition: ParserNode.h:1987
std::unique_ptr< std::string > user_name_
Definition: ParserNode.h:1986
void parse_options(const rapidjson::Value &payload, std::list< std::unique_ptr< NameValueAssign >> &nameValueList, bool stringToNull=false, bool stringToInteger=false)
#define CHECK(condition)
Definition: Logger.h:209

+ Here is the call graph for this function:

Parser::CreateUserStmt::CreateUserStmt ( std::string *  n,
std::list< NameValueAssign * > *  l 
)
inline

Definition at line 1975 of file ParserNode.h.

References options_.

1975  : user_name_(n) {
1976  if (l) {
1977  for (const auto e : *l) {
1978  options_.emplace_back(e);
1979  }
1980  delete l;
1981  }
1982  }
std::list< std::unique_ptr< NameValueAssign > > options_
Definition: ParserNode.h:1987
std::unique_ptr< std::string > user_name_
Definition: ParserNode.h:1986
constexpr double n
Definition: Utm.h:40

Member Function Documentation

void Parser::CreateUserStmt::execute ( const Catalog_Namespace::SessionInfo session)
overridevirtual

Implements Parser::DDLStmt.

Definition at line 6082 of file ParserNode.cpp.

References Parser::checkStringLiteral(), Catalog_Namespace::SessionInfo::get_currentUser(), Catalog_Namespace::UserMetadata::isSuper, and Parser::readBooleanLiteral().

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

6082  {
6083  std::string passwd;
6084  bool is_super = false;
6085  std::string default_db;
6086  bool can_login = true;
6087  for (auto& p : options_) {
6088  if (boost::iequals(*p->get_name(), "password")) {
6089  checkStringLiteral("Password", p);
6090  passwd = *static_cast<const StringLiteral*>(p->get_value())->get_stringval();
6091  } else if (boost::iequals(*p->get_name(), "is_super")) {
6092  checkStringLiteral("IS_SUPER", p);
6093  is_super = readBooleanLiteral("IS_SUPER", p);
6094  } else if (boost::iequals(*p->get_name(), "default_db")) {
6095  checkStringLiteral("DEFAULT_DB", p);
6096  default_db = *static_cast<const StringLiteral*>(p->get_value())->get_stringval();
6097  } else if (boost::iequals(*p->get_name(), "can_login")) {
6098  checkStringLiteral("CAN_LOGIN", p);
6099  can_login = readBooleanLiteral("can_login", p);
6100  } else {
6101  throw std::runtime_error("Invalid CREATE USER option " + *p->get_name() +
6102  ". Should be PASSWORD, IS_SUPER, CAN_LOGIN"
6103  " or DEFAULT_DB.");
6104  }
6105  }
6106  if (!session.get_currentUser().isSuper) {
6107  throw std::runtime_error("Only super user can create new users.");
6108  }
6109  SysCatalog::instance().createUser(
6110  *user_name_, passwd, is_super, default_db, can_login, false);
6111 }
static void checkStringLiteral(const std::string &option_name, const std::unique_ptr< NameValueAssign > &p)
std::list< std::unique_ptr< NameValueAssign > > options_
Definition: ParserNode.h:1987
std::unique_ptr< std::string > user_name_
Definition: ParserNode.h:1986
static bool readBooleanLiteral(const std::string &option_name, const std::unique_ptr< NameValueAssign > &p)
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:73
std::atomic< bool > isSuper
Definition: SysCatalog.h:118

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

std::list<std::unique_ptr<NameValueAssign> > Parser::CreateUserStmt::options_
private

Definition at line 1987 of file ParserNode.h.

Referenced by CreateUserStmt().

std::unique_ptr<std::string> Parser::CreateUserStmt::user_name_
private

Definition at line 1986 of file ParserNode.h.


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