Skip to content

Commit eb89078

Browse files
authored
Merge pull request #496 from hookdeck/claude/clever-bohr-87hc9u
fix(source, connection): source auth flags on WEBHOOK sources, retry status code ranges, and related upsert fixes
2 parents e8c5c6f + 66c793e commit eb89078

43 files changed

Lines changed: 8273 additions & 420 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎AGENTS.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ func validateTypeA(flags map[string]interface{}) error {
185185
186186
### Using the cached OpenAPI spec
187187
- Source type enum and auth rules are available via **`pkg/cmd/sources.FetchSourceTypes()`** (fetches from the API OpenAPI URL, caches under temp with TTL). Use it for **source management** (e.g. `source create`, `source upsert`) and **connection management** (e.g. `connection create` inline source) to validate `--type` and type-specific required auth flags.
188-
- If `FetchSourceTypes()` fails (network, parse), **warn and continue**—do not block the command; let the API validate. If the given type is not in the cached enum, let the API validate.
188+
- It parses the `SourceTypeConfig<TYPE>` schemas: which types require `config.auth` (from `x-required` on the `SourceTypeConfig` oneOf entry) and which fields each type's `config.auth` requires. `validateSourceAuthFromSpec` (`pkg/cmd/source_common.go`) checks the auth flags against those fields. `x-required` also marks types whose *handshake* is required; `optionalAuthSourceTypes` lists the one that still reads as auth-required (ONFLEET).
189+
- If `FetchSourceTypes()` fails (network, parse, or a spec with no source types), **warn and continue**—do not block the command; let the API validate. A failed or empty parse is never cached. If the given type is not in the cached enum, let the API validate.
189190
- Prefer this over hardcoding type lists or required-auth rules so the CLI stays aligned with the API.
190191
191192
### Validation Layers (in order)

‎REFERENCE.md‎

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,8 @@ Create a connection between a source and destination.
342342
343343
You can either reference existing resources by ID or create them inline.
344344
345+
The auth flags build config.auth from the source type's own verification methods in the API spec. `--webhook-secret` sends webhook_secret_key; on WEBHOOK and HTTP it adds the HMAC settings those types need (sha256, hex, header x-webhook-signature), and on every other type it sends the secret alone so the provider's own header and algorithm apply. `--hmac-secret` sends that HMAC shape (with `--hmac-algo`) wherever the type's method takes an algorithm, and otherwise behaves like `--webhook-secret`. `--api-key` sends api_key; WEBHOOK and HTTP also get header x-api-key, while a type that needs its own header name is refused, because no flag sets it: pass config.auth with header_key through `--source-config`. Types that offer a choice of method (WEBHOOK, HTTP, GITLAB, GRAFANA and others) also need auth_type; the flags set it to the method they used. A flag no method of the type can express is refused, with the methods the type accepts. When auth comes from `--source-config` without auth_type, it is set only if the auth fields fit exactly one method (for example, webhook_secret_key alone is STANDARD_WEBHOOKS on WEBHOOK). Set auth_type in `--source-config` to choose the method yourself.
346+
345347
**Usage:**
346348
347349
```bash
@@ -400,7 +402,7 @@ hookdeck gateway connection create [flags]
400402
| `--rule-filter-query` | `string` | Filter on request query parameters using Hookdeck filter syntax (JSON) |
401403
| `--rule-retry-count` | `int` | Number of retry attempts (default "0") |
402404
| `--rule-retry-interval` | `int` | Interval between retries in milliseconds (default "0") |
403-
| `--rule-retry-response-status-codes` | `string` | Comma-separated HTTP status codes to retry on |
405+
| `--rule-retry-response-status-codes` | `string` | Comma-separated HTTP status codes or expressions to retry on: codes (404), ranges (500-599), comparisons (&gt;400, &lt;=499) and exclusions (!401), e.g. "429,500-599" |
404406
| `--rule-retry-strategy` | `string` | Retry strategy (linear, exponential) |
405407
| `--rule-transform-code` | `string` | Transformation code. Creates the transformation named by `--rule-transform-name`, or replaces its code if it exists |
406408
| `--rule-transform-env` | `string` | JSON string representing environment variables for transformation. Replaces the env of an existing transformation |
@@ -421,7 +423,7 @@ hookdeck gateway connection create [flags]
421423
| `--source-id` | `string` | Use existing source by ID |
422424
| `--source-name` | `string` | Source name for inline creation |
423425
| `--source-type` | `string` | Source type (WEBHOOK, STRIPE, etc.) |
424-
| `--source-webhook-secret` | `string` | Webhook secret for source verification (e.g., Stripe) |
426+
| `--source-webhook-secret` | `string` | Webhook secret the source verifies signatures with; sent as webhook_secret_key, plus HMAC settings on WEBHOOK and HTTP only |
425427
426428
**Examples:**
427429
@@ -506,7 +508,7 @@ hookdeck gateway connection update <connection-id> [flags]
506508
| Flag | Type | Description |
507509
|------|------|-------------|
508510
| `--description` | `string` | Connection description |
509-
| `--destination-id` | `string` | Update destination by ID |
511+
| `--destination-id` | `string` | Destination ID the connection already uses (a different value is rejected: a connection's destination cannot be changed) |
510512
| `--name` | `string` | New connection name |
511513
| `--output` | `string` | Output format (json) |
512514
| `--rule-deduplicate-exclude-fields` | `string` | Comma-separated list of fields to exclude for deduplication |
@@ -519,14 +521,14 @@ hookdeck gateway connection update <connection-id> [flags]
519521
| `--rule-filter-query` | `string` | Filter on request query parameters using Hookdeck filter syntax (JSON) |
520522
| `--rule-retry-count` | `int` | Number of retry attempts (default "0") |
521523
| `--rule-retry-interval` | `int` | Interval between retries in milliseconds (default "0") |
522-
| `--rule-retry-response-status-codes` | `string` | Comma-separated HTTP status codes to retry on |
524+
| `--rule-retry-response-status-codes` | `string` | Comma-separated HTTP status codes or expressions to retry on: codes (404), ranges (500-599), comparisons (&gt;400, &lt;=499) and exclusions (!401), e.g. "429,500-599" |
523525
| `--rule-retry-strategy` | `string` | Retry strategy (linear, exponential) |
524526
| `--rule-transform-code` | `string` | Transformation code. Creates the transformation named by `--rule-transform-name`, or replaces its code if it exists |
525527
| `--rule-transform-env` | `string` | JSON string representing environment variables for transformation. Replaces the env of an existing transformation |
526528
| `--rule-transform-name` | `string` | Name or ID of an existing transformation to apply. With `--rule-transform-code`, an existing transformation's code is replaced, or a new transformation is created with this name |
527529
| `--rules` | `string` | JSON string representing the entire rules array |
528530
| `--rules-file` | `string` | Path to a JSON file containing the rules array |
529-
| `--source-id` | `string` | Update source by ID |
531+
| `--source-id` | `string` | Source ID the connection already uses (a different value is rejected: a connection's source cannot be changed) |
530532
531533
**Examples:**
532534
@@ -537,8 +539,9 @@ hookdeck gateway connection update web_abc123 --name "new-name"
537539
# Update description
538540
hookdeck gateway connection update web_abc123 --description "Updated description"
539541
540-
# Change the source on a connection
541-
hookdeck gateway connection update web_abc123 --source-id src_def456
542+
# A connection's source and destination cannot be changed. --source-id and
543+
# --destination-id are accepted only when they match the stored values;
544+
# to use a different one, create a new connection.
542545
543546
# Update rules
544547
hookdeck gateway connection update web_abc123 \
@@ -593,8 +596,18 @@ Create a new connection or update an existing one by name (idempotent).
593596
- Only updates properties that are explicitly provided
594597
- Preserves existing properties that aren't specified
595598
599+
An existing connection's destination cannot be changed. If the destination
600+
you name (by ID or by name) differs from the one the connection already uses,
601+
the command fails before changing anything. Settings of the current
602+
destination can still be updated. The source can be changed.
603+
604+
Rules are replaced as a whole when `--rules` or `--rules-file` is given, and
605+
left alone otherwise. Pass `--rules` '[]' to remove all rules.
606+
596607
Use `--dry-run` to preview changes without applying them.
597608
609+
The auth flags build config.auth from the source type's own verification methods in the API spec. `--webhook-secret` sends webhook_secret_key; on WEBHOOK and HTTP it adds the HMAC settings those types need (sha256, hex, header x-webhook-signature), and on every other type it sends the secret alone so the provider's own header and algorithm apply. `--hmac-secret` sends that HMAC shape (with `--hmac-algo`) wherever the type's method takes an algorithm, and otherwise behaves like `--webhook-secret`. `--api-key` sends api_key; WEBHOOK and HTTP also get header x-api-key, while a type that needs its own header name is refused, because no flag sets it: pass config.auth with header_key through `--source-config`. Types that offer a choice of method (WEBHOOK, HTTP, GITLAB, GRAFANA and others) also need auth_type; the flags set it to the method they used. A flag no method of the type can express is refused, with the methods the type accepts. When auth comes from `--source-config` without auth_type, it is set only if the auth fields fit exactly one method (for example, webhook_secret_key alone is STANDARD_WEBHOOKS on WEBHOOK). Set auth_type in `--source-config` to choose the method yourself.
610+
598611
**Usage:**
599612
600613
```bash
@@ -659,7 +672,7 @@ hookdeck gateway connection upsert <name> [flags]
659672
| `--rule-filter-query` | `string` | Filter on request query parameters using Hookdeck filter syntax (JSON) |
660673
| `--rule-retry-count` | `int` | Number of retry attempts (default "0") |
661674
| `--rule-retry-interval` | `int` | Interval between retries in milliseconds (default "0") |
662-
| `--rule-retry-response-status-codes` | `string` | Comma-separated HTTP status codes to retry on |
675+
| `--rule-retry-response-status-codes` | `string` | Comma-separated HTTP status codes or expressions to retry on: codes (404), ranges (500-599), comparisons (&gt;400, &lt;=499) and exclusions (!401), e.g. "429,500-599" |
663676
| `--rule-retry-strategy` | `string` | Retry strategy (linear, exponential) |
664677
| `--rule-transform-code` | `string` | Transformation code. Creates the transformation named by `--rule-transform-name`, or replaces its code if it exists |
665678
| `--rule-transform-env` | `string` | JSON string representing environment variables for transformation. Replaces the env of an existing transformation |
@@ -680,7 +693,7 @@ hookdeck gateway connection upsert <name> [flags]
680693
| `--source-id` | `string` | Use existing source by ID |
681694
| `--source-name` | `string` | Source name for inline creation |
682695
| `--source-type` | `string` | Source type (WEBHOOK, STRIPE, etc.) |
683-
| `--source-webhook-secret` | `string` | Webhook secret for source verification (e.g., Stripe) |
696+
| `--source-webhook-secret` | `string` | Webhook secret the source verifies signatures with; sent as webhook_secret_key, plus HMAC settings on WEBHOOK and HTTP only |
684697
685698
**Examples:**
686699
@@ -838,6 +851,8 @@ Create a new source.
838851
839852
Requires `--name` and `--type`. Use `--config` or `--config-file` for authentication (e.g. webhook_secret, api_key).
840853
854+
The auth flags build config.auth from the source type's own verification methods in the API spec. `--webhook-secret` sends webhook_secret_key; on WEBHOOK and HTTP it adds the HMAC settings those types need (sha256, hex, header x-webhook-signature), and on every other type it sends the secret alone so the provider's own header and algorithm apply. `--hmac-secret` sends that HMAC shape (with `--hmac-algo`) wherever the type's method takes an algorithm, and otherwise behaves like `--webhook-secret`. `--api-key` sends api_key; WEBHOOK and HTTP also get header x-api-key, while a type that needs its own header name is refused, because no flag sets it: pass config.auth with header_key through `--config`. Types that offer a choice of method (WEBHOOK, HTTP, GITLAB, GRAFANA and others) also need auth_type; the flags set it to the method they used. A flag no method of the type can express is refused, with the methods the type accepts. When auth comes from `--config` without auth_type, it is set only if the auth fields fit exactly one method (for example, webhook_secret_key alone is STANDARD_WEBHOOKS on WEBHOOK). Set auth_type in `--config` to choose the method yourself.
855+
841856
**Usage:**
842857
843858
```bash
@@ -862,7 +877,7 @@ hookdeck gateway source create [flags]
862877
| `--name` | `string` | Source name (required) |
863878
| `--output` | `string` | Output format (json) |
864879
| `--type` | `string` | Source type (e.g. WEBHOOK, STRIPE) (required) |
865-
| `--webhook-secret` | `string` | Webhook secret for source verification (e.g., Stripe) |
880+
| `--webhook-secret` | `string` | Webhook secret the source verifies signatures with; sent as webhook_secret_key, plus HMAC settings on WEBHOOK and HTTP only |
866881
867882
**Examples:**
868883
@@ -899,6 +914,10 @@ hookdeck gateway source get my-source --include-auth
899914
900915
Update an existing source by its ID.
901916
917+
Config flags without `--type` are applied to the source's current type, which is looked up first.
918+
919+
The auth flags build config.auth from the source type's own verification methods in the API spec. `--webhook-secret` sends webhook_secret_key; on WEBHOOK and HTTP it adds the HMAC settings those types need (sha256, hex, header x-webhook-signature), and on every other type it sends the secret alone so the provider's own header and algorithm apply. `--hmac-secret` sends that HMAC shape (with `--hmac-algo`) wherever the type's method takes an algorithm, and otherwise behaves like `--webhook-secret`. `--api-key` sends api_key; WEBHOOK and HTTP also get header x-api-key, while a type that needs its own header name is refused, because no flag sets it: pass config.auth with header_key through `--config`. Types that offer a choice of method (WEBHOOK, HTTP, GITLAB, GRAFANA and others) also need auth_type; the flags set it to the method they used. A flag no method of the type can express is refused, with the methods the type accepts. When auth comes from `--config` without auth_type, it is set only if the auth fields fit exactly one method (for example, webhook_secret_key alone is STANDARD_WEBHOOKS on WEBHOOK). Set auth_type in `--config` to choose the method yourself.
920+
902921
**Usage:**
903922
904923
```bash
@@ -923,7 +942,7 @@ hookdeck gateway source update <source-id> [flags]
923942
| `--name` | `string` | New source name |
924943
| `--output` | `string` | Output format (json) |
925944
| `--type` | `string` | Source type (e.g. WEBHOOK, STRIPE) |
926-
| `--webhook-secret` | `string` | Webhook secret for source verification (e.g., Stripe) |
945+
| `--webhook-secret` | `string` | Webhook secret the source verifies signatures with; sent as webhook_secret_key, plus HMAC settings on WEBHOOK and HTTP only |
927946
928947
**Examples:**
929948
@@ -958,6 +977,13 @@ hookdeck gateway source delete src_abc123 --force
958977
959978
Create a new source or update an existing one by name (idempotent).
960979
980+
When `--type` is omitted and the source already exists, its current type is kept,
981+
along with its verification unless you pass new auth flags or config. When the
982+
source does not exist, it is created as a WEBHOOK source. Pass `--type` to change
983+
an existing source's type.
984+
985+
The auth flags build config.auth from the source type's own verification methods in the API spec. `--webhook-secret` sends webhook_secret_key; on WEBHOOK and HTTP it adds the HMAC settings those types need (sha256, hex, header x-webhook-signature), and on every other type it sends the secret alone so the provider's own header and algorithm apply. `--hmac-secret` sends that HMAC shape (with `--hmac-algo`) wherever the type's method takes an algorithm, and otherwise behaves like `--webhook-secret`. `--api-key` sends api_key; WEBHOOK and HTTP also get header x-api-key, while a type that needs its own header name is refused, because no flag sets it: pass config.auth with header_key through `--config`. Types that offer a choice of method (WEBHOOK, HTTP, GITLAB, GRAFANA and others) also need auth_type; the flags set it to the method they used. A flag no method of the type can express is refused, with the methods the type accepts. When auth comes from `--config` without auth_type, it is set only if the auth fields fit exactly one method (for example, webhook_secret_key alone is STANDARD_WEBHOOKS on WEBHOOK). Set auth_type in `--config` to choose the method yourself.
986+
961987
**Usage:**
962988
963989
```bash
@@ -982,7 +1008,7 @@ hookdeck gateway source upsert <name> [flags]
9821008
| `--hmac-secret` | `string` | HMAC secret for signature verification |
9831009
| `--output` | `string` | Output format (json) |
9841010
| `--type` | `string` | Source type (e.g. WEBHOOK, STRIPE) |
985-
| `--webhook-secret` | `string` | Webhook secret for source verification (e.g., Stripe) |
1011+
| `--webhook-secret` | `string` | Webhook secret the source verifies signatures with; sent as webhook_secret_key, plus HMAC settings on WEBHOOK and HTTP only |
9861012
9871013
**Examples:**
9881014

0 commit comments

Comments
 (0)