rename to wasmcloud, do gitea auth on /login/gitea
This commit is contained in:
parent
f136033688
commit
a871b4e222
|
@ -3139,7 +3139,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1d649a3145108d7d3fbcde896a468d1bd636791823c9921135218ad89be08307"
|
checksum = "1d649a3145108d7d3fbcde896a468d1bd636791823c9921135218ad89be08307"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasmcloud-api"
|
name = "wasmcloud"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"blake3",
|
"blake3",
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
[package]
|
[package]
|
||||||
name = "wasmcloud-api"
|
name = "wasmcloud"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Christine Dodrill <me@christine.website>"]
|
authors = ["Christine Dodrill <me@christine.website>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
|
@ -6,4 +6,4 @@ forms = 5242880
|
||||||
provider = { auth_uri = "https://tulpa.dev/login/oauth/authorize", token_uri = "https://tulpa.dev/login/oauth/access_token" }
|
provider = { auth_uri = "https://tulpa.dev/login/oauth/authorize", token_uri = "https://tulpa.dev/login/oauth/access_token" }
|
||||||
client_id = "..."
|
client_id = "..."
|
||||||
client_secret = "..."
|
client_secret = "..."
|
||||||
redirect_uri = "http://localhost:8000/auth/gitea"
|
redirect_uri = "http://localhost:8000/login/gitea/callback"
|
|
@ -15,7 +15,7 @@ in pkgs.mkShell rec {
|
||||||
|
|
||||||
B2_CREDFILE = "./var/secret/b2-creds.txt";
|
B2_CREDFILE = "./var/secret/b2-creds.txt";
|
||||||
B2_MODULE_BUCKET_NAME = "wasmcloud-modules";
|
B2_MODULE_BUCKET_NAME = "wasmcloud-modules";
|
||||||
RUST_LOG = "info,wasmcloud_api=debug";
|
RUST_LOG = "info,wasmcloud=debug";
|
||||||
DATABASE_URL = "postgresql://postgres:hunter2@localhost:5432/wasmcloud";
|
DATABASE_URL = "postgresql://postgres:hunter2@localhost:5432/wasmcloud";
|
||||||
ROCKET_DATABASES = ''{ main_data = { url = "${DATABASE_URL}" } }'';
|
ROCKET_DATABASES = ''{ main_data = { url = "${DATABASE_URL}" } }'';
|
||||||
JWT_SECRET = "hunter2";
|
JWT_SECRET = "hunter2";
|
||||||
|
|
|
@ -2,7 +2,6 @@ use super::{Error, Result};
|
||||||
use crate::{b2, models, schema, MainDatabase};
|
use crate::{b2, models, schema, MainDatabase};
|
||||||
use chrono::prelude::*;
|
use chrono::prelude::*;
|
||||||
use diesel::prelude::*;
|
use diesel::prelude::*;
|
||||||
use rocket::http::ContentType;
|
|
||||||
use rocket_contrib::{json::Json, uuid::Uuid};
|
use rocket_contrib::{json::Json, uuid::Uuid};
|
||||||
use rocket_upload::MultipartDatas;
|
use rocket_upload::MultipartDatas;
|
||||||
use schema::handlers::dsl::*;
|
use schema::handlers::dsl::*;
|
||||||
|
@ -33,7 +32,11 @@ pub fn create(
|
||||||
.get_result::<models::Handler>(&*conn)
|
.get_result::<models::Handler>(&*conn)
|
||||||
.map_err(Error::Database)?;
|
.map_err(Error::Database)?;
|
||||||
|
|
||||||
info!("created handler {} with id {}", hdl.human_name, hdl.id);
|
info!(
|
||||||
|
handler.id = &hdl.id.to_string()[..],
|
||||||
|
handler.name = &hdl.human_name[..],
|
||||||
|
"created handler"
|
||||||
|
);
|
||||||
|
|
||||||
Ok(Json(hdl))
|
Ok(Json(hdl))
|
||||||
}
|
}
|
||||||
|
@ -50,9 +53,9 @@ pub fn list(user: models::User, conn: MainDatabase) -> Result<Json<Vec<models::H
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(skip(conn), err)]
|
#[instrument(skip(conn), err)]
|
||||||
#[get("/handler/<uuid>")]
|
#[get("/handler/<hdl_id>")]
|
||||||
pub fn get(user: models::User, uuid: Uuid, conn: MainDatabase) -> Result<Json<models::Handler>> {
|
pub fn get(user: models::User, hdl_id: Uuid, conn: MainDatabase) -> Result<Json<models::Handler>> {
|
||||||
let uuid = uuid.into_inner();
|
let uuid = hdl_id.into_inner();
|
||||||
let handler = handlers
|
let handler = handlers
|
||||||
.find(uuid)
|
.find(uuid)
|
||||||
.get_result::<models::Handler>(&*conn)
|
.get_result::<models::Handler>(&*conn)
|
||||||
|
@ -66,9 +69,9 @@ pub fn get(user: models::User, uuid: Uuid, conn: MainDatabase) -> Result<Json<mo
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(skip(conn), err)]
|
#[instrument(skip(conn), err)]
|
||||||
#[delete("/handler/<uuid>")]
|
#[delete("/handler/<hdl_id>")]
|
||||||
pub fn delete(user: models::User, uuid: Uuid, conn: MainDatabase) -> Result {
|
pub fn delete(user: models::User, hdl_id: Uuid, conn: MainDatabase) -> Result {
|
||||||
let uuid = uuid.into_inner();
|
let uuid = hdl_id.into_inner();
|
||||||
|
|
||||||
let hdl: models::Handler = handlers
|
let hdl: models::Handler = handlers
|
||||||
.find(uuid.clone())
|
.find(uuid.clone())
|
||||||
|
@ -122,15 +125,15 @@ pub struct Cfg {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(skip(conn, cfg), err)]
|
#[instrument(skip(conn, cfg), err)]
|
||||||
#[post("/handler/<handler_id_str>/config", format = "json", data = "<cfg>")]
|
#[post("/handler/<hdl_id>/config", format = "json", data = "<cfg>")]
|
||||||
pub fn create_config(
|
pub fn create_config(
|
||||||
user: models::User,
|
user: models::User,
|
||||||
handler_id_str: Uuid,
|
hdl_id: Uuid,
|
||||||
cfg: Json<Vec<Cfg>>,
|
cfg: Json<Vec<Cfg>>,
|
||||||
conn: MainDatabase,
|
conn: MainDatabase,
|
||||||
) -> Result {
|
) -> Result {
|
||||||
use schema::handler_config::table;
|
use schema::handler_config::table;
|
||||||
let uuid = handler_id_str.into_inner();
|
let uuid = hdl_id.into_inner();
|
||||||
|
|
||||||
let handler = handlers
|
let handler = handlers
|
||||||
.find(uuid)
|
.find(uuid)
|
||||||
|
@ -163,12 +166,11 @@ pub fn create_config(
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(skip(conn, data, ct), err)]
|
#[instrument(skip(conn, data), err)]
|
||||||
#[post("/handler/<hdl_id>/upload", data = "<data>")]
|
#[post("/handler/<hdl_id>/upload", data = "<data>")]
|
||||||
pub fn upload_version(
|
pub fn upload_version(
|
||||||
user: models::User,
|
user: models::User,
|
||||||
hdl_id: Uuid,
|
hdl_id: Uuid,
|
||||||
ct: &ContentType,
|
|
||||||
data: MultipartDatas,
|
data: MultipartDatas,
|
||||||
conn: MainDatabase,
|
conn: MainDatabase,
|
||||||
) -> Result<Json<models::Handler>> {
|
) -> Result<Json<models::Handler>> {
|
||||||
|
|
11
src/gitea.rs
11
src/gitea.rs
|
@ -1,11 +1,11 @@
|
||||||
use crate::{MainDatabase, Gitea, models, jwt, schema, api};
|
use crate::{api, jwt, models, schema, Gitea, MainDatabase};
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use diesel::prelude::*;
|
use diesel::prelude::*;
|
||||||
use rocket::{
|
use rocket::{
|
||||||
http::{Cookie, Cookies, SameSite},
|
http::{Cookie, Cookies, SameSite},
|
||||||
response::Redirect,
|
response::Redirect,
|
||||||
};
|
};
|
||||||
use rocket_oauth2::{OAuth2, TokenResponse};
|
use rocket_oauth2::{OAuth2, TokenResponse};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
/// A user.
|
/// A user.
|
||||||
/// https://try.gitea.io/api/swagger#model-User
|
/// https://try.gitea.io/api/swagger#model-User
|
||||||
|
@ -22,9 +22,10 @@ pub struct User {
|
||||||
pub login: String,
|
pub login: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn user(token: String) -> std::io::Result<User> {
|
fn user(token: String) -> std::io::Result<User> {
|
||||||
let resp = ureq::get("https://tulpa.dev/api/v1/user")
|
let resp = ureq::get("https://tulpa.dev/api/v1/user")
|
||||||
.set("Authorization", &format!("bearer {}", token))
|
.set("Authorization", &format!("bearer {}", token))
|
||||||
|
.set("User-Agent", crate::APP_USER_AGENT)
|
||||||
.call();
|
.call();
|
||||||
if !resp.ok() {
|
if !resp.ok() {
|
||||||
todo!("error here");
|
todo!("error here");
|
||||||
|
@ -34,13 +35,13 @@ pub fn user(token: String) -> std::io::Result<User> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(skip(oauth2, cookies))]
|
#[instrument(skip(oauth2, cookies))]
|
||||||
#[get("/login/gitea")]
|
#[get("/")]
|
||||||
pub fn login(oauth2: OAuth2<Gitea>, mut cookies: Cookies<'_>) -> Redirect {
|
pub fn login(oauth2: OAuth2<Gitea>, mut cookies: Cookies<'_>) -> Redirect {
|
||||||
oauth2.get_redirect(&mut cookies, &[""]).unwrap()
|
oauth2.get_redirect(&mut cookies, &[""]).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(skip(conn, token, cookies), err)]
|
#[instrument(skip(conn, token, cookies), err)]
|
||||||
#[get("/auth/gitea")]
|
#[get("/callback")]
|
||||||
pub fn callback(
|
pub fn callback(
|
||||||
conn: MainDatabase,
|
conn: MainDatabase,
|
||||||
token: TokenResponse<Gitea>,
|
token: TokenResponse<Gitea>,
|
||||||
|
|
|
@ -65,7 +65,7 @@ fn main() -> Result<()> {
|
||||||
api::token::create,
|
api::token::create,
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
.mount("/", routes![gitea::login, gitea::callback])
|
.mount("/login/gitea", routes![gitea::login, gitea::callback])
|
||||||
.launch();
|
.launch();
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Reference in New Issue