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