Skip to content

Commit e4dd1a6

Browse files
committed
Continued work, cleanup type conversion, implement API calls, and continue working on fix for scaling
1 parent d086f04 commit e4dd1a6

File tree

4 files changed

+89
-77
lines changed

4 files changed

+89
-77
lines changed

pkg/internal/api/clickpipe.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,3 +322,45 @@ func (c *ClientImpl) DeleteClickPipe(ctx context.Context, serviceId string, clic
322322
_, err = c.doRequest(ctx, req)
323323
return err
324324
}
325+
326+
func (c *ClientImpl) GetClickPipeSettings(ctx context.Context, serviceId string, clickPipeId string) (map[string]any, error) {
327+
req, err := http.NewRequest(http.MethodGet, c.getClickPipePath(serviceId, clickPipeId, "/settings"), nil)
328+
if err != nil {
329+
return nil, err
330+
}
331+
body, err := c.doRequest(ctx, req)
332+
if err != nil {
333+
return nil, err
334+
}
335+
336+
settingsResponse := ResponseWithResult[map[string]any]{}
337+
if err := json.Unmarshal(body, &settingsResponse); err != nil {
338+
return nil, fmt.Errorf("failed to unmarshal ClickPipe settings: %w", err)
339+
}
340+
341+
return settingsResponse.Result, nil
342+
}
343+
344+
func (c *ClientImpl) UpdateClickPipeSettings(ctx context.Context, serviceId string, clickPipeId string, settings map[string]any) (map[string]any, error) {
345+
var payload bytes.Buffer
346+
if err := json.NewEncoder(&payload).Encode(settings); err != nil {
347+
return nil, fmt.Errorf("failed to encode ClickPipe settings: %w", err)
348+
}
349+
350+
req, err := http.NewRequest(http.MethodPut, c.getClickPipePath(serviceId, clickPipeId, "/settings"), &payload)
351+
if err != nil {
352+
return nil, err
353+
}
354+
355+
body, err := c.doRequest(ctx, req)
356+
if err != nil {
357+
return nil, err
358+
}
359+
360+
settingsResponse := ResponseWithResult[map[string]any]{}
361+
if err := json.Unmarshal(body, &settingsResponse); err != nil {
362+
return nil, fmt.Errorf("failed to unmarshal ClickPipe settings: %w", err)
363+
}
364+
365+
return settingsResponse.Result, nil
366+
}

pkg/internal/api/clickpipe_models.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ type ClickPipe struct {
191191
Source ClickPipeSource `json:"source"`
192192
Destination ClickPipeDestination `json:"destination"`
193193
FieldMappings []ClickPipeFieldMapping `json:"fieldMappings"`
194-
Settings map[string]interface{} `json:"settings,omitempty"`
194+
Settings map[string]any `json:"settings,omitempty"`
195195
CreatedAt *time.Time `json:"createdAt,omitempty"`
196196
UpdatedAt *time.Time `json:"updatedAt,omitempty"`
197197
}
@@ -201,5 +201,5 @@ type ClickPipeUpdate struct {
201201
Source *ClickPipeSource `json:"source,omitempty"`
202202
Destination *ClickPipeDestinationUpdate `json:"destination,omitempty"`
203203
FieldMappings []ClickPipeFieldMapping `json:"fieldMappings,omitempty"`
204-
Settings map[string]interface{} `json:"settings,omitempty"`
204+
Settings map[string]any `json:"settings,omitempty"`
205205
}

pkg/internal/api/interface.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ type Client interface {
3232
ScalingClickPipe(ctx context.Context, serviceId string, clickPipeId string, request ClickPipeScalingRequest) (*ClickPipe, error)
3333
ChangeClickPipeState(ctx context.Context, serviceId string, clickPipeId string, command string) (*ClickPipe, error)
3434
DeleteClickPipe(ctx context.Context, serviceId string, clickPipeId string) error
35-
GetClickPipeSettings(ctx context.Context, serviceId string, clickPipeId string) (map[string]interface{}, error)
36-
UpdateClickPipeSettings(ctx context.Context, serviceId string, clickPipeId string, settings map[string]interface{}) (map[string]interface{}, error)
35+
GetClickPipeSettings(ctx context.Context, serviceId string, clickPipeId string) (map[string]any, error)
36+
UpdateClickPipeSettings(ctx context.Context, serviceId string, clickPipeId string, settings map[string]any) (map[string]any, error)
3737

3838
GetReversePrivateEndpointPath(serviceId, reversePrivateEndpointId string) string
3939
ListReversePrivateEndpoints(ctx context.Context, serviceId string) ([]*ReversePrivateEndpoint, error)

pkg/resource/clickpipe.go

Lines changed: 43 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ func (c *ClickPipeResource) Schema(_ context.Context, _ resource.SchemaRequest,
130130
},
131131
},
132132
Optional: true,
133-
Computed: true,
134133
},
135134
"state": schema.StringAttribute{
136135
MarkdownDescription: "The desired state of the ClickPipe. (`Running`, `Stopped`). Default is `Running`.",
@@ -771,48 +770,34 @@ func (c *ClickPipeResource) Create(ctx context.Context, request resource.CreateR
771770

772771
// Handle settings
773772
if !plan.Settings.IsNull() && !plan.Settings.IsUnknown() {
774-
settingsMap := make(map[string]interface{})
773+
settingsMap := make(map[string]any)
775774
underlyingValue := plan.Settings.UnderlyingValue()
776775

777776
// Settings should be an object/map at the top level
778777
if objValue, ok := underlyingValue.(types.Object); ok {
779778
for key, value := range objValue.Attributes() {
779+
var actualValue attr.Value
780780
if dynamicValue, ok := value.(types.Dynamic); ok {
781-
innerValue := dynamicValue.UnderlyingValue()
782-
switch v := innerValue.(type) {
783-
case types.String:
784-
settingsMap[key] = v.ValueString()
785-
case types.Bool:
786-
settingsMap[key] = v.ValueBool()
787-
case types.Number:
788-
if intVal, accuracy := v.ValueBigFloat().Int64(); accuracy == big.Exact {
789-
settingsMap[key] = intVal
790-
} else if floatVal, accuracy := v.ValueBigFloat().Float64(); accuracy == big.Exact {
791-
settingsMap[key] = floatVal
792-
} else {
793-
settingsMap[key] = v.ValueBigFloat().String()
794-
}
795-
default:
796-
settingsMap[key] = fmt.Sprintf("%v", v)
797-
}
781+
actualValue = dynamicValue.UnderlyingValue()
798782
} else {
799-
// Handle direct values
800-
switch v := value.(type) {
801-
case types.String:
802-
settingsMap[key] = v.ValueString()
803-
case types.Bool:
804-
settingsMap[key] = v.ValueBool()
805-
case types.Number:
806-
if intVal, accuracy := v.ValueBigFloat().Int64(); accuracy == big.Exact {
807-
settingsMap[key] = intVal
808-
} else if floatVal, accuracy := v.ValueBigFloat().Float64(); accuracy == big.Exact {
809-
settingsMap[key] = floatVal
810-
} else {
811-
settingsMap[key] = v.ValueBigFloat().String()
812-
}
813-
default:
814-
settingsMap[key] = fmt.Sprintf("%v", v)
783+
actualValue = value
784+
}
785+
786+
switch v := actualValue.(type) {
787+
case types.String:
788+
settingsMap[key] = v.ValueString()
789+
case types.Bool:
790+
settingsMap[key] = v.ValueBool()
791+
case types.Number:
792+
if intVal, accuracy := v.ValueBigFloat().Int64(); accuracy == big.Exact {
793+
settingsMap[key] = intVal
794+
} else if floatVal, accuracy := v.ValueBigFloat().Float64(); accuracy == big.Exact {
795+
settingsMap[key] = floatVal
796+
} else {
797+
settingsMap[key] = v.ValueBigFloat().String()
815798
}
799+
default:
800+
settingsMap[key] = fmt.Sprintf("%v", v)
816801
}
817802
}
818803
}
@@ -1172,7 +1157,8 @@ func (c *ClickPipeResource) syncClickPipeState(ctx context.Context, state *model
11721157

11731158
state.State = types.StringValue(clickPipe.State)
11741159

1175-
if clickPipe.Scaling != nil {
1160+
// Only sync scaling if it was configured (not null)
1161+
if !state.Scaling.IsNull() && clickPipe.Scaling != nil {
11761162
cpuMillicores := clickPipe.Scaling.GetCpuMillicores()
11771163
memoryGb := clickPipe.Scaling.GetMemoryGb()
11781164

@@ -1206,8 +1192,6 @@ func (c *ClickPipeResource) syncClickPipeState(ctx context.Context, state *model
12061192
}
12071193

12081194
state.Scaling = scalingModel.ObjectValue()
1209-
} else {
1210-
state.Scaling = types.ObjectNull(models.ClickPipeScalingModel{}.ObjectType().AttrTypes)
12111195
}
12121196

12131197
stateSourceModel := models.ClickPipeSourceModel{}
@@ -1602,53 +1586,39 @@ func (c *ClickPipeResource) Update(ctx context.Context, req resource.UpdateReque
16021586

16031587
// Handle settings separately using dedicated endpoint
16041588
var settingsChanged bool
1605-
var newSettingsMap map[string]interface{}
1589+
var newSettingsMap map[string]any
16061590

16071591
if !plan.Settings.Equal(state.Settings) {
16081592
settingsChanged = true
1609-
newSettingsMap = make(map[string]interface{})
1593+
newSettingsMap = make(map[string]any)
16101594
if !plan.Settings.IsNull() && !plan.Settings.IsUnknown() {
16111595
underlyingValue := plan.Settings.UnderlyingValue()
16121596

16131597
// Settings should be an object/map at the top level
16141598
if objValue, ok := underlyingValue.(types.Object); ok {
16151599
for key, value := range objValue.Attributes() {
1600+
var actualValue attr.Value
16161601
if dynamicValue, ok := value.(types.Dynamic); ok {
1617-
innerValue := dynamicValue.UnderlyingValue()
1618-
switch v := innerValue.(type) {
1619-
case types.String:
1620-
newSettingsMap[key] = v.ValueString()
1621-
case types.Bool:
1622-
newSettingsMap[key] = v.ValueBool()
1623-
case types.Number:
1624-
if intVal, accuracy := v.ValueBigFloat().Int64(); accuracy == big.Exact {
1625-
newSettingsMap[key] = intVal
1626-
} else if floatVal, accuracy := v.ValueBigFloat().Float64(); accuracy == big.Exact {
1627-
newSettingsMap[key] = floatVal
1628-
} else {
1629-
newSettingsMap[key] = v.ValueBigFloat().String()
1630-
}
1631-
default:
1632-
newSettingsMap[key] = fmt.Sprintf("%v", v)
1633-
}
1602+
actualValue = dynamicValue.UnderlyingValue()
16341603
} else {
1635-
// Handle direct values
1636-
switch v := value.(type) {
1637-
case types.String:
1638-
newSettingsMap[key] = v.ValueString()
1639-
case types.Bool:
1640-
newSettingsMap[key] = v.ValueBool()
1641-
case types.Number:
1642-
if intVal, accuracy := v.ValueBigFloat().Int64(); accuracy == big.Exact {
1643-
newSettingsMap[key] = intVal
1644-
} else if floatVal, accuracy := v.ValueBigFloat().Float64(); accuracy == big.Exact {
1645-
newSettingsMap[key] = floatVal
1646-
} else {
1647-
newSettingsMap[key] = v.ValueBigFloat().String()
1648-
}
1649-
default:
1650-
newSettingsMap[key] = fmt.Sprintf("%v", v)
1604+
actualValue = value
1605+
}
1606+
1607+
switch v := actualValue.(type) {
1608+
case types.String:
1609+
newSettingsMap[key] = v.ValueString()
1610+
case types.Bool:
1611+
newSettingsMap[key] = v.ValueBool()
1612+
case types.Number:
1613+
if intVal, accuracy := v.ValueBigFloat().Int64(); accuracy == big.Exact {
1614+
newSettingsMap[key] = intVal
1615+
} else if floatVal, accuracy := v.ValueBigFloat().Float64(); accuracy == big.Exact {
1616+
newSettingsMap[key] = floatVal
1617+
} else {
1618+
newSettingsMap[key] = v.ValueBigFloat().String()
16511619
}
1620+
default:
1621+
newSettingsMap[key] = fmt.Sprintf("%v", v)
16521622
}
16531623
}
16541624
}

0 commit comments

Comments
 (0)