Skip to content

Commit

Permalink
Merge pull request #46 from lucab/ups/clippy-cleanup
Browse files Browse the repository at this point in the history
dkregistry: fix all clippy warnings
  • Loading branch information
steveej authored Oct 15, 2018
2 parents bacca3b + de4d37a commit 2cd5f12
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 28 deletions.
2 changes: 1 addition & 1 deletion examples/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ fn run(dkr_ref: &reference::Reference, user: Option<String>, passwd: Option<Stri
return Err("API v2 not supported".into());
}

let fut_token = try!(dclient.login(vec![&format!("repository:{}:pull", image)]));
let fut_token = try!(dclient.login(&[&format!("repository:{}:pull", image)]));
let token_auth = try!(tcore.run(fut_token));

let futauth = try!(dclient.is_auth(Some(token_auth.token())));
Expand Down
2 changes: 1 addition & 1 deletion examples/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fn run(host: &str, user: Option<String>, passwd: Option<String>) -> Result<()> {
return Err("no login performed, but already authenticated".into());
}

let fut_token = try!(dclient.login(vec![]));
let fut_token = try!(dclient.login(&[]));
let token = try!(tcore.run(fut_token));

let futauth = try!(dclient.is_auth(Some(token.token())));
Expand Down
2 changes: 1 addition & 1 deletion examples/tags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fn run(host: &str, user: Option<String>, passwd: Option<String>, image: &str) ->
return Err("API v2 not supported".into());
}

let fut_token = try!(dclient.login(vec![&format!("repository:{}:pull", image)]));
let fut_token = try!(dclient.login(&[&format!("repository:{}:pull", image)]));
let token_auth = try!(tcore.run(fut_token));

let futauth = try!(dclient.is_auth(Some(token_auth.token())));
Expand Down
2 changes: 1 addition & 1 deletion examples/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ fn run(dkr_ref: &reference::Reference, user: Option<String>, passwd: Option<Stri
return Err("API v2 not supported".into());
}

let fut_token = try!(dclient.login(vec![&format!("repository:{}:pull", image)]));
let fut_token = try!(dclient.login(&[&format!("repository:{}:pull", image)]));
let token_auth = try!(tcore.run(fut_token));

let futauth = try!(dclient.is_auth(Some(token_auth.token())));
Expand Down
32 changes: 16 additions & 16 deletions src/reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,19 @@ impl Default for Version {

impl fmt::Debug for Version {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
let v = match self {
&Version::Tag(ref s) => ":".to_string() + s,
&Version::Digest(ref t, ref d) => "@".to_string() + t + ":" + d,
let v = match *self {
Version::Tag(ref s) => ":".to_string() + s,
Version::Digest(ref t, ref d) => "@".to_string() + t + ":" + d,
};
write!(f, "{}", v)
}
}

impl fmt::Display for Version {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
let v = match self {
&Version::Tag(ref s) => s.to_string(),
&Version::Digest(ref t, ref d) => t.to_string() + ":" + d,
let v = match *self {
Version::Tag(ref s) => s.to_string(),
Version::Digest(ref t, ref d) => t.to_string() + ":" + d,
};
write!(f, "{}", v)
}
Expand All @@ -96,13 +96,13 @@ pub struct Reference {

impl Reference {
pub fn new(registry: Option<String>, repository: String, version: Option<Version>) -> Self {
let reg = registry.unwrap_or("registry-1.docker.io".to_string());
let ver = version.unwrap_or(Version::Tag("latest".to_string()));
let reg = registry.unwrap_or_else(|| "registry-1.docker.io".to_string());
let ver = version.unwrap_or_else(|| Version::Tag("latest".to_string()));
Self {
has_schema: false,
raw_input: "".into(),
registry: reg,
repository: repository,
repository,
version: ver,
}
}
Expand Down Expand Up @@ -152,34 +152,34 @@ fn parse_url(s: &str) -> Result<Reference, ::errors::Error> {
if has_schema {
rest = s.trim_left_matches("docker://");
};
let (rest, ver) = match (rest.rfind('@'), rest.rfind(':')) {
let (rest, version) = match (rest.rfind('@'), rest.rfind(':')) {
(Some(i), _) | (None, Some(i)) => {
let s = rest.split_at(i);
(s.0, Version::from_str(s.1)?)
}
(None, None) => (rest, Version::default()),
};
if rest.len() < 1 {
if rest.is_empty() {
bail!("name too short");
}
let mut reg = "registry-1.docker.io";
let split: Vec<&str> = rest.rsplitn(3, '/').collect();
let image = match split.len() {
let repository = match split.len() {
1 => "library/".to_string() + rest,
2 => rest.to_string(),
_ => {
reg = split[2];
split[1].to_string() + "/" + split[0]
}
};
if image.len() > 127 {
if repository.len() > 127 {
bail!("name too long");
}
Ok(Reference {
has_schema: has_schema,
has_schema,
raw_input: s.to_string(),
registry: reg.to_string(),
repository: image,
version: ver,
repository,
version,
})
}
2 changes: 1 addition & 1 deletion src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub fn unpack(layers: &[Vec<u8>], target_dir: &path::Path) -> Result<()> {
for entry in archive.entries()? {
let file = entry?;
let path = file.path()?;
let parent = path.parent().unwrap_or(path::Path::new("/"));
let parent = path.parent().unwrap_or_else(|| path::Path::new("/"));
if let Some(fname) = path.file_name() {
let wh_name = fname.to_string_lossy();
if wh_name == ".wh..wh..opq" {
Expand Down
6 changes: 3 additions & 3 deletions src/v2/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl Client {
let a = r
.headers()
.get(hyper::header::WWW_AUTHENTICATE)
.ok_or(Error::from("get_token: missing Auth header"))?;
.ok_or_else(|| Error::from("get_token: missing Auth header"))?;
let chal = String::from_utf8(a.as_bytes().to_vec())?;
Ok(chal)
}).and_then(move |hdr| {
Expand All @@ -45,7 +45,7 @@ impl Client {
let kv: Vec<&str> = item.split('=').collect();
match (kv.get(0), kv.get(1)) {
(Some(&"realm"), Some(v)) => auth_ep = v.trim_matches('"').to_owned(),
(Some(&"service"), Some(v)) => service = Some(v.trim_matches('"').clone()),
(Some(&"service"), Some(v)) => service = Some(v.trim_matches('"')),
(Some(&"scope"), _) => {}
(_, _) => return Err("unsupported key".to_owned().into()),
};
Expand All @@ -71,7 +71,7 @@ impl Client {
/// Perform registry authentication and return an authenticated token.
///
/// On success, the returned token will be valid for all requested scopes.
pub fn login(&self, scopes: Vec<&str>) -> Result<FutureTokenAuth> {
pub fn login(&self, scopes: &[&str]) -> Result<FutureTokenAuth> {
let subclient = self.hclient.clone();
let creds = self.credentials.clone();
let scope = scopes
Expand Down
12 changes: 8 additions & 4 deletions src/v2/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@ impl Config {

/// Return a `Client` to interact with a v2 registry.
pub fn build(self) -> Result<Client> {
let base = match self.insecure_registry {
false => "https://".to_string() + &self.index,
true => "http://".to_string() + &self.index,
let base = if self.insecure_registry {
"http://".to_string() + &self.index
} else {
"https://".to_string() + &self.index
};
trace!(
"Built client for {:?}: endpoint {:?} - user {:?}",
Expand All @@ -82,7 +83,10 @@ impl Config {
);
let creds = match (self.username, self.password) {
(None, None) => None,
(u, p) => Some((u.unwrap_or("".into()), p.unwrap_or("".into()))),
(u, p) => Some((
u.unwrap_or_else(|| "".into()),
p.unwrap_or_else(|| "".into()),
)),
};
let c = Client {
base_url: base,
Expand Down

0 comments on commit 2cd5f12

Please sign in to comment.