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"
|
||||
|
||||
[[package]]
|
||||
name = "wasmcloud-api"
|
||||
name = "wasmcloud"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"blake3",
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
[package]
|
||||
name = "wasmcloud-api"
|
||||
name = "wasmcloud"
|
||||
version = "0.1.0"
|
||||
authors = ["Christine Dodrill <me@christine.website>"]
|
||||
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" }
|
||||
client_id = "..."
|
||||
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_MODULE_BUCKET_NAME = "wasmcloud-modules";
|
||||
RUST_LOG = "info,wasmcloud_api=debug";
|
||||
RUST_LOG = "info,wasmcloud=debug";
|
||||
DATABASE_URL = "postgresql://postgres:hunter2@localhost:5432/wasmcloud";
|
||||
ROCKET_DATABASES = ''{ main_data = { url = "${DATABASE_URL}" } }'';
|
||||
JWT_SECRET = "hunter2";
|
||||
|
|
|
@ -2,7 +2,6 @@ use super::{Error, Result};
|
|||
use crate::{b2, models, schema, MainDatabase};
|
||||
use chrono::prelude::*;
|
||||
use diesel::prelude::*;
|
||||
use rocket::http::ContentType;
|
||||
use rocket_contrib::{json::Json, uuid::Uuid};
|
||||
use rocket_upload::MultipartDatas;
|
||||
use schema::handlers::dsl::*;
|
||||
|
@ -33,7 +32,11 @@ pub fn create(
|
|||
.get_result::<models::Handler>(&*conn)
|
||||
.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))
|
||||
}
|
||||
|
@ -50,9 +53,9 @@ pub fn list(user: models::User, conn: MainDatabase) -> Result<Json<Vec<models::H
|
|||
}
|
||||
|
||||
#[instrument(skip(conn), err)]
|
||||
#[get("/handler/<uuid>")]
|
||||
pub fn get(user: models::User, uuid: Uuid, conn: MainDatabase) -> Result<Json<models::Handler>> {
|
||||
let uuid = uuid.into_inner();
|
||||
#[get("/handler/<hdl_id>")]
|
||||
pub fn get(user: models::User, hdl_id: Uuid, conn: MainDatabase) -> Result<Json<models::Handler>> {
|
||||
let uuid = hdl_id.into_inner();
|
||||
let handler = handlers
|
||||
.find(uuid)
|
||||
.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)]
|
||||
#[delete("/handler/<uuid>")]
|
||||
pub fn delete(user: models::User, uuid: Uuid, conn: MainDatabase) -> Result {
|
||||
let uuid = uuid.into_inner();
|
||||
#[delete("/handler/<hdl_id>")]
|
||||
pub fn delete(user: models::User, hdl_id: Uuid, conn: MainDatabase) -> Result {
|
||||
let uuid = hdl_id.into_inner();
|
||||
|
||||
let hdl: models::Handler = handlers
|
||||
.find(uuid.clone())
|
||||
|
@ -122,15 +125,15 @@ pub struct Cfg {
|
|||
}
|
||||
|
||||
#[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(
|
||||
user: models::User,
|
||||
handler_id_str: Uuid,
|
||||
hdl_id: Uuid,
|
||||
cfg: Json<Vec<Cfg>>,
|
||||
conn: MainDatabase,
|
||||
) -> Result {
|
||||
use schema::handler_config::table;
|
||||
let uuid = handler_id_str.into_inner();
|
||||
let uuid = hdl_id.into_inner();
|
||||
|
||||
let handler = handlers
|
||||
.find(uuid)
|
||||
|
@ -163,12 +166,11 @@ pub fn create_config(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[instrument(skip(conn, data, ct), err)]
|
||||
#[instrument(skip(conn, data), err)]
|
||||
#[post("/handler/<hdl_id>/upload", data = "<data>")]
|
||||
pub fn upload_version(
|
||||
user: models::User,
|
||||
hdl_id: Uuid,
|
||||
ct: &ContentType,
|
||||
data: MultipartDatas,
|
||||
conn: MainDatabase,
|
||||
) -> 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 serde::{Deserialize, Serialize};
|
||||
use crate::{api, jwt, models, schema, Gitea, MainDatabase};
|
||||
use diesel::prelude::*;
|
||||
use rocket::{
|
||||
http::{Cookie, Cookies, SameSite},
|
||||
response::Redirect,
|
||||
};
|
||||
use rocket_oauth2::{OAuth2, TokenResponse};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// A user.
|
||||
/// https://try.gitea.io/api/swagger#model-User
|
||||
|
@ -22,9 +22,10 @@ pub struct User {
|
|||
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")
|
||||
.set("Authorization", &format!("bearer {}", token))
|
||||
.set("User-Agent", crate::APP_USER_AGENT)
|
||||
.call();
|
||||
if !resp.ok() {
|
||||
todo!("error here");
|
||||
|
@ -34,13 +35,13 @@ pub fn user(token: String) -> std::io::Result<User> {
|
|||
}
|
||||
|
||||
#[instrument(skip(oauth2, cookies))]
|
||||
#[get("/login/gitea")]
|
||||
#[get("/")]
|
||||
pub fn login(oauth2: OAuth2<Gitea>, mut cookies: Cookies<'_>) -> Redirect {
|
||||
oauth2.get_redirect(&mut cookies, &[""]).unwrap()
|
||||
}
|
||||
|
||||
#[instrument(skip(conn, token, cookies), err)]
|
||||
#[get("/auth/gitea")]
|
||||
#[get("/callback")]
|
||||
pub fn callback(
|
||||
conn: MainDatabase,
|
||||
token: TokenResponse<Gitea>,
|
||||
|
|
|
@ -65,7 +65,7 @@ fn main() -> Result<()> {
|
|||
api::token::create,
|
||||
],
|
||||
)
|
||||
.mount("/", routes![gitea::login, gitea::callback])
|
||||
.mount("/login/gitea", routes![gitea::login, gitea::callback])
|
||||
.launch();
|
||||
|
||||
Ok(())
|
||||
|
|
Loading…
Reference in New Issue