risingwave_frontend/catalog/
connection_catalog.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_pb::catalog::connection::Info;
16use risingwave_pb::catalog::{PbConnection, connection};
17
18use crate::catalog::{ConnectionId, OwnedByUserCatalog};
19use crate::user::UserId;
20
21#[derive(Clone, Debug, PartialEq)]
22pub struct ConnectionCatalog {
23    pub id: ConnectionId,
24    pub name: String,
25    pub info: connection::Info,
26    pub owner: UserId,
27}
28
29impl ConnectionCatalog {
30    pub fn connection_type(&self) -> &str {
31        match &self.info {
32            #[expect(deprecated)]
33            Info::PrivateLinkService(srv) => srv.get_provider().unwrap().as_str_name(),
34            Info::ConnectionParams(params) => params.get_connection_type().unwrap().as_str_name(),
35        }
36    }
37
38    pub fn provider(&self) -> &str {
39        match &self.info {
40            #[expect(deprecated)]
41            Info::PrivateLinkService(_) => "PRIVATELINK",
42            Info::ConnectionParams(_) => panic!("ConnectionParams is not supported as provider."),
43        }
44    }
45}
46
47impl From<&PbConnection> for ConnectionCatalog {
48    fn from(prost: &PbConnection) -> Self {
49        Self {
50            id: prost.id,
51            name: prost.name.clone(),
52            info: prost.info.clone().unwrap(),
53            owner: prost.owner,
54        }
55    }
56}
57
58impl OwnedByUserCatalog for ConnectionCatalog {
59    fn owner(&self) -> UserId {
60        self.owner
61    }
62}