Add lastpassed to rdsys-backend-api

This commit is contained in:
onyinyang 2023-06-14 16:12:24 -04:00
parent a57778a232
commit d1710d2f80
No known key found for this signature in database
GPG Key ID: 156A6435430C2036
3 changed files with 11 additions and 0 deletions

1
Cargo.lock generated
View File

@ -1399,6 +1399,7 @@ name = "rdsys_backend"
version = "0.1.0"
dependencies = [
"bytes",
"chrono",
"crc64",
"futures",
"futures-util",

View File

@ -19,3 +19,4 @@ reqwest = { version = "0.11", features = ["stream"]}
tokio-stream = "0.1.12"
futures = "0.3.27"
tokio-util = "0.7.7"
chrono = { version = "0.4.26", features = ["serde", "clock"] }

View File

@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};
use sha1::{Digest, Sha1};
use std::collections::HashMap;
use chrono::{DateTime, offset::Utc};
/// The body of the request for resources made to the rdsys backend
#[derive(Serialize)]
@ -14,6 +15,7 @@ pub struct ResourceRequest {
pub struct Resource {
pub r#type: String,
pub blocked_in: HashMap<String, bool>,
pub last_passed: DateTime<Utc>,
pub protocol: String,
pub address: String,
pub port: u16,
@ -60,6 +62,8 @@ pub struct ResourceDiff {
#[cfg(test)]
mod tests {
use chrono::Utc;
use super::*;
#[test]
@ -88,6 +92,7 @@ mod tests {
let bridge = Resource {
r#type: String::from("scramblesuit"),
blocked_in: HashMap::new(),
last_passed: "2023-05-30T14:20:28Z".parse::<DateTime<Utc>>().unwrap(),
protocol: String::from("tcp"),
address: String::from("216.117.3.62"),
port: 63174,
@ -102,6 +107,7 @@ mod tests {
{
"type": "scramblesuit",
"blocked_in": {},
"last_passed": "2023-05-30T14:20:28.000+00:00",
"protocol": "tcp",
"address": "216.117.3.62",
"port": 63174,
@ -129,6 +135,7 @@ mod tests {
{
"type": "obfs2",
"blocked_in": {},
"last_passed": "2023-05-30T11:42:28.000+07:00",
"Location": null,
"protocol": "tcp",
"address": "176.247.216.207",
@ -146,6 +153,7 @@ mod tests {
{
"type": "obfs2",
"blocked_in": {},
"last_passed": "2023-05-30T12:20:28.000+07:00",
"protocol": "tcp",
"address": "133.69.16.145",
"port": 58314,
@ -164,6 +172,7 @@ mod tests {
{
"type": "scramblesuit",
"blocked_in": {},
"last_passed": "2023-05-30T14:20:28.000+07:00",
"protocol": "tcp",
"address": "216.117.3.62",
"port": 63174,