1// Copyright 2025 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.
1415use risingwave_common::types::Fields;
16use risingwave_frontend_macro::system_catalog;
1718use crate::catalog::system_catalog::SysCatalogReaderImpl;
19use crate::error::Result;
20use crate::handler::create_connection::print_connection_params;
2122#[derive(Fields)]
23struct RwConnection {
24#[primary_key]
25id: i32,
26 name: String,
27 schema_id: i32,
28 owner: i32,
29 type_: String,
30 provider: String,
31 acl: Vec<String>,
32 connection_params: String,
33}
3435#[system_catalog(table, "rw_catalog.rw_connections")]
36fn read_rw_connections(reader: &SysCatalogReaderImpl) -> Result<Vec<RwConnection>> {
37let catalog_reader = reader.catalog_reader.read_guard();
38let schemas = catalog_reader.iter_schemas(&reader.auth_context.database)?;
3940// todo: redesign the internal table for connection params
41Ok(schemas
42 .flat_map(|schema| {
43 schema.iter_connections().map(|conn| {
44let mut rw_connection = RwConnection {
45 id: conn.id as i32,
46 name: conn.name.clone(),
47 schema_id: schema.id() as i32,
48 owner: conn.owner as i32,
49 type_: conn.connection_type().into(),
50 provider: "".to_owned(),
51 acl: vec![],
52 connection_params: "".to_owned(),
53 };
54match &conn.info {
55 risingwave_pb::catalog::connection::Info::PrivateLinkService(_) => {
56 rw_connection.provider = conn.provider().into();
57 }
58 risingwave_pb::catalog::connection::Info::ConnectionParams(params) => {
59 rw_connection.connection_params = print_connection_params(params, schema);
60 }
61 };
6263 rw_connection
64 })
65 })
66 .collect())
67}