Procházet zdrojové kódy

Follow microrm changes.

Kestrel před 2 roky
rodič
revize
180644f15a
4 změnil soubory, kde provedl 16 přidání a 21 odebrání
  1. 7 6
      src/cert.rs
  2. 0 1
      src/main.rs
  3. 9 9
      src/schema.rs
  4. 0 5
      src/storage.rs

+ 7 - 6
src/cert.rs

@@ -1,6 +1,7 @@
 use std::collections::HashMap;
 use ring::signature::Ed25519KeyPair;
 use sha2::Digest;
+use crate::schema;
 
 pub struct CertStore<'a> {
     db: &'a crate::DB,
@@ -12,8 +13,8 @@ impl<'a> CertStore<'a> {
         Self { db, keys: HashMap::new() }
     }
 
-    fn realm_id(&self, realm_name: &str) -> Option<microrm::query::ID> {
-        microrm::query::get_one_by(self.db, crate::schema::RealmColumns::Shortname, realm_name).map(|x| x.id())
+    fn realm_id(&self, realm_name: &str) -> Option<schema::RealmID> {
+        microrm::query::get_one_by(self.db, schema::RealmColumns::Shortname, realm_name).map(|x| x.id())
     }
 
     pub fn generate_in(&self, realm_name: &str) -> Result<String, &'static str> {
@@ -22,7 +23,7 @@ impl<'a> CertStore<'a> {
 
         let realm_id = self.realm_id(realm_name).ok_or("Failed to find realm")?;
 
-        if let Err(e) = sign_generated {
+        if let Err(_) = sign_generated {
             return Err("Failed to generate key")
         }
         let sign_generated = sign_generated.unwrap();
@@ -34,7 +35,7 @@ impl<'a> CertStore<'a> {
         let mut key_id = base64::encode(key_hasher.finalize());
         key_id.truncate(16);
 
-        microrm::query::add(self.db, &crate::schema::Key { realm: realm_id, key_id: key_id.clone(), keydata }).expect("Couldn't add key");
+        microrm::query::add(self.db, &schema::Key { realm: realm_id, key_id: key_id.clone(), keydata }).expect("Couldn't add key");
 
         Ok(key_id)
     }
@@ -43,7 +44,7 @@ impl<'a> CertStore<'a> {
 pub fn inspect(db: &crate::DB, realm_name: &str) {
     let cs = CertStore::new(db);
     println!("Certstore loaded.");
-    let realm = microrm::query::get_one_by(db, crate::schema::RealmColumns::Shortname, realm_name);
+    let realm = microrm::query::get_one_by(db, schema::RealmColumns::Shortname, realm_name);
     if realm.is_none() {
         println!("No such realm {}", realm_name);
         return
@@ -51,7 +52,7 @@ pub fn inspect(db: &crate::DB, realm_name: &str) {
     let realm = realm.unwrap();
 
     println!("Retrieving keys for {} realm...", realm_name);
-    let keys = microrm::query::get_all_by(db, crate::schema::KeyColumns::Realm, realm.id()).expect("Can get keys");
+    let keys = microrm::query::get_all_by(db, schema::KeyColumns::Realm, realm.id()).expect("Can get keys");
     for key in keys {
         println!("[{:20}]", key.key_id);
     }

+ 0 - 1
src/main.rs

@@ -1,7 +1,6 @@
 pub use microrm::DB;
 
 mod schema;
-mod storage;
 mod cli;
 mod cert;
 

+ 9 - 9
src/schema.rs

@@ -1,5 +1,5 @@
 use serde::{Serialize,Deserialize};
-pub use microrm::{Entity, model::SchemaModel, query::ID};
+pub use microrm::{Entity, model::SchemaModel};
 
 #[derive(Entity,Serialize,Deserialize)]
 pub struct Realm {
@@ -8,7 +8,7 @@ pub struct Realm {
 
 #[derive(Entity,Serialize,Deserialize)]
 pub struct Key {
-    pub realm: ID,
+    pub realm: RealmID,
     pub key_id: String,
     #[serde(with = "serde_bytes")]
     pub keydata: Vec<u8>
@@ -16,40 +16,40 @@ pub struct Key {
 
 #[derive(Entity,Serialize,Deserialize)]
 pub struct User {
-    pub realm: ID,
+    pub realm: RealmID,
     pub username: String,
 }
 
 #[derive(Entity,Serialize,Deserialize)]
 pub struct Password {
-    pub user: ID,
+    pub user: UserID,
     pub salt: String,
     pub hash: String
 }
 
 #[derive(Entity,Serialize,Deserialize)]
 pub struct Group {
-    pub realm: ID,
+    pub realm: RealmID,
     pub shortname: String,
 }
 
 #[derive(Entity,Serialize,Deserialize)]
 pub struct Client {
-    pub realm: ID,
+    pub realm: RealmID,
     pub shortname: String,
     pub secret: String,
 }
 
 #[derive(Entity,Serialize,Deserialize)]
 pub struct Scope {
-    pub realm: ID,
+    pub realm: RealmID,
     pub shortname: String,
 }
 
 #[derive(Entity,Serialize,Deserialize)]
 pub struct Role {
-    pub realm: ID,
-    pub group: ID,
+    pub realm: RealmID,
+    pub group: GroupID,
     pub shortname: String,
 }
 

+ 0 - 5
src/storage.rs

@@ -1,5 +0,0 @@
-
-
-pub struct DB {
-    
-}