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
34 changes: 33 additions & 1 deletion src/commands/datasets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::formatter;
use crate::util;

fn make_api(cfg: &Config) -> DatasetsAPI {
crate::make_api_no_auth!(DatasetsAPI, cfg)
crate::make_api!(DatasetsAPI, cfg)
Comment thread
platinummonkey marked this conversation as resolved.
Comment thread
platinummonkey marked this conversation as resolved.
}

pub async fn list(cfg: &Config) -> Result<()> {
Expand Down Expand Up @@ -76,6 +76,38 @@ mod tests {
std::env::remove_var("DD_TOKEN_STORAGE");
}

#[tokio::test]
async fn test_datasets_list_accepts_oauth_bearer_token() {
let _lock = lock_env().await;
std::env::set_var("DD_TOKEN_STORAGE", "file");
let mut server = mockito::Server::new_async().await;
let mut cfg = test_config(&server.url());
// Simulate OAuth-only auth: bearer token configured, no API/APP keys.
cfg.api_key = None;
cfg.app_key = None;
cfg.access_token = Some("oauth-bearer-token".into());
std::env::remove_var("DD_API_KEY");
std::env::remove_var("DD_APP_KEY");

let _mock = server
.mock("GET", mockito::Matcher::Any)
.match_header("Authorization", "Bearer oauth-bearer-token")
.with_status(200)
.with_header("content-type", "application/json")
.with_body(r#"{"data":[]}"#)
.create_async()
.await;

let result = super::list(&cfg).await;
assert!(
result.is_ok(),
"datasets list with OAuth bearer failed: {:?}",
result.err()
);
cleanup_env();
std::env::remove_var("DD_TOKEN_STORAGE");
}

#[tokio::test]
async fn test_datasets_get() {
let _lock = lock_env().await;
Expand Down
6 changes: 6 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1074,6 +1074,12 @@ enum Commands {
/// pup datasets list
/// pup datasets get my-dataset-id
/// pup datasets create --file dataset.json
///
/// AUTHENTICATION:
/// Requires either OAuth2 authentication or API keys.
/// All operations, including list/get, require the user_access_manage
/// scope, which is not requested by default -- opt in with:
/// pup auth login --extra-scopes user_access_manage
#[command(verbatim_doc_comment)]
Datasets {
#[command(subcommand)]
Expand Down