Skip to content

Commit ed83b12

Browse files
committed
CLI should use Agent in requests #986
1 parent 0c808ed commit ed83b12

File tree

4 files changed

+26
-10
lines changed

4 files changed

+26
-10
lines changed

cli/src/commit.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub fn set(context: &Context, subject: &str, property: &str, value: &str) -> Ato
88
Ok(r) => r,
99
Err(_) => atomic_lib::Resource::new(subject.into()),
1010
};
11-
resource.set_shortname(&property, &value, &context.store)?;
11+
resource.set_shortname(property, value, &context.store)?;
1212
resource.save(&context.store)?;
1313
Ok(())
1414
}
@@ -22,22 +22,22 @@ pub fn edit(context: &Context, subject: &str, prop: &str) -> AtomicResult<()> {
2222
Err(_) => atomic_lib::Resource::new(subject.into()),
2323
};
2424
// If the prop is not found, create it
25-
let current_val = match resource.get_shortname(&prop, &context.store) {
25+
let current_val = match resource.get_shortname(prop, &context.store) {
2626
Ok(val) => val.to_string(),
2727
Err(_) => "".to_string(),
2828
};
2929
let edited = edit::edit(current_val)?;
3030
// Remove newline - or else I can's save shortnames or numbers using vim;
3131
let trimmed = edited.trim_end_matches('\n');
32-
resource.set_shortname(&prop, trimmed, &context.store)?;
32+
resource.set_shortname(prop, trimmed, &context.store)?;
3333
resource.save(&context.store)?;
3434
Ok(())
3535
}
3636

3737
/// Apply a Commit using the Remove method - removes a property from a resource
3838
pub fn remove(context: &Context, subject: &str, prop: &str) -> AtomicResult<()> {
3939
let mut resource = context.store.get_resource(subject)?;
40-
resource.remove_propval_shortname(&prop, &context.store)?;
40+
resource.remove_propval_shortname(prop, &context.store)?;
4141
resource.save(&context.store)?;
4242
Ok(())
4343
}

cli/src/main.rs

+1
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ fn main() -> AtomicResult<()> {
223223

224224
fn exec_command(context: &mut Context) -> AtomicResult<()> {
225225
let command = context.matches.clone();
226+
context.read_config();
226227

227228
match command {
228229
Commands::Destroy { subject } => {

cli/src/path.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,31 @@ use atomic_lib::{agents::ForAgent, errors::AtomicResult, serialize, storelike, A
44
/// Resolves an Atomic Path query
55
pub fn get_path(
66
context: &mut Context,
7-
path_vec: &Vec<String>,
7+
path_vec: &[String],
88
serialize: &SerializeOptions,
99
) -> AtomicResult<()> {
1010
// let subcommand_matches = context.matches.subcommand_matches("get").unwrap();
1111
let path_string: String = path_vec.join(" ");
1212

13+
let for_agent: ForAgent = context.store.get_default_agent()?.into();
1314
// Returns a URL or Value
14-
let store = &mut context.store;
15-
let path = store.get_path(
15+
let path = context.store.get_path(
1616
&path_string,
1717
Some(&context.mapping.lock().unwrap()),
18-
&ForAgent::Sudo,
18+
&for_agent,
1919
)?;
2020
let out = match path {
2121
storelike::PathReturn::Subject(subject) => {
22-
let resource = store.get_resource_extended(&subject, false, &ForAgent::Sudo)?;
22+
let resource = context
23+
.store
24+
.get_resource_extended(&subject, false, &for_agent)?;
2325
print_resource(context, &resource, serialize)?;
2426
return Ok(());
2527
}
2628
storelike::PathReturn::Atom(atom) => match serialize {
2729
SerializeOptions::NTriples => {
2830
let atoms: Vec<Atom> = vec![*atom];
29-
serialize::atoms_to_ntriples(atoms, store)?
31+
serialize::atoms_to_ntriples(atoms, &context.store)?
3032
}
3133
_other => atom.value.to_string(),
3234
},

lib/src/agents.rs

+13
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,19 @@ impl<T: Into<String>> From<T> for ForAgent {
4444
}
4545
}
4646

47+
// From Agent to ForAgent
48+
impl From<&Agent> for ForAgent {
49+
fn from(agent: &Agent) -> Self {
50+
ForAgent::AgentSubject(agent.subject.clone())
51+
}
52+
}
53+
54+
impl From<Agent> for ForAgent {
55+
fn from(agent: Agent) -> Self {
56+
ForAgent::AgentSubject(agent.subject)
57+
}
58+
}
59+
4760
/// An Agent can be thought of as a User. Agents are used for authentication and authorization.
4861
/// The private key of the Agent is used to sign [crate::Commit]s.
4962
#[derive(Clone, Debug)]

0 commit comments

Comments
 (0)