• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2023 Huawei Device Co., Ltd.
2 // Licensed under the Apache License, Version 2.0 (the "License");
3 // you may not use this file except in compliance with the License.
4 // You may obtain a copy of the License at
5 //
6 //     http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13 
14 mod cert_manager;
15 mod system_proxy;
16 
17 use cert_manager::CertManager;
18 use system_proxy::SystemProxyManager;
19 use ylong_http_client::Certificate;
20 
21 #[derive(Clone)]
22 pub(crate) struct SystemConfigManager {
23     cert: CertManager,
24     proxy: SystemProxyManager,
25 }
26 
27 impl SystemConfigManager {
init() -> Self28     pub(crate) fn init() -> Self {
29         Self {
30             cert: CertManager::init(),
31             proxy: SystemProxyManager::init(),
32         }
33     }
34 
system_config(&self) -> SystemConfig35     pub(crate) fn system_config(&self) -> SystemConfig {
36         let mut certs = self.cert.certificate();
37 
38         if certs.is_none() {
39             self.cert.force_update();
40             certs = self.cert.certificate();
41         }
42 
43         SystemConfig {
44             proxy_host: self.proxy.host(),
45             proxy_port: self.proxy.port(),
46             proxy_exlist: self.proxy.exlist(),
47             certs,
48         }
49     }
50 }
51 
52 pub(crate) struct SystemConfig {
53     pub(crate) proxy_host: String,
54     pub(crate) proxy_port: String,
55     pub(crate) proxy_exlist: String,
56     pub(crate) certs: Option<Vec<Certificate>>,
57 }
58