Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

serde SecretString default_type #1228

Closed
nbari opened this issue Sep 25, 2024 · 2 comments · Fixed by #1232
Closed

serde SecretString default_type #1228

nbari opened this issue Sep 25, 2024 · 2 comments · Fixed by #1232

Comments

@nbari
Copy link

nbari commented Sep 25, 2024

Hi, I am using this:

#[derive(Debug, Deserialize)]
pub struct Host {
    pub endpoint: Option<String>,
    pub region: Option<String>,

    #[serde(default)]
    pub access_key: String,

    #[serde(default = "default_secret_key")]
    pub secret_key: SecretKey,

    pub bucket: Option<String>,

    pub enc_key: Option<String>,
    pub enc_type: Option<String>,
    pub compress: Option<bool>,
}

pub type SecretKey = SecretString;

pub fn default_secret_key() -> SecretKey {
    SecretString::new(String::new().into())
}

But for the #[serde(default... how to use Self::new in


pub fn default_secret_key() -> SecretKey {
    SecretString::new(String::new().into())
}

What could be the best (recommended way) to initialize the SecretString?

@tony-iqlusion
Copy link
Member

Let me know if #1232 addresses your problem and I can cut a release

@nbari
Copy link
Author

nbari commented Oct 4, 2024

hi @tony-iqlusion thanks, it works now I can only use:

#[derive(Debug, Deserialize)]
pub struct Host {
    pub endpoint: Option<String>,
    pub region: Option<String>,

    #[serde(default)]
    pub access_key: String,

    #[serde(default)]
    pub secret_key: SecretKey,

    pub bucket: Option<String>,

    pub enc_key: Option<String>,
    pub enc_type: Option<String>,
    pub compress: Option<bool>,
} 
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants