feat: impl static_user_provider (#739)

* feat: add MemUserProvider and impl auth

* feat: impl user_provider option in fe and standalone mode

* chore: add file impl for mem provider

* chore: remove mem opts

* chore: minor change

* chore: refac pg server to use user_provider as indicator for using pwd auth

* chore: fix test

* chore: extract common code

* chore: add unit test

* chore: rebase develop

* chore: add user provider to http server

* chore: minor rename

* chore: change to ref when convert to anymap

* chore: fix according to clippy

* chore: remove clone on startcommand

* chore: fix cr issue

* chore: update tempdir use

* chore: change TryFrom to normal func while parsing anymap

* chore: minor change

* chore: remove to_lowercase
This commit is contained in:
shuiyisong
2022-12-14 16:38:29 +08:00
committed by GitHub
parent 756c068166
commit fda9e80cbf
17 changed files with 482 additions and 73 deletions

View File

@@ -5,6 +5,7 @@ edition = "2021"
license = "Apache-2.0"
[dependencies]
anymap = "1.0.0-beta.2"
api = { path = "../api" }
async-stream = "0.3"
async-trait = "0.1"

View File

@@ -14,7 +14,7 @@
use std::sync::Arc;
use common_telemetry::info;
use anymap::AnyMap;
use meta_client::MetaClientOpts;
use serde::{Deserialize, Serialize};
use servers::auth::UserProviderRef;
@@ -67,29 +67,18 @@ where
{
opts: FrontendOptions,
instance: Option<T>,
user_provider: Option<UserProviderRef>,
plugins: AnyMap,
}
impl<T> Frontend<T>
where
T: FrontendInstance,
{
pub fn new(opts: FrontendOptions, instance: T) -> Self {
impl<T: FrontendInstance> Frontend<T> {
pub fn new(opts: FrontendOptions, instance: T, plugins: AnyMap) -> Self {
Self {
opts,
instance: Some(instance),
user_provider: None,
plugins,
}
}
pub fn set_user_provider(&mut self, user_provider: Option<UserProviderRef>) {
info!(
"Configured user provider: {:?}",
user_provider.as_ref().map(|u| u.name())
);
self.user_provider = user_provider;
}
pub async fn start(&mut self) -> Result<()> {
let mut instance = self
.instance
@@ -100,6 +89,9 @@ where
instance.start().await?;
let instance = Arc::new(instance);
Services::start(&self.opts, instance, self.user_provider.clone()).await
let provider = self.plugins.get::<UserProviderRef>().cloned();
Services::start(&self.opts, instance, provider).await
}
}

View File

@@ -21,7 +21,6 @@ use servers::tls::TlsOption;
pub struct PostgresOptions {
pub addr: String,
pub runtime_size: usize,
pub check_pwd: bool,
#[serde(default = "Default::default")]
pub tls: Arc<TlsOption>,
}
@@ -31,7 +30,6 @@ impl Default for PostgresOptions {
Self {
addr: "127.0.0.1:4003".to_string(),
runtime_size: 2,
check_pwd: false,
tls: Default::default(),
}
}

View File

@@ -99,10 +99,9 @@ impl Services {
let pg_server = Box::new(PostgresServer::new(
instance.clone(),
opts.check_pwd,
opts.tls.clone(),
pg_io_runtime,
user_provider,
user_provider.clone(),
)) as Box<dyn Server>;
Some((pg_server, pg_addr))
@@ -132,6 +131,10 @@ impl Services {
let http_addr = parse_addr(&http_options.addr)?;
let mut http_server = HttpServer::new(instance.clone(), http_options.clone());
if let Some(user_provider) = user_provider {
http_server.set_user_provider(user_provider);
}
if opentsdb_server_and_addr.is_some() {
http_server.set_opentsdb_handler(instance.clone());
}