@@ -12,11 +12,6 @@ import (
1212 "github.com/splunk/vault-plugin-splunk/clients/splunk"
1313)
1414
15- const (
16- SEARCHHEAD = "search_head"
17- INDEXER = "indexer"
18- )
19-
2015func (b * backend ) pathCredsCreate () * framework.Path {
2116 return & framework.Path {
2217 Pattern : "creds/" + framework .GenericNameRegex ("name" ),
@@ -129,20 +124,23 @@ func (b *backend) credsReadHandlerStandalone(ctx context.Context, req *logical.R
129124 return resp , nil
130125}
131126
132- func findNode (nodeFQDN string , hosts []splunk.ServerInfoEntry ) (bool , error ) {
127+ func findNode (nodeFQDN string , hosts []splunk.ServerInfoEntry , roleConfig * roleConfig ) (bool , error ) {
133128 for _ , host := range hosts {
134129 // check if node_fqdn is in either of HostFQDN or Host. User might not always the FQDN on the cli input
135130 if host .Content .HostFQDN == nodeFQDN || host .Content .Host == nodeFQDN {
136- // Return true if the requested node is a search head
131+ // Return true if the requested node type is allowed
132+ if strutil .StrListContains (roleConfig .AllowedNodeTypes , "*" ) {
133+ return true , nil
134+ }
137135 for _ , role := range host .Content .Roles {
138- if role == SEARCHHEAD {
136+ if strutil . StrListContainsGlob ( roleConfig . AllowedNodeTypes , role ) {
139137 return true , nil
140138 }
141139 }
142- return false , fmt .Errorf ("host: %s isn't search head; creating ephemeral creds is only supported for search heads " , nodeFQDN )
140+ return false , fmt .Errorf ("host %q does not have an allowed node type " , nodeFQDN )
143141 }
144142 }
145- return false , fmt .Errorf ("host: %s not found" , nodeFQDN )
143+ return false , fmt .Errorf ("host %q not found" , nodeFQDN )
146144}
147145
148146func (b * backend ) credsReadHandlerMulti (ctx context.Context , req * logical.Request , d * framework.FieldData ) (* logical.Response , error ) {
@@ -181,7 +179,7 @@ func (b *backend) credsReadHandlerMulti(ctx context.Context, req *logical.Reques
181179 b .Logger ().Error ("Error while reading SearchPeers from cluster master" , err )
182180 return nil , errwrap .Wrapf ("unable to read searchpeers from cluster master: {{err}}" , err )
183181 }
184- _ , err = findNode (nodeFQDN , nodes )
182+ _ , err = findNode (nodeFQDN , nodes , role )
185183 if err != nil {
186184 return nil , err
187185 }
@@ -207,7 +205,6 @@ func (b *backend) credsReadHandlerMulti(ctx context.Context, req *logical.Reques
207205 if err != nil {
208206 return nil , errwrap .Wrapf ("error generating new password: {{err}}" , err )
209207 }
210- conn .Params ().BaseURL = nodeFQDN
211208 opts := splunk.CreateUserOptions {
212209 Name : username ,
213210 Password : passwd ,
0 commit comments