kanidmd/
opt.rs

1#[derive(Debug, Args)]
2struct CommonOpt {
3    /// Path to the server's configuration file.
4    #[clap(short, long = "config", env = "KANIDM_CONFIG")]
5    config_path: Option<PathBuf>,
6    /// Log format (still in very early development)
7    #[clap(short, long = "output", env = "KANIDM_OUTPUT", default_value = "text")]
8    output_mode: String,
9}
10
11#[derive(Debug, Args)]
12struct BackupOpt {
13    #[clap(value_parser)]
14    /// Output path for the backup content.
15    path: PathBuf,
16    #[clap(flatten)]
17    commonopts: CommonOpt,
18}
19
20#[derive(Debug, Args)]
21struct RestoreOpt {
22    #[clap(value_parser)]
23    /// Restore from this path. Should be created with "backup".
24    path: PathBuf,
25    #[clap(flatten)]
26    commonopts: CommonOpt,
27}
28
29#[derive(Debug, Subcommand)]
30enum DomainSettingsCmds {
31    /// Show the current domain
32    #[clap(name = "show")]
33    Show {
34        #[clap(flatten)]
35        commonopts: CommonOpt,
36    },
37    /// Change the IDM domain name based on the values in the configuration
38    #[clap(name = "rename")]
39    Change {
40        #[clap(flatten)]
41        commonopts: CommonOpt,
42    },
43    /// Perform a pre-upgrade-check of this domains content. This will report possible
44    /// incompatibilities that can block a successful upgrade to the next version of
45    /// Kanidm. This is a safe read only operation.
46    #[clap(name = "upgrade-check")]
47    UpgradeCheck {
48        #[clap(flatten)]
49        commonopts: CommonOpt,
50    },
51    /// ⚠️  Do not use this command unless directed by a project member. ⚠️ 
52    /// - Raise the functional level of this domain to the maximum available.
53    #[clap(name = "raise")]
54    Raise {
55        #[clap(flatten)]
56        commonopts: CommonOpt,
57    },
58    /// ⚠️  Do not use this command unless directed by a project member. ⚠️ 
59    /// - Rerun migrations of this domains database, optionally nominating the level
60    ///   to start from.
61    #[clap(name = "remigrate")]
62    Remigrate {
63        #[clap(flatten)]
64        commonopts: CommonOpt,
65        level: Option<u32>,
66    },
67}
68
69#[derive(Debug, Subcommand)]
70enum DbCommands {
71    #[clap(name = "vacuum")]
72    /// Vacuum the database to reclaim space or change db_fs_type/page_size (offline)
73    Vacuum(CommonOpt),
74    #[clap(name = "backup")]
75    /// Backup the database content (offline)
76    Backup(BackupOpt),
77    #[clap(name = "restore")]
78    /// Restore the database content (offline)
79    Restore(RestoreOpt),
80    #[clap(name = "verify")]
81    /// Verify database and entity consistency.
82    Verify(CommonOpt),
83    #[clap(name = "reindex")]
84    /// Reindex the database (offline)
85    Reindex(CommonOpt),
86}
87
88#[derive(Debug, Args)]
89struct DbScanListIndex {
90    /// The name of the index to list
91    index_name: String,
92    #[clap(flatten)]
93    commonopts: CommonOpt,
94}
95
96#[derive(Debug, Parser)]
97struct HealthCheckArgs {
98    /// Disable TLS verification
99    #[clap(short, long, action)]
100    verify_tls: bool,
101    /// Check the 'origin' URL from the server configuration file, instead of the 'address'
102    #[clap(short = 'O', long, action)]
103    check_origin: bool,
104    #[clap(flatten)]
105    commonopts: CommonOpt,
106}
107
108#[derive(Debug, Args)]
109struct DbScanGetId2Entry {
110    /// The id of the entry to display
111    id: u64,
112    #[clap(flatten)]
113    commonopts: CommonOpt,
114}
115
116#[derive(Debug, Subcommand)]
117enum DbScanOpt {
118    #[clap(name = "list-all-indexes")]
119    /// List all index tables that exist on the system.
120    ListIndexes(CommonOpt),
121    #[clap(name = "list-index")]
122    /// List all content of a named index
123    ListIndex(DbScanListIndex),
124    // #[structopt(name = "get_index")]
125    // /// Display the content of a single index key
126    // GetIndex(DbScanGetIndex),
127    #[clap(name = "list-id2entry")]
128    /// List all id2entry values with reduced entry content
129    ListId2Entry(CommonOpt),
130    #[clap(name = "get-id2entry")]
131    /// View the data of a specific entry from id2entry
132    GetId2Entry(DbScanGetId2Entry),
133    #[clap(name = "list-index-analysis")]
134    /// List all content of index analysis
135    ListIndexAnalysis(CommonOpt),
136    #[clap(name = "quarantine-id2entry")]
137    /// Given an entry id, quarantine the entry in a hidden db partition
138    QuarantineId2Entry {
139        /// The id of the entry to display
140        id: u64,
141        #[clap(flatten)]
142        commonopts: CommonOpt,
143    },
144    #[clap(name = "list-quarantined")]
145    /// List the entries in quarantine
146    ListQuarantined {
147        #[clap(flatten)]
148        commonopts: CommonOpt,
149    },
150    #[clap(name = "restore-quarantined")]
151    /// Given an entry id, restore the entry from the hidden db partition
152    RestoreQuarantined {
153        /// The id of the entry to display
154        id: u64,
155        #[clap(flatten)]
156        commonopts: CommonOpt,
157    },
158}
159
160#[derive(Debug, Parser)]
161#[command(name = "kanidmd")]
162struct KanidmdParser {
163    #[command(subcommand)]
164    commands: KanidmdOpt,
165}
166
167impl KanidmdParser {
168    /// Returns the configuration path that was specified on the command line, if any.
169    fn config_path(&self) -> Option<PathBuf> {
170        match self.commands {
171            KanidmdOpt::Server(ref c) => c.config_path.clone(),
172            KanidmdOpt::ConfigTest(ref c) => c.config_path.clone(),
173            KanidmdOpt::CertGenerate(ref c) => c.config_path.clone(),
174            KanidmdOpt::RecoverAccount { ref commonopts, .. } |
175            KanidmdOpt::DisableAccount { ref commonopts, .. }
176                => commonopts.config_path.clone(),
177            KanidmdOpt::ShowReplicationCertificate { ref commonopts, .. } => {
178                commonopts.config_path.clone()
179            }
180            KanidmdOpt::RenewReplicationCertificate { ref commonopts, .. } => {
181                commonopts.config_path.clone()
182            }
183            KanidmdOpt::RefreshReplicationConsumer { ref commonopts, .. } => {
184                commonopts.config_path.clone()
185            }
186            KanidmdOpt::DbScan { ref commands } => match commands {
187                DbScanOpt::ListIndexes(ref c) => c.config_path.clone(),
188                DbScanOpt::ListIndex(ref c) => c.commonopts.config_path.clone(),
189                DbScanOpt::ListId2Entry(ref c) => c.config_path.clone(),
190                DbScanOpt::GetId2Entry(ref c) => c.commonopts.config_path.clone(),
191                DbScanOpt::ListIndexAnalysis(ref c) => c.config_path.clone(),
192                DbScanOpt::QuarantineId2Entry { ref commonopts, .. } => {
193                    commonopts.config_path.clone()
194                }
195                DbScanOpt::ListQuarantined { ref commonopts } => commonopts.config_path.clone(),
196                DbScanOpt::RestoreQuarantined { ref commonopts, .. } => {
197                    commonopts.config_path.clone()
198                }
199            },
200            KanidmdOpt::Database { ref commands } => match commands {
201                DbCommands::Vacuum(ref c) => c.config_path.clone(),
202                DbCommands::Backup(ref c) => c.commonopts.config_path.clone(),
203                DbCommands::Restore(ref c) => c.commonopts.config_path.clone(),
204                DbCommands::Verify(ref c) => c.config_path.clone(),
205                DbCommands::Reindex(ref c) => c.config_path.clone(),
206            },
207            KanidmdOpt::DomainSettings { ref commands } => match commands {
208                DomainSettingsCmds::Show { ref commonopts } => commonopts.config_path.clone(),
209                DomainSettingsCmds::Change { ref commonopts } => commonopts.config_path.clone(),
210                DomainSettingsCmds::UpgradeCheck { ref commonopts } => commonopts.config_path.clone(),
211                DomainSettingsCmds::Raise { ref commonopts } => commonopts.config_path.clone(),
212                DomainSettingsCmds::Remigrate { ref commonopts, .. } => {
213                    commonopts.config_path.clone()
214                }
215            },
216            KanidmdOpt::HealthCheck(ref c) => c.commonopts.config_path.clone(),
217            KanidmdOpt::Version(ref c) => c.config_path.clone(),
218        }
219    }
220}
221
222#[derive(Debug, Subcommand)]
223enum KanidmdOpt {
224    #[clap(name = "server")]
225    /// Start the IDM Server
226    Server(CommonOpt),
227    #[clap(name = "configtest")]
228    /// Test the IDM Server configuration, without starting network listeners.
229    ConfigTest(CommonOpt),
230    #[clap(name = "cert-generate")]
231    /// Create a self-signed ca and tls certificate in the locations listed from the
232    /// configuration. These certificates should *not* be used in production, they
233    /// are for testing and evaluation only!
234    CertGenerate(CommonOpt),
235    #[clap(name = "recover-account")]
236    /// Recover an account's password
237    RecoverAccount {
238        #[clap(value_parser)]
239        /// The account name to recover credentials for.
240        name: String,
241        #[clap(flatten)]
242        commonopts: CommonOpt,
243    },
244    #[clap(name = "disable-account")]
245    /// Disable an account so that it can not be used. This can be reset with `recover-account`.
246    DisableAccount {
247        #[clap(value_parser)]
248        /// The account name to disable.
249        name: String,
250        #[clap(flatten)]
251        commonopts: CommonOpt,
252    },
253    /// Display this server's replication certificate
254    ShowReplicationCertificate {
255        #[clap(flatten)]
256        commonopts: CommonOpt,
257    },
258    /// Renew this server's replication certificate
259    RenewReplicationCertificate {
260        #[clap(flatten)]
261        commonopts: CommonOpt,
262    },
263    /// Refresh this servers database content with the content from a supplier. This means
264    /// that all local content will be deleted and replaced with the supplier content.
265    RefreshReplicationConsumer {
266        #[clap(flatten)]
267        commonopts: CommonOpt,
268        /// Acknowledge that this database content will be refreshed from a supplier.
269        #[clap(long = "i-want-to-refresh-this-servers-database")]
270        proceed: bool,
271    },
272    // #[clap(name = "reset_server_id")]
273    // ResetServerId(CommonOpt),
274    #[clap(name = "db-scan")]
275    /// Inspect the internal content of the database datastructures.
276    DbScan {
277        #[clap(subcommand)]
278        commands: DbScanOpt,
279    },
280    /// Database maintenance, backups, restoration etc.
281    #[clap(name = "database")]
282    Database {
283        #[clap(subcommand)]
284        commands: DbCommands,
285    },
286    /// Change domain settings
287    #[clap(name = "domain")]
288    DomainSettings {
289        #[clap(subcommand)]
290        commands: DomainSettingsCmds,
291    },
292
293    /// Load the server config and check services are listening
294    #[clap(name = "healthcheck")]
295    HealthCheck(HealthCheckArgs),
296
297    /// Print the program version and exit
298    #[clap(name = "version")]
299    Version(CommonOpt),
300}