Skip to content

Commit 39cc576

Browse files
authored
Fix UCI type for wireless.wifi-device
This typo is everything that's wrong with UCI. There's no consistency in the naming scheme. And, there's nothing stopping you from using the incorrect UCI type. Nothing failed for any of the tests here because at its core, UCI allows basically any config to have any name with any section with any options. It's way too lenient, and it means that you have to be extra careful whenever you're using it directly (like we're doing here). If there's a way to accurately test that we're using the correct thing, we should switch to it. But, it's not clear how we'd actually catch a mistake like this. In any case, we fix this typo, so a `wireless.wifi-device` can actually be created now. Branch: joneshf/fix-uci-type-for-wireless-wifi-device Pull-Request: #124
1 parent 9503ae6 commit 39cc576

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

openwrt/internal/lucirpcglue/data_source.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package lucirpcglue
33
import (
44
"context"
55
"fmt"
6+
"strings"
67

78
"github.com/hashicorp/terraform-plugin-framework/datasource"
89
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
@@ -133,5 +134,7 @@ func (d *dataSource[Model]) Schema(
133134
func (d dataSource[Model]) getFullTypeName(
134135
providerTypeName string,
135136
) string {
136-
return fmt.Sprintf("%s_%s_%s", providerTypeName, d.uciConfig, d.uciType)
137+
uciConfig := strings.ReplaceAll(d.uciConfig, "-", "_")
138+
uciType := strings.ReplaceAll(d.uciType, "-", "_")
139+
return fmt.Sprintf("%s_%s_%s", providerTypeName, uciConfig, uciType)
137140
}

openwrt/internal/lucirpcglue/resource.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package lucirpcglue
33
import (
44
"context"
55
"fmt"
6+
"strings"
67

78
"github.com/hashicorp/terraform-plugin-framework/path"
89
frameworkresource "github.com/hashicorp/terraform-plugin-framework/resource"
@@ -307,5 +308,7 @@ func (d *resource[Model]) Update(
307308
func (d resource[Model]) getFullTypeName(
308309
providerTypeName string,
309310
) string {
310-
return fmt.Sprintf("%s_%s_%s", providerTypeName, d.uciConfig, d.uciType)
311+
uciConfig := strings.ReplaceAll(d.uciConfig, "-", "_")
312+
uciType := strings.ReplaceAll(d.uciType, "-", "_")
313+
return fmt.Sprintf("%s_%s_%s", providerTypeName, uciConfig, uciType)
311314
}

openwrt/wireless/wifidevice/wifi_device.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ const (
6565
typeUCIOption = "type"
6666

6767
uciConfig = "wireless"
68-
uciType = "wifi_device"
68+
uciType = "wifi-device"
6969
)
7070

7171
var (

0 commit comments

Comments
 (0)