Add a keystore selector (to support Patchwork-style and GoSbot-style paths) #39

Merged
glyph merged 2 commits from keystore_selector into main 2022-05-11 14:33:52 +00:00
Owner

We were previously using the GoSbot keystore path by default. This PR introduces a Keystore enum and adds it as an argument to the Sbot::init method.

Here are the relevant code changes:

/// Keystore selector to specify the location of the secret file.
///
/// This enum is used when initiating a connection with an sbot instance.
pub enum Keystore {
    /// Patchwork default keystore path: `.ssb/secret` in the user's home directory.
    Patchwork,
    /// GoSbot default keystore path: `.ssb-go/secret` in the user's home directory.
    GoSbot,
}
pub async fn init(
        keystore: Keystore,
        ip_port: Option<String>,
        net_id: Option<String>,
    ) -> Result<Sbot, GolgiError> {
    
    // ...
    
    let OwnedIdentity { pk, sk, id } = match keystore {
        Keystore::Patchwork => keystore::from_patchwork_local()
            .await
            .expect("couldn't read local secret"),
        Keystore::GoSbot => keystore::from_gosbot_local()
            .await
            .expect("couldn't read local secret"),
    };

And it's invoked like this:

let mut sbot_client = Sbot::init(Keystore::Patchwork, None, None).await?;

CC: @notplants

We were previously using the GoSbot keystore path by default. This PR introduces a `Keystore enum` and adds it as an argument to the `Sbot::init` method. Here are the relevant code changes: ```rust /// Keystore selector to specify the location of the secret file. /// /// This enum is used when initiating a connection with an sbot instance. pub enum Keystore { /// Patchwork default keystore path: `.ssb/secret` in the user's home directory. Patchwork, /// GoSbot default keystore path: `.ssb-go/secret` in the user's home directory. GoSbot, } ``` ```rust pub async fn init( keystore: Keystore, ip_port: Option<String>, net_id: Option<String>, ) -> Result<Sbot, GolgiError> { // ... let OwnedIdentity { pk, sk, id } = match keystore { Keystore::Patchwork => keystore::from_patchwork_local() .await .expect("couldn't read local secret"), Keystore::GoSbot => keystore::from_gosbot_local() .await .expect("couldn't read local secret"), }; ``` And it's invoked like this: ```rust let mut sbot_client = Sbot::init(Keystore::Patchwork, None, None).await?; ``` CC: @notplants
glyph added 2 commits 2022-05-11 12:19:47 +00:00
glyph added the
enhancement
label 2022-05-11 12:19:53 +00:00
glyph requested review from notplants 2022-05-11 12:19:59 +00:00
Owner

looks good!

cool that it takes advantage of the work already in kuska-ssb, nice detective work

looks good! cool that it takes advantage of the work already in kuska-ssb, nice detective work
notplants approved these changes 2022-05-11 13:41:53 +00:00
glyph merged commit 0aa616d92b into main 2022-05-11 14:33:52 +00:00
glyph deleted branch keystore_selector 2022-05-11 14:33:52 +00:00
Sign in to join this conversation.
No reviewers
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: golgi-ssb/golgi#39
No description provided.