YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/yql/cql/ql/ptree/pt_alter_role.h
Line
Count
Source
1
//--------------------------------------------------------------------------------------------------
2
// Copyright (c) YugaByte, Inc.
3
//
4
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5
// in compliance with the License.  You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software distributed under the License
10
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11
// or implied.  See the License for the specific language governing permissions and limitations
12
// under the License.
13
//
14
//
15
// Tree node definitions for ALTER ROLE statement.
16
//--------------------------------------------------------------------------------------------------
17
18
#ifndef YB_YQL_CQL_QL_PTREE_PT_ALTER_ROLE_H
19
#define YB_YQL_CQL_QL_PTREE_PT_ALTER_ROLE_H
20
21
#include <boost/optional.hpp>
22
23
#include "yb/yql/cql/ql/ptree/tree_node.h"
24
#include "yb/yql/cql/ql/ptree/pt_name.h"
25
#include "yb/yql/cql/ql/ptree/pt_create_role.h"
26
#include "yb/util/crypt.h"
27
28
namespace yb {
29
namespace ql {
30
using yb::util::kBcryptHashSize;
31
32
//--------------------------------------------------------------------------------------------------
33
// ALTER ROLE statement.
34
35
class PTAlterRole : public TreeNode {
36
 public:
37
  //------------------------------------------------------------------------------------------------
38
  // Public types.
39
  typedef MCSharedPtr<PTAlterRole> SharedPtr;
40
  typedef MCSharedPtr<const PTAlterRole> SharedPtrConst;
41
42
  //------------------------------------------------------------------------------------------------
43
  // Constructor and destructor.
44
  PTAlterRole(MemoryContext* memctx,
45
              YBLocationPtr loc,
46
              const MCSharedPtr<MCString>& name,
47
              const PTRoleOptionListNode::SharedPtr& roleOptions);
48
49
  virtual ~PTAlterRole();
50
51
  // Node type.
52
280
  virtual TreeNodeOpcode opcode() const override {
53
280
    return TreeNodeOpcode::kPTAlterRole;
54
280
  }
55
56
  // Support for shared_ptr.
57
  template<typename... TypeArgs>
58
58
  inline static PTAlterRole::SharedPtr MakeShared(MemoryContext* memctx, TypeArgs&&... args) {
59
58
    return MCMakeShared<PTAlterRole>(memctx, std::forward<TypeArgs>(args)...);
60
58
  }
61
62
  // Node semantics analysis.
63
  virtual CHECKED_STATUS Analyze(SemContext* sem_context) override;
64
  void PrintSemanticAnalysisResult(SemContext* sem_context);
65
66
  // Role name.
67
174
  const char* role_name() const {
68
174
    return name_->c_str();
69
174
  }
70
71
58
  boost::optional<std::string> salted_hash() const {
72
58
    boost::optional<std::string> ret_salted_hash;
73
    // Empty salted hash denotes no password, salted_hash can contain null characters.
74
58
    if (salted_hash_ != nullptr) {
75
9
      ret_salted_hash = std::string(salted_hash_->c_str(), kBcryptHashSize);
76
9
    }
77
58
    return ret_salted_hash;
78
58
  }
79
80
58
  boost::optional<bool> superuser() const {
81
58
    return superuser_;
82
58
  }
83
84
58
  boost::optional<bool> login() const {
85
58
    return login_;
86
58
  }
87
88
 private:
89
  const MCSharedPtr<MCString>  name_;
90
  PTRoleOptionListNode::SharedPtr roleOptions_;
91
  MCSharedPtr<MCString> salted_hash_ = nullptr;
92
  boost::optional<bool> login_;
93
  boost::optional<bool> superuser_;
94
};
95
96
}  // namespace ql
97
}  // namespace yb
98
99
#endif // YB_YQL_CQL_QL_PTREE_PT_ALTER_ROLE_H