OmniSciDB  a5dc49c757
 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, bool read_only_mode) 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 2011 of file ParserNode.h.

Constructor & Destructor Documentation

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

Definition at line 6957 of file ParserNode.cpp.

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

6957  {
6958  CHECK(payload.HasMember("name"));
6959  user_name_ = std::make_unique<std::string>(json_str(payload["name"]));
6960 
6961  parse_options(payload, options_);
6962 }
const std::string json_str(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:46
std::list< std::unique_ptr< NameValueAssign > > options_
Definition: ParserNode.h:2027
std::unique_ptr< std::string > user_name_
Definition: ParserNode.h:2026
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:291

+ Here is the call graph for this function:

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

Definition at line 2014 of file ParserNode.h.

References options_.

2014  : user_name_(n) {
2015  if (l) {
2016  for (const auto e : *l) {
2017  options_.emplace_back(e);
2018  }
2019  delete l;
2020  }
2021  }
std::list< std::unique_ptr< NameValueAssign > > options_
Definition: ParserNode.h:2027
std::unique_ptr< std::string > user_name_
Definition: ParserNode.h:2026
constexpr double n
Definition: Utm.h:38

Member Function Documentation

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

Implements Parser::DDLStmt.

Definition at line 6964 of file ParserNode.cpp.

References Catalog_Namespace::UserAlterations::can_login, Parser::checkStringLiteral(), Catalog_Namespace::UserAlterations::default_db, Catalog_Namespace::SessionInfo::get_currentUser(), lockmgr::instance(), Catalog_Namespace::UserAlterations::is_super, Catalog_Namespace::UserMetadata::isSuper, options_, Catalog_Namespace::UserAlterations::passwd, Parser::readBooleanLiteral(), and user_name_.

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

6965  {
6966  if (read_only_mode) {
6967  throw std::runtime_error("CREATE USER invalid in read only mode.");
6968  }
6970  for (auto& p : options_) {
6971  if (boost::iequals(*p->get_name(), "password")) {
6972  checkStringLiteral("Password", p);
6973  alts.passwd = *static_cast<const StringLiteral*>(p->get_value())->get_stringval();
6974  } else if (boost::iequals(*p->get_name(), "is_super")) {
6975  checkStringLiteral("IS_SUPER", p);
6976  alts.is_super = readBooleanLiteral("IS_SUPER", p);
6977  } else if (boost::iequals(*p->get_name(), "default_db")) {
6978  checkStringLiteral("DEFAULT_DB", p);
6979  alts.default_db =
6980  *static_cast<const StringLiteral*>(p->get_value())->get_stringval();
6981  } else if (boost::iequals(*p->get_name(), "can_login")) {
6982  checkStringLiteral("CAN_LOGIN", p);
6983  alts.can_login = readBooleanLiteral("can_login", p);
6984  } else {
6985  throw std::runtime_error("Invalid CREATE USER option " + *p->get_name() +
6986  ". Should be PASSWORD, IS_SUPER, CAN_LOGIN"
6987  " or DEFAULT_DB.");
6988  }
6989  }
6990  if (!session.get_currentUser().isSuper) {
6991  throw std::runtime_error("Only super user can create new users.");
6992  }
6993  SysCatalog::instance().createUser(*user_name_, alts, /*is_temporary=*/false);
6994 }
std::optional< std::string > passwd
Definition: SysCatalog.h:117
std::optional< std::string > default_db
Definition: SysCatalog.h:119
static void checkStringLiteral(const std::string &option_name, const std::unique_ptr< NameValueAssign > &p)
std::list< std::unique_ptr< NameValueAssign > > options_
Definition: ParserNode.h:2027
std::unique_ptr< std::string > user_name_
Definition: ParserNode.h:2026
std::optional< bool > is_super
Definition: SysCatalog.h:118
T & instance()
Definition: LockMgr.cpp:101
std::optional< bool > can_login
Definition: SysCatalog.h:120
static bool readBooleanLiteral(const std::string &option_name, const std::unique_ptr< NameValueAssign > &p)
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:88
std::atomic< bool > isSuper
Definition: SysCatalog.h:107

+ 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 2027 of file ParserNode.h.

Referenced by CreateUserStmt(), and execute().

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

Definition at line 2026 of file ParserNode.h.

Referenced by CreateUserStmt(), and execute().


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