Skip to content

Commit 847bf05

Browse files
committed
fix: remove deprecated cli_path field, use config.path for CLI destinations
- Remove CliPath field from Destination and DestinationCreateRequest structs - Add GetCLIPath() and SetCLIPath() helper methods to access config.path - Update connection_get.go to use GetCLIPath() helper method - Aligns with OpenAPI spec 2025-07-01 where CLI destinations use config.path
1 parent 4edd734 commit 847bf05

File tree

7 files changed

+66
-757
lines changed

7 files changed

+66
-757
lines changed

pkg/cmd/connection_create.go

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -279,28 +279,44 @@ func (cc *connectionCreateCmd) runConnectionCreateCmd(cmd *cobra.Command, args [
279279
return fmt.Errorf("failed to create connection: %w", err)
280280
}
281281

282+
// Verify the created connection by fetching it again
283+
if cc.output != "json" {
284+
fmt.Println("Verifying created connection...")
285+
}
286+
verifiedConnection, err := client.GetConnection(context.Background(), connection.ID)
287+
if err != nil {
288+
return fmt.Errorf("failed to verify connection: %w", err)
289+
}
290+
291+
// Quick integrity check
292+
if verifiedConnection.Source != nil && cc.sourceType != "" && strings.ToUpper(cc.sourceType) != verifiedConnection.Source.Type {
293+
return fmt.Errorf("Source type mismatch for connection %s.\nExpected: %s, Got: %s",
294+
verifiedConnection.ID, strings.ToUpper(cc.sourceType), verifiedConnection.Source.Type)
295+
}
296+
282297
// Display results
283298
if cc.output == "json" {
284-
jsonBytes, err := json.MarshalIndent(connection, "", " ")
299+
jsonBytes, err := json.MarshalIndent(verifiedConnection, "", " ")
285300
if err != nil {
286301
return fmt.Errorf("failed to marshal connection to json: %w", err)
287302
}
288303
fmt.Println(string(jsonBytes))
289304
} else {
290-
fmt.Printf("\n✓ Connection created successfully\n\n")
291-
if connection.Name != nil {
292-
fmt.Printf("Connection: %s (%s)\n", *connection.Name, connection.ID)
305+
fmt.Printf("Successfully created connection with ID: %s\n", verifiedConnection.ID)
306+
307+
if verifiedConnection.Name != nil {
308+
fmt.Printf("Connection: %s (%s)\n", *verifiedConnection.Name, verifiedConnection.ID)
293309
} else {
294310
fmt.Printf("Connection: (unnamed)\n")
295311
}
296312

297-
if connection.Source != nil {
298-
fmt.Printf("Source: %s (%s)\n", connection.Source.Name, connection.Source.ID)
299-
fmt.Printf("Source URL: %s\n", connection.Source.URL)
313+
if verifiedConnection.Source != nil {
314+
fmt.Printf("Source: %s (%s)\n", verifiedConnection.Source.Name, verifiedConnection.Source.ID)
315+
fmt.Printf("Source URL: %s\n", verifiedConnection.Source.URL)
300316
}
301317

302-
if connection.Destination != nil {
303-
fmt.Printf("Destination: %s (%s)\n", connection.Destination.Name, connection.Destination.ID)
318+
if verifiedConnection.Destination != nil {
319+
fmt.Printf("Destination: %s (%s)\n", verifiedConnection.Destination.Name, verifiedConnection.Destination.ID)
304320
}
305321
}
306322

pkg/cmd/connection_get.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ func (cc *connectionGetCmd) runConnectionGetCmd(cmd *cobra.Command, args []strin
9898
fmt.Printf(" Name: %s\n", conn.Destination.Name)
9999
fmt.Printf(" ID: %s\n", conn.Destination.ID)
100100

101-
if conn.Destination.CliPath != nil {
102-
fmt.Printf(" CLI Path: %s\n", *conn.Destination.CliPath)
101+
if cliPath := conn.Destination.GetCLIPath(); cliPath != nil {
102+
fmt.Printf(" CLI Path: %s\n", *cliPath)
103103
}
104104

105105
if conn.Destination.URL != nil {

pkg/hookdeck/connections_test.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ func TestListConnections(t *testing.T) {
120120
if r.Method != http.MethodGet {
121121
t.Errorf("expected GET request, got %s", r.Method)
122122
}
123-
if r.URL.Path != "/2024-03-01/connections" {
124-
t.Errorf("expected path /2024-03-01/connections, got %s", r.URL.Path)
123+
if r.URL.Path != "/2025-07-01/connections" {
124+
t.Errorf("expected path /2025-07-01/connections, got %s", r.URL.Path)
125125
}
126126

127127
// Verify query parameters
@@ -214,7 +214,7 @@ func TestGetConnection(t *testing.T) {
214214
if r.Method != http.MethodGet {
215215
t.Errorf("expected GET request, got %s", r.Method)
216216
}
217-
expectedPath := "/2024-03-01/connections/" + tt.connectionID
217+
expectedPath := "/2025-07-01/connections/" + tt.connectionID
218218
if r.URL.Path != expectedPath {
219219
t.Errorf("expected path %s, got %s", expectedPath, r.URL.Path)
220220
}
@@ -334,8 +334,8 @@ func TestCreateConnection(t *testing.T) {
334334
if r.Method != http.MethodPost {
335335
t.Errorf("expected POST request, got %s", r.Method)
336336
}
337-
if r.URL.Path != "/2024-03-01/connections" {
338-
t.Errorf("expected path /2024-03-01/connections, got %s", r.URL.Path)
337+
if r.URL.Path != "/2025-07-01/connections" {
338+
t.Errorf("expected path /2025-07-01/connections, got %s", r.URL.Path)
339339
}
340340

341341
// Verify request body
@@ -441,7 +441,7 @@ func TestUpdateConnection(t *testing.T) {
441441
if r.Method != http.MethodPut {
442442
t.Errorf("expected PUT request, got %s", r.Method)
443443
}
444-
expectedPath := "/2024-03-01/connections/" + tt.connectionID
444+
expectedPath := "/2025-07-01/connections/" + tt.connectionID
445445
if r.URL.Path != expectedPath {
446446
t.Errorf("expected path %s, got %s", expectedPath, r.URL.Path)
447447
}
@@ -511,7 +511,7 @@ func TestDeleteConnection(t *testing.T) {
511511
if r.Method != http.MethodDelete {
512512
t.Errorf("expected DELETE request, got %s", r.Method)
513513
}
514-
expectedPath := "/2024-03-01/connections/" + tt.connectionID
514+
expectedPath := "/2025-07-01/connections/" + tt.connectionID
515515
if r.URL.Path != expectedPath {
516516
t.Errorf("expected path %s, got %s", expectedPath, r.URL.Path)
517517
}
@@ -584,7 +584,7 @@ func TestEnableConnection(t *testing.T) {
584584
if r.Method != http.MethodPut {
585585
t.Errorf("expected PUT request, got %s", r.Method)
586586
}
587-
expectedPath := "/2024-03-01/connections/" + tt.connectionID + "/enable"
587+
expectedPath := "/2025-07-01/connections/" + tt.connectionID + "/enable"
588588
if r.URL.Path != expectedPath {
589589
t.Errorf("expected path %s, got %s", expectedPath, r.URL.Path)
590590
}
@@ -663,7 +663,7 @@ func TestDisableConnection(t *testing.T) {
663663
if r.Method != http.MethodPut {
664664
t.Errorf("expected PUT request, got %s", r.Method)
665665
}
666-
expectedPath := "/2024-03-01/connections/" + tt.connectionID + "/disable"
666+
expectedPath := "/2025-07-01/connections/" + tt.connectionID + "/disable"
667667
if r.URL.Path != expectedPath {
668668
t.Errorf("expected path %s, got %s", expectedPath, r.URL.Path)
669669
}
@@ -742,7 +742,7 @@ func TestPauseConnection(t *testing.T) {
742742
if r.Method != http.MethodPut {
743743
t.Errorf("expected PUT request, got %s", r.Method)
744744
}
745-
expectedPath := "/2024-03-01/connections/" + tt.connectionID + "/pause"
745+
expectedPath := "/2025-07-01/connections/" + tt.connectionID + "/pause"
746746
if r.URL.Path != expectedPath {
747747
t.Errorf("expected path %s, got %s", expectedPath, r.URL.Path)
748748
}
@@ -821,7 +821,7 @@ func TestUnpauseConnection(t *testing.T) {
821821
if r.Method != http.MethodPut {
822822
t.Errorf("expected PUT request, got %s", r.Method)
823823
}
824-
expectedPath := "/2024-03-01/connections/" + tt.connectionID + "/unpause"
824+
expectedPath := "/2025-07-01/connections/" + tt.connectionID + "/unpause"
825825
if r.URL.Path != expectedPath {
826826
t.Errorf("expected path %s, got %s", expectedPath, r.URL.Path)
827827
}
@@ -899,7 +899,7 @@ func TestArchiveConnection(t *testing.T) {
899899
if r.Method != http.MethodPut {
900900
t.Errorf("expected PUT request, got %s", r.Method)
901901
}
902-
expectedPath := "/2024-03-01/connections/" + tt.connectionID + "/archive"
902+
expectedPath := "/2025-07-01/connections/" + tt.connectionID + "/archive"
903903
if r.URL.Path != expectedPath {
904904
t.Errorf("expected path %s, got %s", expectedPath, r.URL.Path)
905905
}
@@ -977,7 +977,7 @@ func TestUnarchiveConnection(t *testing.T) {
977977
if r.Method != http.MethodPut {
978978
t.Errorf("expected PUT request, got %s", r.Method)
979979
}
980-
expectedPath := "/2024-03-01/connections/" + tt.connectionID + "/unarchive"
980+
expectedPath := "/2025-07-01/connections/" + tt.connectionID + "/unarchive"
981981
if r.URL.Path != expectedPath {
982982
t.Errorf("expected path %s, got %s", expectedPath, r.URL.Path)
983983
}
@@ -1063,8 +1063,8 @@ func TestCountConnections(t *testing.T) {
10631063
if r.Method != http.MethodGet {
10641064
t.Errorf("expected GET request, got %s", r.Method)
10651065
}
1066-
if r.URL.Path != "/2024-03-01/connections/count" {
1067-
t.Errorf("expected path /2024-03-01/connections/count, got %s", r.URL.Path)
1066+
if r.URL.Path != "/2025-07-01/connections/count" {
1067+
t.Errorf("expected path /2025-07-01/connections/count, got %s", r.URL.Path)
10681068
}
10691069

10701070
w.WriteHeader(tt.mockStatusCode)

pkg/hookdeck/destinations.go

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package hookdeck
22

33
import (
4-
"context"
5-
"encoding/json"
6-
"fmt"
74
"time"
85
)
96

@@ -14,13 +11,36 @@ type Destination struct {
1411
Description *string `json:"description"`
1512
URL *string `json:"url"`
1613
Type string `json:"type"`
17-
CliPath *string `json:"cli_path"`
1814
Config map[string]interface{} `json:"config"`
1915
DisabledAt *time.Time `json:"disabled_at"`
2016
UpdatedAt time.Time `json:"updated_at"`
2117
CreatedAt time.Time `json:"created_at"`
2218
}
2319

20+
// GetCLIPath returns the CLI path from config for CLI-type destinations
21+
// For CLI destinations, the path is stored in config.path according to the OpenAPI spec
22+
func (d *Destination) GetCLIPath() *string {
23+
if d.Type != "CLI" || d.Config == nil {
24+
return nil
25+
}
26+
27+
if path, ok := d.Config["path"].(string); ok {
28+
return &path
29+
}
30+
31+
return nil
32+
}
33+
34+
// SetCLIPath sets the CLI path in config for CLI-type destinations
35+
func (d *Destination) SetCLIPath(path string) {
36+
if d.Type == "CLI" {
37+
if d.Config == nil {
38+
d.Config = make(map[string]interface{})
39+
}
40+
d.Config["path"] = path
41+
}
42+
}
43+
2444
// DestinationCreateInput represents input for creating a destination inline
2545
type DestinationCreateInput struct {
2646
Name string `json:"name"`
@@ -34,27 +54,5 @@ type DestinationCreateRequest struct {
3454
Name string `json:"name"`
3555
Description *string `json:"description,omitempty"`
3656
URL *string `json:"url,omitempty"`
37-
CliPath *string `json:"cli_path,omitempty"`
3857
Config map[string]interface{} `json:"config,omitempty"`
3958
}
40-
41-
// CreateDestination creates a new destination
42-
func (c *Client) CreateDestination(ctx context.Context, req *DestinationCreateRequest) (*Destination, error) {
43-
data, err := json.Marshal(req)
44-
if err != nil {
45-
return nil, fmt.Errorf("failed to marshal destination request: %w", err)
46-
}
47-
48-
resp, err := c.Post(ctx, "/2024-03-01/destinations", data, nil)
49-
if err != nil {
50-
return nil, err
51-
}
52-
53-
var destination Destination
54-
_, err = postprocessJsonResponse(resp, &destination)
55-
if err != nil {
56-
return nil, fmt.Errorf("failed to parse destination response: %w", err)
57-
}
58-
59-
return &destination, nil
60-
}

0 commit comments

Comments
 (0)