Skip to content

Commit

Permalink
Develop (#13)
Browse files Browse the repository at this point in the history
* folder structure created and routes configured

* stale constants removed

* stale constants removed

* cache cleared

* duplicate function removed

* Updated README.md

* framework changed to actix-web

* accidental removal restored
  • Loading branch information
CA-MKSingh authored Oct 5, 2023
1 parent fda081d commit e85b27e
Show file tree
Hide file tree
Showing 11 changed files with 448 additions and 521 deletions.
839 changes: 383 additions & 456 deletions Cargo.lock

Large diffs are not rendered by default.

15 changes: 4 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
[package]
name = "rust-shield"
name = "shield"
version = "0.1.0"
edition = "2021"
license = "MIT AND Apache-2.0"
description = "This is going to be an IAM system. Just reserving the name for time being."
documentation = "https://shield-docs.rustsea.com"
homepage = "https://www.rustsea.com/shield"
keywords = ["auth", "iam-provider", "identity-and-access", "idp"]
readme = "README.md"
repository = "https://github.com/rustsea/shield/"

[dependencies]
rocket = "0.5.0-rc.3"
shuttle-rocket = "0.28.0"
actix-web = "4.3.1"
shuttle-actix-web = "0.28.0"
shuttle-runtime = "0.28.0"
tokio = "1.32.0"
tokio = "1.26.0"
36 changes: 14 additions & 22 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,21 @@
mod routes;
use actix_web::{get, web::{ServiceConfig, scope}};
use shuttle_actix_web::ShuttleActixWeb;
use crate::organisation::factory::organisation_factory;

mod organisation;
mod project;

use routes::{get_routes, RouteKey};
use organisation::{index as org_index};
use project::{index as project_index};

#[macro_use]
extern crate rocket;

#[shuttle_runtime::main]
async fn rocket() -> shuttle_rocket::ShuttleRocket {
let rocket = rocket::build()
.mount("/", routes![index])
.mount(&get_path(&RouteKey::Organisations), routes![org_index])
.mount(&get_path(&RouteKey::Projects), routes![project_index]);
Ok(rocket.into())
}

#[get("/")]
fn index() -> &'static str {
#[get("")]
async fn hello_world() -> &'static str {
"Hello World! It's your Shield"
}

fn get_path(route: &RouteKey) -> String {
let routes_map = get_routes();
routes_map.get(route).map(|s|s.to_string()).expect("Route not found")
#[shuttle_runtime::main]
async fn actix_web() -> ShuttleActixWeb<impl FnOnce(&mut ServiceConfig) + Send + Clone + 'static> {
let config = move |cfg: &mut ServiceConfig| {
cfg.service(scope("/").service(hello_world))
.service(scope("/organisations").service(organisation_factory()));
};

Ok(config.into())
}
16 changes: 12 additions & 4 deletions src/organisation/controller.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
#[get("/")]
pub fn index() -> &'static str {
"Hello from Shield, this is Organisations Route"
}
use actix_web::{get, HttpResponse, Result};
use actix_web::web::Path;

#[get("")]
pub async fn index() -> Result<HttpResponse> {
Ok(HttpResponse::Ok().body("Hello from the organization index!"))
}

#[get("/{organisation_id}")]
pub async fn org_info(path: Path<String>) -> Result<HttpResponse> {
Ok(HttpResponse::Ok().body(format!("Your organisation id: {}", path)))
}
10 changes: 10 additions & 0 deletions src/organisation/factory.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use actix_web::{Scope, web};
use crate::organisation::controller::{index, org_info};
use crate::project::factory::project_factory;

pub fn organisation_factory () -> Scope {
web::scope("")
.service(index)
.service(org_info)
.service(web::scope("/{organisation_id}/projects").service(project_factory()))
}
5 changes: 2 additions & 3 deletions src/organisation/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
mod controller;

pub use controller::{index};
pub mod controller;
pub mod factory;
17 changes: 13 additions & 4 deletions src/project/controller.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
#[get("/")]
pub fn index() -> &'static str {
"Hello from Shield, this is Projects Route"
}
use actix_web::{get, HttpResponse, Result};
use actix_web::web::Path;

#[get("")]
pub async fn index() -> Result<HttpResponse> {
Ok(HttpResponse::Ok().body("Hello from Shield, this is Projects Route"))
}

#[get("/{project_id}")]
pub async fn project_info(path: Path<(String, String)>) -> Result<HttpResponse> {
let (organisation_id, project_id) = path.into_inner();
Ok(HttpResponse::Ok().body(format!("Your project id is: {} belongs to: {}", project_id, organisation_id)))
}
8 changes: 8 additions & 0 deletions src/project/factory.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use actix_web::{Scope, web};
use crate::project::controller::{index, project_info};

pub fn project_factory () -> Scope {
web::scope("")
.service(index)
.service(project_info)
}
5 changes: 2 additions & 3 deletions src/project/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
mod controller;

pub use controller::{index};
pub mod controller;
pub mod factory;
3 changes: 0 additions & 3 deletions src/routes/mod.rs

This file was deleted.

15 changes: 0 additions & 15 deletions src/routes/v1.rs

This file was deleted.

0 comments on commit e85b27e

Please sign in to comment.