Skip to content

Commit

Permalink
fix(auth): fix auth log level (#592)
Browse files Browse the repository at this point in the history
* fix(auth): fix auth log level

* update
  • Loading branch information
RWDai authored Jan 15, 2024
1 parent 5f501db commit a2bd819
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 30 deletions.
34 changes: 15 additions & 19 deletions gateway/spacegate-lib/src/plugin/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use std::{
use tardis::{
async_trait,
basic::{error::TardisError, result::TardisResult},
config::config_dto::{AppConfig, CacheModuleConfig, FrameworkConfig, LogConfig, TardisConfig},
config::config_dto::{AppConfig, CacheModuleConfig, FrameworkConfig, TardisConfig},
log,
serde_json::{self, json, Value},
tokio::{sync::RwLock, task::JoinHandle},
Expand Down Expand Up @@ -124,20 +124,6 @@ impl SgPluginFilter for SgFilterAuth {
}

async fn init(&mut self, init_dto: &SgPluginFilterInitDto) -> TardisResult<()> {
if let Some(log_level) = &init_dto.gateway_parameters.log_level {
let mut log_config = TardisFuns::fw_config().log().clone();
fn directive(path: &str, lvl: &str) -> Directive {
let s = format!("{path}={lvl}");
format!("{path}={lvl}").parse().unwrap_or_else(|e| {
tracing::error!("[SG.Filter.Auth] failed to parse directive {:?}: {}", s, e);
Default::default()
})
}
log_config.directives.push(directive(crate::PACKAGE_NAME, log_level));
log_config.directives.push(directive(bios_auth::auth_constants::PACKAGE_NAME, log_level));
TardisFuns::tracing().update_config(&log_config)?;
}

let config_md5 = TardisFuns::crypto.digest.md5(TardisFuns::json.obj_to_string(self)?)?;

let mut instance = INSTANCE.get_or_init(Default::default).write().await;
Expand Down Expand Up @@ -177,15 +163,25 @@ impl SgPluginFilter for SgFilterAuth {
.build()
.into(),
),
log: init_dto.gateway_parameters.log_level.as_ref().map(|l| LogConfig {
level: Some(l.parse().unwrap_or_default()),
..Default::default()
}),
..Default::default()
},
})
.await?;

if let Some(log_level) = &init_dto.gateway_parameters.log_level {
let mut log_config = TardisFuns::fw_config().log().clone();
fn directive(path: &str, lvl: &str) -> Directive {
let s = format!("{path}={lvl}");
format!("{path}={lvl}").parse().unwrap_or_else(|e| {
tracing::error!("[SG.Filter.Auth] failed to parse directive {:?}: {}", s, e);
Default::default()
})
}
log_config.directives.push(directive(crate::PACKAGE_NAME, log_level));
log_config.directives.push(directive(bios_auth::auth_constants::PACKAGE_NAME, log_level));
TardisFuns::tracing().update_config(&log_config)?;
}

let handle = auth_initializer::init().await?;
*instance = Some((config_md5, handle));
log::info!("[SG.Filter.Auth] init done");
Expand Down
22 changes: 11 additions & 11 deletions services/spacegate/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@ FROM ubuntu

# Set time zone
RUN apt-get update && \
apt-get install -yq tzdata && \
ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
dpkg-reconfigure -f noninteractive tzdata
apt-get install -yq tzdata && \
ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
dpkg-reconfigure -f noninteractive tzdata
# When error: `libssl. so.1.1: cannot open shared object file: No such file or directory` appears, please use the following statement to install libssl
# RUN apt update && apt install -y wget && wget http://nz2.archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1f-1ubuntu2.19_amd64.deb && dpkg -i libssl1.1_1.1.1f-1ubuntu2.19_amd64.deb
# RUN apt update && apt install -y wget && wget http://nz2.archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1f-1ubuntu2.20_amd64.deb && dpkg -i libssl1.1_1.1.1f-1ubuntu2.20_amd64.deb
RUN apt update && apt install -y --reinstall ca-certificates
RUN update-ca-certificates -f
RUN echo 'ca_certificate=/etc/ssl/certs/ca-certificates.crt' >> /root/.wgetrc

RUN sed -i '1i\openssl_conf = default_conf' /usr/lib/ssl/openssl.cnf
RUN echo '[ default_conf ] \n\
ssl_conf = ssl_sect \n\
[ssl_sect] \n\
system_default = system_default_sect \n\
[system_default_sect] \n\
MinProtocol = TLSv1 \n\
CipherString = DEFAULT:@SECLEVEL=1 \n'\
>>/usr/lib/ssl/openssl.cnf
ssl_conf = ssl_sect \n\
[ssl_sect] \n\
system_default = system_default_sect \n\
[system_default_sect] \n\
MinProtocol = TLSv1 \n\
CipherString = DEFAULT:@SECLEVEL=1 \n'\
>>/usr/lib/ssl/openssl.cnf

COPY ./bios-spacegate ./spacegate

Expand Down

0 comments on commit a2bd819

Please sign in to comment.