gardesk/gargears / aeb0522

Browse files

Add garcard lifecycle command adapter methods

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
aeb0522ba84ce5923abf417f85485ac0992e8d7c
Parents
eadd636
Tree
aefc2cd

1 changed file

StatusFile+-
M gargears/src/ipc/adapters/garcard.rs 61 1
gargears/src/ipc/adapters/garcard.rsmodified
@@ -1,11 +1,28 @@
11
 //! IPC adapter for garcard (authentication agent)
22
 
3
-use crate::ipc::client::IpcClient;
3
+use crate::ipc::client::{IpcClient, StandardResponse};
44
 use crate::ipc::discovery::socket_path_for;
55
 use crate::panels::Component;
66
 use anyhow::Result;
7
+use serde::Serialize;
8
+use serde_json::Value;
79
 use std::path::PathBuf;
810
 
11
+/// Commands for garcard daemon.
12
+#[derive(Debug, Serialize)]
13
+#[serde(tag = "command", rename_all = "snake_case")]
14
+enum GarcardCommand {
15
+    Ping,
16
+    Status,
17
+    Diagnose,
18
+    Version,
19
+    AuthSummary,
20
+    TempList,
21
+    TempRevoke { authorization_id: String },
22
+    TempRevokeAll,
23
+    Quit,
24
+}
25
+
926
 /// Adapter for garcard authentication agent
1027
 pub struct GarcardAdapter {
1128
     client: IpcClient,
@@ -49,6 +66,49 @@ impl GarcardAdapter {
4966
     pub fn is_connected(&self) -> bool {
5067
         self.client.is_connected()
5168
     }
69
+
70
+    fn send_command(&mut self, command: GarcardCommand) -> Result<Option<Value>> {
71
+        let response: StandardResponse = self.client.send_receive(&command)?;
72
+        response.into_result()
73
+    }
74
+
75
+    pub fn ping(&mut self) -> Result<Option<Value>> {
76
+        self.send_command(GarcardCommand::Ping)
77
+    }
78
+
79
+    pub fn status(&mut self) -> Result<Option<Value>> {
80
+        self.send_command(GarcardCommand::Status)
81
+    }
82
+
83
+    pub fn diagnose(&mut self) -> Result<Option<Value>> {
84
+        self.send_command(GarcardCommand::Diagnose)
85
+    }
86
+
87
+    pub fn version(&mut self) -> Result<Option<Value>> {
88
+        self.send_command(GarcardCommand::Version)
89
+    }
90
+
91
+    pub fn auth_summary(&mut self) -> Result<Option<Value>> {
92
+        self.send_command(GarcardCommand::AuthSummary)
93
+    }
94
+
95
+    pub fn temp_list(&mut self) -> Result<Option<Value>> {
96
+        self.send_command(GarcardCommand::TempList)
97
+    }
98
+
99
+    pub fn temp_revoke(&mut self, authorization_id: impl Into<String>) -> Result<Option<Value>> {
100
+        self.send_command(GarcardCommand::TempRevoke {
101
+            authorization_id: authorization_id.into(),
102
+        })
103
+    }
104
+
105
+    pub fn temp_revoke_all(&mut self) -> Result<Option<Value>> {
106
+        self.send_command(GarcardCommand::TempRevokeAll)
107
+    }
108
+
109
+    pub fn quit(&mut self) -> Result<Option<Value>> {
110
+        self.send_command(GarcardCommand::Quit)
111
+    }
52112
 }
53113
 
54114
 impl Default for GarcardAdapter {