Skip to main content

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