|
| 1 | +package client |
| 2 | + |
| 3 | +import ( |
| 4 | + "log" |
| 5 | + "net/http" |
| 6 | + "net/http/httputil" |
| 7 | + |
| 8 | + "github.com/google/go-querystring/query" |
| 9 | + "github.com/splunk/terraform-provider-splunk/client/models" |
| 10 | +) |
| 11 | + |
| 12 | +func (client *Client) CreateLookupDefinitionObject(owner string, app string, splunkLookupDefObj *models.SplunkLookupDefinitionObject) error { |
| 13 | + values, err := query.Values(&splunkLookupDefObj) |
| 14 | + if err != nil { |
| 15 | + return err |
| 16 | + } |
| 17 | + endpoint := client.BuildSplunkURL(nil, "servicesNS", owner, app, "data", "transforms", "lookups") |
| 18 | + resp, err := client.Post(endpoint, values) |
| 19 | + if err != nil { |
| 20 | + return err |
| 21 | + } |
| 22 | + defer resp.Body.Close() |
| 23 | + |
| 24 | + respBody, error := httputil.DumpResponse(resp, true) |
| 25 | + if error != nil { |
| 26 | + log.Printf("[ERROR] Error occured during CreateLookupDefinition %s", error) |
| 27 | + } |
| 28 | + |
| 29 | + log.Printf("[DEBUG] Response object returned from CreateLookupDefinition is: %s", string(respBody)) |
| 30 | + return nil |
| 31 | +} |
| 32 | + |
| 33 | +func (client *Client) ReadLookupDefinitionObject(name, owner, app string) (*http.Response, error) { |
| 34 | + endpoint := client.BuildSplunkURL(nil, "servicesNS", owner, app, "data", "transforms", "lookups", name) |
| 35 | + resp, err := client.Get(endpoint) |
| 36 | + requestBody, _ := httputil.DumpRequest(resp.Request, true) |
| 37 | + if err != nil { |
| 38 | + log.Printf("[ERROR] Error occured during ReadLookupDefinitionObject %s", string(requestBody)) |
| 39 | + return nil, err |
| 40 | + } |
| 41 | + respBody, error := httputil.DumpResponse(resp, true) |
| 42 | + if error != nil { |
| 43 | + log.Printf("[ERROR] Error occured during ReadLookupDefinitionObject %s", error) |
| 44 | + } |
| 45 | + |
| 46 | + log.Printf("[DEBUG] Request object returned from ReadLookupDefinitionObject is: %s", string(requestBody)) |
| 47 | + log.Printf("[DEBUG] Response object returned from ReadLookupDefinitionObject is: %s", string(respBody)) |
| 48 | + |
| 49 | + return resp, nil |
| 50 | +} |
| 51 | + |
| 52 | +func (client *Client) UpdateLookupDefinitionObject(owner string, app string, name string, splunkLookupDefObj *models.SplunkLookupDefinitionObject) error { |
| 53 | + values, err := query.Values(&splunkLookupDefObj) |
| 54 | + values.Del("name") |
| 55 | + if err != nil { |
| 56 | + return err |
| 57 | + } |
| 58 | + endpoint := client.BuildSplunkURL(nil, "servicesNS", owner, app, "data", "transforms", "lookups", name) |
| 59 | + resp, err := client.Post(endpoint, values) |
| 60 | + if err != nil { |
| 61 | + return err |
| 62 | + } |
| 63 | + respBody, error := httputil.DumpResponse(resp, true) |
| 64 | + if error != nil { |
| 65 | + log.Printf("[ERROR] Error occured during UpdateLookupDefinitionObject %s", error) |
| 66 | + } |
| 67 | + |
| 68 | + log.Printf("[DEBUG] Response object returned from UpdateLookupDefinitionObject is: %s", string(respBody)) |
| 69 | + |
| 70 | + defer resp.Body.Close() |
| 71 | + |
| 72 | + return nil |
| 73 | +} |
| 74 | + |
| 75 | +func (client *Client) DeleteLookupDefinitionObject(owner string, app string, name string) (*http.Response, error) { |
| 76 | + endpoint := client.BuildSplunkURL(nil, "servicesNS", owner, app, "data", "transforms", "lookups", name) |
| 77 | + resp, err := client.Delete(endpoint) |
| 78 | + if err != nil { |
| 79 | + return nil, err |
| 80 | + } |
| 81 | + respBody, error := httputil.DumpResponse(resp, true) |
| 82 | + if error != nil { |
| 83 | + log.Printf("[ERROR] Error occured during DeleteLookupDefinitionObject %s", error) |
| 84 | + } |
| 85 | + |
| 86 | + log.Printf("[DEBUG] Response object returned from DeleteLookupDefinitionObject is: %s", string(respBody)) |
| 87 | + |
| 88 | + defer resp.Body.Close() |
| 89 | + |
| 90 | + return resp, nil |
| 91 | +} |
0 commit comments