cubestore 添加auth 认证

实际上官方支持auth 的认证的,只是模式为None,我们可以自定义自己的一个auth,以下主要说明下关于mysql 协议的,因为特殊性
http 走的是websocket(后期添加)

参考修改的代码

  • auth
 
#[async_trait]
impl SqlAuthService for SqlAuthDefaultImpl {
    async fn authenticate(&self, _user: Option<String>) -> Result<Option<String>, CubeError> {
      let m =  match _user {
            None => {
                println!("{}", "user is null");
                Err(CubeError {
                    message: "error".to_string(),
                    cause: CubeErrorCauseType::User,
                })
            }
            Some(user) => {
                println!("auth user{}", user);
                Ok(None)
            }
        };
        m
    }
}
  • 协议处理
 tokio::spawn(async move {
                if let Err(e) = AsyncMysqlIntermediary::run_on(
                    Backend {
                        sql_service,
                        auth,
                       // 使用自定义环境变量
                        user: env::var("CUBESTORE_USERNAME").ok(),
                    },
                    socket,
                )
                .await
                {
                    error!("Error during processing MySQL connection: {}", e);
                }
            });

运行

export CUBESTORE_LOG_LEVEL=debug
export CUBESTORE_SERVER_NAME=localhost:9999
export CUBESTORE_META_PORT=9999
export CUBESTORE_S3_BUCKET=test
export CUBESTORE_S3_ENDPOINT=http://localhost:9000
export CUBESTORE_S3_REGION=us-east-1
export CUBESTORE_S3_PATH_STYLE=1
export CUBESTORE_USERNAME=dalong
export CUBESTORE_REMOTE_DIR=./cube/data
export CUBESTORE_AWS_ACCESS_KEY_ID=dalongrong
export CUBESTORE_AWS_SECRET_ACCESS_KEY=dalongrong
 ./target/debug/cubestored 

使用

可以使用以下命令测试

mysql -udalong -h127.0.0.1 

说明

因为http 以及websocket 的特殊性,后期调整添加

原文地址:https://www.cnblogs.com/rongfengliang/p/14737227.html