Skip to content
This repository was archived by the owner on Mar 15, 2024. It is now read-only.

Commit 60b216c

Browse files
author
Amey Bhide
committed
Add GetSearchPeers() method
This will be used for creating ephemeral users for multi-node Splunk deployments
1 parent ed05ac3 commit 60b216c

File tree

6 files changed

+31
-5
lines changed

6 files changed

+31
-5
lines changed

clients/splunk/deployment.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package splunk
2+
3+
// DeploymentService encapsulates the Deployment portion of the Splunk API
4+
type DeploymentService struct {
5+
client *Client
6+
}
7+
8+
func newDeploymentService(client *Client) *DeploymentService {
9+
return &DeploymentService{
10+
client: client,
11+
}
12+
}
13+
14+
// GetSearchPeers returns information about all search peers
15+
func (d *DeploymentService) GetSearchPeers() ([]ServerInfoEntry, *Response, error) {
16+
info := make([]ServerInfoEntry, 0)
17+
resp, err := Receive(d.client.New().Get("search/distributed/peers"), &info)
18+
return info, resp, err
19+
}

clients/splunk/properties.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ type Entry struct {
2929
// stringResponseDecoder decodes http response string
3030
// Properties API operates on particular key in the configuration file.
3131
// CRUD for properties API returns JSON/XML encoded response for error cases and returns a string response for success
32-
type stringResponseDecoder struct{
32+
type stringResponseDecoder struct {
3333
}
3434

35-
func getPropertiesUri(file string, stanza string, key string) (string) {
35+
func getPropertiesUri(file string, stanza string, key string) string {
3636
return fmt.Sprintf("properties/%s/%s/%s", url.PathEscape(file), url.PathEscape(stanza), url.PathEscape(key))
3737
}
3838

@@ -74,4 +74,4 @@ func (p *PropertiesService) GetKey(file string, stanza string, key string) (*str
7474
return nil, resp, relevantError(err, apiError)
7575
}
7676
return &output.Value, resp, relevantError(err, apiError)
77-
}
77+
}

clients/splunk/properties_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ func TestPropertiesService_GetKey(t *testing.T) {
1212
_, response, err := propertiesSvc.GetKey("foo", "bar", "key")
1313
assert.ErrorContains(t, err, "splunk: foo does not exist")
1414
assert.Equal(t, response.StatusCode, 404)
15-
_, response, err = propertiesSvc.GetKey("b/a/z","b-ar", "k-ey")
15+
_, response, err = propertiesSvc.GetKey("b/a/z", "b-ar", "k-ey")
1616
assert.ErrorContains(t, err, "ERROR splunk: Directory traversal risk in /nobody/system/b/a/z at segment \"b/a/z\"")
1717
assert.Equal(t, response.StatusCode, 403)
1818
_, response, err = propertiesSvc.GetKey("foo-bar", "b/a/z", "k-ey")
@@ -22,7 +22,6 @@ func TestPropertiesService_GetKey(t *testing.T) {
2222
assert.ErrorContains(t, err, "splunk: bar does not exist")
2323
assert.Equal(t, response.StatusCode, 404)
2424

25-
2625
_, response, _ = propertiesSvc.GetKey("server", "general", "pass4SymmKey")
2726
assert.Equal(t, response.StatusCode, 200)
2827

clients/splunk/splunk.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ type API struct {
2020
Introspection *IntrospectionService
2121
AccessControl *AccessControlService
2222
Properties *PropertiesService
23+
Deployment *DeploymentService
2324
// XXX ...
2425
}
2526

@@ -39,6 +40,7 @@ func (params *APIParams) NewAPI(ctx context.Context) *API {
3940
Introspection: newIntrospectionService(client.New()),
4041
AccessControl: newAccessControlService(client.New()),
4142
Properties: newPropertiesService(client.New()),
43+
Deployment: newDeploymentService(client.New()),
4244
}
4345
}
4446

conn.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ type splunkConfig struct {
3030
Username string `json:"username" structs:"username"`
3131
Password string `json:"password" structs:"password"`
3232
URL string `json:"url" structs:"url"`
33+
IsStandalone bool `json:"is_standalone" structs:"is_standalone"`
3334
AllowedRoles []string `json:"allowed_roles" structs:"allowed_roles"`
3435
Verify bool `json:"verify" structs:"verify"`
3536
InsecureTLS bool `json:"insecure_tls" structs:"insecure_tls"`

path_config_connection.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ func (b *backend) pathConfigConnection() *framework.Path {
3333
Type: framework.TypeString,
3434
Description: "Splunk server URL.",
3535
},
36+
"is_standalone": &framework.FieldSchema{
37+
Type: framework.TypeBool,
38+
Description: "Whether this is a standalone or multi-node deployment",
39+
Default: false,
40+
},
3641
"allowed_roles": &framework.FieldSchema{
3742
Type: framework.TypeCommaStringSlice,
3843
Description: trimIndent(`

0 commit comments

Comments
 (0)