Skip to content

Commit 52c50ba

Browse files
committed
Use new helpers for type casting
1 parent 924f1d7 commit 52c50ba

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

internal/kibana/security_list/models.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,11 @@ func (m *SecurityListModel) toUpdateRequest() (*kbapi.UpdateListJSONRequestBody,
112112
func (m *SecurityListModel) fromAPI(ctx context.Context, apiList *kbapi.SecurityListsAPIList) diag.Diagnostics {
113113
var diags diag.Diagnostics
114114

115-
m.ID = types.StringValue(string(apiList.Id))
116-
m.ListID = types.StringValue(string(apiList.Id))
117-
m.Name = types.StringValue(string(apiList.Name))
118-
m.Description = types.StringValue(string(apiList.Description))
119-
m.Type = types.StringValue(string(apiList.Type))
115+
m.ID = utils.StringishValue(apiList.Id)
116+
m.ListID = utils.StringishValue(apiList.Id)
117+
m.Name = utils.StringishValue(apiList.Name)
118+
m.Description = utils.StringishValue(apiList.Description)
119+
m.Type = utils.StringishValue(apiList.Type)
120120
m.Immutable = types.BoolValue(apiList.Immutable)
121121
m.Version = types.Int64Value(int64(apiList.Version))
122122
m.TieBreakerID = types.StringValue(apiList.TieBreakerId)
@@ -127,19 +127,19 @@ func (m *SecurityListModel) fromAPI(ctx context.Context, apiList *kbapi.Security
127127

128128
// Set optional _version field
129129
if apiList.UnderscoreVersion != nil {
130-
m.VersionID = types.StringValue(string(*apiList.UnderscoreVersion))
130+
m.VersionID = utils.StringishPointerValue(apiList.UnderscoreVersion)
131131
} else {
132132
m.VersionID = types.StringNull()
133133
}
134134

135135
if apiList.Deserializer != nil {
136-
m.Deserializer = types.StringValue(string(*apiList.Deserializer))
136+
m.Deserializer = utils.StringishPointerValue(apiList.Deserializer)
137137
} else {
138138
m.Deserializer = types.StringNull()
139139
}
140140

141141
if apiList.Serializer != nil {
142-
m.Serializer = types.StringValue(string(*apiList.Serializer))
142+
m.Serializer = utils.StringishPointerValue(apiList.Serializer)
143143
} else {
144144
m.Serializer = types.StringNull()
145145
}

internal/utils/utils.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,16 @@ func NonNilSlice[T any](s []T) []T {
231231
func TimeToStringValue(t time.Time) types.String {
232232
return types.StringValue(FormatStrictDateTime(t))
233233
}
234+
235+
// StringishPointerValue converts a pointer to a string-like type to a Terraform types.String value.
236+
func StringishPointerValue[T ~string](ptr *T) types.String {
237+
if ptr == nil {
238+
return types.StringNull()
239+
}
240+
return types.StringValue(string(*ptr))
241+
}
242+
243+
// StringishValue converts a value of any string-like type T to a Terraform types.String.
244+
func StringishValue[T ~string](value T) types.String {
245+
return types.StringValue(string(value))
246+
}

0 commit comments

Comments
 (0)