Skip to content

Commit

Permalink
adapt to changes in git-sec (#386)
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Apr 15, 2022
1 parent 37a607d commit c5e2346
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 27 deletions.
4 changes: 2 additions & 2 deletions git-credentials/src/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl NextAction {
/// The outcome of [`action()`].
pub struct Outcome {
/// The obtained identity.
pub identity: git_sec::Identity,
pub identity: git_sec::identity::Account,
/// A handle to the action to perform next using another call to [`action()`].
pub next: NextAction,
}
Expand Down Expand Up @@ -127,7 +127,7 @@ pub fn action(action: Action<'_>) -> Result {
.map(|(_, n)| n.to_owned())
};
Ok(Some(Outcome {
identity: git_sec::Identity::Account {
identity: git_sec::identity::Account {
username: find("username")?,
password: find("password")?,
},
Expand Down
8 changes: 4 additions & 4 deletions git-protocol/src/fetch/tests/arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ struct Transport<T> {
mod impls {
use git_transport::{
client,
client::{Error, Identity, MessageKind, RequestWriter, SetServiceResponse, WriteMode},
client::{Error, MessageKind, RequestWriter, SetServiceResponse, WriteMode},
Protocol, Service,
};

use crate::fetch::tests::arguments::Transport;

impl<T: client::TransportWithoutIO> client::TransportWithoutIO for Transport<T> {
fn set_identity(&mut self, identity: Identity) -> Result<(), Error> {
fn set_identity(&mut self, identity: client::Account) -> Result<(), Error> {
self.inner.set_identity(identity)
}

Expand Down Expand Up @@ -64,13 +64,13 @@ mod impls {
use async_trait::async_trait;
use git_transport::{
client,
client::{Error, Identity, MessageKind, RequestWriter, SetServiceResponse, WriteMode},
client::{Error, MessageKind, RequestWriter, SetServiceResponse, WriteMode},
Protocol, Service,
};

use crate::fetch::tests::arguments::Transport;
impl<T: client::TransportWithoutIO + Send> client::TransportWithoutIO for Transport<T> {
fn set_identity(&mut self, identity: Identity) -> Result<(), Error> {
fn set_identity(&mut self, identity: client::Account) -> Result<(), Error> {
self.inner.set_identity(identity)
}

Expand Down
28 changes: 12 additions & 16 deletions git-transport/src/client/blocking_io/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub struct Transport<H: Http> {
http: H,
service: Option<Service>,
line_provider: Option<git_packetline::StreamingPeekableIter<H::ResponseBody>>,
identity: Option<git_sec::Identity>,
identity: Option<git_sec::identity::Account>,
}

impl Transport<Impl> {
Expand Down Expand Up @@ -71,21 +71,17 @@ impl<H: Http> Transport<H> {

#[allow(clippy::unnecessary_wraps, unknown_lints)]
fn add_basic_auth_if_present(&self, headers: &mut Vec<Cow<'_, str>>) -> Result<(), client::Error> {
if let Some(identity) = &self.identity {
match identity {
git_sec::Identity::Account { username, password } => {
#[cfg(not(debug_assertions))]
if self.url.starts_with("http://") {
return Err(client::Error::AuthenticationRefused(
"Will not send credentials in clear text over http",
));
}
headers.push(Cow::Owned(format!(
"Authorization: Basic {}",
base64::encode(format!("{}:{}", username, password))
)))
}
if let Some(git_sec::identity::Account { username, password }) = &self.identity {
#[cfg(not(debug_assertions))]
if self.url.starts_with("http://") {
return Err(client::Error::AuthenticationRefused(
"Will not send credentials in clear text over http",
));
}
headers.push(Cow::Owned(format!(
"Authorization: Basic {}",
base64::encode(format!("{}:{}", username, password))
)))
}
Ok(())
}
Expand All @@ -100,7 +96,7 @@ fn append_url(base: &str, suffix: &str) -> String {
}

impl<H: Http> client::TransportWithoutIO for Transport<H> {
fn set_identity(&mut self, identity: git_sec::Identity) -> Result<(), client::Error> {
fn set_identity(&mut self, identity: git_sec::identity::Account) -> Result<(), client::Error> {
self.identity = Some(identity);
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion git-transport/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub use capabilities::Capabilities;
mod non_io_types;
pub use non_io_types::{Error, MessageKind, WriteMode};

pub use git_sec::Identity;
pub use git_sec::identity::Account;

///
#[cfg(any(feature = "blocking-client", feature = "async-client"))]
Expand Down
6 changes: 3 additions & 3 deletions git-transport/src/client/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub trait TransportWithoutIO {
/// of the identity in order to mark it as invalid. Otherwise the user might have difficulty updating obsolete
/// credentials.
/// Please note that most transport layers are unauthenticated and thus return [an error][Error::AuthenticationUnsupported] here.
fn set_identity(&mut self, _identity: git_sec::Identity) -> Result<(), Error> {
fn set_identity(&mut self, _identity: git_sec::identity::Account) -> Result<(), Error> {
Err(Error::AuthenticationUnsupported)
}
/// Get a writer for sending data and obtaining the response. It can be configured in various ways
Expand Down Expand Up @@ -50,7 +50,7 @@ pub trait TransportWithoutIO {

// Would be nice if the box implementation could auto-forward to all implemented traits.
impl<T: TransportWithoutIO + ?Sized> TransportWithoutIO for Box<T> {
fn set_identity(&mut self, identity: git_sec::Identity) -> Result<(), Error> {
fn set_identity(&mut self, identity: git_sec::identity::Account) -> Result<(), Error> {
self.deref_mut().set_identity(identity)
}

Expand All @@ -73,7 +73,7 @@ impl<T: TransportWithoutIO + ?Sized> TransportWithoutIO for Box<T> {
}

impl<T: TransportWithoutIO + ?Sized> TransportWithoutIO for &mut T {
fn set_identity(&mut self, identity: git_sec::Identity) -> Result<(), Error> {
fn set_identity(&mut self, identity: git_sec::identity::Account) -> Result<(), Error> {
self.deref_mut().set_identity(identity)
}

Expand Down
2 changes: 1 addition & 1 deletion git-transport/tests/client/blocking_io/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fn assert_error_status(
fn http_authentication_error_can_be_differentiated_and_identity_is_transmitted() -> crate::Result {
let (server, mut client) = assert_error_status(401, std::io::ErrorKind::PermissionDenied)?;
server.next_read_and_respond_with(fixture_bytes("v1/http-handshake.response"));
client.set_identity(git_sec::Identity::Account {
client.set_identity(git_sec::identity::Account {
username: "user".into(),
password: "password".into(),
})?;
Expand Down

0 comments on commit c5e2346

Please sign in to comment.