risingwave_frontend/catalog/system_catalog/rw_catalog/
rw_users.rs

1// Copyright 2023 RisingWave Labs
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// 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
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use risingwave_common::id::UserId;
16use risingwave_common::types::Fields;
17use risingwave_frontend_macro::system_catalog;
18
19use crate::catalog::system_catalog::SysCatalogReaderImpl;
20use crate::error::Result;
21
22#[derive(Fields)]
23struct RwUser {
24    #[primary_key]
25    id: UserId,
26    name: String,
27    is_super: bool,
28    create_db: bool,
29    create_user: bool,
30    can_login: bool,
31    is_admin: bool,
32}
33
34#[system_catalog(table, "rw_catalog.rw_users")]
35fn read_rw_user_info(reader: &SysCatalogReaderImpl) -> Result<Vec<RwUser>> {
36    let reader = reader.user_info_reader.read_guard();
37    let users = reader.get_all_users();
38
39    Ok(users
40        .into_iter()
41        .map(|user| RwUser {
42            id: user.id,
43            name: user.name,
44            is_super: user.is_super,
45            create_db: user.can_create_db,
46            create_user: user.can_create_user,
47            can_login: user.can_login,
48            is_admin: user.is_admin,
49        })
50        .collect())
51}