Skip to content

Commit 3d339d5

Browse files
committed
feat: use git-sec::Identity type (#386)
It's shared across crates.
1 parent cdf3c3e commit 3d339d5

File tree

3 files changed

+11
-23
lines changed

3 files changed

+11
-23
lines changed

git-credentials/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ doctest = false
1212

1313
[features]
1414
## Data structures implement `serde::Serialize` and `serde::Deserialize`.
15-
serde1 = ["serde", "bstr/serde1"]
15+
serde1 = ["serde", "bstr/serde1", "git-sec/serde1"]
1616

1717
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1818

1919
[dependencies]
20+
git-sec = { version = "^0.1.0", path = "../git-sec" }
2021
quick-error = "2.0.0"
2122
serde = { version = "1.0.114", optional = true, default-features = false, features = ["derive"] }
2223
bstr = { version = "0.2.13", default-features = false, features = ["std"]}

git-credentials/src/helper.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ use std::{
33
process::{Command, Stdio},
44
};
55

6-
use crate::Identity;
76
use quick_error::quick_error;
87

9-
/// The result used in [`helper()`].
8+
/// The result used in [`action()`].
109
pub type Result = std::result::Result<Option<Outcome>, Error>;
1110

1211
quick_error! {
13-
/// The error used in the [credentials helper][helper()].
12+
/// The error used in the [credentials helper][action()].
1413
#[derive(Debug)]
1514
#[allow(missing_docs)]
1615
pub enum Error {
@@ -28,7 +27,7 @@ quick_error! {
2827
}
2928
}
3029

31-
/// The action to perform by the credentials [`helper()`].
30+
/// The action to perform by the credentials [`action()`].
3231
#[derive(Clone, Debug)]
3332
pub enum Action<'a> {
3433
/// Provide credentials using the given repository URL (as &str) as context.
@@ -69,11 +68,11 @@ impl NextAction {
6968
}
7069
}
7170

72-
/// The outcome of [`helper()`].
71+
/// The outcome of [`action()`].
7372
pub struct Outcome {
7473
/// The obtained identity.
75-
pub identity: Identity,
76-
/// A handle to the action to perform next using another call to [`helper()`].
74+
pub identity: git_sec::Identity,
75+
/// A handle to the action to perform next using another call to [`action()`].
7776
pub next: NextAction,
7877
}
7978

@@ -91,7 +90,7 @@ fn git_program() -> &'static str {
9190
///
9291
/// Usually the first call is performed with [`Action::Fill`] to obtain an identity, which subsequently can be used.
9392
/// On successful usage, use [`NextAction::approve()`], otherwise [`NextAction::reject()`].
94-
pub fn helper(action: Action<'_>) -> Result {
93+
pub fn action(action: Action<'_>) -> Result {
9594
let mut cmd = Command::new(git_program());
9695
cmd.arg("credential")
9796
.arg(action.as_str())
@@ -128,7 +127,7 @@ pub fn helper(action: Action<'_>) -> Result {
128127
.map(|(_, n)| n.to_owned())
129128
};
130129
Ok(Some(Outcome {
131-
identity: Identity::Account {
130+
identity: git_sec::Identity::Account {
132131
username: find("username")?,
133132
password: find("password")?,
134133
},

git-credentials/src/lib.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,6 @@
22
#![deny(missing_docs, rust_2018_idioms)]
33
//! Interact with git credentials in various ways and launch helper programs.
44
5-
#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]
6-
#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
7-
/// An identity for use when authenticating the transport layer.
8-
pub enum Identity {
9-
/// An account based identity
10-
Account {
11-
/// The user's name
12-
username: String,
13-
/// The user's password
14-
password: String,
15-
},
16-
}
17-
185
///
196
pub mod helper;
7+
pub use helper::action as helper;

0 commit comments

Comments
 (0)