@@ -118,30 +118,31 @@ func (b *backend) credsReadHandlerStandalone(ctx context.Context, req *logical.R
118
118
"username" : username ,
119
119
"role" : name ,
120
120
"connection" : role .Connection ,
121
+ "url" : conn .Params ().BaseURL , // new in v0.7.0
121
122
})
122
123
resp .Secret .TTL = role .DefaultTTL
123
124
resp .Secret .MaxTTL = role .MaxTTL
124
125
125
126
return resp , nil
126
127
}
127
128
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 ) {
129
130
for _ , host := range hosts {
130
131
// check if node_fqdn is in either of HostFQDN or Host. User might not always the FQDN on the cli input
131
132
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
133
134
if strutil .StrListContains (roleConfig .AllowedServerRoles , "*" ) {
134
- return true , nil
135
+ return & host , nil
135
136
}
136
137
for _ , role := range host .Content .Roles {
137
138
if strutil .StrListContainsGlob (roleConfig .AllowedServerRoles , role ) {
138
- return true , nil
139
+ return & host , nil
139
140
}
140
141
}
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 )
142
143
}
143
144
}
144
- return false , fmt .Errorf ("host %q not found" , nodeFQDN )
145
+ return nil , fmt .Errorf ("host %q not found" , nodeFQDN )
145
146
}
146
147
147
148
func (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
181
182
return nil , errwrap .Wrapf ("unable to read searchpeers from cluster master: {{err}}" , err )
182
183
}
183
184
184
- _ , err = findNode (nodeFQDN , nodes , role )
185
+ foundNode , err : = findNode (nodeFQDN , nodes , role )
185
186
if err != nil {
186
187
return nil , err
187
188
}
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
188
193
189
194
// 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 )
193
196
if err != nil {
194
197
return nil , err
195
198
}
@@ -232,6 +235,7 @@ func (b *backend) credsReadHandlerMulti(ctx context.Context, req *logical.Reques
232
235
"role" : name ,
233
236
"connection" : role .Connection ,
234
237
"node_fqdn" : nodeFQDN ,
238
+ "url" : conn .Params ().BaseURL , // new in v0.7.0
235
239
})
236
240
resp .Secret .TTL = role .DefaultTTL
237
241
resp .Secret .MaxTTL = role .MaxTTL
0 commit comments