|
@@ -1,5 +1,5 @@
|
|
use crate::{
|
|
use crate::{
|
|
- key, client_management, config, schema::{self, RealmID}, server, token, user_management, UIDCError,
|
|
|
|
|
|
+ key, client_management, config, schema::{self, RealmID}, server, token, user_management, UIDCError, group_management, token_management,
|
|
};
|
|
};
|
|
use clap::{Parser, Subcommand};
|
|
use clap::{Parser, Subcommand};
|
|
use microrm::prelude::*;
|
|
use microrm::prelude::*;
|
|
@@ -113,13 +113,12 @@ impl KeyArgs {
|
|
async fn run(&self, args: RunArgs) -> Result<(), UIDCError> {
|
|
async fn run(&self, args: RunArgs) -> Result<(), UIDCError> {
|
|
match &self.command {
|
|
match &self.command {
|
|
KeyCommand::Inspect => {
|
|
KeyCommand::Inspect => {
|
|
- key::inspect(&args.db, args.realm_id);
|
|
|
|
|
|
+ key::inspect(&args.db, args.realm_id)
|
|
}
|
|
}
|
|
KeyCommand::Generate => {
|
|
KeyCommand::Generate => {
|
|
- key::generate(&args.db, args.realm_id);
|
|
|
|
|
|
+ key::generate(&args.db, args.realm_id)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- Ok(())
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -140,14 +139,13 @@ impl ClientArgs {
|
|
async fn run(&self, args: RunArgs) -> Result<(), UIDCError> {
|
|
async fn run(&self, args: RunArgs) -> Result<(), UIDCError> {
|
|
match &self.command {
|
|
match &self.command {
|
|
ClientCommand::Create { name } => {
|
|
ClientCommand::Create { name } => {
|
|
- client_management::create(&args.db, args.realm_id, name);
|
|
|
|
|
|
+ client_management::create(&args.db, args.realm_id, name)
|
|
}
|
|
}
|
|
- ClientCommand::List => {}
|
|
|
|
|
|
+ ClientCommand::List => { todo!() }
|
|
ClientCommand::Inspect { name } => {
|
|
ClientCommand::Inspect { name } => {
|
|
- client_management::inspect(&args.db, args.realm_id, name);
|
|
|
|
|
|
+ client_management::inspect(&args.db, args.realm_id, name)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- Ok(())
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -206,79 +204,22 @@ impl GroupArgs {
|
|
let qi = args.db.query_interface();
|
|
let qi = args.db.query_interface();
|
|
match &self.command {
|
|
match &self.command {
|
|
GroupCommand::Create { group_name } => {
|
|
GroupCommand::Create { group_name } => {
|
|
- match qi.add(&schema::Group {
|
|
|
|
- realm: args.realm_id,
|
|
|
|
- shortname: group_name.clone(),
|
|
|
|
- }) {
|
|
|
|
- Ok(_) => {
|
|
|
|
- println!("Added group {}", group_name);
|
|
|
|
- },
|
|
|
|
- Err(e) => {
|
|
|
|
- println!("Failed to add group: {:?}", e);
|
|
|
|
- },
|
|
|
|
- }
|
|
|
|
|
|
+ group_management::create_group(&qi, args.realm_id, group_name)?;
|
|
},
|
|
},
|
|
GroupCommand::Members { group_name } => {
|
|
GroupCommand::Members { group_name } => {
|
|
- todo!()
|
|
|
|
|
|
+ group_management::list_members(&qi, args.realm_id, group_name.as_str())?;
|
|
},
|
|
},
|
|
GroupCommand::AttachRole { group_name, role_name } => {
|
|
GroupCommand::AttachRole { group_name, role_name } => {
|
|
- let group = qi.get().by(schema::Group::Realm, &args.realm_id).by(schema::Group::Shortname, group_name).one().unwrap();
|
|
|
|
- let role = qi.get().by(schema::Role::Realm, &args.realm_id).by(schema::Role::Shortname, role_name).one().unwrap();
|
|
|
|
-
|
|
|
|
- match (group, role) {
|
|
|
|
- (None, _) => {
|
|
|
|
- println!("No such group!");
|
|
|
|
- },
|
|
|
|
- (_, None) => {
|
|
|
|
- println!("No such role!");
|
|
|
|
- },
|
|
|
|
- (Some(group), Some(role)) => {
|
|
|
|
- match qi.add(&schema::GroupRole {
|
|
|
|
- group: group.id(),
|
|
|
|
- role: role.id(),
|
|
|
|
- }) {
|
|
|
|
- Ok(_) => {
|
|
|
|
- println!("Attached role {} to {}", role_name, group_name);
|
|
|
|
- },
|
|
|
|
- Err(e) => {
|
|
|
|
- println!("Failed to attach role: {:?}", e);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ group_management::attach_role(&qi, args.realm_id, group_name.as_str(), role_name.as_str())?;
|
|
},
|
|
},
|
|
GroupCommand::DetachRole { group_name, role_name } => {
|
|
GroupCommand::DetachRole { group_name, role_name } => {
|
|
-
|
|
|
|
|
|
+ group_management::detach_role(&qi, args.realm_id, group_name.as_str(), role_name.as_str())?;
|
|
},
|
|
},
|
|
GroupCommand::AttachUser { group_name, username } => {
|
|
GroupCommand::AttachUser { group_name, username } => {
|
|
- let group = qi.get().by(schema::Group::Realm, &args.realm_id).by(schema::Group::Shortname, group_name).one().unwrap();
|
|
|
|
- let user = qi.get().by(schema::User::Realm, &args.realm_id).by(schema::User::Username, username).one().unwrap();
|
|
|
|
-
|
|
|
|
- match (group, user) {
|
|
|
|
- (None, _) => {
|
|
|
|
- println!("No such group!");
|
|
|
|
- },
|
|
|
|
- (_, None) => {
|
|
|
|
- println!("No such user!");
|
|
|
|
- },
|
|
|
|
- (Some(group), Some(user)) => {
|
|
|
|
- match qi.add(&schema::GroupMembership {
|
|
|
|
- group: group.id(),
|
|
|
|
- user: user.id(),
|
|
|
|
- }) {
|
|
|
|
- Ok(_) => {
|
|
|
|
- println!("Attached user {} to {}", username, group_name);
|
|
|
|
- },
|
|
|
|
- Err(e) => {
|
|
|
|
- println!("Failed to attach user: {:?}", e);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
- }
|
|
|
|
|
|
+ group_management::attach_user(&qi, args.realm_id, group_name.as_str(), username.as_str())?;
|
|
},
|
|
},
|
|
GroupCommand::DetachUser { group_name, username } => {
|
|
GroupCommand::DetachUser { group_name, username } => {
|
|
-
|
|
|
|
|
|
+ group_management::detach_user(&qi, args.realm_id, group_name.as_str(), username.as_str())?;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
Ok(())
|
|
Ok(())
|
|
@@ -330,50 +271,24 @@ struct TokenArgs {
|
|
impl TokenArgs {
|
|
impl TokenArgs {
|
|
async fn run(&self, args: RunArgs) -> Result<(), UIDCError> {
|
|
async fn run(&self, args: RunArgs) -> Result<(), UIDCError> {
|
|
let config = config::Config::build_from(&args.db.query_interface(), None);
|
|
let config = config::Config::build_from(&args.db.query_interface(), None);
|
|
|
|
+ let qi = args.db.query_interface();
|
|
match &self.command {
|
|
match &self.command {
|
|
TokenCommand::GenerateAuth {
|
|
TokenCommand::GenerateAuth {
|
|
client,
|
|
client,
|
|
username,
|
|
username,
|
|
scopes,
|
|
scopes,
|
|
} => {
|
|
} => {
|
|
- let qi = args.db.query_interface();
|
|
|
|
- let token = token::generate_auth_token(
|
|
|
|
- &config,
|
|
|
|
- &qi,
|
|
|
|
- args.realm_id,
|
|
|
|
- qi.get()
|
|
|
|
- .by(schema::Client::Realm, &args.realm_id)
|
|
|
|
- .by(schema::Client::Shortname, client.as_str())
|
|
|
|
- .one()
|
|
|
|
- .unwrap()
|
|
|
|
- .expect("no such client")
|
|
|
|
- .id(),
|
|
|
|
- qi.get()
|
|
|
|
- .by(schema::User::Realm, &args.realm_id)
|
|
|
|
- .by(schema::User::Username, username.as_str())
|
|
|
|
- .one()
|
|
|
|
- .unwrap()
|
|
|
|
- .expect("no such user")
|
|
|
|
- .id(),
|
|
|
|
- scopes.split_whitespace(),
|
|
|
|
- );
|
|
|
|
- match token {
|
|
|
|
- Ok(t) => {
|
|
|
|
- println!("token: {t}");
|
|
|
|
- }
|
|
|
|
- Err(e) => {
|
|
|
|
- println!("could not generate token: {:?}", e);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ let token = token_management::create_auth_token(&qi, &config, args.realm_id, client.as_str(), username.as_str(), scopes.as_str())?;
|
|
|
|
+ println!("{}", token);
|
|
|
|
+ Ok(())
|
|
}
|
|
}
|
|
TokenCommand::GenerateRefresh {
|
|
TokenCommand::GenerateRefresh {
|
|
client,
|
|
client,
|
|
username,
|
|
username,
|
|
scopes,
|
|
scopes,
|
|
- } => {}
|
|
|
|
- TokenCommand::Inspect { token } => {}
|
|
|
|
|
|
+ } => { todo!() }
|
|
|
|
+ TokenCommand::Inspect { token } => { todo!() }
|
|
}
|
|
}
|
|
- Ok(())
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|