@@ -118,30 +118,31 @@ func (b *backend) credsReadHandlerStandalone(ctx context.Context, req *logical.R
118118 "username" : username ,
119119 "role" : name ,
120120 "connection" : role .Connection ,
121+ "url" : conn .Params ().BaseURL , // new in v0.7.0
121122 })
122123 resp .Secret .TTL = role .DefaultTTL
123124 resp .Secret .MaxTTL = role .MaxTTL
124125
125126 return resp , nil
126127}
127128
128- func findNode (nodeFQDN string , hosts []splunk.ServerInfoEntry , roleConfig * roleConfig ) (bool , error ) {
129+ func findNode (nodeFQDN string , hosts []splunk.ServerInfoEntry , roleConfig * roleConfig ) (* splunk. ServerInfoEntry , error ) {
129130 for _ , host := range hosts {
130131 // check if node_fqdn is in either of HostFQDN or Host. User might not always the FQDN on the cli input
131132 if strings .EqualFold (host .Content .HostFQDN , nodeFQDN ) || strings .EqualFold (host .Content .Host , nodeFQDN ) {
132- // Return true if the requested node type is allowed
133+ // Return host if the requested node type is allowed
133134 if strutil .StrListContains (roleConfig .AllowedServerRoles , "*" ) {
134- return true , nil
135+ return & host , nil
135136 }
136137 for _ , role := range host .Content .Roles {
137138 if strutil .StrListContainsGlob (roleConfig .AllowedServerRoles , role ) {
138- return true , nil
139+ return & host , nil
139140 }
140141 }
141- return false , fmt .Errorf ("host %q does not have any of the allowed server roles: %q" , nodeFQDN , roleConfig .AllowedServerRoles )
142+ return nil , fmt .Errorf ("host %q does not have any of the allowed server roles: %q" , nodeFQDN , roleConfig .AllowedServerRoles )
142143 }
143144 }
144- return false , fmt .Errorf ("host %q not found" , nodeFQDN )
145+ return nil , fmt .Errorf ("host %q not found" , nodeFQDN )
145146}
146147
147148func (b * backend ) credsReadHandlerMulti (ctx context.Context , req * logical.Request , d * framework.FieldData ) (* logical.Response , error ) {
@@ -181,15 +182,17 @@ func (b *backend) credsReadHandlerMulti(ctx context.Context, req *logical.Reques
181182 return nil , errwrap .Wrapf ("unable to read searchpeers from cluster master: {{err}}" , err )
182183 }
183184
184- _ , err = findNode (nodeFQDN , nodes , role )
185+ foundNode , err : = findNode (nodeFQDN , nodes , role )
185186 if err != nil {
186187 return nil , err
187188 }
189+ if foundNode .Content .Host == "" {
190+ return nil , fmt .Errorf ("host field unexpectedly empty for %q" , nodeFQDN )
191+ }
192+ nodeFQDN = foundNode .Content .Host // the actual FQDN as returned by the cluster master, confusingly
188193
189194 // Re-create connection for node
190- config .URL = "https://" + nodeFQDN + ":8089"
191- // XXX config.ID = ""
192- conn , err = config .newConnection (ctx ) // XXX cache
195+ conn , err = b .ensureNodeConnection (ctx , config , nodeFQDN )
193196 if err != nil {
194197 return nil , err
195198 }
@@ -232,6 +235,7 @@ func (b *backend) credsReadHandlerMulti(ctx context.Context, req *logical.Reques
232235 "role" : name ,
233236 "connection" : role .Connection ,
234237 "node_fqdn" : nodeFQDN ,
238+ "url" : conn .Params ().BaseURL , // new in v0.7.0
235239 })
236240 resp .Secret .TTL = role .DefaultTTL
237241 resp .Secret .MaxTTL = role .MaxTTL
0 commit comments