dbbfb747a4
- Replace InternalAuthService with TokenService using JWT tokens - Add support for token issuance, refresh, verification and revocation - Implement automatic signing key rotation with Redis storage - Add database migration checks for indexes and foreign key constraints - Update gRPC endpoints to use token-based authentication - Remove deprecated API key based authentication system - Add JSON Web Token support with HMAC-SHA256 signing - Implement refresh token handling with automatic rotation - Add token revocation by JTI and user ID - Update build configuration to include core proto files - Migrate database schema to handle token-based authentication - Add comprehensive token validation and verification logic
130 lines
2.8 KiB
Rust
130 lines
2.8 KiB
Rust
use std::sync::Arc;
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use crate::cache::AppCache;
|
|
use crate::cache::redis::AppRedis;
|
|
use crate::config::AppConfig;
|
|
use crate::etcd::EtcdRegistry;
|
|
use crate::models::db::AppDatabase;
|
|
use crate::queue::NatsQueue;
|
|
use crate::service::im::events::ImEventBus;
|
|
use crate::storage::s3::AppS3Storage;
|
|
|
|
pub mod context;
|
|
pub mod util;
|
|
|
|
pub mod auth;
|
|
pub mod im;
|
|
pub mod internal_auth;
|
|
pub mod issues;
|
|
pub mod notify;
|
|
pub mod pr;
|
|
pub mod repo;
|
|
pub mod user;
|
|
pub mod wiki;
|
|
pub mod workspace;
|
|
|
|
pub use context::ServiceContext;
|
|
|
|
#[derive(Clone)]
|
|
pub struct AuthService {
|
|
pub ctx: Arc<ServiceContext>,
|
|
}
|
|
|
|
#[derive(Clone)]
|
|
pub struct UserService {
|
|
pub ctx: Arc<ServiceContext>,
|
|
}
|
|
|
|
#[derive(Clone)]
|
|
pub struct WorkspaceService {
|
|
pub ctx: Arc<ServiceContext>,
|
|
}
|
|
|
|
#[derive(Clone)]
|
|
pub struct RepoService {
|
|
pub ctx: Arc<ServiceContext>,
|
|
}
|
|
|
|
#[derive(Clone)]
|
|
pub struct IssueService {
|
|
pub ctx: Arc<ServiceContext>,
|
|
}
|
|
|
|
#[derive(Clone)]
|
|
pub struct PrService {
|
|
pub ctx: Arc<ServiceContext>,
|
|
}
|
|
|
|
#[derive(Clone)]
|
|
pub struct NotificationService {
|
|
pub ctx: Arc<ServiceContext>,
|
|
}
|
|
|
|
pub use im::ImService;
|
|
pub use internal_auth::TokenService;
|
|
|
|
#[derive(Clone)]
|
|
pub struct AppService {
|
|
pub auth: AuthService,
|
|
pub user: UserService,
|
|
pub workspace: WorkspaceService,
|
|
pub repo: RepoService,
|
|
pub issue: IssueService,
|
|
pub pr: PrService,
|
|
pub notify: NotificationService,
|
|
pub im: ImService,
|
|
pub internal_auth: TokenService,
|
|
pub ctx: Arc<ServiceContext>,
|
|
}
|
|
|
|
impl AppService {
|
|
#[allow(clippy::too_many_arguments)]
|
|
pub async fn new(
|
|
version: String,
|
|
db: AppDatabase,
|
|
redis: AppRedis,
|
|
cache: Arc<AppCache>,
|
|
config: AppConfig,
|
|
storage: AppS3Storage,
|
|
registry: Arc<EtcdRegistry>,
|
|
nats: Arc<NatsQueue>,
|
|
) -> Self {
|
|
let token_service = TokenService::new(redis.clone())
|
|
.await
|
|
.expect("failed to initialize TokenService");
|
|
|
|
let ctx = Arc::new(ServiceContext {
|
|
version,
|
|
db,
|
|
redis,
|
|
cache,
|
|
config,
|
|
storage,
|
|
registry,
|
|
nats,
|
|
im_events: Arc::new(ImEventBus::default()),
|
|
});
|
|
|
|
Self {
|
|
auth: AuthService { ctx: ctx.clone() },
|
|
user: UserService { ctx: ctx.clone() },
|
|
workspace: WorkspaceService { ctx: ctx.clone() },
|
|
repo: RepoService { ctx: ctx.clone() },
|
|
issue: IssueService { ctx: ctx.clone() },
|
|
pr: PrService { ctx: ctx.clone() },
|
|
notify: NotificationService { ctx: ctx.clone() },
|
|
im: ImService { ctx: ctx.clone() },
|
|
internal_auth: token_service,
|
|
ctx,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Deserialize, Serialize, Clone, Debug, utoipa::ToSchema)]
|
|
pub struct Pager {
|
|
pub page: i64,
|
|
pub per_page: i64,
|
|
}
|