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

Switch to Rust edition 2018 #133

Merged
merged 2 commits into from
Jan 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ exclude = [
".gitignore",
".travis.yml",
]
edition = "2018"

[package.metadata.release]
sign-commit = true
Expand Down
5 changes: 2 additions & 3 deletions examples/checkregistry.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
extern crate dkregistry;
extern crate tokio;

use std::{boxed, error};
Expand All @@ -20,10 +19,10 @@ fn main() {

fn run(host: &str) -> Result<bool, boxed::Box<dyn error::Error>> {
let mut runtime = Runtime::new()?;
let dclient = try!(dkregistry::v2::Client::configure()
let dclient = dkregistry::v2::Client::configure()
.registry(host)
.insecure_registry(false)
.build());
.build()?;
let futcheck = dclient.is_v2_supported();

let supported = runtime.block_on(futcheck)?;
Expand Down
1 change: 0 additions & 1 deletion examples/common/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
extern crate dkregistry;
extern crate futures;

use futures::prelude::*;
Expand Down
1 change: 0 additions & 1 deletion examples/image-labels.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
extern crate dirs;
extern crate dkregistry;
extern crate futures;
extern crate serde_json;
extern crate tokio;
Expand Down
3 changes: 0 additions & 3 deletions examples/image.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
extern crate dirs;
extern crate dkregistry;
extern crate futures;
extern crate serde_json;
extern crate tokio;
Expand Down Expand Up @@ -88,8 +87,6 @@ fn run(
.and_then(|manifest| Ok((dclient, manifest.layers_digests(None)?)))
})
.and_then(|(dclient, layers_digests)| {
let image = image.clone();

println!("{} -> got {} layer(s)", &image, layers_digests.len(),);

futures::stream::iter_ok::<_, dkregistry::errors::Error>(layers_digests)
Expand Down
1 change: 0 additions & 1 deletion examples/login.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
extern crate dkregistry;
extern crate futures;
extern crate tokio;

Expand Down
1 change: 0 additions & 1 deletion examples/tags.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
extern crate dkregistry;
extern crate futures;
extern crate tokio;

Expand Down
1 change: 0 additions & 1 deletion examples/trace.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
extern crate dirs;
extern crate dkregistry;
extern crate futures;
extern crate serde_json;
extern crate tokio;
Expand Down
18 changes: 3 additions & 15 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,14 @@

#![deny(missing_debug_implementations)]

extern crate base64;
extern crate futures;
extern crate http;
extern crate mime;
extern crate serde;
extern crate serde_json;
#[macro_use]
extern crate error_chain;
#[macro_use]
extern crate serde_derive;
#[macro_use]
extern crate log;
extern crate libflate;
extern crate regex;
extern crate strum;
extern crate tar;
#[macro_use]
extern crate strum_macros;
extern crate reqwest;
extern crate sha2;

pub mod errors;
pub mod mediatypes;
Expand All @@ -77,17 +65,17 @@ pub fn get_credentials<T: Read>(
reader: T,
index: &str,
) -> Result<(Option<String>, Option<String>)> {
let map: Auths = try!(serde_json::from_reader(reader));
let map: Auths = serde_json::from_reader(reader)?;
let real_index = match index {
// docker.io has some special casing in config.json
"docker.io" | "registry-1.docker.io" => "https://index.docker.io/v1/",
other => other,
};
let auth = match map.auths.get(real_index) {
Some(x) => try!(base64::decode(x.auth.as_str())),
Some(x) => base64::decode(x.auth.as_str())?,
None => bail!("no auth for index {}", real_index),
};
let s = try!(String::from_utf8(auth));
let s = String::from_utf8(auth)?;
let creds: Vec<&str> = s.splitn(2, ':').collect();
let up = match (creds.get(0), creds.get(1)) {
(Some(&""), Some(p)) => (None, Some(p.to_string())),
Expand Down
2 changes: 1 addition & 1 deletion src/mediatypes.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Media-types for API objects.

use errors::*;
use crate::errors::*;
use futures;
use mime;
use strum::EnumProperty;
Expand Down
6 changes: 3 additions & 3 deletions src/reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
// The `docker://` schema is not officially documented, but has a reference implementation:
// https://github.com/docker/distribution/blob/v2.6.1/reference/reference.go

use errors::Error;
use crate::errors::Error;
use regex;
use std::collections::VecDeque;
use std::str::FromStr;
Expand All @@ -47,7 +47,7 @@ pub enum Version {
}

impl str::FromStr for Version {
type Err = ::errors::Error;
type Err = Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
let v = match s.chars().nth(0) {
Some(':') => Version::Tag(s.trim_start_matches(':').to_string()),
Expand Down Expand Up @@ -146,7 +146,7 @@ impl fmt::Display for Reference {
}

impl str::FromStr for Reference {
type Err = ::errors::Error;
type Err = Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
parse_url(s)
}
Expand Down
2 changes: 1 addition & 1 deletion src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Docker image format is specified at
// https://github.com/moby/moby/blob/v17.05.0-ce/image/spec/v1.md

use errors::*;
use crate::errors::*;
use libflate::gzip;
use std::{fs, path};
use tar;
Expand Down
10 changes: 5 additions & 5 deletions src/v2/auth.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use futures::{future, prelude::*};
use crate::v2::*;
use futures::future;
use reqwest::{StatusCode, Url};
use v2::*;

/// Convenience alias for future `TokenAuth` result.
pub type FutureTokenAuth = Box<dyn Future<Item = TokenAuth, Error = Error> + Send>;
Expand Down Expand Up @@ -37,7 +37,7 @@ impl Client {
};

let fres = self
.build_reqwest(reqwest::async::Client::new().get(url.clone()))
.build_reqwest(reqwest::r#async::Client::new().get(url.clone()))
.send()
.map_err(|e| Error::from(format!("{}", e)))
.and_then(move |r| {
Expand Down Expand Up @@ -95,7 +95,7 @@ impl Client {
})
.and_then(move |u| {
let auth_req = {
let auth_req = subclient.build_reqwest(reqwest::async::Client::new().get(u));
let auth_req = subclient.build_reqwest(reqwest::r#async::Client::new().get(u));
if let Some(creds) = creds {
auth_req.basic_auth(creds.0, Some(creds.1))
} else {
Expand Down Expand Up @@ -158,7 +158,7 @@ impl Client {
}
};

let req = self.build_reqwest(reqwest::async::Client::new().get(url.clone()));
let req = self.build_reqwest(reqwest::r#async::Client::new().get(url.clone()));
let req = if let Some(t) = token {
req.bearer_auth(t)
} else {
Expand Down
18 changes: 9 additions & 9 deletions src/v2/blobs.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::v2::*;
use futures::Stream;
use reqwest;
use reqwest::StatusCode;
use v2::*;

/// Convenience alias for future binary blob.
pub type FutureBlob = Box<dyn futures::Future<Item = Vec<u8>, Error = Error> + Send>;
Expand All @@ -23,7 +23,7 @@ impl Client {
};

let fres = self
.build_reqwest(reqwest::async::Client::new().head(url))
.build_reqwest(reqwest::r#async::Client::new().head(url))
.send()
.inspect(|res| trace!("Blob HEAD status: {:?}", res.status()))
.and_then(|res| match res.status() {
Expand All @@ -41,16 +41,16 @@ impl Client {
let fres_blob = {
let ep = format!("{}/v2/{}/blobs/{}", self.base_url, name, digest);
reqwest::Url::parse(&ep).map_err(|e|{
::errors::Error::from(format!(
crate::errors::Error::from(format!(
"failed to parse url from string: {}",
e
))
})
.map(|url|{
self.build_reqwest(reqwest::async::Client::new()
self.build_reqwest(reqwest::r#async::Client::new()
.get(url))
.send()
.map_err(|e| ::errors::Error::from(format!("{}", e)))
.map_err(|e| crate::errors::Error::from(format!("{}", e)))
})
.into_future()
.flatten()
Expand All @@ -64,17 +64,17 @@ impl Client {
{
Ok(res)
} else {
Err(::errors::Error::from(format!(
Err(crate::errors::Error::from(format!(
"GET request failed with status '{}'",
status
)))
}
}).and_then(|mut res| {
std::mem::replace(res.body_mut(), reqwest::async::Decoder::empty())
std::mem::replace(res.body_mut(), reqwest::r#async::Decoder::empty())
.concat2()
.map_err(|e| ::errors::Error::from(format!("{}", e)))
.map_err(|e| crate::errors::Error::from(format!("{}", e)))
.join(futures::future::ok(res))
}).map_err(|e| ::errors::Error::from(format!("{}", e)))
}).map_err(|e| crate::errors::Error::from(format!("{}", e)))
.and_then(|(body, res)| {
let body_vec = body.to_vec();
let len = body_vec.len();
Expand Down
6 changes: 3 additions & 3 deletions src/v2/catalog.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use errors::{Error, Result};
use crate::errors::{Error, Result};
use crate::v2;
use futures::{self, stream, Future, Stream};
use reqwest::StatusCode;
use serde_json;
use v2;

/// Convenience alias for a stream of `String` repos.
pub type StreamCatalog = Box<dyn futures::Stream<Item = String, Error = Error>>;
Expand Down Expand Up @@ -32,7 +32,7 @@ impl v2::Client {
}
};

let req = self.build_reqwest(reqwest::async::Client::new().get(url));
let req = self.build_reqwest(reqwest::r#async::Client::new().get(url));

let fres = req
.send()
Expand Down
6 changes: 3 additions & 3 deletions src/v2/config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use v2::*;
use crate::v2::*;

/// Configuration for a `Client`.
#[derive(Debug)]
Expand All @@ -16,7 +16,7 @@ impl Config {
Self {
index: "registry-1.docker.io".into(),
insecure_registry: false,
user_agent: Some(::USER_AGENT.to_owned()),
user_agent: Some(crate::USER_AGENT.to_owned()),
username: None,
password: None,
}
Expand Down Expand Up @@ -54,7 +54,7 @@ impl Config {

/// Read credentials from a JSON config file
pub fn read_credentials<T: ::std::io::Read>(mut self, reader: T) -> Self {
if let Ok(creds) = ::get_credentials(reader, &self.index) {
if let Ok(creds) = crate::get_credentials(reader, &self.index) {
self.username = creds.0;
self.password = creds.1;
};
Expand Down
2 changes: 1 addition & 1 deletion src/v2/content_digest.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::v2::*;
/// Implements types and methods for content verification
use sha2::{self, Digest};
use v2::*;

/// ContentDigest stores a digest and its DigestAlgorithm
#[derive(Clone, Debug, PartialEq)]
Expand Down
2 changes: 1 addition & 1 deletion src/v2/manifest/manifest_schema1.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::v2::*;
use std::collections::HashMap;
use v2::*;

/// Manifest version 2 schema 1, signed.
///
Expand Down
4 changes: 2 additions & 2 deletions src/v2/manifest/manifest_schema2.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::v2::{Error, FutureResult};
use futures::future::{self, Future};
use futures::stream::Stream;
use serde_json;
use v2::{Error, FutureResult};

/// Manifest version 2 schema 2.
///
Expand Down Expand Up @@ -114,7 +114,7 @@ impl ManifestSchema2Spec {
};

let manifest_future = client
.build_reqwest(reqwest::async::Client::new().get(url.clone()))
.build_reqwest(reqwest::r#async::Client::new().get(url.clone()))
.send()
.map_err(|e| crate::v2::Error::from(format!("{}", e)))
.and_then(move |r| {
Expand Down
8 changes: 4 additions & 4 deletions src/v2/manifest/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Manifest types.
use mediatypes;
use v2::*;
use crate::mediatypes;
use crate::v2::*;

use futures::future::Either;
use futures::{future, Stream};
Expand Down Expand Up @@ -78,7 +78,7 @@ impl Client {

let fres = self
.build_reqwest(
reqwest::async::Client::new()
reqwest::r#async::Client::new()
.get(url)
.headers(accept_headers),
)
Expand Down Expand Up @@ -222,7 +222,7 @@ impl Client {
}

let fres = self
.build_reqwest(reqwest::async::Client::new().get(url.clone()))
.build_reqwest(reqwest::r#async::Client::new().get(url.clone()))
.headers(accept_headers)
.send()
.map_err(Error::from)
Expand Down
8 changes: 4 additions & 4 deletions src/v2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
//! ```

use super::errors::*;
use crate::v2::manifest::Manifest;
use futures::prelude::*;
use reqwest::StatusCode;
use serde_json;
use v2::manifest::Manifest;

mod config;
pub use self::config::Config;
Expand Down Expand Up @@ -107,7 +107,7 @@ impl Client {
.chain_err(|| format!("failed to parse url string '{}'", &v2_endpoint))
.map(|url| {
trace!("GET {:?}", url);
self.build_reqwest(reqwest::async::Client::new().get(url))
self.build_reqwest(reqwest::r#async::Client::new().get(url))
})
.into_future()
.and_then(|req| req.send().from_err());
Expand All @@ -131,8 +131,8 @@ impl Client {
/// Takes reqwest's async RequestBuilder and injects an authentication header if a token is present
fn build_reqwest(
&self,
req_builder: reqwest::async::RequestBuilder,
) -> reqwest::async::RequestBuilder {
req_builder: reqwest::r#async::RequestBuilder,
) -> reqwest::r#async::RequestBuilder {
let mut builder = req_builder;

if let Some(token) = &self.token {
Expand Down
Loading