Skip to content

Add URL support to data_view field_formats #812

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/resources/kibana_data_view.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ Optional:

Optional:

- `labeltemplate` (String)
- `pattern` (String)
- `urltemplate` (String)



Expand Down
27 changes: 23 additions & 4 deletions internal/kibana/data_view/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ func getSchema() schema.Schema {
"pattern": schema.StringAttribute{
Optional: true,
},
"urltemplate": schema.StringAttribute{
Optional: true,
},
"labeltemplate": schema.StringAttribute{
Optional: true,
},
},
},
},
Expand Down Expand Up @@ -334,8 +340,15 @@ func dataViewFromResponse(resp data_views.DataViewResponseObjectDataView) apiDat

if params, ok := formatMap["params"]; ok {
if paramsMap, ok := params.(map[string]interface{}); ok {
apiFormat.Params = &apiFieldFormatParams{}
if pattern, ok := paramsMap["pattern"]; ok {
apiFormat.Params = &apiFieldFormatParams{Pattern: pattern.(string)}
apiFormat.Params.Pattern = utils.Pointer(pattern.(string))
}
if urltemplate, ok := paramsMap["urlTemplate"]; ok {
apiFormat.Params.UrlTemplate = utils.Pointer(urltemplate.(string))
}
if labeltemplate, ok := paramsMap["labelTemplate"]; ok {
apiFormat.Params.LabelTemplate = utils.Pointer(labeltemplate.(string))
}
}
}
Expand Down Expand Up @@ -600,7 +613,9 @@ func tfFieldFormatsToAPI(ctx context.Context, fieldFormats types.Map) (map[strin
}

apiParams = &apiFieldFormatParams{
Pattern: tfParams.Pattern.ValueString(),
Pattern: tfParams.Pattern.ValueStringPointer(),
UrlTemplate: tfParams.UrlTemplate.ValueStringPointer(),
LabelTemplate: tfParams.LabelTemplate.ValueStringPointer(),
}
}

Expand Down Expand Up @@ -658,9 +673,13 @@ type apiFieldFormat struct {
}

type tfFieldFormatParamsV0 struct {
Pattern types.String `tfsdk:"pattern"`
Pattern types.String `tfsdk:"pattern"`
UrlTemplate types.String `tfsdk:"urltemplate"`
LabelTemplate types.String `tfsdk:"labeltemplate"`
}

type apiFieldFormatParams struct {
Pattern string `tfsdk:"pattern" json:"pattern"`
Pattern *string `tfsdk:"pattern" json:"pattern,omitempty"`
UrlTemplate *string `tfsdk:"urltemplate" json:"urlTemplate,omitempty"`
LabelTemplate *string `tfsdk:"labeltemplate" json:"labelTemplate,omitempty"`
}
16 changes: 12 additions & 4 deletions internal/kibana/data_view/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ func Test_tfModelV0_ToCreateRequest(t *testing.T) {
"field1": {
ID: "field1",
Params: &apiFieldFormatParams{
Pattern: "0.00",
Pattern: utils.Pointer("0.00"),
UrlTemplate: utils.Pointer("https://test.com/{{value}}"),
LabelTemplate: utils.Pointer("{{value}}"),
},
},
},
Expand All @@ -66,7 +68,9 @@ func Test_tfModelV0_ToCreateRequest(t *testing.T) {
"field1": apiFieldFormat{
ID: "field1",
Params: &apiFieldFormatParams{
Pattern: "0.00",
Pattern: utils.Pointer("0.00"),
UrlTemplate: utils.Pointer("https://test.com/{{value}}"),
LabelTemplate: utils.Pointer("{{value}}"),
},
},
},
Expand Down Expand Up @@ -161,7 +165,9 @@ func Test_tfModelV0_ToUpdateRequest(t *testing.T) {
"field1": {
ID: "field1",
Params: &apiFieldFormatParams{
Pattern: "0.00",
Pattern: utils.Pointer("0.00"),
UrlTemplate: utils.Pointer("https://test.com/{{value}}"),
LabelTemplate: utils.Pointer("{{value}}"),
},
},
},
Expand All @@ -176,7 +182,9 @@ func Test_tfModelV0_ToUpdateRequest(t *testing.T) {
"field1": apiFieldFormat{
ID: "field1",
Params: &apiFieldFormatParams{
Pattern: "0.00",
Pattern: utils.Pointer("0.00"),
UrlTemplate: utils.Pointer("https://test.com/{{value}}"),
LabelTemplate: utils.Pointer("{{value}}"),
},
},
},
Expand Down
Loading