Skip to content

Commit 6820bd2

Browse files
author
vsilent
committed
actix-web upgrade
1 parent 3e78c5e commit 6820bd2

File tree

10 files changed

+69
-20
lines changed

10 files changed

+69
-20
lines changed

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,18 @@
22
name = "stackdog"
33
version = "0.1.0"
44
authors = ["Vasili Pascal <info@try.direct>"]
5-
edition = "2018"
5+
edition = "2021"
66

77
#[package.metadata.docs.rs]
88
features = ["openssl", "rustls", "compress", "secure-cookies"]
99

1010
[dependencies]
11-
bollard = "0.11"
11+
#actix-web = { version = "3.0.0-beta.3", features=["rustls"] }
1212
actix-web = { version = "3.3.3", features=["rustls"] }
13-
actix-rt = "2.1.0"
13+
actix-rt = "1.1.1"
1414
actix-service = "1.0.6"
1515
actix-cors = "0.3.0"
1616
actix-http = "2.1.0"
17-
#actix = "0.12"
1817
log = "0.4.11"
1918
env_logger = "0.9.0"
2019
serde = "1.0.116"
@@ -29,6 +28,7 @@ derive_more = "0.99.10"
2928
jsonwebtoken = "7.2.0"
3029
bcrypt = "0.10.0"
3130
actix-tls = "3.0.0"
31+
bollard = "0.11.1"
3232
awc = { version = "2.0.0", default-features = false }
3333
open-ssl = { package = "openssl", version = "0.10", optional = true }
3434
rust-tls = { package = "rustls", version = "0.18.0", optional = true }

ROADMAP.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
# Roadmap
22

3-
## 03-2021
3+
## 03-2022
44

5-
* [ ] Implement tests
5+
* [ ] Implement tests
66
* [ ] Implement base components
77
* [ ] Implement plugin/extension subsystem
88
* [ ] Implement Web UI
9-
10-
## 04-2021
9+
10+
## 04-2022
1111
* [ ] Implement RESTful API (read-only)
1212
* [ ] Security testing
1313
* [ ] Beta release
1414

15-
## 05-2021
15+
## 05-2022
1616
* [ ] Release v1.0
1717

18-
## 08-2021
18+
## 08-2022
1919
* [ ] Release v1.1
2020

2121

@@ -37,17 +37,17 @@
3737
- * [ ] View container logs
3838
- * [ ] Container command
3939
* [ ] Task Manager
40-
- * [ ] Scheduler
41-
40+
- * [ ] Scheduler
41+
4242
## Plugin/Extension subsystem:
4343
* [ ] IPtables firewall manager
4444
* [ ] Crontab Manager
45-
45+
4646
## RESTful API:
4747
- * [ ] Display status
4848

4949

5050
## Web UI:
5151
* [ ] Docker manager
5252
* [ ] DNS indicator
53-
53+

docker-compose.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ services:
99
build:
1010
context: .
1111
dockerfile: docker/local/Dockerfile
12-
# entrypoint: [ 'bash', '-c', 'sleep infinity' ]
12+
#entrypoint: [ 'bash', '-c', 'sleep infinity' ]
13+
entrypoint: ['/app/stackdog']
1314
# restart: always
1415
ports:
1516
- "5003:5000"

docker/prod/Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ RUN apt-get update; \
1313
# copy binary and configuration files
1414
COPY ./stackdog .
1515
COPY ./.env .
16-
COPY ./migrations .
1716
# expose port
1817
EXPOSE 5000
1918

src/api/docker_controller.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,50 @@ pub async fn find_all() -> Result<HttpResponse> {
1010
Err(err) => Ok(err.response()),
1111
}
1212
}
13+
14+
#[cfg(test)]
15+
mod tests {
16+
use crate::{App, config};
17+
use actix_cors::Cors;
18+
use actix_service::Service;
19+
use actix_web::{test, http, http::StatusCode};
20+
use futures::FutureExt;
21+
use http::header;
22+
23+
24+
#[actix_rt::test]
25+
async fn test_list_ok() {
26+
let mut app = test::init_service(
27+
App::new()
28+
.wrap(Cors::new()
29+
.send_wildcard()
30+
.allowed_methods(vec!["GET", "POST", "PUT", "DELETE"])
31+
.allowed_header(http::header::CONTENT_TYPE)
32+
.max_age(3600)
33+
.finish())
34+
.data(config::db::migrate_and_config_db(":memory:"))
35+
.wrap(actix_web::middleware::Logger::default())
36+
.wrap(crate::middleware::authen_middleware::Authentication)
37+
.wrap_fn(|req, srv| {
38+
srv.call(req).map(|res| res)
39+
})
40+
.configure(crate::config::app::config_services)
41+
).await;
42+
43+
let resp = test::TestRequest::post()
44+
.uri("/api/auth/login")
45+
.set(header::ContentType::json())
46+
.set_payload(r#"{"username_or_email":"admin","password":"password"}"#.as_bytes())
47+
.send_request(&mut app)
48+
.await;
49+
50+
assert_eq!(resp.status(), StatusCode::OK);
51+
52+
let resp = test::TestRequest::post()
53+
.uri("/api/services")
54+
.set(header::ContentType::json())
55+
// .set(header::ContentType::json()) // here we need to set bearer token
56+
.send_request(&mut app)
57+
.await;
58+
}
59+
}

src/config/app.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub fn config_services(cfg: &mut web::ServiceConfig) {
2020
.service(
2121
web::scope("/services")
2222
.service(
23-
web::resource("")
23+
web::resource("/")
2424
.route(web::get().to(docker_controller::find_all))
2525
)
2626
// .service(

src/config/db.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use diesel::{
55
r2d2::{self, ConnectionManager},
66
dsl
77
};
8-
use crate::schema::users::columns::updated_at;
9-
use chrono::Utc;
8+
9+
1010

1111
embed_migrations!();
1212

src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ async fn main() -> io::Result<()> {
5252
let app_url = format!("{}:{}", &app_host, &app_port);
5353
let db_url = env::var("DATABASE_URL").expect("DATABASE_URL not found.");
5454

55+
println!("Starting server..");
5556
HttpServer::new(move || {
5657
App::new()
5758
.wrap(Cors::new() // allowed_origin return access-control-allow-origin: * by default

src/services/account_service.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use actix_web::{
1313
},
1414
web,
1515
};
16-
use crate::models::user::UserDTO;
16+
1717

1818
#[derive(Serialize, Deserialize)]
1919
pub struct TokenBodyResponse {

src/services/docker_service.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::collections::HashMap;
22
use bollard::container::ListContainersOptions;
33
use bollard::Docker;
4+
// use bollard::models::ContainerSummaryInner;
45
use serde_json;
56

67
use crate::{

0 commit comments

Comments
 (0)