-
Notifications
You must be signed in to change notification settings - Fork 26
docs(dev): fix stale structure.md and document drapi client conventions #879
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ajalon1
wants to merge
10
commits into
datarobot-oss:main
Choose a base branch
from
ajalon1:aj/update-agents-and-bugbot-for-workload
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
bcb6104
docs(dev): fix stale structure.md and document drapi client conventions
ajalon1 a44e914
chore(bugbot): add five rules found while auditing workload/auth patt…
ajalon1 1ced8d7
chore(bugbot): add count-flag parse-time validation rules
ajalon1 5959134
chore(bugbot): generalize the count-flag rule to repeated flag shapes
ajalon1 8089391
chore(bugbot): add drapi extend-vs-reimplement boundary rules
ajalon1 5c9eccc
Update docs/development/drapi-client.md
ajalon1 c2b26cf
Update docs/development/structure.md
ajalon1 52aefd0
Update .cursor/bugbot-cmd.md
ajalon1 01e2c53
Update .cursor/bugbot-cmd.md
ajalon1 2861434
chore(bugbot): add local-callback-listener and security-claim rules
ajalon1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| # drapi client conventions | ||
|
|
||
| `internal/drapi` is the one shared HTTP client every authenticated call to | ||
| the DataRobot API is expected to build on. This page is the dev-doc mirror | ||
| of `internal/drapi/doc.go` (`go doc ./internal/drapi` for the canonical | ||
| source) — read this first when wiring in a new API call; read the package | ||
| doc when you need the full detail. | ||
|
|
||
| ## Always build on the verb functions | ||
|
|
||
| Use `drapi.Get`, `drapi.Post`, `drapi.Patch`, or `drapi.Delete` (or their | ||
| `*JSON` variants) with a URL from `drapi.EndpointURL()` / | ||
| `config.GetEndpointURL()`. Never construct your own `http.Client` or set | ||
| the `Authorization` header by hand — `AuthorizeRequest` (`internal/drapi/auth.go`) | ||
| is called internally by every verb function and sets the bearer token, | ||
| `User-Agent`, and the optional API-consumer trace header consistently. | ||
|
|
||
| If you must build your own `*http.Request` (multipart uploads, custom error | ||
| decoding), use `drapi.Do(req, timeout)` rather than duplicating | ||
| `NewHTTPClient(t).Do(req)` — it applies the same timeout clamp described | ||
| below. | ||
|
|
||
| ## Timeouts | ||
|
|
||
| Every verb function takes an optional trailing `time.Duration`. Omit it, or | ||
| pass `<=0`, and `NewHTTPClient` clamps it to `DefaultClientTimeout` (30s) | ||
| internally — the clamp cannot be bypassed by a caller. This was tightened | ||
| specifically so a stray `0` or negative duration could never produce | ||
| an unbounded request. | ||
|
|
||
| ## The `HTTPError` / `errors.As` contract | ||
|
|
||
| A non-2xx response becomes a `*drapi.HTTPError{StatusCode, URL, Detail, Body}`, | ||
| unpackable via `errors.As`. Roughly 32 call sites across the codebase depend | ||
| on this contract holding — treat it as load-bearing when touching | ||
| `internal/drapi`. | ||
|
|
||
| `Body` is the raw, uninterpreted response body (different DataRobot APIs | ||
| disagree on their error envelope shape); `Detail` is best-effort and | ||
| populated by the caller — see `internal/workload/apiclient.LiftDetail` for | ||
| the pattern of parsing a FastAPI `{"detail": ...}` envelope into `Detail`. | ||
|
|
||
| **Known gap, don't copy this as the pattern**: `Get()` currently builds a | ||
| bare `&HTTPError{StatusCode, URL}` on failure instead of calling | ||
| `ErrFromResp()` the way `Post`, `Patch`, and `Delete` do — so a `GET` | ||
| failure carries no `Body`/`Detail` today, unlike every other verb. This is | ||
| a known asymmetry, not an intentional design choice; a fix is a reasonable | ||
| follow-up, but a new caller should not assume `Get()` failures carry the | ||
| same diagnostic detail as the others until it's closed. | ||
|
|
||
| ## Origin safety | ||
|
|
||
| Before attaching the bearer token to any URL your code did not build | ||
| locally — a server-returned pagination cursor, a workload's live `endpoint` | ||
| URL — call `drapi.URLMatchesConfiguredBase(rawURL)` first and skip | ||
| authorization when it doesn't match. Attaching a CLI credential to an | ||
| arbitrary server-supplied URL would leak it to whatever origin that URL | ||
| points at. | ||
|
|
||
| Two worked examples: | ||
|
|
||
| - `AssertNextOnSameHost` (`internal/drapi/pagination.go`) guards a paginated | ||
| list response's `Next` cursor before the client follows it. | ||
| - `endpointCheckAuthForURL` (`internal/workload/up/endpoint_check.go`) | ||
| authenticates a post-deploy endpoint check only when the URL is the | ||
| DataRobot-hosted workload gateway path *and* matches the configured base; | ||
| a direct/customer-container URL always stays anonymous, so the CLI token | ||
| never lands in a customer container's access log (RAPTOR-19741). | ||
|
|
||
| ## See also | ||
|
|
||
| - [Authentication](authentication.md) — the OAuth-style login flow that | ||
| produces the token these conventions consume. | ||
| - `go doc ./internal/drapi` — the full package doc. |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I need or want worked examples in the bugbot cursor rules.