File tree Expand file tree Collapse file tree 7 files changed +44
-3
lines changed Expand file tree Collapse file tree 7 files changed +44
-3
lines changed Original file line number Diff line number Diff line change @@ -184,6 +184,7 @@ k8s支持使用 [helm](https://github.com/nacos-group/r-nacos/tree/master/deploy
184
184
| RNACOS_ENABLE_OPEN_API_AUTH| 是否对openapi开启鉴权;(注:nacos切换到r-nacos过程中不要开启鉴权)| false| true| 0.5.8|
185
185
| RNACOS_API_LOGIN_TIMEOUT| open api鉴权有效时长,单位为秒;(注:从不鉴权到开启鉴权,需要间隔对应时长以保证客户端token能更新生效)| 一小时,3600秒| 3600| 0.5.8|
186
186
| RNACOS_CLUSTER_TOKEN| 集群间的通信请求校验token,空表示不开启校验,设置后只有相同token的节点间才可通讯| 空字符串| 1234567890abcdefg| 0.5.8|
187
+ | RNACOS_BACKUP_TOKEN| 数据备份接口请求校验token,空或长度小于32位表示不开启备份接口| 空字符串| 1234567890abcdefg1234567890abcdefg| 0.6.6|
187
188
| RNACOS_INIT_ADMIN_USERNAME| 初始化管理员用户名,只在主节点第一次启动时生效| admin| rnacos| 0.5.11|
188
189
| RNACOS_INIT_ADMIN_PASSWORD| 初始化管理员密码,只在主节点第一次启动时生效| admin| rnacos123456| 0.5.11|
189
190
| RNACOS_ENABLE_METRICS| 是否开启监控指标功能| true| true| 0.5.13|
Original file line number Diff line number Diff line change @@ -56,6 +56,9 @@ RNACOS_ENABLE_NO_AUTH_CONSOLE=false
56
56
# 集群间的通信请求校验token,空表示不开启校验,设置后只有相同token的节点间才可通讯;默认为字符串
57
57
# RNACOS_CLUSTER_TOKEN=bbd8b0b391254e00ae1a7c8ac6ed5f82
58
58
59
+ # 数据备份接口请求校验token,空或长度小于32位表示不开启备份接口
60
+ # RNACOS_BACKUP_TOKEN=
61
+
59
62
# 初始化管理员用户名,只在主节点第一次启动时生效,默认值:admin
60
63
RNACOS_INIT_ADMIN_USERNAME = admin
61
64
Original file line number Diff line number Diff line change @@ -78,6 +78,7 @@ pub struct AppSysConfig {
78
78
pub openapi_login_one_minute_limit : u32 ,
79
79
pub openapi_enable_auth : bool ,
80
80
pub cluster_token : Arc < String > ,
81
+ pub backup_token : Arc < String > ,
81
82
pub init_admin_username : String ,
82
83
pub init_admin_password : String ,
83
84
pub metrics_enable : bool ,
@@ -165,6 +166,12 @@ impl AppSysConfig {
165
166
let cluster_token = std:: env:: var ( "RNACOS_CLUSTER_TOKEN" )
166
167
. map ( Arc :: new)
167
168
. unwrap_or ( constant:: EMPTY_ARC_STRING . clone ( ) ) ;
169
+ let mut backup_token = std:: env:: var ( "RNACOS_BACKUP_TOKEN" )
170
+ . map ( Arc :: new)
171
+ . unwrap_or ( constant:: EMPTY_ARC_STRING . clone ( ) ) ;
172
+ if backup_token. len ( ) < 32 {
173
+ backup_token = constant:: EMPTY_ARC_STRING . clone ( ) ;
174
+ }
168
175
let init_admin_username =
169
176
StringUtils :: map_not_empty ( std:: env:: var ( "RNACOS_INIT_ADMIN_USERNAME" ) . ok ( ) )
170
177
. unwrap_or ( "admin" . to_owned ( ) ) ;
@@ -236,6 +243,7 @@ impl AppSysConfig {
236
243
gmt_fixed_offset_hours,
237
244
openapi_enable_auth,
238
245
cluster_token,
246
+ backup_token,
239
247
init_admin_username,
240
248
init_admin_password,
241
249
metrics_enable,
Original file line number Diff line number Diff line change @@ -13,9 +13,7 @@ use std::sync::Arc;
13
13
use tokio:: fs:: OpenOptions ;
14
14
use tokio:: io:: { AsyncReadExt , AsyncSeekExt } ;
15
15
16
- pub async fn download_transfer_file (
17
- app_share_data : web:: Data < Arc < AppShareData > > ,
18
- ) -> impl Responder {
16
+ pub async fn download_transfer_file ( app_share_data : web:: Data < Arc < AppShareData > > ) -> HttpResponse {
19
17
if let Ok ( Ok ( TransferManagerResponse :: BackupFile ( temp_file) ) ) = app_share_data
20
18
. transfer_writer_manager
21
19
. send ( TransferManagerAsyncRequest :: Backup (
Original file line number Diff line number Diff line change
1
+ use crate :: common:: appdata:: AppShareData ;
2
+ use crate :: console:: transfer_api:: download_transfer_file;
3
+ use actix_web:: { web, HttpResponse , Responder } ;
4
+ use serde:: { Deserialize , Serialize } ;
5
+ use std:: sync:: Arc ;
6
+
7
+ #[ derive( Debug , Deserialize , Serialize ) ]
8
+ pub struct BackupParam {
9
+ pub token : Arc < String > ,
10
+ }
11
+
12
+ pub async fn backup (
13
+ app_share_data : web:: Data < Arc < AppShareData > > ,
14
+ web:: Query ( params) : web:: Query < BackupParam > ,
15
+ ) -> impl Responder {
16
+ if app_share_data. sys_config . backup_token . is_empty ( ) {
17
+ HttpResponse :: InternalServerError ( ) . body ( "backup api is not open" )
18
+ } else if params. token . as_str ( ) != app_share_data. sys_config . backup_token . as_str ( ) {
19
+ HttpResponse :: InternalServerError ( ) . body ( "backup token is not matched" )
20
+ } else {
21
+ download_transfer_file ( app_share_data) . await
22
+ }
23
+ }
24
+
25
+ pub fn backup_config ( config : & mut web:: ServiceConfig ) {
26
+ config. service ( web:: resource ( "/rnacos/backup" ) . route ( web:: get ( ) . to ( backup) ) ) ;
27
+ }
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ use crate::common::AppSysConfig;
4
4
use crate :: openapi:: constant:: NACOS_PREFIX ;
5
5
6
6
pub ( crate ) mod auth;
7
+ pub ( crate ) mod backup;
7
8
pub ( crate ) mod config;
8
9
mod constant;
9
10
pub ( crate ) mod health;
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ use rnacos_web_dist_wrap::get_embedded_file;
6
6
use crate :: common:: AppSysConfig ;
7
7
use crate :: console:: api:: { console_api_config_v1, console_api_config_v2} ;
8
8
use crate :: openapi:: auth:: { login_config, mock_token} ;
9
+ use crate :: openapi:: backup:: backup_config;
9
10
use crate :: openapi:: health:: health_config;
10
11
use crate :: openapi:: metrics:: metrics_config;
11
12
use crate :: openapi:: { openapi_config, v1:: console as nacos_console} ;
@@ -85,6 +86,7 @@ async fn disable_no_auth_console_index() -> impl Responder {
85
86
pub fn app_config ( conf_data : AppSysConfig ) -> impl FnOnce ( & mut ServiceConfig ) {
86
87
move |config : & mut ServiceConfig | {
87
88
if !conf_data. enable_no_auth_console || conf_data. openapi_enable_auth {
89
+ backup_config ( config) ;
88
90
config
89
91
. service ( web:: resource ( "/" ) . route ( web:: get ( ) . to ( disable_no_auth_console_index) ) )
90
92
. service (
@@ -107,6 +109,7 @@ pub fn app_config(conf_data: AppSysConfig) -> impl FnOnce(&mut ServiceConfig) {
107
109
nacos_console_api_config ( config) ;
108
110
config. configure ( openapi_config ( conf_data) ) ;
109
111
} else {
112
+ backup_config ( config) ;
110
113
login_config ( config) ;
111
114
metrics_config ( config) ;
112
115
health_config ( config) ;
You can’t perform that action at this time.
0 commit comments