Skip to content

Commit

Permalink
Fix breaking changes
Browse files Browse the repository at this point in the history
  • Loading branch information
1riatsila1 committed Oct 9, 2024
1 parent 064dd84 commit bcee980
Show file tree
Hide file tree
Showing 18 changed files with 118 additions and 154 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,18 @@ func (d *networkGroupAssignmentDataSource) Read(ctx context.Context, req datasou
Uid(state.Filter.NetworkGroupAssignmentID)
networkGroupAssignmentResponse, _, err := util.RetryFor429(request.Execute)

if err != nil || len(networkGroupAssignmentResponse.NetworkGroupAssignments) != 1 {
if err != nil || len(networkGroupAssignmentResponse.Items) != 1 {
resp.Diagnostics.AddError(
"Error reading Network Group Assignment",
"Could not retrieve Network Group Assignment, unexpected error: "+err.Error(),
)
return
}

networkGroupAssignment := networkGroupAssignmentResponse.NetworkGroupAssignments[0]
state.ID = types.StringValue(networkGroupAssignment.Uid)
state.NetworkID = types.StringValue(networkGroupAssignment.NetworkUid)
state.GroupID = types.StringValue(networkGroupAssignment.GroupUid)
networkGroupAssignment := networkGroupAssignmentResponse.Items[0]
state.ID = types.StringValue(networkGroupAssignment.Id)
state.NetworkID = types.StringValue(networkGroupAssignment.Network.Id)
state.GroupID = types.StringValue(networkGroupAssignment.Group.Id)

diags = resp.State.Set(ctx, &state)
resp.Diagnostics.Append(diags...)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,18 @@ func (d *sensorGroupAssignmentDataSource) Read(ctx context.Context, req datasour
Uid(state.Filter.SensorGroupAssignmentID)
sensorGroupAssignmentResponse, _, err := util.RetryFor429(request.Execute)

if err != nil || len(sensorGroupAssignmentResponse.SensorGroupAssignments) != 1 {
if err != nil || len(sensorGroupAssignmentResponse.Items) != 1 {
resp.Diagnostics.AddError(
"Error reading Sensor Group Assignment",
"Could not retrieve Sensor Group Assignment, unexpected error: "+err.Error(),
)
return
}

sensorGroupAssignment := sensorGroupAssignmentResponse.SensorGroupAssignments[0]
state.ID = types.StringValue(sensorGroupAssignment.Uid)
state.SensorID = types.StringValue(sensorGroupAssignment.SensorUid)
state.GroupID = types.StringValue(sensorGroupAssignment.GroupUid)
sensorGroupAssignment := sensorGroupAssignmentResponse.Items[0]
state.ID = types.StringValue(sensorGroupAssignment.Id)
state.SensorID = types.StringValue(sensorGroupAssignment.Sensor.Id)
state.GroupID = types.StringValue(sensorGroupAssignment.Group.Id)

// Set state
diags = resp.State.Set(ctx, &state)
Expand Down
10 changes: 5 additions & 5 deletions pkg/config-api-provider/provider/data-sources/wired_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,24 +101,24 @@ func (d *wiredNetworkDataSource) Read(ctx context.Context, req datasource.ReadRe
Uid(state.Filter.WiredNetworkID)
networkResponse, _, err := util.RetryFor429(request.Execute)

if err != nil || len(networkResponse.WiredNetworks) != 1 {
if err != nil || len(networkResponse.Items) != 1 {
resp.Diagnostics.AddError(
"Error reading Wired Network",
"Could not retrieve Wired Network, unexpected error: "+err.Error(),
)
return
}

network := networkResponse.WiredNetworks[0]
state.ID = types.StringValue(network.Uid)
state.Alias = types.StringValue(network.Alias)
network := networkResponse.Items[0]
state.ID = types.StringValue(network.Id)
state.Alias = types.StringValue(network.Name)
state.IpVersion = types.StringValue(network.IpVersion)
state.Security = types.StringValue(*network.Security.Get())
state.DnsLookupDomain = types.StringValue(*network.DnsLookupDomain.Get())
state.DisableEdns = types.BoolValue(network.DisableEdns)
state.UseDns64 = types.BoolValue(network.UseDns64)
state.ExternalConnectivity = types.BoolValue(network.ExternalConnectivity)
state.VlanId = types.Int64Value(int64(*network.VlanId.Get()))
state.VlanId = types.Int64Value(int64(*network.VLanId.Get()))

// Set state
diags = resp.State.Set(ctx, &state)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,18 @@ func (d *wirelessNetworkDataSource) Read(ctx context.Context, req datasource.Rea
Uid(state.Filter.WirelessNetworkID)
networkResponse, _, err := util.RetryFor429(request.Execute)

if err != nil || len(networkResponse.WirelessNetworks) != 1 {
if err != nil || len(networkResponse.Items) != 1 {
resp.Diagnostics.AddError(
"Error reading Wireless Network",
"Could not retrieve Wireless Network, unexpected error: "+err.Error(),
)
return
}

network := networkResponse.WirelessNetworks[0]
state.ID = types.StringValue(network.Uid)
network := networkResponse.Items[0]
state.ID = types.StringValue(network.Id)
state.Ssid = types.StringValue(network.Ssid)
state.Alias = types.StringValue(network.Alias)
state.Alias = types.StringValue(network.Name)
state.IpVersion = types.StringValue(network.IpVersion)
state.Security = types.StringValue(*network.Security.Get())
state.Hidden = types.BoolValue(network.Hidden)
Expand Down
14 changes: 7 additions & 7 deletions pkg/config-api-provider/provider/resources/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ func (r *groupResource) Create(ctx context.Context, req resource.CreateRequest,
}

// Update the state to match the plan (replace with response from client)
plan.ID = types.StringValue(group.Uid)
plan.ID = types.StringValue(group.Id)
plan.Name = types.StringValue(group.Name)
plan.ParentGroupId = types.StringValue(group.ParentUid)
plan.ParentGroupId = types.StringValue(group.Parent.Id)

// Set state to fully populated data
diags = resp.State.Set(ctx, plan)
Expand Down Expand Up @@ -178,7 +178,7 @@ func (r *groupResource) Update(ctx context.Context, req resource.UpdateRequest,

// Update the state to match the plan (replace with response from client)
plan.Name = types.StringValue(group.Name)
plan.ParentGroupId = types.StringValue(group.ParentUid)
plan.ParentGroupId = types.StringValue(group.Parent.Id)

// Set state to fully populated data
diags = resp.State.Set(ctx, plan)
Expand Down Expand Up @@ -210,9 +210,9 @@ var UpdateGroup = func(request GroupUpdateRequestModel) config_api_client.Groups
parent_uid := "mock_parent_uid"

return config_api_client.GroupsPostResponse{
Uid: "mock_uid",
Name: "mock_name",
ParentUid: parent_uid,
Path: "mock_path",
Id: "mock_uid",
Name: "mock_name",
Parent: *config_api_client.NewParent(parent_uid),
Path: "mock_path",
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,18 +134,18 @@ func (r *networkGroupAssignmentResource) Read(ctx context.Context, req resource.
Uid(state.ID.ValueString())

networkGroupAssignmentResponse, _, err := util.RetryFor429(request.Execute)
if err != nil || len(networkGroupAssignmentResponse.NetworkGroupAssignments) != 1 {
if err != nil || len(networkGroupAssignmentResponse.Items) != 1 {
resp.Diagnostics.AddError(
"Error reading Network Group Assignment",
"Could not retrieve Network Group Assignment, unexpected error: "+err.Error(),
)
return
}
networkGroupAssignment := networkGroupAssignmentResponse.NetworkGroupAssignments[0]
networkGroupAssignment := networkGroupAssignmentResponse.Items[0]

// Update state from client response
state.GroupID = types.StringValue(networkGroupAssignment.GroupUid)
state.NetworkID = types.StringValue(networkGroupAssignment.NetworkUid)
state.GroupID = types.StringValue(networkGroupAssignment.Group.Id)
state.NetworkID = types.StringValue(networkGroupAssignment.Network.Id)

// Set refreshed state
diags = resp.State.Set(ctx, &state)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,19 +139,19 @@ func (r *sensorGroupAssignmentResource) Read(ctx context.Context, req resource.R
Uid(state.ID.ValueString())
sensorGroupAssignmentResponse, _, err := util.RetryFor429(request.Execute)

if err != nil || len(sensorGroupAssignmentResponse.SensorGroupAssignments) != 1 {
if err != nil || len(sensorGroupAssignmentResponse.Items) != 1 {
resp.Diagnostics.AddError(
"Error reading Sensor Group Assignment",
"Could not retrieve Sensor Group Assignment, unexpected error: "+err.Error(),
)
return
}

sensorGroupAssignment := sensorGroupAssignmentResponse.SensorGroupAssignments[0]
sensorGroupAssignment := sensorGroupAssignmentResponse.Items[0]

// Update state from client response
state.GroupID = types.StringValue(sensorGroupAssignment.GroupUid)
state.SensorID = types.StringValue(sensorGroupAssignment.SensorUid)
state.GroupID = types.StringValue(sensorGroupAssignment.Group.Id)
state.SensorID = types.StringValue(sensorGroupAssignment.Sensor.Id)

// Set refreshed state
diags = resp.State.Set(ctx, &state)
Expand Down
6 changes: 3 additions & 3 deletions pkg/config-api-provider/provider/resources/wired_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,18 @@ func (r *wiredNetworkResource) Read(ctx context.Context, req resource.ReadReques
Uid(state.ID.ValueString())
networkResponse, _, err := util.RetryFor429(request.Execute)

if err != nil || len(networkResponse.WiredNetworks) != 1 {
if err != nil || len(networkResponse.Items) != 1 {
resp.Diagnostics.AddError(
"Error reading Wired Network",
"Could not retrieve Wired Network, unexpected error: "+err.Error(),
)
return
}

network := networkResponse.WiredNetworks[0]
network := networkResponse.Items[0]

// Update state from client response
state.Alias = types.StringValue(network.Alias)
state.Alias = types.StringValue(network.Name)

// Set refreshed state
diags = resp.State.Set(ctx, &state)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,18 @@ func (r *wirelessNetworkResource) Read(ctx context.Context, req resource.ReadReq
Uid(state.ID.ValueString())
networkResponse, _, err := util.RetryFor429(request.Execute)

if err != nil || len(networkResponse.WirelessNetworks) != 1 {
if err != nil || len(networkResponse.Items) != 1 {
resp.Diagnostics.AddError(
"Error reading Wireless Networks",
"Could not retrieve Wireless Network, unexpected error: "+err.Error(),
)
return
}

network := networkResponse.WirelessNetworks[0]
network := networkResponse.Items[0]

// Update state from client response
state.Alias = types.StringValue(network.Alias)
state.Alias = types.StringValue(network.Name)

// Set refreshed state
diags = resp.State.Set(ctx, &state)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestNetworkGroupAssignmentDataSource(t *testing.T) {
PreConfig: func() {
util.MockGetNetworkGroupAssignment(
"uid",
util.GenerateNetworkGroupAssignmentPaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentGetResponse("uid", "")}),
util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentGetResponse("uid", "")}),
3,
)
},
Expand Down Expand Up @@ -67,7 +67,7 @@ func TestNetworkGroupAssignmentSource429Handling(t *testing.T) {
})
util.MockGetNetworkGroupAssignment(
"uid",
util.GenerateNetworkGroupAssignmentPaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentGetResponse("uid", "")}),
util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateNetworkGroupAssignmentGetResponse("uid", "")}),
3,
)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestSensorGroupAssignmentDataSource(t *testing.T) {
PreConfig: func() {
util.MockGetSensorGroupAssignment(
"uid",
util.GenerateSensorGroupAssignmentPaginatedResponse([]map[string]interface{}{util.GenerateSensorGroupAssignmentGetResponse("uid", "")}),
util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateSensorGroupAssignmentGetResponse("uid", "")}),
3,
)
},
Expand Down Expand Up @@ -67,7 +67,7 @@ func TestSensorGroupAssignmentSource429Handling(t *testing.T) {
})
util.MockGetSensorGroupAssignment(
"uid",
util.GenerateSensorGroupAssignmentPaginatedResponse([]map[string]interface{}{util.GenerateSensorGroupAssignmentGetResponse("uid", "")}),
util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateSensorGroupAssignmentGetResponse("uid", "")}),
3,
)
},
Expand Down
4 changes: 2 additions & 2 deletions pkg/config-api-provider/test/data-sources/wired_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestWiredNetworkDataSource(t *testing.T) {
PreConfig: func() {
util.MockGetWiredNetwork(
"uid",
util.GenerateWiredNetworkPaginatedResponse([]map[string]interface{}{util.GenerateWiredNetworkResponse("uid", "")}),
util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateWiredNetworkResponse("uid", "")}),
3,
)
},
Expand Down Expand Up @@ -74,7 +74,7 @@ func TestWiredNetworkDataSource429Handling(t *testing.T) {
})
util.MockGetWiredNetwork(
"uid",
util.GenerateWiredNetworkPaginatedResponse([]map[string]interface{}{util.GenerateWiredNetworkResponse("uid", "")}),
util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateWiredNetworkResponse("uid", "")}),
3,
)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestWirelessNetworkDataSource(t *testing.T) {
PreConfig: func() {
util.MockGetWirelessNetwork(
"uid",
util.GenerateWirelessNetworkPaginatedResponse([]map[string]interface{}{util.GenerateWirelessNetworkResponse("uid", "")}),
util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateWirelessNetworkResponse("uid", "")}),
3,
)
},
Expand Down Expand Up @@ -76,7 +76,7 @@ func TestWirelessNetworkDataSource429Handling(t *testing.T) {
})
util.MockGetWirelessNetwork(
"uid",
util.GenerateWirelessNetworkPaginatedResponse([]map[string]interface{}{util.GenerateWirelessNetworkResponse("uid", "")}),
util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateWirelessNetworkResponse("uid", "")}),
3,
)
},
Expand Down
Loading

0 comments on commit bcee980

Please sign in to comment.