Skip to content
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.4.35
* Fix: lookup_table_file - handle nil values in file_contents by converting to empty strings before JSON marshaling
* Fix: lookup_table_file - properly URL-encode form parameters in Create/Read/Update operations

## 1.4.34
* Support for Slack alert params in saved_Searches

Expand Down
22 changes: 18 additions & 4 deletions client/lookup_table_file.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package client

import (
"fmt"
"log"
"net/http"
"net/http/httputil"
"net/url"
)

func (client *Client) CreateLookupTableFile(name string, owner string, app string, contents string) error {
values := []byte(fmt.Sprintf("namespace=%s&lookup_file=%s&owner=%s&contents=%s", app, name, owner, contents))
values := []byte(url.Values{
"namespace": {app},
"lookup_file": {name},
"owner": {owner},
"contents": {contents},
}.Encode())
endpoint := client.BuildSplunkURL(nil, "services", "data", "lookup_edit", "lookup_contents")
client.urlEncoded = true
resp, err := client.Post(endpoint, values)
Expand All @@ -28,15 +33,24 @@ func (client *Client) CreateLookupTableFile(name string, owner string, app strin
}

func (client *Client) ReadLookupTableFile(name, owner, app string) (*http.Response, error) {
values := []byte(fmt.Sprintf("namespace=%s&lookup_file=%s&owner=%s", app, name, owner))
values := []byte(url.Values{
"namespace": {app},
"lookup_file": {name},
"owner": {owner},
}.Encode())
client.urlEncoded = true
endpoint := client.BuildSplunkURL(nil, "services", "data", "lookup_edit", "lookup_data")
resp, err := client.Post(endpoint, values)
return resp, err
}

func (client *Client) UpdateLookupTableFile(name string, owner string, app string, contents string) error {
values := []byte(fmt.Sprintf("namespace=%s&lookup_file=%s&owner=%s&contents=%s", app, name, owner, contents))
values := []byte(url.Values{
"namespace": {app},
"lookup_file": {name},
"owner": {owner},
"contents": {contents},
}.Encode())
endpoint := client.BuildSplunkURL(nil, "services", "data", "lookup_edit", "lookup_contents")
client.urlEncoded = true
resp, err := client.Post(endpoint, values)
Expand Down
15 changes: 14 additions & 1 deletion splunk/resource_splunk_lookup_table_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,20 @@ func lookupTableFileDelete(d *schema.ResourceData, meta interface{}) error {
}

func getLookupTableFile(d *schema.ResourceData) (lookupTableFile *models.LookupTableFile) {
fileContents, _ := json.Marshal(d.Get("file_contents"))
rawContents := d.Get("file_contents").([]interface{})
contents := make([][]string, len(rawContents))
for i, row := range rawContents {
rawRow := row.([]interface{})
contents[i] = make([]string, len(rawRow))
for j, val := range rawRow {
if val == nil {
contents[i][j] = ""
} else {
contents[i][j] = val.(string)
}
}
}
fileContents, _ := json.Marshal(contents)
lookupTableFile = &models.LookupTableFile{
App: d.Get("app").(string),
Owner: d.Get("owner").(string),
Expand Down
Loading