2014-09-27 04:14:46 +00:00
|
|
|
extern crate curl;
|
2016-03-07 08:19:40 +00:00
|
|
|
extern crate url;
|
2015-03-26 18:17:44 +00:00
|
|
|
extern crate rustc_serialize;
|
2014-09-27 04:14:46 +00:00
|
|
|
|
|
|
|
use std::collections::HashMap;
|
2015-02-27 01:04:25 +00:00
|
|
|
use std::fmt;
|
2016-04-02 01:06:20 +00:00
|
|
|
use std::fs::File;
|
2015-02-27 01:04:25 +00:00
|
|
|
use std::io::prelude::*;
|
|
|
|
use std::io::{self, Cursor};
|
2014-09-27 04:14:46 +00:00
|
|
|
use std::result;
|
|
|
|
|
2016-05-18 17:01:40 +00:00
|
|
|
use curl::easy::{Easy, List};
|
2016-11-29 18:19:07 +00:00
|
|
|
use rustc_serialize::json::{self, Json};
|
2014-12-24 02:45:46 +00:00
|
|
|
|
2016-03-07 08:19:40 +00:00
|
|
|
use url::percent_encoding::{percent_encode, QUERY_ENCODE_SET};
|
|
|
|
|
2014-09-27 04:14:46 +00:00
|
|
|
pub struct Registry {
|
|
|
|
host: String,
|
2014-11-22 14:36:14 +00:00
|
|
|
token: Option<String>,
|
2016-05-18 17:01:40 +00:00
|
|
|
handle: Easy,
|
2014-09-27 04:14:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub type Result<T> = result::Result<T, Error>;
|
|
|
|
|
2015-04-05 07:00:01 +00:00
|
|
|
#[derive(PartialEq, Clone, Copy)]
|
2014-11-22 14:36:14 +00:00
|
|
|
pub enum Auth {
|
|
|
|
Authorized,
|
|
|
|
Unauthorized
|
|
|
|
}
|
|
|
|
|
2014-09-27 04:14:46 +00:00
|
|
|
pub enum Error {
|
2016-05-18 17:01:40 +00:00
|
|
|
Curl(curl::Error),
|
|
|
|
NotOkResponse(u32, Vec<String>, Vec<u8>),
|
2014-09-27 04:14:46 +00:00
|
|
|
NonUtf8Body,
|
2014-11-19 06:29:19 +00:00
|
|
|
Api(Vec<String>),
|
2014-09-27 04:14:46 +00:00
|
|
|
Unauthorized,
|
2014-11-22 14:36:14 +00:00
|
|
|
TokenMissing,
|
2015-02-27 01:04:25 +00:00
|
|
|
Io(io::Error),
|
2015-08-12 06:21:06 +00:00
|
|
|
NotFound,
|
2016-03-08 16:40:39 +00:00
|
|
|
JsonEncodeError(json::EncoderError),
|
|
|
|
JsonDecodeError(json::DecoderError),
|
2016-11-29 18:19:07 +00:00
|
|
|
JsonParseError(json::ParserError),
|
2016-03-08 16:40:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl From<json::EncoderError> for Error {
|
|
|
|
fn from(err: json::EncoderError) -> Error {
|
|
|
|
Error::JsonEncodeError(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<json::DecoderError> for Error {
|
|
|
|
fn from(err: json::DecoderError) -> Error {
|
|
|
|
Error::JsonDecodeError(err)
|
|
|
|
}
|
2014-09-27 04:14:46 +00:00
|
|
|
}
|
|
|
|
|
2016-11-29 18:19:07 +00:00
|
|
|
impl From<json::ParserError> for Error {
|
|
|
|
fn from(err: json::ParserError) -> Error {
|
|
|
|
Error::JsonParseError(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-18 17:01:40 +00:00
|
|
|
impl From<curl::Error> for Error {
|
|
|
|
fn from(err: curl::Error) -> Error {
|
|
|
|
Error::Curl(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-04 09:02:16 +00:00
|
|
|
#[derive(RustcDecodable)]
|
2014-11-22 14:36:14 +00:00
|
|
|
pub struct Crate {
|
|
|
|
pub name: String,
|
|
|
|
pub description: Option<String>,
|
|
|
|
pub max_version: String
|
|
|
|
}
|
|
|
|
|
2015-01-04 09:02:16 +00:00
|
|
|
#[derive(RustcEncodable)]
|
2014-09-27 04:14:46 +00:00
|
|
|
pub struct NewCrate {
|
|
|
|
pub name: String,
|
|
|
|
pub vers: String,
|
|
|
|
pub deps: Vec<NewCrateDependency>,
|
|
|
|
pub features: HashMap<String, Vec<String>>,
|
|
|
|
pub authors: Vec<String>,
|
|
|
|
pub description: Option<String>,
|
|
|
|
pub documentation: Option<String>,
|
|
|
|
pub homepage: Option<String>,
|
|
|
|
pub readme: Option<String>,
|
|
|
|
pub keywords: Vec<String>,
|
2016-11-18 21:49:55 +00:00
|
|
|
pub categories: Vec<String>,
|
2014-09-27 04:14:46 +00:00
|
|
|
pub license: Option<String>,
|
2014-11-25 06:18:54 +00:00
|
|
|
pub license_file: Option<String>,
|
2014-09-27 04:14:46 +00:00
|
|
|
pub repository: Option<String>,
|
2017-01-01 20:14:34 +00:00
|
|
|
pub badges: HashMap<String, HashMap<String, String>>,
|
2014-09-27 04:14:46 +00:00
|
|
|
}
|
|
|
|
|
2015-01-04 09:02:16 +00:00
|
|
|
#[derive(RustcEncodable)]
|
2014-09-27 04:14:46 +00:00
|
|
|
pub struct NewCrateDependency {
|
|
|
|
pub optional: bool,
|
|
|
|
pub default_features: bool,
|
|
|
|
pub name: String,
|
|
|
|
pub features: Vec<String>,
|
|
|
|
pub version_req: String,
|
|
|
|
pub target: Option<String>,
|
2014-11-21 02:17:31 +00:00
|
|
|
pub kind: String,
|
2014-09-27 04:14:46 +00:00
|
|
|
}
|
|
|
|
|
2015-01-04 09:02:16 +00:00
|
|
|
#[derive(RustcDecodable)]
|
2014-11-13 06:15:41 +00:00
|
|
|
pub struct User {
|
2015-01-13 16:41:04 +00:00
|
|
|
pub id: u32,
|
2014-11-13 06:15:41 +00:00
|
|
|
pub login: String,
|
2015-08-05 18:33:56 +00:00
|
|
|
pub avatar: Option<String>,
|
2014-11-13 06:15:41 +00:00
|
|
|
pub email: Option<String>,
|
|
|
|
pub name: Option<String>,
|
|
|
|
}
|
|
|
|
|
2016-12-05 17:36:44 +00:00
|
|
|
pub struct Warnings {
|
|
|
|
pub invalid_categories: Vec<String>,
|
2017-01-01 20:14:34 +00:00
|
|
|
pub invalid_badges: Vec<String>,
|
2016-12-05 17:36:44 +00:00
|
|
|
}
|
|
|
|
|
2015-01-04 09:02:16 +00:00
|
|
|
#[derive(RustcDecodable)] struct R { ok: bool }
|
|
|
|
#[derive(RustcDecodable)] struct ApiErrorList { errors: Vec<ApiError> }
|
|
|
|
#[derive(RustcDecodable)] struct ApiError { detail: String }
|
|
|
|
#[derive(RustcEncodable)] struct OwnersReq<'a> { users: &'a [&'a str] }
|
|
|
|
#[derive(RustcDecodable)] struct Users { users: Vec<User> }
|
2016-03-07 08:19:40 +00:00
|
|
|
#[derive(RustcDecodable)] struct TotalCrates { total: u32 }
|
|
|
|
#[derive(RustcDecodable)] struct Crates { crates: Vec<Crate>, meta: TotalCrates }
|
2014-09-27 04:14:46 +00:00
|
|
|
impl Registry {
|
2014-11-22 14:36:14 +00:00
|
|
|
pub fn new(host: String, token: Option<String>) -> Registry {
|
2016-05-18 17:01:40 +00:00
|
|
|
Registry::new_handle(host, token, Easy::new())
|
2014-09-27 04:14:46 +00:00
|
|
|
}
|
|
|
|
|
2016-05-18 17:01:40 +00:00
|
|
|
pub fn new_handle(host: String,
|
|
|
|
token: Option<String>,
|
|
|
|
handle: Easy) -> Registry {
|
2014-09-27 04:14:46 +00:00
|
|
|
Registry {
|
|
|
|
host: host,
|
|
|
|
token: token,
|
|
|
|
handle: handle,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn add_owners(&mut self, krate: &str, owners: &[&str]) -> Result<()> {
|
2016-11-11 13:25:20 +00:00
|
|
|
let body = json::encode(&OwnersReq { users: owners })?;
|
|
|
|
let body = self.put(format!("/crates/{}/owners", krate),
|
|
|
|
body.as_bytes())?;
|
|
|
|
assert!(json::decode::<R>(&body)?.ok);
|
2014-09-27 04:14:46 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn remove_owners(&mut self, krate: &str, owners: &[&str]) -> Result<()> {
|
2016-11-11 13:25:20 +00:00
|
|
|
let body = json::encode(&OwnersReq { users: owners })?;
|
|
|
|
let body = self.delete(format!("/crates/{}/owners", krate),
|
|
|
|
Some(body.as_bytes()))?;
|
|
|
|
assert!(json::decode::<R>(&body)?.ok);
|
2014-09-27 04:14:46 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2014-11-13 06:15:41 +00:00
|
|
|
pub fn list_owners(&mut self, krate: &str) -> Result<Vec<User>> {
|
2016-11-11 13:25:20 +00:00
|
|
|
let body = self.get(format!("/crates/{}/owners", krate))?;
|
|
|
|
Ok(json::decode::<Users>(&body)?.users)
|
2014-11-13 06:15:41 +00:00
|
|
|
}
|
|
|
|
|
2016-11-29 18:19:07 +00:00
|
|
|
pub fn publish(&mut self, krate: &NewCrate, tarball: &File)
|
2016-12-05 17:36:44 +00:00
|
|
|
-> Result<Warnings> {
|
2016-11-11 13:25:20 +00:00
|
|
|
let json = json::encode(krate)?;
|
2014-09-27 04:14:46 +00:00
|
|
|
// Prepare the body. The format of the upload request is:
|
|
|
|
//
|
|
|
|
// <le u32 of json>
|
|
|
|
// <json request> (metadata for the package)
|
|
|
|
// <le u32 of tarball>
|
|
|
|
// <source tarball>
|
2016-11-11 13:25:20 +00:00
|
|
|
let stat = tarball.metadata().map_err(Error::Io)?;
|
2014-09-27 04:14:46 +00:00
|
|
|
let header = {
|
2015-02-27 01:04:25 +00:00
|
|
|
let mut w = Vec::new();
|
|
|
|
w.extend([
|
|
|
|
(json.len() >> 0) as u8,
|
|
|
|
(json.len() >> 8) as u8,
|
|
|
|
(json.len() >> 16) as u8,
|
|
|
|
(json.len() >> 24) as u8,
|
2015-03-09 18:30:37 +00:00
|
|
|
].iter().map(|x| *x));
|
|
|
|
w.extend(json.as_bytes().iter().map(|x| *x));
|
2015-02-27 01:04:25 +00:00
|
|
|
w.extend([
|
|
|
|
(stat.len() >> 0) as u8,
|
|
|
|
(stat.len() >> 8) as u8,
|
|
|
|
(stat.len() >> 16) as u8,
|
|
|
|
(stat.len() >> 24) as u8,
|
2015-03-09 18:30:37 +00:00
|
|
|
].iter().map(|x| *x));
|
2015-02-27 01:04:25 +00:00
|
|
|
w
|
2014-09-27 04:14:46 +00:00
|
|
|
};
|
2015-02-27 01:04:25 +00:00
|
|
|
let size = stat.len() as usize + header.len();
|
|
|
|
let mut body = Cursor::new(header).chain(tarball);
|
2014-09-27 04:14:46 +00:00
|
|
|
|
|
|
|
let url = format!("{}/api/v1/crates/new", self.host);
|
2014-11-22 14:36:14 +00:00
|
|
|
|
2015-03-09 18:30:37 +00:00
|
|
|
let token = match self.token.as_ref() {
|
|
|
|
Some(s) => s,
|
|
|
|
None => return Err(Error::TokenMissing),
|
|
|
|
};
|
2016-11-11 13:25:20 +00:00
|
|
|
self.handle.put(true)?;
|
|
|
|
self.handle.url(&url)?;
|
|
|
|
self.handle.in_filesize(size as u64)?;
|
2016-05-18 17:01:40 +00:00
|
|
|
let mut headers = List::new();
|
2016-11-11 13:25:20 +00:00
|
|
|
headers.append("Accept: application/json")?;
|
|
|
|
headers.append(&format!("Authorization: {}", token))?;
|
|
|
|
self.handle.http_headers(headers)?;
|
2016-05-18 17:01:40 +00:00
|
|
|
|
2016-11-29 18:19:07 +00:00
|
|
|
let body = handle(&mut self.handle, &mut |buf| {
|
2016-05-18 17:01:40 +00:00
|
|
|
body.read(buf).unwrap_or(0)
|
2016-11-11 13:25:20 +00:00
|
|
|
})?;
|
2017-01-01 20:14:34 +00:00
|
|
|
|
2016-11-29 18:19:07 +00:00
|
|
|
// Can't derive RustcDecodable because JSON has a key named "crate" :(
|
2016-11-29 21:09:00 +00:00
|
|
|
let response = if body.len() > 0 {
|
|
|
|
Json::from_str(&body)?
|
|
|
|
} else {
|
|
|
|
Json::from_str("{}")?
|
|
|
|
};
|
2017-01-01 20:14:34 +00:00
|
|
|
|
2016-11-29 18:19:07 +00:00
|
|
|
let invalid_categories: Vec<String> =
|
|
|
|
response
|
|
|
|
.find_path(&["warnings", "invalid_categories"])
|
|
|
|
.and_then(Json::as_array)
|
|
|
|
.map(|x| {
|
|
|
|
x.iter().flat_map(Json::as_string).map(Into::into).collect()
|
|
|
|
})
|
|
|
|
.unwrap_or_else(Vec::new);
|
2017-01-01 20:14:34 +00:00
|
|
|
|
|
|
|
let invalid_badges: Vec<String> =
|
|
|
|
response
|
|
|
|
.find_path(&["warnings", "invalid_badges"])
|
|
|
|
.and_then(Json::as_array)
|
|
|
|
.map(|x| {
|
|
|
|
x.iter().flat_map(Json::as_string).map(Into::into).collect()
|
|
|
|
})
|
|
|
|
.unwrap_or_else(Vec::new);
|
|
|
|
|
|
|
|
Ok(Warnings {
|
|
|
|
invalid_categories: invalid_categories,
|
|
|
|
invalid_badges: invalid_badges,
|
|
|
|
})
|
2014-09-27 04:14:46 +00:00
|
|
|
}
|
|
|
|
|
2016-03-07 08:19:40 +00:00
|
|
|
pub fn search(&mut self, query: &str, limit: u8) -> Result<(Vec<Crate>, u32)> {
|
|
|
|
let formated_query = percent_encode(query.as_bytes(), QUERY_ENCODE_SET);
|
2016-11-11 13:25:20 +00:00
|
|
|
let body = self.req(
|
2016-03-07 08:19:40 +00:00
|
|
|
format!("/crates?q={}&per_page={}", formated_query, limit),
|
2016-05-18 17:01:40 +00:00
|
|
|
None, Auth::Unauthorized
|
2016-11-11 13:25:20 +00:00
|
|
|
)?;
|
2014-11-22 14:36:14 +00:00
|
|
|
|
2016-11-11 13:25:20 +00:00
|
|
|
let crates = json::decode::<Crates>(&body)?;
|
2016-03-07 08:19:40 +00:00
|
|
|
Ok((crates.crates, crates.meta.total))
|
2014-11-22 14:36:14 +00:00
|
|
|
}
|
|
|
|
|
2014-09-27 04:14:46 +00:00
|
|
|
pub fn yank(&mut self, krate: &str, version: &str) -> Result<()> {
|
2016-11-11 13:25:20 +00:00
|
|
|
let body = self.delete(format!("/crates/{}/{}/yank", krate, version),
|
|
|
|
None)?;
|
|
|
|
assert!(json::decode::<R>(&body)?.ok);
|
2014-09-27 04:14:46 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn unyank(&mut self, krate: &str, version: &str) -> Result<()> {
|
2016-11-11 13:25:20 +00:00
|
|
|
let body = self.put(format!("/crates/{}/{}/unyank", krate, version),
|
|
|
|
&[])?;
|
|
|
|
assert!(json::decode::<R>(&body)?.ok);
|
2014-09-27 04:14:46 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn put(&mut self, path: String, b: &[u8]) -> Result<String> {
|
2016-11-11 13:25:20 +00:00
|
|
|
self.handle.put(true)?;
|
2016-05-18 17:01:40 +00:00
|
|
|
self.req(path, Some(b), Auth::Authorized)
|
2014-11-13 06:15:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn get(&mut self, path: String) -> Result<String> {
|
2016-11-11 13:25:20 +00:00
|
|
|
self.handle.get(true)?;
|
2016-05-18 17:01:40 +00:00
|
|
|
self.req(path, None, Auth::Authorized)
|
2014-09-27 04:14:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn delete(&mut self, path: String, b: Option<&[u8]>) -> Result<String> {
|
2016-11-11 13:25:20 +00:00
|
|
|
self.handle.custom_request("DELETE")?;
|
2016-05-18 17:01:40 +00:00
|
|
|
self.req(path, b, Auth::Authorized)
|
2014-11-13 06:15:41 +00:00
|
|
|
}
|
|
|
|
|
2016-05-18 17:01:40 +00:00
|
|
|
fn req(&mut self,
|
|
|
|
path: String,
|
|
|
|
body: Option<&[u8]>,
|
|
|
|
authorized: Auth) -> Result<String> {
|
2016-11-11 13:25:20 +00:00
|
|
|
self.handle.url(&format!("{}/api/v1{}", self.host, path))?;
|
2016-05-18 17:01:40 +00:00
|
|
|
let mut headers = List::new();
|
2016-11-11 13:25:20 +00:00
|
|
|
headers.append("Accept: application/json")?;
|
|
|
|
headers.append("Content-Type: application/json")?;
|
2014-11-22 14:36:14 +00:00
|
|
|
|
|
|
|
if authorized == Auth::Authorized {
|
2015-03-09 18:30:37 +00:00
|
|
|
let token = match self.token.as_ref() {
|
|
|
|
Some(s) => s,
|
|
|
|
None => return Err(Error::TokenMissing),
|
|
|
|
};
|
2016-11-11 13:25:20 +00:00
|
|
|
headers.append(&format!("Authorization: {}", token))?;
|
2014-11-22 14:36:14 +00:00
|
|
|
}
|
2016-11-11 13:25:20 +00:00
|
|
|
self.handle.http_headers(headers)?;
|
2014-11-13 06:15:41 +00:00
|
|
|
match body {
|
2016-05-18 17:01:40 +00:00
|
|
|
Some(mut body) => {
|
2016-11-11 13:25:20 +00:00
|
|
|
self.handle.upload(true)?;
|
|
|
|
self.handle.in_filesize(body.len() as u64)?;
|
2016-05-18 17:01:40 +00:00
|
|
|
handle(&mut self.handle, &mut |buf| body.read(buf).unwrap_or(0))
|
|
|
|
}
|
|
|
|
None => handle(&mut self.handle, &mut |_| 0),
|
2014-09-27 04:14:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-18 17:01:40 +00:00
|
|
|
fn handle(handle: &mut Easy,
|
|
|
|
read: &mut FnMut(&mut [u8]) -> usize) -> Result<String> {
|
|
|
|
let mut headers = Vec::new();
|
|
|
|
let mut body = Vec::new();
|
|
|
|
{
|
|
|
|
let mut handle = handle.transfer();
|
2016-11-11 13:25:20 +00:00
|
|
|
handle.read_function(|buf| Ok(read(buf)))?;
|
|
|
|
handle.write_function(|data| {
|
2016-05-18 17:01:40 +00:00
|
|
|
body.extend_from_slice(data);
|
|
|
|
Ok(data.len())
|
2016-11-11 13:25:20 +00:00
|
|
|
})?;
|
|
|
|
handle.header_function(|data| {
|
2016-05-18 17:01:40 +00:00
|
|
|
headers.push(String::from_utf8_lossy(data).into_owned());
|
|
|
|
true
|
2016-11-11 13:25:20 +00:00
|
|
|
})?;
|
|
|
|
handle.perform()?;
|
2016-05-18 17:01:40 +00:00
|
|
|
}
|
|
|
|
|
2016-11-11 13:25:20 +00:00
|
|
|
match handle.response_code()? {
|
2014-09-27 04:14:46 +00:00
|
|
|
0 => {} // file upload url sometimes
|
|
|
|
200 => {}
|
2014-11-19 06:29:19 +00:00
|
|
|
403 => return Err(Error::Unauthorized),
|
2015-08-12 06:21:06 +00:00
|
|
|
404 => return Err(Error::NotFound),
|
2016-05-18 17:01:40 +00:00
|
|
|
code => return Err(Error::NotOkResponse(code, headers, body))
|
2014-09-27 04:14:46 +00:00
|
|
|
}
|
|
|
|
|
2016-05-18 17:01:40 +00:00
|
|
|
let body = match String::from_utf8(body) {
|
2014-09-27 04:14:46 +00:00
|
|
|
Ok(body) => body,
|
2014-11-19 06:29:19 +00:00
|
|
|
Err(..) => return Err(Error::NonUtf8Body),
|
2014-09-27 04:14:46 +00:00
|
|
|
};
|
2015-02-06 08:06:39 +00:00
|
|
|
match json::decode::<ApiErrorList>(&body) {
|
2014-09-27 04:14:46 +00:00
|
|
|
Ok(errors) => {
|
2014-11-19 06:29:19 +00:00
|
|
|
return Err(Error::Api(errors.errors.into_iter().map(|s| s.detail)
|
|
|
|
.collect()))
|
2014-09-27 04:14:46 +00:00
|
|
|
}
|
|
|
|
Err(..) => {}
|
|
|
|
}
|
|
|
|
Ok(body)
|
|
|
|
}
|
|
|
|
|
2015-01-23 18:42:29 +00:00
|
|
|
impl fmt::Display for Error {
|
2014-09-27 04:14:46 +00:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
match *self {
|
2015-05-06 00:05:41 +00:00
|
|
|
Error::NonUtf8Body => write!(f, "response body was not utf-8"),
|
2014-11-19 06:29:19 +00:00
|
|
|
Error::Curl(ref err) => write!(f, "http error: {}", err),
|
2016-05-18 17:01:40 +00:00
|
|
|
Error::NotOkResponse(code, ref headers, ref body) => {
|
2016-11-11 13:25:20 +00:00
|
|
|
writeln!(f, "failed to get a 200 OK response, got {}", code)?;
|
|
|
|
writeln!(f, "headers:")?;
|
2016-05-18 17:01:40 +00:00
|
|
|
for header in headers {
|
2016-11-11 13:25:20 +00:00
|
|
|
writeln!(f, " {}", header)?;
|
2016-05-18 17:01:40 +00:00
|
|
|
}
|
2016-11-11 13:25:20 +00:00
|
|
|
writeln!(f, "body:")?;
|
|
|
|
writeln!(f, "{}", String::from_utf8_lossy(body))?;
|
2016-05-18 17:01:40 +00:00
|
|
|
Ok(())
|
2014-09-27 04:14:46 +00:00
|
|
|
}
|
2014-11-19 06:29:19 +00:00
|
|
|
Error::Api(ref errs) => {
|
2016-03-09 08:12:57 +00:00
|
|
|
write!(f, "api errors: {}", errs.join(", "))
|
2014-09-27 04:14:46 +00:00
|
|
|
}
|
2014-11-19 06:29:19 +00:00
|
|
|
Error::Unauthorized => write!(f, "unauthorized API access"),
|
2014-11-22 14:36:14 +00:00
|
|
|
Error::TokenMissing => write!(f, "no upload token found, please run `cargo login`"),
|
2014-11-19 06:29:19 +00:00
|
|
|
Error::Io(ref e) => write!(f, "io error: {}", e),
|
2015-08-12 06:21:06 +00:00
|
|
|
Error::NotFound => write!(f, "cannot find crate"),
|
2016-03-08 16:40:39 +00:00
|
|
|
Error::JsonEncodeError(ref e) => write!(f, "json encode error: {}", e),
|
|
|
|
Error::JsonDecodeError(ref e) => write!(f, "json decode error: {}", e),
|
2016-11-29 18:19:07 +00:00
|
|
|
Error::JsonParseError(ref e) => write!(f, "json parse error: {}", e),
|
2014-09-27 04:14:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|