Skip to main content

wb_api_client/general/apis/
configuration.rs

1/*
2 * Общее
3 *
4 * В этом разделе: - [общая информация о WB API](https://dev.wildberries.ru/openapi/api-information#tag/introduction) - как [начать работу с WB API](https://dev.wildberries.ru/openapi/api-information#tag/introduction/Kak-nachat-rabotu-s-API) - как [авторизоваться](https://dev.wildberries.ru/openapi/api-information#tag/authorization) и [создавать токены](https://dev.wildberries.ru/openapi/api-information#tag/authorization/Kak-sozdat-personalnyj-bazovyj-ili-testovyj-token) - основные [статус-коды ответов](https://dev.wildberries.ru/openapi/api-information#tag/introduction/Status-kody-HTTP) - [лимиты запросов](https://dev.wildberries.ru/openapi/api-information#tag/introduction/Limity-zaprosov) - как обратиться в [поддержку](https://dev.wildberries.ru/openapi/api-information#tag/introduction/Podderzhka) С помощью методов этого раздела вы можете: - проверить [подключение к WB API](https://dev.wildberries.ru/openapi/api-information#tag/connectionCheck/operation/getPing) - получить [новости](https://dev.wildberries.ru/openapi/api-information#tag/newsApi/operation/getV2News) и [уведомления](https://dev.wildberries.ru/openapi/api-information#tag/newsApi/operation/getV1Notifications) портала продавцов - получить [информацию о продавце](https://dev.wildberries.ru/openapi/api-information#tag/sellerInformation/operation/getV1SellerInfo) - [управлять пользователями продавца](https://dev.wildberries.ru/openapi/api-information#tag/sellerUserManagement)
5 *
6 * The version of the OpenAPI document: general
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}