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

chore: Update code for Rust 1.54.0 #1123

Merged
merged 1 commit into from
Jul 29, 2021
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
8 changes: 4 additions & 4 deletions src/bin/purge_ttl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ fn delete_incremental(
max_to_delete: u64,
) -> Result<(), Box<grpcio::Error>> {
let mut total: u64 = 0;
let (mut req, mut txn) = begin_transaction(&client, &session, RequestType::ReadWrite)?;
let (mut req, mut txn) = begin_transaction(client, session, RequestType::ReadWrite)?;
loop {
let select_sql = format!("SELECT fxa_uid, fxa_kid, collection_id, {} FROM {} WHERE expiry < CURRENT_TIMESTAMP() LIMIT {}", column, table, chunk_size);
trace!(
Expand Down Expand Up @@ -214,12 +214,12 @@ fn delete_incremental(
delete_sql.trim_end_matches(&", ".to_string()).to_string()
);
trace!("Deleting chunk with: {}", delete_sql);
let mut delete_req = continue_transaction(&session, txn.clone());
let mut delete_req = continue_transaction(session, txn.clone());
delete_req.set_sql(delete_sql);
client.execute_sql(&delete_req)?;
info!("{}: removed {} rows", table, total);
commit_transaction(&client, &session, txn.clone())?;
let (newreq, newtxn) = begin_transaction(&client, &session, RequestType::ReadWrite)?;
commit_transaction(client, session, txn.clone())?;
let (newreq, newtxn) = begin_transaction(client, session, RequestType::ReadWrite)?;
req = newreq;
txn = newtxn;
}
Expand Down
4 changes: 2 additions & 2 deletions src/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,8 @@ pub async fn pool_from_settings(
let url =
Url::parse(&settings.database_url).map_err(|e| DbErrorKind::InvalidUrl(e.to_string()))?;
Ok(match url.scheme() {
"mysql" => Box::new(mysql::pool::MysqlDbPool::new(&settings, &metrics)?),
"spanner" => Box::new(spanner::pool::SpannerDbPool::new(&settings, &metrics).await?),
"mysql" => Box::new(mysql::pool::MysqlDbPool::new(settings, metrics)?),
"spanner" => Box::new(spanner::pool::SpannerDbPool::new(settings, metrics).await?),
_ => Err(DbErrorKind::InvalidUrl(settings.database_url.to_owned()))?,
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/db/mysql/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,7 @@ impl MysqlDb {
batch_db_method!(delete_batch_sync, delete, DeleteBatch);

pub fn get_batch_sync(&self, params: params::GetBatch) -> Result<Option<results::GetBatch>> {
batch::get(&self, params)
batch::get(self, params)
}

pub fn timestamp(&self) -> SyncTimestamp {
Expand Down
2 changes: 1 addition & 1 deletion src/db/mysql/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub fn db(settings: &Settings) -> Result<MysqlDb> {
let _ = env_logger::try_init();
// inherit SYNC_DATABASE_URL from the env

let pool = MysqlDbPool::new(&settings, &metrics::Metrics::noop())?;
let pool = MysqlDbPool::new(settings, &metrics::Metrics::noop())?;
pool.get_sync()
}

Expand Down
6 changes: 3 additions & 3 deletions src/db/spanner/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ impl SpannerDb {
.one_or_none()
.await?
.ok_or(DbErrorKind::CollectionNotFound)?;
let modified = SyncTimestamp::from_rfc3339(&result[0].get_string_value())?;
let modified = SyncTimestamp::from_rfc3339(result[0].get_string_value())?;
Ok(modified)
}

Expand Down Expand Up @@ -609,7 +609,7 @@ impl SpannerDb {
.get_string_value()
.parse::<i32>()
.map_err(|e| DbErrorKind::Integrity(e.to_string()))?;
let modified = SyncTimestamp::from_rfc3339(&row[1].get_string_value())?;
let modified = SyncTimestamp::from_rfc3339(row[1].get_string_value())?;
results.insert(collection_id, modified);
}
self.map_collection_names(results).await
Expand Down Expand Up @@ -1509,7 +1509,7 @@ impl SpannerDb {
.one_or_none()
.await?;
if let Some(result) = result {
SyncTimestamp::from_rfc3339(&result[0].get_string_value())
SyncTimestamp::from_rfc3339(result[0].get_string_value())
} else {
SyncTimestamp::from_i64(0)
}
Expand Down
2 changes: 1 addition & 1 deletion src/db/spanner/support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ pub fn bso_from_row(mut row: Vec<Value>) -> Result<results::GetBso> {
},
payload: row[2].take_string_value(),
modified,
expiry: SyncTimestamp::from_rfc3339(&row[4].get_string_value())?.as_i64(),
expiry: SyncTimestamp::from_rfc3339(row[4].get_string_value())?.as_i64(),
})
}

Expand Down
4 changes: 2 additions & 2 deletions src/db/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ impl FromRequest for DbTransactionPool {
.to_str()
.unwrap_or("NONE");

let col_result = CollectionParam::extrude(&req.uri(), &mut req.extensions_mut());
let col_result = CollectionParam::extrude(req.uri(), &mut req.extensions_mut());
let state = match req.app_data::<Data<ServerState>>() {
Some(v) => v,
None => {
Expand Down Expand Up @@ -251,7 +251,7 @@ impl FromRequest for DbTransactionPool {
let bso_opt = bso.map(|b| b.bso);

let is_read = matches!(method, Method::GET | Method::HEAD);
let precondition = PreConditionHeaderOpt::extrude(&req.headers())?;
let precondition = PreConditionHeaderOpt::extrude(req.headers())?;
let pool = Self {
pool: state.db_pool.clone(),
is_read,
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
// Avoid its default reqwest transport for now due to issues w/
// likely grpcio's boringssl
let curl_transport_factory = |options: &sentry::ClientOptions| {
Arc::new(sentry::transports::CurlHttpTransport::new(&options))
Arc::new(sentry::transports::CurlHttpTransport::new(options))
as Arc<dyn sentry::internals::Transport>
};
let _sentry = sentry::init(sentry::ClientOptions {
Expand Down
4 changes: 2 additions & 2 deletions src/server/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl Drop for Metrics {
let tags = timer.tags.tags.clone();
let keys = tags.keys();
for tag in keys {
tagged = tagged.with_tag(tag, &tags.get(tag).unwrap())
tagged = tagged.with_tag(tag, tags.get(tag).unwrap())
}
match tagged.try_send() {
Err(e) => {
Expand Down Expand Up @@ -142,7 +142,7 @@ impl Metrics {
}
for key in mtags.tags.keys().clone() {
if let Some(val) = mtags.tags.get(key) {
tagged = tagged.with_tag(&key, val.as_ref());
tagged = tagged.with_tag(key, val.as_ref());
}
}
// Include any "hard coded" tags.
Expand Down
2 changes: 1 addition & 1 deletion src/server/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ fn get_test_settings() -> Settings {
async fn get_test_state(settings: &Settings) -> ServerState {
let metrics = Metrics::sink();
ServerState {
db_pool: pool_from_settings(&settings, &Metrics::from(&metrics))
db_pool: pool_from_settings(settings, &Metrics::from(&metrics))
.await
.expect("Could not get db_pool in get_test_state"),
limits: Arc::clone(&SERVER_LIMITS),
Expand Down
10 changes: 5 additions & 5 deletions src/server/user_agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const VALID_UA_OS: &[&str] = &["Firefox OS", "Linux", "Mac OSX"];

pub fn parse_user_agent(agent: &str) -> (WootheeResult<'_>, &str, &str) {
let parser = Parser::new();
let wresult = parser.parse(&agent).unwrap_or_else(|| WootheeResult {
let wresult = parser.parse(agent).unwrap_or_else(|| WootheeResult {
name: "",
category: "",
os: "",
Expand Down Expand Up @@ -46,7 +46,7 @@ mod tests {
#[test]
fn test_linux() {
let agent = r#"Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.2) Gecko/20090807 Mandriva Linux/1.9.1.2-1.1mud2009.1 (2009.1) Firefox/3.5.2 FirePHP/0.3,gzip(gfe),gzip(gfe)"#;
let (ua_result, metrics_os, metrics_browser) = parse_user_agent(&agent);
let (ua_result, metrics_os, metrics_browser) = parse_user_agent(agent);
assert_eq!(metrics_os, "Linux");
assert_eq!(ua_result.os, "Linux");
assert_eq!(metrics_browser, "Firefox");
Expand All @@ -55,7 +55,7 @@ mod tests {
#[test]
fn test_windows() {
let agent = r#"Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 (.NET CLR 3.5.30729)"#;
let (ua_result, metrics_os, metrics_browser) = parse_user_agent(&agent);
let (ua_result, metrics_os, metrics_browser) = parse_user_agent(agent);
assert_eq!(metrics_os, "Windows");
assert_eq!(ua_result.os, "Windows 7");
assert_eq!(metrics_browser, "Firefox");
Expand All @@ -65,7 +65,7 @@ mod tests {
fn test_osx() {
let agent =
r#"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.5; rv:2.1.1) Gecko/ Firefox/5.0.1"#;
let (ua_result, metrics_os, metrics_browser) = parse_user_agent(&agent);
let (ua_result, metrics_os, metrics_browser) = parse_user_agent(agent);
assert_eq!(metrics_os, "Mac OSX");
assert_eq!(ua_result.os, "Mac OSX");
assert_eq!(metrics_browser, "Firefox");
Expand All @@ -75,7 +75,7 @@ mod tests {
fn test_other() {
let agent =
r#"BlackBerry9000/4.6.0.167 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/102"#;
let (ua_result, metrics_os, metrics_browser) = parse_user_agent(&agent);
let (ua_result, metrics_os, metrics_browser) = parse_user_agent(agent);
assert_eq!(metrics_os, "Other");
assert_eq!(ua_result.os, "BlackBerry");
assert_eq!(metrics_browser, "Other");
Expand Down
4 changes: 2 additions & 2 deletions src/tokenserver/support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ impl Tokenlib {
})?;
let kwargs = [("secret", shared_secret)].into_py_dict(py);
let token = module
.call("make_token", (plaintext,), Some(&kwargs))
.call("make_token", (plaintext,), Some(kwargs))
.map_err(|e| {
e.print_and_set_sys_last_vars(py);
e
})
.and_then(|x| x.extract())?;
let derived_secret = module
.call("get_derived_secret", (&token,), Some(&kwargs))
.call("get_derived_secret", (&token,), Some(kwargs))
.map_err(|e| {
e.print_and_set_sys_last_vars(py);
e
Expand Down
2 changes: 1 addition & 1 deletion src/web/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ impl HawkPayload {
Utc::now().timestamp() as u64
};

HawkPayload::new(header, method, path.as_str(), host, port, &secrets, expiry)
HawkPayload::new(header, method, path.as_str(), host, port, secrets, expiry)
}
}

Expand Down
22 changes: 11 additions & 11 deletions src/web/extractors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ impl FromRequest for BsoBodies {
let mut bsos = Vec::new();
for item in body.lines() {
// Check that its a valid JSON map like we expect
if let Ok(raw_json) = serde_json::from_str::<Value>(&item) {
if let Ok(raw_json) = serde_json::from_str::<Value>(item) {
bsos.push(raw_json);
} else {
// Per Python version, BSO's must json deserialize
Expand Down Expand Up @@ -398,7 +398,7 @@ impl FromRequest for BsoBody {

let max_payload_size = state.limits.max_record_payload_bytes as usize;

let fut = <Json<BsoBody>>::from_request(&req, payload)
let fut = <Json<BsoBody>>::from_request(req, payload)
.map_err(|e| {
warn!("⚠️ Could not parse BSO Body: {:?}", e);
let err: ApiError = ValidationErrorKind::FromDetails(
Expand Down Expand Up @@ -569,7 +569,7 @@ impl CollectionParam {
return Ok(collection.clone());
}

let collection = Self::col_from_path(&uri)?;
let collection = Self::col_from_path(uri)?;
let result = if let Some(collection) = collection {
collection.validate().map_err(|e| {
ValidationErrorKind::FromValidationErrors(e, RequestErrorLocation::Path, None)
Expand All @@ -592,7 +592,7 @@ impl FromRequest for CollectionParam {
fn from_request(req: &HttpRequest, _payload: &mut Payload) -> Self::Future {
let req = req.clone();
Box::pin(async move {
if let Some(collection) = Self::extrude(&req.uri(), &mut req.extensions_mut())? {
if let Some(collection) = Self::extrude(req.uri(), &mut req.extensions_mut())? {
Ok(collection)
} else {
Err(ValidationErrorKind::FromDetails(
Expand Down Expand Up @@ -1067,7 +1067,7 @@ impl HawkIdentifier {
uri: &Uri,
) -> Result<Self, Error> {
let payload = HawkPayload::extrude(header, method, secrets, connection_info, uri)?;
let puid = Self::uid_from_path(&uri)?;
let puid = Self::uid_from_path(uri)?;
if payload.user_id != puid {
warn!("⚠️ Hawk UID not in URI: {:?} {:?}", payload.user_id, uri);
Err(ValidationErrorKind::FromDetails(
Expand Down Expand Up @@ -1114,7 +1114,7 @@ impl FromRequest for HawkIdentifier {
let connection_info = req.connection_info().clone();
let method = req.method().as_str();
let uri = req.uri();
Self::extrude(&req, method, uri, &connection_info, &state)
Self::extrude(&req, method, uri, &connection_info, state)
})
}
}
Expand Down Expand Up @@ -1400,7 +1400,7 @@ impl FromRequest for BatchRequestOpt {

let id = match params.batch {
None => None,
Some(ref batch) if batch.is_empty() || TRUE_REGEX.is_match(&batch) => None,
Some(ref batch) if batch.is_empty() || TRUE_REGEX.is_match(batch) => None,
Some(batch) => {
let transaction_pool = DbTransactionPool::extract(&req).await?;
let pool = transaction_pool.get_pool()?;
Expand Down Expand Up @@ -1558,7 +1558,7 @@ fn validate_qs_ids(ids: &[String]) -> Result<(), ValidationError> {
));
}
for id in ids {
if !VALID_ID_REGEX.is_match(&id) {
if !VALID_ID_REGEX.is_match(id) {
return Err(request_error(
"Invalid id in ids",
RequestErrorLocation::QueryString,
Expand Down Expand Up @@ -2175,7 +2175,7 @@ mod tests {
#[test]
fn test_invalid_precondition_headers() {
fn assert_invalid_header(req: HttpRequest, _error_header: &str, _error_message: &str) {
let result = PreConditionHeaderOpt::extrude(&req.headers());
let result = PreConditionHeaderOpt::extrude(req.headers());
assert!(result.is_err());
let response: HttpResponse = result.err().unwrap().into();
assert_eq!(response.status(), 400);
Expand Down Expand Up @@ -2215,7 +2215,7 @@ mod tests {
.data(make_state())
.header("X-If-Modified-Since", "32.1")
.to_http_request();
let result = PreConditionHeaderOpt::extrude(&req.headers())
let result = PreConditionHeaderOpt::extrude(req.headers())
.unwrap()
.opt
.unwrap();
Expand All @@ -2227,7 +2227,7 @@ mod tests {
.data(make_state())
.header("X-If-Unmodified-Since", "32.14")
.to_http_request();
let result = PreConditionHeaderOpt::extrude(&req.headers())
let result = PreConditionHeaderOpt::extrude(req.headers())
.unwrap()
.opt
.unwrap();
Expand Down
4 changes: 2 additions & 2 deletions src/web/middleware/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl SyncServerRequest for ServiceRequest {
let state = &self.app_data::<ServerState>().ok_or_else(|| -> ApiError {
ApiErrorKind::Internal("No app_data ServerState".to_owned()).into()
})?;
HawkIdentifier::extrude(self, &method.as_str(), &self.uri(), &ci, &state)
HawkIdentifier::extrude(self, method.as_str(), self.uri(), ci, state)
}
}

Expand All @@ -51,6 +51,6 @@ impl SyncServerRequest for HttpRequest {
.ok_or_else(|| -> ApiError {
ApiErrorKind::Internal("No app_data ServerState".to_owned()).into()
})?;
HawkIdentifier::extrude(self, &method.as_str(), &self.uri(), &ci, &state)
HawkIdentifier::extrude(self, method.as_str(), self.uri(), ci, state)
}
}
2 changes: 1 addition & 1 deletion src/web/tags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ impl From<Tags> for BTreeMap<String, String> {
impl KV for Tags {
fn serialize(&self, _rec: &Record<'_>, serializer: &mut dyn slog::Serializer) -> slog::Result {
for (key, val) in &self.tags {
serializer.emit_str(Key::from(key.clone()), &val)?;
serializer.emit_str(Key::from(key.clone()), val)?;
}
Ok(())
}
Expand Down