omni-dev 0.31.0

AI-powered git commit rewriter, PR generator, and MCP server for Jira, Confluence, and Datadog.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
//! Datadog CLI commands (read-only).

pub(crate) mod auth;
pub(crate) mod dashboard;
pub(crate) mod downtime;
pub(crate) mod events;
pub(crate) mod format;
pub(crate) mod helpers;
pub(crate) mod hosts;
pub(crate) mod logs;
pub(crate) mod metrics;
pub(crate) mod monitor;
pub(crate) mod slo;

use anyhow::Result;
use clap::{Parser, Subcommand};

use crate::datadog::client::DatadogClient;

/// Datadog: read-only API operations.
#[derive(Parser)]
pub struct DatadogCommand {
    /// The Datadog subcommand to execute.
    #[command(subcommand)]
    pub command: DatadogSubcommands,
}

/// Datadog subcommands.
#[derive(Subcommand)]
pub enum DatadogSubcommands {
    /// Manages Datadog API credentials.
    Auth(auth::AuthCommand),
    /// Inspects Datadog dashboards.
    Dashboard(dashboard::DashboardCommand),
    /// Inspects Datadog scheduled downtimes.
    Downtime(downtime::DowntimeCommand),
    /// Inspects the Datadog events stream.
    Events(events::EventsCommand),
    /// Inspects Datadog reporting hosts.
    Hosts(hosts::HostsCommand),
    /// Searches Datadog logs.
    Logs(logs::LogsCommand),
    /// Queries Datadog metrics.
    Metrics(metrics::MetricsCommand),
    /// Inspects Datadog monitors.
    Monitor(monitor::MonitorCommand),
    /// Inspects Datadog Service Level Objectives.
    Slo(slo::SloCommand),
}

impl DatadogCommand {
    /// Executes the Datadog command.
    ///
    /// `auth` manages credentials and must run without them; every other
    /// subcommand needs an authenticated client, which is resolved **once**
    /// here and threaded down so each leaf takes `&DatadogClient` and stays
    /// free of process env (issue #1030).
    pub async fn execute(self) -> Result<()> {
        match self.command {
            DatadogSubcommands::Auth(cmd) => cmd.execute().await,
            data => {
                // The one `create_client` call for the read-only surface.
                let (client, _site) = helpers::create_client()?;
                data.dispatch(&client).await
            }
        }
    }
}

impl DatadogSubcommands {
    /// Routes a non-`Auth` subcommand against the shared client. Kept separate
    /// from credential resolution so it is testable without env (tests pass a
    /// client pointed at an unreachable URL). The `Auth` arm is unreachable
    /// because it is handled before client resolution in
    /// [`DatadogCommand::execute`].
    async fn dispatch(self, client: &DatadogClient) -> Result<()> {
        match self {
            Self::Auth(_) => {
                unreachable!("Auth is dispatched before client resolution")
            }
            Self::Dashboard(cmd) => cmd.execute(client).await,
            Self::Downtime(cmd) => cmd.execute(client).await,
            Self::Events(cmd) => cmd.execute(client).await,
            Self::Hosts(cmd) => cmd.execute(client).await,
            Self::Logs(cmd) => cmd.execute(client).await,
            Self::Metrics(cmd) => cmd.execute(client).await,
            Self::Monitor(cmd) => cmd.execute(client).await,
            Self::Slo(cmd) => cmd.execute(client).await,
        }
    }
}

#[cfg(test)]
#[allow(clippy::unwrap_used)]
mod tests {
    use super::*;
    use crate::cli::datadog::format::OutputFormat;
    use crate::datadog::client::DatadogClient;

    /// A client pointed at an unreachable URL. Routing tests use it so a
    /// command runs through dispatch -> mid -> leaf to the HTTP layer and fails
    /// with a connection error — exercising the routing without touching
    /// credentials, the process environment, or a mock server.
    fn dead_client() -> DatadogClient {
        DatadogClient::new("http://127.0.0.1:1", "api", "app").unwrap()
    }

    #[test]
    fn datadog_subcommands_auth_variant() {
        let cmd = DatadogCommand {
            command: DatadogSubcommands::Auth(auth::AuthCommand {
                command: auth::AuthSubcommands::Status(auth::StatusCommand),
            }),
        };
        assert!(matches!(cmd.command, DatadogSubcommands::Auth(_)));
    }

    #[test]
    fn datadog_subcommands_metrics_variant() {
        let cmd = DatadogCommand {
            command: DatadogSubcommands::Metrics(metrics::MetricsCommand {
                command: metrics::MetricsSubcommands::Query(metrics::query::QueryCommand {
                    query: "m".into(),
                    from: "1h".into(),
                    to: None,
                    output: OutputFormat::Table,
                }),
            }),
        };
        assert!(matches!(cmd.command, DatadogSubcommands::Metrics(_)));
    }

    #[tokio::test]
    async fn dispatch_routes_metrics_query() {
        let cmd = DatadogSubcommands::Metrics(metrics::MetricsCommand {
            command: metrics::MetricsSubcommands::Query(metrics::query::QueryCommand {
                query: "m".into(),
                from: "1h".into(),
                to: None,
                output: OutputFormat::Table,
            }),
        });
        // Verifies routing reaches the leaf's HTTP call without env.
        assert!(cmd.dispatch(&dead_client()).await.is_err());
    }

    #[tokio::test]
    async fn dispatch_routes_monitor_get() {
        let cmd = DatadogSubcommands::Monitor(monitor::MonitorCommand {
            command: monitor::MonitorSubcommands::Get(monitor::get::GetCommand {
                id: 1,
                output: OutputFormat::Table,
            }),
        });
        // Verifies routing reaches the leaf's HTTP call without env.
        assert!(cmd.dispatch(&dead_client()).await.is_err());
    }

    #[tokio::test]
    async fn dispatch_routes_monitor_list() {
        let cmd = DatadogSubcommands::Monitor(monitor::MonitorCommand {
            command: monitor::MonitorSubcommands::List(monitor::list::ListCommand {
                name: None,
                tags: None,
                monitor_tags: None,
                limit: 5,
                output: OutputFormat::Table,
            }),
        });
        // Verifies routing reaches the leaf's HTTP call without env.
        assert!(cmd.dispatch(&dead_client()).await.is_err());
    }

    #[tokio::test]
    async fn dispatch_routes_monitor_search() {
        let cmd = DatadogSubcommands::Monitor(monitor::MonitorCommand {
            command: monitor::MonitorSubcommands::Search(monitor::search::SearchCommand {
                query: "q".into(),
                limit: 5,
                output: OutputFormat::Table,
            }),
        });
        // Verifies routing reaches the leaf's HTTP call without env.
        assert!(cmd.dispatch(&dead_client()).await.is_err());
    }

    #[test]
    fn datadog_subcommands_dashboard_variant() {
        let cmd = DatadogCommand {
            command: DatadogSubcommands::Dashboard(dashboard::DashboardCommand {
                command: dashboard::DashboardSubcommands::List(dashboard::list::ListCommand {
                    filter_shared: false,
                    output: OutputFormat::Table,
                }),
            }),
        };
        assert!(matches!(cmd.command, DatadogSubcommands::Dashboard(_)));
    }

    #[tokio::test]
    async fn dispatch_routes_dashboard_list() {
        let cmd = DatadogSubcommands::Dashboard(dashboard::DashboardCommand {
            command: dashboard::DashboardSubcommands::List(dashboard::list::ListCommand {
                filter_shared: true,
                output: OutputFormat::Table,
            }),
        });
        // Verifies routing reaches the leaf's HTTP call without env.
        assert!(cmd.dispatch(&dead_client()).await.is_err());
    }

    #[tokio::test]
    async fn dispatch_routes_dashboard_get() {
        let cmd = DatadogSubcommands::Dashboard(dashboard::DashboardCommand {
            command: dashboard::DashboardSubcommands::Get(dashboard::get::GetCommand {
                id: "abc".into(),
                output: OutputFormat::Table,
            }),
        });
        // Verifies routing reaches the leaf's HTTP call without env.
        assert!(cmd.dispatch(&dead_client()).await.is_err());
    }

    #[test]
    fn datadog_subcommands_logs_variant() {
        let cmd = DatadogCommand {
            command: DatadogSubcommands::Logs(logs::LogsCommand {
                command: logs::LogsSubcommands::Search(logs::search::SearchCommand {
                    filter: "*".into(),
                    from: "15m".into(),
                    to: "now".into(),
                    limit: 10,
                    sort: logs::search::SortArg::TimestampDesc,
                    output: OutputFormat::Table,
                }),
            }),
        };
        assert!(matches!(cmd.command, DatadogSubcommands::Logs(_)));
    }

    #[tokio::test]
    async fn dispatch_routes_logs_search() {
        let cmd = DatadogSubcommands::Logs(logs::LogsCommand {
            command: logs::LogsSubcommands::Search(logs::search::SearchCommand {
                filter: "*".into(),
                from: "15m".into(),
                to: "now".into(),
                limit: 10,
                sort: logs::search::SortArg::TimestampDesc,
                output: OutputFormat::Table,
            }),
        });
        // Verifies routing reaches the leaf's HTTP call without env.
        assert!(cmd.dispatch(&dead_client()).await.is_err());
    }

    #[test]
    fn datadog_subcommands_events_variant() {
        let cmd = DatadogCommand {
            command: DatadogSubcommands::Events(events::EventsCommand {
                command: events::EventsSubcommands::List(events::list::ListCommand {
                    filter: None,
                    from: "1h".into(),
                    to: "now".into(),
                    limit: 10,
                    sources: None,
                    tags: None,
                    output: OutputFormat::Table,
                }),
            }),
        };
        assert!(matches!(cmd.command, DatadogSubcommands::Events(_)));
    }

    #[tokio::test]
    async fn dispatch_routes_events_list() {
        let cmd = DatadogSubcommands::Events(events::EventsCommand {
            command: events::EventsSubcommands::List(events::list::ListCommand {
                filter: None,
                from: "1h".into(),
                to: "now".into(),
                limit: 10,
                sources: None,
                tags: None,
                output: OutputFormat::Table,
            }),
        });
        // Verifies routing reaches the leaf's HTTP call without env.
        assert!(cmd.dispatch(&dead_client()).await.is_err());
    }

    #[test]
    fn datadog_subcommands_slo_variant() {
        let cmd = DatadogCommand {
            command: DatadogSubcommands::Slo(slo::SloCommand {
                command: slo::SloSubcommands::List(slo::list::ListCommand {
                    tags: None,
                    query: None,
                    ids: None,
                    metrics_query: None,
                    limit: 5,
                    output: OutputFormat::Table,
                }),
            }),
        };
        assert!(matches!(cmd.command, DatadogSubcommands::Slo(_)));
    }

    #[tokio::test]
    async fn dispatch_routes_slo_list() {
        let cmd = DatadogSubcommands::Slo(slo::SloCommand {
            command: slo::SloSubcommands::List(slo::list::ListCommand {
                tags: None,
                query: None,
                ids: None,
                metrics_query: None,
                limit: 5,
                output: OutputFormat::Table,
            }),
        });
        // Verifies routing reaches the leaf's HTTP call without env.
        assert!(cmd.dispatch(&dead_client()).await.is_err());
    }

    #[tokio::test]
    async fn dispatch_routes_slo_get() {
        let cmd = DatadogSubcommands::Slo(slo::SloCommand {
            command: slo::SloSubcommands::Get(slo::get::GetCommand {
                id: "abc".into(),
                output: OutputFormat::Table,
            }),
        });
        // Verifies routing reaches the leaf's HTTP call without env.
        assert!(cmd.dispatch(&dead_client()).await.is_err());
    }

    #[test]
    fn datadog_subcommands_hosts_variant() {
        let cmd = DatadogCommand {
            command: DatadogSubcommands::Hosts(hosts::HostsCommand {
                command: hosts::HostsSubcommands::List(hosts::list::ListCommand {
                    filter: None,
                    from: None,
                    limit: 5,
                    output: OutputFormat::Table,
                }),
            }),
        };
        assert!(matches!(cmd.command, DatadogSubcommands::Hosts(_)));
    }

    #[tokio::test]
    async fn dispatch_routes_hosts_list() {
        let cmd = DatadogSubcommands::Hosts(hosts::HostsCommand {
            command: hosts::HostsSubcommands::List(hosts::list::ListCommand {
                filter: None,
                from: None,
                limit: 5,
                output: OutputFormat::Table,
            }),
        });
        // Verifies routing reaches the leaf's HTTP call without env.
        assert!(cmd.dispatch(&dead_client()).await.is_err());
    }

    #[test]
    fn datadog_subcommands_downtime_variant() {
        let cmd = DatadogCommand {
            command: DatadogSubcommands::Downtime(downtime::DowntimeCommand {
                command: downtime::DowntimeSubcommands::List(downtime::list::ListCommand {
                    active_only: false,
                    output: OutputFormat::Table,
                }),
            }),
        };
        assert!(matches!(cmd.command, DatadogSubcommands::Downtime(_)));
    }

    #[tokio::test]
    async fn dispatch_routes_downtime_list() {
        let cmd = DatadogSubcommands::Downtime(downtime::DowntimeCommand {
            command: downtime::DowntimeSubcommands::List(downtime::list::ListCommand {
                active_only: true,
                output: OutputFormat::Table,
            }),
        });
        // Verifies routing reaches the leaf's HTTP call without env.
        assert!(cmd.dispatch(&dead_client()).await.is_err());
    }

    #[tokio::test]
    async fn dispatch_routes_metrics_catalog_list() {
        let cmd = DatadogSubcommands::Metrics(metrics::MetricsCommand {
            command: metrics::MetricsSubcommands::Catalog(metrics::catalog::CatalogCommand {
                command: metrics::catalog::CatalogSubcommands::List(
                    metrics::catalog::list::ListCommand {
                        host: None,
                        from: None,
                        output: OutputFormat::Table,
                    },
                ),
            }),
        });
        // Verifies routing reaches the leaf's HTTP call without env.
        assert!(cmd.dispatch(&dead_client()).await.is_err());
    }
}