Skip to main content

wb_api_client/finances/apis/
configuration.rs

1/*
2 * Документы и бухгалтерия
3 *
4 * Узнать больше о документах и бухгалтерии можно в [справочном центре](https://seller.wildberries.ru/instructions/category/ba929b64-1f89-4426-82d7-ce998ee552bd?goBackOption=prevRoute&categoryId=3c971375-9939-45e8-ab82-376019be8942)  Просмотр [баланса](https://dev.wildberries.ru/openapi/documents-and-accounting#tag/balance), [финансовых отчётов](https://dev.wildberries.ru/openapi/documents-and-accounting#tag/financialReports) и [документов](https://dev.wildberries.ru/openapi/documents-and-accounting#tag/documents) продавца.
5 *
6 * The version of the OpenAPI document: finances
7 *
8 * Generated by: https://openapi-generator.tech
9 */
10
11/// Wrapper around a bearer JWT that redacts under Debug and Display.
12/// Call [`SecretString::expose_secret`] to get the raw value — deliberately
13/// awkward so accidental leaks (logs, `println!("{:?}", config)`) become explicit.
14#[derive(Clone)]
15pub struct SecretString(String);
16
17impl SecretString {
18    pub fn new<S: Into<String>>(value: S) -> Self {
19        SecretString(value.into())
20    }
21
22    pub fn expose_secret(&self) -> &str {
23        &self.0
24    }
25}
26
27impl std::fmt::Debug for SecretString {
28    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
29        f.write_str("<REDACTED>")
30    }
31}
32
33impl std::fmt::Display for SecretString {
34    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
35        f.write_str("<REDACTED>")
36    }
37}
38
39#[derive(Debug, Clone)]
40pub struct Configuration {
41    pub base_path: String,
42    pub user_agent: Option<String>,
43    pub client: reqwest::Client,
44    pub basic_auth: Option<BasicAuth>,
45    pub oauth_access_token: Option<String>,
46    pub bearer_access_token: Option<SecretString>,
47    pub api_key: Option<ApiKey>,
48}
49
50pub type BasicAuth = (String, Option<String>);
51
52#[derive(Debug, Clone)]
53pub struct ApiKey {
54    pub prefix: Option<String>,
55    pub key: String,
56}
57
58impl Configuration {
59    pub fn new() -> Configuration {
60        Configuration::default()
61    }
62
63    /// Store the WB bearer JWT wrapped in a [`SecretString`] so it redacts
64    /// under Debug/Display; the raw value leaves only via `expose_secret()`.
65    pub fn set_access_token(&mut self, token: &str) {
66        self.bearer_access_token = Some(SecretString::new(token));
67    }
68}
69
70impl Default for Configuration {
71    fn default() -> Self {
72        Configuration {
73            base_path: "http://localhost".to_owned(),
74            user_agent: Some("ValeryVerkhoturov/wb-api-client/rust".to_owned()),
75            client: reqwest::Client::new(),
76            basic_auth: None,
77            oauth_access_token: None,
78            bearer_access_token: None,
79            api_key: None,
80        }
81    }
82}