Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,017 changes: 2 additions & 1,015 deletions src/client.rs

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/commands/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ pub async fn run(

// Path used for per-endpoint auth routing. For relative endpoints this is the
// normalized API path; for absolute URLs on the Datadog host we use the URL's
// path component so the OAuth-exclusion table (client::requires_api_key_fallback)
// path component so the OAuth-exclusion table (raw_client::requires_api_key_fallback)
// still applies.
let auth_path = if is_absolute {
reqwest::Url::parse(&url)
Expand Down Expand Up @@ -179,7 +179,7 @@ pub async fn run(
// Datadog credentials are never sent to an arbitrary host (see above); the
// request is sent unauthenticated and the caller may add headers via -H.
if credentials_allowed {
req = crate::client::apply_auth(req, cfg, &method_upper, &auth_path)?;
req = crate::raw_client::apply_auth(req, cfg, &method_upper, &auth_path)?;
} else if cfg.access_token.is_some() || cfg.api_key.is_some() {
eprintln!(
"warning: not sending Datadog credentials to non-Datadog host {:?}; \
Expand Down Expand Up @@ -614,7 +614,7 @@ mod tests {

/// OAuth-excluded endpoints (e.g. GET /api/v2/api_keys) must use API-key auth
/// even when a bearer token is present. This exercises the reuse of
/// client::apply_auth's per-endpoint fallback table.
/// raw_client::apply_auth's per-endpoint fallback table.
#[tokio::test]
async fn test_api_oauth_excluded_uses_api_keys() {
let _lock = lock_env().await;
Expand Down
88 changes: 45 additions & 43 deletions src/commands/apm.rs
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
use anyhow::Result;

use crate::client;
use crate::config::Config;
use crate::formatter;
use crate::util;
use crate::raw_client;
use crate::util_ext;

pub async fn services_list(cfg: &Config, env: String, from: String, to: String) -> Result<()> {
let from_ts = util::parse_time_to_unix(&from)?;
let to_ts = util::parse_time_to_unix(&to)?;
let from_ts = util_ext::parse_time_to_unix(&from)?;
let to_ts = util_ext::parse_time_to_unix(&to)?;
let path = format!("/api/v2/apm/services?start={from_ts}&end={to_ts}&filter[env]={env}");
let data = client::raw_get(cfg, &path, &[]).await?;
let data = raw_client::raw_get(cfg, &path, &[]).await?;
formatter::output(cfg, &data)
}

pub async fn services_stats(cfg: &Config, env: String, from: String, to: String) -> Result<()> {
let from_ts = util::parse_time_to_unix(&from)?;
let to_ts = util::parse_time_to_unix(&to)?;
let from_ts = util_ext::parse_time_to_unix(&from)?;
let to_ts = util_ext::parse_time_to_unix(&to)?;
let path = format!("/api/v2/apm/services/stats?start={from_ts}&end={to_ts}&filter[env]={env}");
let data = client::raw_get(cfg, &path, &[]).await?;
let data = raw_client::raw_get(cfg, &path, &[]).await?;
formatter::output(cfg, &data)
}

pub async fn entities_list(cfg: &Config, from: String, to: String) -> Result<()> {
let from_ts = util::parse_time_to_unix(&from)?;
let to_ts = util::parse_time_to_unix(&to)?;
let from_ts = util_ext::parse_time_to_unix(&from)?;
let to_ts = util_ext::parse_time_to_unix(&to)?;
let path = format!("/api/unstable/apm/entities?start={from_ts}&end={to_ts}");
let data = client::raw_get(cfg, &path, &[]).await?;
let data = raw_client::raw_get(cfg, &path, &[]).await?;
formatter::output(cfg, &data)
}

pub async fn dependencies_list(cfg: &Config, env: String, from: String, to: String) -> Result<()> {
let from_ts = util::parse_time_to_unix(&from)?;
let to_ts = util::parse_time_to_unix(&to)?;
let from_ts = util_ext::parse_time_to_unix(&from)?;
let to_ts = util_ext::parse_time_to_unix(&to)?;
let path = format!("/api/v1/service_dependencies?start={from_ts}&end={to_ts}&env={env}");
let data = client::raw_get(cfg, &path, &[]).await?;
let data = raw_client::raw_get(cfg, &path, &[]).await?;
formatter::output(cfg, &data)
}

Expand All @@ -44,11 +44,11 @@ pub async fn services_operations(
from: String,
to: String,
) -> Result<()> {
let from_ts = util::parse_time_to_unix(&from)?;
let to_ts = util::parse_time_to_unix(&to)?;
let from_ts = util_ext::parse_time_to_unix(&from)?;
let to_ts = util_ext::parse_time_to_unix(&to)?;
let path =
format!("/api/v1/trace/operation_names/{service}?env={env}&start={from_ts}&end={to_ts}");
let data = client::raw_get(cfg, &path, &[]).await?;
let data = raw_client::raw_get(cfg, &path, &[]).await?;
formatter::output(cfg, &data)
}

Expand All @@ -60,12 +60,12 @@ pub async fn services_resources(
from: String,
to: String,
) -> Result<()> {
let from_ts = util::parse_time_to_unix(&from)?;
let to_ts = util::parse_time_to_unix(&to)?;
let from_ts = util_ext::parse_time_to_unix(&from)?;
let to_ts = util_ext::parse_time_to_unix(&to)?;
let path = format!(
"/api/ui/apm/resources?service={service}&name={name}&env={env}&from={from_ts}&to={to_ts}"
);
let data = client::raw_get(cfg, &path, &[]).await?;
let data = raw_client::raw_get(cfg, &path, &[]).await?;
formatter::output(cfg, &data)
}

Expand All @@ -76,11 +76,11 @@ pub async fn flow_map(
from: String,
to: String,
) -> Result<()> {
let from_ts = util::parse_time_to_unix(&from)?;
let to_ts = util::parse_time_to_unix(&to)?;
let from_ts = util_ext::parse_time_to_unix(&from)?;
let to_ts = util_ext::parse_time_to_unix(&to)?;
let path =
format!("/api/ui/apm/flow-map?query={query}&limit={limit}&start={from_ts}&end={to_ts}");
let data = client::raw_get(cfg, &path, &[]).await?;
let data = raw_client::raw_get(cfg, &path, &[]).await?;
formatter::output(cfg, &data)
}

Expand All @@ -105,12 +105,12 @@ pub async fn troubleshooting_list(
.iter()
.map(|(k, v)| (k.as_str(), v.as_str()))
.collect();
let data = client::raw_get(cfg, path, &query).await?;
let data = raw_client::raw_get(cfg, path, &query).await?;
formatter::output(cfg, &data)
}

pub async fn service_remapping_list(cfg: &Config) -> Result<()> {
let data = client::raw_get(cfg, "/api/v2/service-naming-rules", &[]).await?;
let data = raw_client::raw_get(cfg, "/api/v2/service-naming-rules", &[]).await?;
formatter::output(cfg, &data)
}

Expand All @@ -132,12 +132,12 @@ pub async fn service_remapping_create(
}
}
});
let data = client::raw_post(cfg, "/api/v2/service-naming-rules", body).await?;
let data = raw_client::raw_post(cfg, "/api/v2/service-naming-rules", body).await?;
formatter::output(cfg, &data)
}

pub async fn service_remapping_get(cfg: &Config, id: String) -> Result<()> {
let data = client::raw_get(cfg, &format!("/api/v2/service-naming-rules/{id}"), &[]).await?;
let data = raw_client::raw_get(cfg, &format!("/api/v2/service-naming-rules/{id}"), &[]).await?;
formatter::output(cfg, &data)
}

Expand All @@ -162,12 +162,13 @@ pub async fn service_remapping_update(
}
}
});
let data = client::raw_put(cfg, &format!("/api/v2/service-naming-rules/{id}"), body).await?;
let data =
raw_client::raw_put(cfg, &format!("/api/v2/service-naming-rules/{id}"), body).await?;
formatter::output(cfg, &data)
}

pub async fn service_remapping_delete(cfg: &Config, id: String, version: i64) -> Result<()> {
client::raw_delete(cfg, &format!("/api/v2/service-naming-rules/{id}/{version}")).await
raw_client::raw_delete(cfg, &format!("/api/v2/service-naming-rules/{id}/{version}")).await
}

// =============================================================================
Expand All @@ -186,15 +187,15 @@ pub async fn sampling_rules_list(
// If service + env are both given, prefer the narrowed by_target endpoint.
if let (Some(svc), Some(e)) = (service.as_deref(), env.as_deref()) {
let path = format!("{SAMPLING_RULES_BASE}/by_target");
let data = client::raw_get(cfg, &path, &[("service", svc), ("env", e)]).await?;
let data = raw_client::raw_get(cfg, &path, &[("service", svc), ("env", e)]).await?;
return formatter::output(cfg, &data);
}
let data = client::raw_get(cfg, SAMPLING_RULES_BASE, &[]).await?;
let data = raw_client::raw_get(cfg, SAMPLING_RULES_BASE, &[]).await?;
formatter::output(cfg, &data)
}

pub async fn sampling_rules_get(cfg: &Config, id: String) -> Result<()> {
let data = client::raw_get(cfg, &format!("{SAMPLING_RULES_BASE}/{id}"), &[]).await?;
let data = raw_client::raw_get(cfg, &format!("{SAMPLING_RULES_BASE}/{id}"), &[]).await?;
formatter::output(cfg, &data)
}

Expand Down Expand Up @@ -229,7 +230,7 @@ pub async fn sampling_rules_create(
}
}
});
let data = client::raw_post(cfg, SAMPLING_RULES_BASE, body).await?;
let data = raw_client::raw_post(cfg, SAMPLING_RULES_BASE, body).await?;
formatter::output(cfg, &data)
}

Expand Down Expand Up @@ -266,12 +267,12 @@ pub async fn sampling_rules_update(
}
}
});
let data = client::raw_put(cfg, &format!("{SAMPLING_RULES_BASE}/{id}"), body).await?;
let data = raw_client::raw_put(cfg, &format!("{SAMPLING_RULES_BASE}/{id}"), body).await?;
formatter::output(cfg, &data)
}

pub async fn sampling_rules_delete(cfg: &Config, id: String) -> Result<()> {
client::raw_delete(cfg, &format!("{SAMPLING_RULES_BASE}/{id}")).await
raw_client::raw_delete(cfg, &format!("{SAMPLING_RULES_BASE}/{id}")).await
}

// =============================================================================
Expand Down Expand Up @@ -315,7 +316,7 @@ pub async fn adaptive_sampling_onboarding_status(
if let Some(e) = env.as_deref() {
params.push(("env", e));
}
let data = client::raw_get(cfg, &path, &params).await?;
let data = raw_client::raw_get(cfg, &path, &params).await?;
formatter::output(cfg, &data)
}

Expand All @@ -336,7 +337,7 @@ async fn post_onboarding(
}
}
});
let data = client::raw_post(
let data = raw_client::raw_post(
cfg,
&format!("{ADAPTIVE_SAMPLING_BASE}/onboarding_status"),
body,
Expand All @@ -355,7 +356,7 @@ pub async fn adaptive_sampling_offboard(cfg: &Config, service: String, env: Stri

pub async fn adaptive_sampling_get_allotment(cfg: &Config) -> Result<()> {
let path = format!("{ADAPTIVE_SAMPLING_BASE}/allotment_config");
let data = client::raw_get(cfg, &path, &[]).await?;
let data = raw_client::raw_get(cfg, &path, &[]).await?;
formatter::output(cfg, &data)
}

Expand All @@ -372,7 +373,7 @@ pub async fn adaptive_sampling_set_allotment(
"attributes": attrs,
}
});
let data = client::raw_post(
let data = raw_client::raw_post(
cfg,
&format!("{ADAPTIVE_SAMPLING_BASE}/allotment_config"),
body,
Expand All @@ -383,7 +384,7 @@ pub async fn adaptive_sampling_set_allotment(

pub async fn adaptive_sampling_check(cfg: &Config) -> Result<()> {
let path = format!("{ADAPTIVE_SAMPLING_BASE}/allotment_check");
let data = client::raw_get(cfg, &path, &[]).await?;
let data = raw_client::raw_get(cfg, &path, &[]).await?;
formatter::output(cfg, &data)
}

Expand All @@ -400,7 +401,8 @@ pub async fn adaptive_sampling_preview(
"attributes": attrs,
}
});
let data = client::raw_post(cfg, &format!("{ADAPTIVE_SAMPLING_BASE}/preview"), body).await?;
let data =
raw_client::raw_post(cfg, &format!("{ADAPTIVE_SAMPLING_BASE}/preview"), body).await?;
formatter::output(cfg, &data)
}

Expand All @@ -421,7 +423,7 @@ pub async fn service_config_get(
ids_owned = ids.clone();
query.push(("service_instance_ids", ids_owned.as_str()));
}
let data = client::raw_get(cfg, "/api/unstable/apm/service-config", &query).await?;
let data = raw_client::raw_get(cfg, "/api/unstable/apm/service-config", &query).await?;
formatter::output(cfg, &data)
}

Expand All @@ -446,7 +448,7 @@ pub async fn service_library_config_get(
if mixed {
query.push(("is_mixed", "true"));
}
let data = client::raw_get(cfg, "/api/unstable/apm/service-library-config", &query).await?;
let data = raw_client::raw_get(cfg, "/api/unstable/apm/service-library-config", &query).await?;
formatter::output(cfg, &data)
}

Expand Down
13 changes: 7 additions & 6 deletions src/commands/app_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use datadog_api_client::datadogV2::model::{
use crate::config::Config;
use crate::formatter;
use crate::util;
use crate::util_ext;

pub async fn list(cfg: &Config, query: Option<&str>) -> Result<()> {
let api = crate::make_api!(AppBuilderAPI, cfg);
Expand All @@ -24,7 +25,7 @@ pub async fn list(cfg: &Config, query: Option<&str>) -> Result<()> {

pub async fn get(cfg: &Config, app_id: &str) -> Result<()> {
let api = crate::make_api!(AppBuilderAPI, cfg);
let uuid = util::parse_uuid(app_id, "app")?;
let uuid = util_ext::parse_uuid(app_id, "app")?;
let resp = api
.get_app(uuid, Default::default())
.await
Expand All @@ -44,7 +45,7 @@ pub async fn create(cfg: &Config, file: &str) -> Result<()> {

pub async fn update(cfg: &Config, app_id: &str, file: &str) -> Result<()> {
let api = crate::make_api!(AppBuilderAPI, cfg);
let uuid = util::parse_uuid(app_id, "app")?;
let uuid = util_ext::parse_uuid(app_id, "app")?;
let body: UpdateAppRequest = util::read_json_file(file)?;
let resp = api
.update_app(uuid, body)
Expand All @@ -55,7 +56,7 @@ pub async fn update(cfg: &Config, app_id: &str, file: &str) -> Result<()> {

pub async fn delete(cfg: &Config, app_id: &str) -> Result<()> {
let api = crate::make_api!(AppBuilderAPI, cfg);
let uuid = util::parse_uuid(app_id, "app")?;
let uuid = util_ext::parse_uuid(app_id, "app")?;
api.delete_app(uuid)
.await
.map_err(|e| anyhow::anyhow!("failed to delete app: {e:?}"))?;
Expand All @@ -68,7 +69,7 @@ pub async fn delete_batch(cfg: &Config, app_ids: &[String]) -> Result<()> {
let items: Result<Vec<_>> = app_ids
.iter()
.map(|id| {
let uuid = util::parse_uuid(id, "app")?;
let uuid = util_ext::parse_uuid(id, "app")?;
Ok(DeleteAppsRequestDataItems::new(
uuid,
AppDefinitionType::APPDEFINITIONS,
Expand All @@ -85,7 +86,7 @@ pub async fn delete_batch(cfg: &Config, app_ids: &[String]) -> Result<()> {

pub async fn publish(cfg: &Config, app_id: &str) -> Result<()> {
let api = crate::make_api!(AppBuilderAPI, cfg);
let uuid = util::parse_uuid(app_id, "app")?;
let uuid = util_ext::parse_uuid(app_id, "app")?;
let resp = api
.publish_app(uuid)
.await
Expand All @@ -95,7 +96,7 @@ pub async fn publish(cfg: &Config, app_id: &str) -> Result<()> {

pub async fn unpublish(cfg: &Config, app_id: &str) -> Result<()> {
let api = crate::make_api!(AppBuilderAPI, cfg);
let uuid = util::parse_uuid(app_id, "app")?;
let uuid = util_ext::parse_uuid(app_id, "app")?;
api.unpublish_app(uuid)
.await
.map_err(|e| anyhow::anyhow!("failed to unpublish app: {e:?}"))?;
Expand Down
10 changes: 5 additions & 5 deletions src/commands/audit_logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ use datadog_api_client::datadogV2::model::{

use crate::config::Config;
use crate::formatter;
use crate::util;
use crate::util_ext;

pub async fn list(cfg: &Config, from: String, to: String, limit: i32) -> Result<()> {
let api = crate::make_api!(AuditAPI, cfg);

let from_dt = util::parse_time_to_datetime(&from)?;
let to_dt = util::parse_time_to_datetime(&to)?;
let from_dt = util_ext::parse_time_to_datetime(&from)?;
let to_dt = util_ext::parse_time_to_datetime(&to)?;

let params = ListAuditLogsOptionalParams::default()
.filter_from(from_dt)
Expand All @@ -37,8 +37,8 @@ pub async fn search(
) -> Result<()> {
let api = crate::make_api!(AuditAPI, cfg);

let from_ms = util::parse_time_to_unix_millis(&from)?;
let to_ms = util::parse_time_to_unix_millis(&to)?;
let from_ms = util_ext::parse_time_to_unix_millis(&from)?;
let to_ms = util_ext::parse_time_to_unix_millis(&to)?;

let from_str = chrono::DateTime::from_timestamp_millis(from_ms)
.unwrap()
Expand Down
Loading