|
| 1 | +package api |
| 2 | + |
| 3 | +import ( |
| 4 | + "encoding/json" |
| 5 | + "fmt" |
| 6 | +) |
| 7 | + |
| 8 | +type ConnectionResourceID struct { |
| 9 | + ConnecctionID string `json:"connectionId"` |
| 10 | +} |
| 11 | + |
| 12 | +type ConnectionResource struct { |
| 13 | + Name string `json:"name"` |
| 14 | + SourceID string `json:"sourceId,omitempty"` |
| 15 | + DestinationID string `json:"destinationId,omitempty"` |
| 16 | + ConnectionID string `json:"connectionId,omitempty"` |
| 17 | + // SyncCatalog interface{} `json:"syncCatalog"` |
| 18 | + DataResidency string `json:"dataResidency,omitempty"` |
| 19 | + NamespaceDefinition string `json:"namespaceDefinition,omitempty"` |
| 20 | + NamespaceFormat string `json:"namespaceFormat,omitempty"` |
| 21 | + NonBreakingSchemaUpdatesBehavior string `json:"nonBreakingSchemaUpdatesBehavior,omitempty"` |
| 22 | + Prefix string `json:"prefix,omitempty"` |
| 23 | + Status string `json:"status,omitempty"` |
| 24 | + Schedule ConnScheduleData `json:"schedule"` |
| 25 | + //OperatorConfiguration connOperatorConfig `json:"operator_configuration"` |
| 26 | +} |
| 27 | +type ConnScheduleData struct { |
| 28 | + ScheduleType string `json:"scheduleType"` |
| 29 | + CronExpression string `json:"cronExpression,omitempty"` |
| 30 | +} |
| 31 | + |
| 32 | +type DiscoverSourceSchemaCatalog struct { |
| 33 | + SourceID string `json:"sourceId"` |
| 34 | + DisableCache bool `json:"disable_cache"` |
| 35 | +} |
| 36 | + |
| 37 | +func (c *Client) CreateConnectionResource(payload ConnectionResource) (ConnectionResource, error) { |
| 38 | + // logger := fwhelpers.GetLogger() |
| 39 | + |
| 40 | + method := "POST" |
| 41 | + url := c.Host + "/v1/connections" |
| 42 | + body, err := json.Marshal(payload) |
| 43 | + if err != nil { |
| 44 | + return ConnectionResource{}, err |
| 45 | + } |
| 46 | + |
| 47 | + b, statusCode, _, _, err := c.doRequest(method, url, body, nil) |
| 48 | + if err != nil { |
| 49 | + return ConnectionResource{}, err |
| 50 | + } |
| 51 | + |
| 52 | + connection := ConnectionResource{} |
| 53 | + if statusCode >= 200 && statusCode <= 299 { |
| 54 | + err = json.Unmarshal(b, &connection) |
| 55 | + return connection, err |
| 56 | + } else { |
| 57 | + msg, err := c.getAPIError(b) |
| 58 | + if err != nil { |
| 59 | + return connection, err |
| 60 | + } else { |
| 61 | + return connection, fmt.Errorf(msg) |
| 62 | + } |
| 63 | + } |
| 64 | +} |
| 65 | + |
| 66 | +func (c *Client) ReadConnectionResource(connectionId string) (ConnectionResource, error) { |
| 67 | + // logger := fwhelpers.GetLogger() |
| 68 | + |
| 69 | + method := "GET" |
| 70 | + url := c.Host + "/v1/connections/" + connectionId |
| 71 | + |
| 72 | + b, statusCode, _, _, err := c.doRequest(method, url, []byte{}, nil) |
| 73 | + if err != nil { |
| 74 | + return ConnectionResource{}, err |
| 75 | + } |
| 76 | + connection := ConnectionResource{} |
| 77 | + if statusCode >= 200 && statusCode <= 299 { |
| 78 | + err = json.Unmarshal(b, &connection) |
| 79 | + return connection, err |
| 80 | + } else { |
| 81 | + msg, err := c.getAPIError(b) |
| 82 | + if err != nil { |
| 83 | + return connection, err |
| 84 | + } else { |
| 85 | + return connection, fmt.Errorf(msg) |
| 86 | + } |
| 87 | + } |
| 88 | +} |
| 89 | + |
| 90 | +func (c *Client) UpdateConnectionResource(payload ConnectionResource) (ConnectionResource, error) { |
| 91 | + // logger := fwhelpers.GetLogger() |
| 92 | + |
| 93 | + return ConnectionResource{}, fmt.Errorf("update resource is not supported") |
| 94 | +} |
| 95 | + |
| 96 | +func (c *Client) DeleteConnectionResource(connectionId string) error { |
| 97 | + // logger := fwhelpers.GetLogger() |
| 98 | + |
| 99 | + method := "DELETE" |
| 100 | + url := c.Host + "/v1/connections/" + connectionId |
| 101 | + |
| 102 | + b, statusCode, _, _, err := c.doRequest(method, url, []byte{}, nil) |
| 103 | + if err != nil { |
| 104 | + return err |
| 105 | + } |
| 106 | + |
| 107 | + if statusCode >= 200 && statusCode <= 299 { |
| 108 | + return nil |
| 109 | + } else { |
| 110 | + msg, err := c.getAPIError(b) |
| 111 | + if err != nil { |
| 112 | + return err |
| 113 | + } else { |
| 114 | + return fmt.Errorf(msg) |
| 115 | + } |
| 116 | + } |
| 117 | +} |
0 commit comments