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

fix: fixed compilation warnings & deprecations #479

Merged
merged 2 commits into from
May 11, 2024
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: 0 additions & 1 deletion aw-client-rust/src/blocking.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::future::Future;
use std::vec::Vec;
use std::{collections::HashMap, error::Error};

use chrono::{DateTime, Utc};
Expand Down
1 change: 0 additions & 1 deletion aw-client-rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ extern crate tokio;

pub mod blocking;

use std::vec::Vec;
use std::{collections::HashMap, error::Error};

use chrono::{DateTime, Utc};
Expand Down
22 changes: 4 additions & 18 deletions aw-datastore/src/datastore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use std::collections::HashMap;

use chrono::DateTime;
use chrono::Duration;
use chrono::NaiveDateTime;
use chrono::TimeZone;
use chrono::Utc;

use rusqlite::Connection;
Expand Down Expand Up @@ -233,10 +231,7 @@ impl DatastoreInstance {
Some(starttime_ns) => {
let seconds: i64 = starttime_ns / 1_000_000_000;
let subnanos: u32 = (starttime_ns % 1_000_000_000) as u32;
Some(TimeZone::from_utc_datetime(
&Utc,
&NaiveDateTime::from_timestamp_opt(seconds, subnanos).unwrap(),
))
Some(DateTime::from_timestamp(seconds, subnanos).unwrap())
}
None => None,
};
Expand All @@ -246,10 +241,7 @@ impl DatastoreInstance {
Some(endtime_ns) => {
let seconds: i64 = endtime_ns / 1_000_000_000;
let subnanos: u32 = (endtime_ns % 1_000_000_000) as u32;
Some(TimeZone::from_utc_datetime(
&Utc,
&NaiveDateTime::from_timestamp_opt(seconds, subnanos).unwrap(),
))
Some(DateTime::from_timestamp(seconds, subnanos).unwrap())
}
None => None,
};
Expand Down Expand Up @@ -689,10 +681,7 @@ impl DatastoreInstance {

Ok(Event {
id: Some(id),
timestamp: TimeZone::from_utc_datetime(
&Utc,
&NaiveDateTime::from_timestamp_opt(time_seconds, time_subnanos).unwrap(),
),
timestamp: DateTime::from_timestamp(time_seconds, time_subnanos).unwrap(),
duration: Duration::nanoseconds(duration_ns),
data,
})
Expand Down Expand Up @@ -784,10 +773,7 @@ impl DatastoreInstance {

Ok(Event {
id: Some(id),
timestamp: TimeZone::from_utc_datetime(
&Utc,
&NaiveDateTime::from_timestamp_opt(time_seconds, time_subnanos).unwrap(),
),
timestamp: DateTime::from_timestamp(time_seconds, time_subnanos).unwrap(),
duration: Duration::nanoseconds(duration_ns),
data,
})
Expand Down
1 change: 0 additions & 1 deletion aw-query/src/datatype.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::collections::HashMap;
use std::convert::{TryFrom, TryInto};
use std::fmt;

use super::functions;
Expand Down
3 changes: 0 additions & 3 deletions aw-query/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,6 @@ pub fn fill_env(env: &mut VarEnv) {
}

mod qfunctions {
use std::convert::TryFrom;
use std::convert::TryInto;

use aw_datastore::Datastore;
use aw_models::Event;
use aw_transform::classify::Rule;
Expand Down
42 changes: 21 additions & 21 deletions aw-server/src/endpoints/bucket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub fn buckets_get(

#[get("/<bucket_id>")]
pub fn bucket_get(
bucket_id: String,
bucket_id: &str,
state: &State<ServerState>,
) -> Result<Json<Bucket>, HttpErrorJson> {
let datastore = endpoints_get_lock!(state.datastore);
Expand All @@ -46,13 +46,13 @@ pub fn bucket_get(
/// This is useful for watchers which are known/assumed to run locally but might not know their hostname (like aw-watcher-web).
#[post("/<bucket_id>", data = "<message>", format = "application/json")]
pub fn bucket_new(
bucket_id: String,
bucket_id: &str,
message: Json<Bucket>,
state: &State<ServerState>,
) -> Result<(), HttpErrorJson> {
let mut bucket = message.into_inner();
if bucket.id != bucket_id {
bucket.id = bucket_id;
bucket.id = bucket_id.to_string();
}
if bucket.hostname == "!local" {
bucket.hostname = gethostname()
Expand All @@ -72,7 +72,7 @@ pub fn bucket_new(

#[get("/<bucket_id>/events?<start>&<end>&<limit>")]
pub fn bucket_events_get(
bucket_id: String,
bucket_id: &str,
start: Option<String>,
end: Option<String>,
limit: Option<u64>,
Expand Down Expand Up @@ -104,7 +104,7 @@ pub fn bucket_events_get(
None => None,
};
let datastore = endpoints_get_lock!(state.datastore);
let res = datastore.get_events(&bucket_id, starttime, endtime, limit);
let res = datastore.get_events(bucket_id, starttime, endtime, limit);
match res {
Ok(events) => Ok(Json(events)),
Err(err) => Err(err.into()),
Expand All @@ -115,13 +115,13 @@ pub fn bucket_events_get(
// See: https://api.rocket.rs/master/rocket/struct.Route.html#resolving-collisions
#[get("/<bucket_id>/events/<event_id>?<_unused..>")]
pub fn bucket_events_get_single(
bucket_id: String,
bucket_id: &str,
event_id: i64,
_unused: Option<u64>,
state: &State<ServerState>,
) -> Result<Json<Event>, HttpErrorJson> {
let datastore = endpoints_get_lock!(state.datastore);
let res = datastore.get_event(&bucket_id, event_id);
let res = datastore.get_event(bucket_id, event_id);
match res {
Ok(events) => Ok(Json(events)),
Err(err) => Err(err.into()),
Expand All @@ -130,12 +130,12 @@ pub fn bucket_events_get_single(

#[post("/<bucket_id>/events", data = "<events>", format = "application/json")]
pub fn bucket_events_create(
bucket_id: String,
bucket_id: &str,
events: Json<Vec<Event>>,
state: &State<ServerState>,
) -> Result<Json<Vec<Event>>, HttpErrorJson> {
let datastore = endpoints_get_lock!(state.datastore);
let res = datastore.insert_events(&bucket_id, &events);
let res = datastore.insert_events(bucket_id, &events);
match res {
Ok(events) => Ok(Json(events)),
Err(err) => Err(err.into()),
Expand All @@ -148,26 +148,26 @@ pub fn bucket_events_create(
format = "application/json"
)]
pub fn bucket_events_heartbeat(
bucket_id: String,
bucket_id: &str,
heartbeat_json: Json<Event>,
pulsetime: f64,
state: &State<ServerState>,
) -> Result<Json<Event>, HttpErrorJson> {
let heartbeat = heartbeat_json.into_inner();
let datastore = endpoints_get_lock!(state.datastore);
match datastore.heartbeat(&bucket_id, heartbeat, pulsetime) {
match datastore.heartbeat(bucket_id, heartbeat, pulsetime) {
Ok(e) => Ok(Json(e)),
Err(err) => Err(err.into()),
}
}

#[get("/<bucket_id>/events/count")]
pub fn bucket_event_count(
bucket_id: String,
bucket_id: &str,
state: &State<ServerState>,
) -> Result<Json<u64>, HttpErrorJson> {
let datastore = endpoints_get_lock!(state.datastore);
let res = datastore.get_event_count(&bucket_id, None, None);
let res = datastore.get_event_count(bucket_id, None, None);
match res {
Ok(eventcount) => Ok(Json(eventcount as u64)),
Err(err) => Err(err.into()),
Expand All @@ -176,44 +176,44 @@ pub fn bucket_event_count(

#[delete("/<bucket_id>/events/<event_id>")]
pub fn bucket_events_delete_by_id(
bucket_id: String,
bucket_id: &str,
event_id: i64,
state: &State<ServerState>,
) -> Result<(), HttpErrorJson> {
let datastore = endpoints_get_lock!(state.datastore);
match datastore.delete_events_by_id(&bucket_id, vec![event_id]) {
match datastore.delete_events_by_id(bucket_id, vec![event_id]) {
Ok(_) => Ok(()),
Err(err) => Err(err.into()),
}
}

#[get("/<bucket_id>/export")]
pub fn bucket_export(
bucket_id: String,
bucket_id: &str,
state: &State<ServerState>,
) -> Result<BucketsExportRocket, HttpErrorJson> {
let datastore = endpoints_get_lock!(state.datastore);
let mut export = BucketsExport {
buckets: HashMap::new(),
};
let mut bucket = match datastore.get_bucket(&bucket_id) {
let mut bucket = match datastore.get_bucket(bucket_id) {
Ok(bucket) => bucket,
Err(err) => return Err(err.into()),
};
/* TODO: Replace expect with http error */
let events = datastore
.get_events(&bucket_id, None, None, None)
.get_events(bucket_id, None, None, None)
.expect("Failed to get events for bucket");
bucket.events = Some(TryVec::new(events));
export.buckets.insert(bucket_id, bucket);
export.buckets.insert(bucket_id.into(), bucket);

Ok(export.into())
}

#[delete("/<bucket_id>")]
pub fn bucket_delete(bucket_id: String, state: &State<ServerState>) -> Result<(), HttpErrorJson> {
pub fn bucket_delete(bucket_id: &str, state: &State<ServerState>) -> Result<(), HttpErrorJson> {
let datastore = endpoints_get_lock!(state.datastore);
match datastore.delete_bucket(&bucket_id) {
match datastore.delete_bucket(bucket_id) {
Ok(_) => Ok(()),
Err(err) => Err(err.into()),
}
Expand Down
1 change: 0 additions & 1 deletion aw-sync/src/sync_wrapper.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::boxed::Box;
use std::error::Error;
use std::fs;
use std::net::TcpStream;
Expand Down
1 change: 0 additions & 1 deletion aw-sync/src/util.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::boxed::Box;
use std::error::Error;
use std::ffi::OsStr;
use std::fs;
Expand Down
Loading