feat(notebooks): add create and update commands#62
Merged
platinummonkey merged 11 commits intodatadog-labs:mainfrom Feb 14, 2026
Merged
feat(notebooks): add create and update commands#62platinummonkey merged 11 commits intodatadog-labs:mainfrom
platinummonkey merged 11 commits intodatadog-labs:mainfrom
Conversation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The Notebooks V1 API doesn't support OAuth authentication. Register all notebook endpoints in the auth validator fallback registry and switch all commands to use getClientForEndpoint() for automatic API key fallback. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
getClientForEndpoint was calling client.New which prefers OAuth over API keys, causing 403s on endpoints without OAuth support. Add an apiKeyClientFactory injection point that uses NewWithAPIKeys to force API key auth for fallback endpoints. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Switch list/get from fmt.Println to printOutput for testability - Switch delete from fmt.Scanln to readConfirmation (uses inputReader) - Switch delete from fmt.Printf/Print to printOutput - Update auth description: OAuth not supported, API keys required - Simplify BodyRequired test to use ValidateRequiredFlags directly Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Replace inline error formatting with formatAPIError for richer user-facing error messages (status-specific hints for 401, 403, etc.) - Add create, update, and delete examples to long description - Add TestNotebooksUpdateCmd_BodyRequired for symmetry with create Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Collaborator
|
Thanks! The CI error is a configuration error on my end, will take care of this when I'm at my desk |
Contributor
Author
No worries! These commands are pretty narrowly focused for agents. I don't think that end users will care too much about editing a notebook with the CLI. I tried it with an investigation using Pup and capturing findings in a notebook, and it was chef kiss. |
Collaborator
|
okay |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
createandupdatesubcommands topup notebooks, completing the full CRUD surface for the Notebooks API. The primary goal is enabling agents (e.g., Claude Code) to programmatically create and update notebooks with investigation findings that can be attached to incident post-mortems.Motivation
Notebooks are a natural fit for agent-assisted investigations — they combine graphs, logs, and narrative text. With
createandupdate, an agent can:Only
list,get, anddeleteexisted before this PR.Design Decisions
JSON body via
--bodyflag — Both commands accept--body @file.json(file) or--body -(stdin). This was chosen over individual flags (e.g.,--title,--cell) because:Full replacement for updates —
updatereplaces the entire notebook body (PUT semantics), matching the Datadog API. The expected agent workflow is GET → modify → PUT.No confirmation prompt on update — Updates are reversible (just update again), so no prompt. This keeps automation frictionless.
deleteretains its existing confirmation.OAuth fallback to API keys — The Notebooks API is a V1 endpoint that does not support OAuth2. All five notebook commands use
getClientForEndpoint()to automatically fall back to API key authentication. During testing we found thatgetClientForEndpointwas callingclient.New(which prefers OAuth), causing 403s. This is fixed by adding a dedicatedapiKeyClientFactorythat callsclient.NewWithAPIKeysto force API key auth for fallback endpoints.Usage
Changes
cmd/notebooks.goreadBodyhelper — parses@file/-stdin, validates JSONcreateandupdatecommands with--bodyflag (required)getClient()togetClientForEndpoint()for V1 OAuth fallbackformatAPIErrorfor consistent error handlinglist/getfromfmt.PrintlntoprintOutputfor testabilitydeletefromfmt.ScanlntoreadConfirmation()andfmt.Printf/PrinttoprintOutputcmd/notebooks_test.goreadBody(file, stdin, missing file, invalid JSON file, invalid JSON stdin, empty value), create command structure + body-required, update command structure + body-requiredcmd/root.godefaultAPIKeyClientFactoryusingclient.NewWithAPIKeysandapiKeyClientFactoryinjection pointgetClientForEndpointto useapiKeyClientFactoryinstead ofclientFactoryfor endpoints without OAuth supportcmd/api_keys_test.gosetupTestClientto mock and restoreapiKeyClientFactoryalongsideclientFactoryTesting
go test ./cmd/ -run TestNotebooks -vandgo test ./cmd/ -run TestReadBody -vgo test -race ./...readBodytested via table-driven tests covering file read, stdin read, missing file, and invalid JSON for both input methods🤖 Generated with Claude Code