plugins/
frontend.rs

1// Copyright 2023 Greptime Team
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 auth::{DefaultPermissionChecker, PermissionCheckerRef, UserProviderRef};
16use common_base::Plugins;
17use frontend::error::{IllegalAuthConfigSnafu, Result};
18use frontend::frontend::FrontendOptions;
19use snafu::ResultExt;
20
21use crate::options::PluginOptions;
22
23#[allow(unused_mut)]
24pub async fn setup_frontend_plugins(
25    plugins: &mut Plugins,
26    _plugin_options: &[PluginOptions],
27    fe_opts: &FrontendOptions,
28) -> Result<()> {
29    if let Some(user_provider) = fe_opts.user_provider.as_ref() {
30        let provider =
31            auth::user_provider_from_option(user_provider).context(IllegalAuthConfigSnafu)?;
32        let permission_checker = DefaultPermissionChecker::arc();
33
34        plugins.insert::<PermissionCheckerRef>(permission_checker);
35        plugins.insert::<UserProviderRef>(provider);
36    }
37    Ok(())
38}
39
40/// Setup dynamic plugins based on the meta config in frontend.
41/// This is called after the `setup_frontend_plugins` because the meta client needs to be created first.
42///
43/// For those configs/plugins which are corresponding with the metasrv's config,
44/// we pull from metasrv first, then create/override the current config/plugin.
45/// Note: make sure the override works as expected.
46pub async fn setup_frontend_dynamic_plugins(
47    _meta_config: Vec<PluginOptions>,
48    _plugins: &mut Plugins,
49) -> Result<()> {
50    Ok(())
51}
52
53pub async fn start_frontend_plugins(_plugins: Plugins) -> Result<()> {
54    Ok(())
55}
56
57pub mod context {
58    use std::sync::Arc;
59
60    use flow::FrontendClient;
61    use meta_client::MetaClientRef;
62
63    /// The context for [`catalog::kvbackend::CatalogManagerConfiguratorRef`] in standalone or
64    /// distributed.
65    pub enum CatalogManagerConfigureContext {
66        Distributed(DistributedCatalogManagerConfigureContext),
67        Standalone(StandaloneCatalogManagerConfigureContext),
68    }
69
70    pub struct DistributedCatalogManagerConfigureContext {
71        pub meta_client: MetaClientRef,
72    }
73
74    pub struct StandaloneCatalogManagerConfigureContext {
75        pub fe_client: Arc<FrontendClient>,
76    }
77}