From patchwork Fri Nov 9 04:21:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Russell Currey X-Patchwork-Id: 995302 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42rn6d3nN9z9s8r for ; Fri, 9 Nov 2018 15:22:01 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=russell.cc Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="fTBK+llT"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42rn6d19X5zF3Wj for ; Fri, 9 Nov 2018 15:22:01 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=russell.cc Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="fTBK+llT"; dkim-atps=neutral X-Original-To: snowpatch@lists.ozlabs.org Delivered-To: snowpatch@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (helo) smtp.helo=out5-smtp.messagingengine.com (client-ip=66.111.4.29; helo=out5-smtp.messagingengine.com; envelope-from=ruscur@russell.cc; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=russell.cc Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="fTBK+llT"; dkim-atps=neutral Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42rn6T5yDMzF3MD for ; Fri, 9 Nov 2018 15:21:52 +1100 (AEDT) Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 66E202296A; Thu, 8 Nov 2018 23:21:49 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Thu, 08 Nov 2018 23:21:49 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :message-id:mime-version:subject:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=q+/B5pnwRwpLxncb6 M0Gfm4Jk83MK4gm8IYZGhgjVZA=; b=fTBK+llTPhWt5H5/j8ZKnZFfWBvDt8Q5Y IZFjTEOLzjYZVPuZi7lRO+iQRlY/rEIC3avLqDWlHaKhgKQJeesH+G81vlmD23/9 q6BNDCU33kEDL4xsel0kgUqNvPeS/seHptVkTjK1SYgMwQLn2UChN75BepINtmyY sXdDuAbggMnTcbnxuFZC6z5JGrMqC84XSgj8Gm25dAIDhcVF+q4pBPsR68uBgzTj Em9sBxfQPjshkN3mnea8PMVMHn2Nd0s2qZYFguFmP6KxqQRVzsjMwaeUcIn5ADlT iimn9Ej3kxouhEoeWDyATGAkfYas6MfG+88yGReQcHahkOBaJ70bQ== X-ME-Sender: X-ME-Proxy: Received: from crackle.ozlabs.ibm.com (unknown [1.144.241.96]) by mail.messagingengine.com (Postfix) with ESMTPA id 60498102DD; Thu, 8 Nov 2018 23:21:46 -0500 (EST) From: Russell Currey To: snowpatch@lists.ozlabs.org Date: Fri, 9 Nov 2018 15:21:52 +1100 Message-Id: <20181109042154.16361-1-ruscur@russell.cc> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 Subject: [snowpatch] [PATCH 1/3] setup_rustfmt_hook: create hooks dir if it doesn't exist X-BeenThere: snowpatch@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Continuous Integration for patch-based workflows List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Russell Currey Errors-To: snowpatch-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "snowpatch" Signed-off-by: Russell Currey --- setup_rustfmt_hook.sh | 1 + src/jenkins.rs | 25 ++++++++++++------------- src/main.rs | 1 + src/patchwork.rs | 42 ++++++++++++++++++------------------------ 4 files changed, 32 insertions(+), 37 deletions(-) diff --git a/setup_rustfmt_hook.sh b/setup_rustfmt_hook.sh index 76a8932..4088926 100755 --- a/setup_rustfmt_hook.sh +++ b/setup_rustfmt_hook.sh @@ -2,6 +2,7 @@ rustup component add rustfmt-preview rustfmt_path=`which rustfmt` +mkdir -p .git/hooks echo "#!/bin/bash declare -a rust_files=() files=\$(git diff-index --name-only HEAD) diff --git a/src/jenkins.rs b/src/jenkins.rs index 0aa5212..9db11f3 100644 --- a/src/jenkins.rs +++ b/src/jenkins.rs @@ -29,7 +29,7 @@ use std::sync::Arc; use std::thread::sleep; use std::time::Duration; -use reqwest::header::{Authorization, Basic, Headers, Location}; +use reqwest::header::{HeaderMap, AUTHORIZATION, LOCATION}; use reqwest::{Client, IntoUrl, Response}; use serde_json::{self, Value}; @@ -68,8 +68,8 @@ impl CIBackend for JenkinsBackend { .extend_pairs(params) .finish(); - let resp = - self.post_url(&format!( + let resp = self + .post_url(&format!( "{}/job/{}/buildWithParameters?{}", self.base_url, job_name, params )).expect("HTTP request error"); // TODO don't panic here @@ -88,8 +88,8 @@ pub enum JenkinsBuildStatus { } impl JenkinsBackend { - fn headers(&self) -> Headers { - let mut headers = Headers::new(); + fn headers(&self) -> HeaderMap { + let mut headers = HeaderMap::new(); if let Some(ref username) = self.username { headers.set(Authorization(Basic { username: username.clone(), @@ -139,14 +139,13 @@ impl JenkinsBackend { match entry.get("executable") { Some(exec) => { return Some( - exec - .as_object() // Option - .unwrap() // BTreeMap - .get("url") // Option<&str> - .unwrap() // &str ? - .as_str() - .unwrap() - .to_string(), + exec.as_object() // Option + .unwrap() // BTreeMap + .get("url") // Option<&str> + .unwrap() // &str ? + .as_str() + .unwrap() + .to_string(), ); } None => sleep(Duration::from_millis(JENKINS_POLLING_INTERVAL)), diff --git a/src/main.rs b/src/main.rs index 7a0deba..6fe0bdb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -30,6 +30,7 @@ extern crate env_logger; extern crate serde; #[macro_use] extern crate serde_derive; +extern crate base64; extern crate serde_json; extern crate toml; diff --git a/src/patchwork.rs b/src/patchwork.rs index a0722c7..0072225 100644 --- a/src/patchwork.rs +++ b/src/patchwork.rs @@ -25,9 +25,7 @@ use std::result::Result; use tempdir::TempDir; use reqwest; -use reqwest::header::{ - qitem, Accept, Authorization, Basic, Connection, ContentType, Headers, Link, RelationType, -}; +use reqwest::header::{HeaderMap, ACCEPT, AUTHORIZATION, CONTENT_TYPE}; use reqwest::Client; use reqwest::Response; use reqwest::StatusCode; @@ -35,6 +33,8 @@ use reqwest::StatusCode; use serde::{self, Serializer}; use serde_json; +use base64; + use utils; // TODO: more constants. constants for format strings of URLs and such. @@ -205,16 +205,16 @@ impl TestResult { pub struct PatchworkServer { pub url: String, - headers: Headers, + headers: HeaderMap, pub client: std::sync::Arc, } impl PatchworkServer { #[cfg_attr(feature = "cargo-clippy", allow(ptr_arg))] pub fn new(url: &String, client: &std::sync::Arc) -> PatchworkServer { - let mut headers = Headers::new(); - headers.set(Accept(vec![qitem(reqwest::mime::APPLICATION_JSON)])); - headers.set(ContentType(reqwest::mime::APPLICATION_JSON)); + let mut headers = HeaderMap::new(); + headers.insert(ACCEPT, "application/json"); + headers.insert(CONTENT_TYPE, "application/json"); PatchworkServer { url: url.clone(), client: client.clone(), @@ -231,34 +231,28 @@ impl PatchworkServer { ) { match (username, password, token) { (&None, &None, &Some(ref token)) => { - self.headers.set(Authorization(format!("Token {}", token))); + self.headers + .insert(AUTHORIZATION, format!("Token {}", token)); } (&Some(ref username), &Some(ref password), &None) => { - self.headers.set(Authorization(Basic { - username: username.clone(), - password: Some(password.clone()), - })); + self.headers.insert( + AUTHORIZATION, + format!( + "Basic {}", + base64::encode(format!("{}:{}", username, password)) + ), + ); } _ => panic!("Invalid patchwork authentication details"), } } pub fn get_url(&self, url: &str) -> std::result::Result { - self.client - .get(&*url) - .headers(self.headers.clone()) - .header(Connection::close()) - .send() + self.client.get(&*url).headers(self.headers.clone()).send() } pub fn get_url_string(&self, url: &str) -> std::result::Result { - let mut resp = try!( - self.client - .get(&*url) - .headers(self.headers.clone()) - .header(Connection::close()) - .send() - ); + let mut resp = try!(self.client.get(&*url).headers(self.headers.clone()).send()); let mut body: Vec = vec![]; io::copy(&mut resp, &mut body).unwrap(); Ok(String::from_utf8(body).unwrap())