risingwave_connector/
enforce_secret.rs

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.
14
15use phf::{Set, phf_set};
16
17use crate::error::ConnectorResult as Result;
18
19#[derive(Debug, thiserror::Error)]
20#[error("{key} is enforced to be a SECRET on RisingWave Cloud, please use `CREATE SECRET` first")]
21pub struct EnforceSecretError {
22    pub key: String,
23}
24
25pub trait EnforceSecret {
26    const ENFORCE_SECRET_PROPERTIES: Set<&'static str> = phf_set! {};
27
28    fn enforce_secret<'a>(prop_iter: impl Iterator<Item = &'a str>) -> Result<()> {
29        for prop in prop_iter {
30            if Self::ENFORCE_SECRET_PROPERTIES.contains(prop) {
31                return Err(EnforceSecretError {
32                    key: prop.to_owned(),
33                }
34                .into());
35            }
36        }
37        Ok(())
38    }
39
40    fn enforce_one(prop: &str) -> Result<()> {
41        if Self::ENFORCE_SECRET_PROPERTIES.contains(prop) {
42            return Err(EnforceSecretError {
43                key: prop.to_owned(),
44            }
45            .into());
46        }
47        Ok(())
48    }
49}