mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
[kbn/es] retry fetching native realm users (#66511)
This commit is contained in:
parent
523e0e2264
commit
77a89c2c3b
1 changed files with 13 additions and 16 deletions
|
@ -76,10 +76,6 @@ exports.NativeRealm = class NativeRealm {
|
|||
}
|
||||
|
||||
const reservedUsers = await this.getReservedUsers();
|
||||
if (!reservedUsers || reservedUsers.length < 1) {
|
||||
throw new Error('no reserved users found, unable to set native realm passwords');
|
||||
}
|
||||
|
||||
await Promise.all(
|
||||
reservedUsers.map(async user => {
|
||||
await this.setPassword(user, options[`password.${user}`]);
|
||||
|
@ -88,16 +84,18 @@ exports.NativeRealm = class NativeRealm {
|
|||
}
|
||||
|
||||
async getReservedUsers() {
|
||||
const users = await this._autoRetry(async () => {
|
||||
return await this._client.security.getUser();
|
||||
});
|
||||
return await this._autoRetry(async () => {
|
||||
const resp = await this._client.security.getUser();
|
||||
const usernames = Object.keys(resp.body).filter(
|
||||
user => resp.body[user].metadata._reserved === true
|
||||
);
|
||||
|
||||
return Object.keys(users.body).reduce((acc, user) => {
|
||||
if (users.body[user].metadata._reserved === true) {
|
||||
acc.push(user);
|
||||
if (!usernames?.length) {
|
||||
throw new Error('no reserved users found, unable to set native realm passwords');
|
||||
}
|
||||
return acc;
|
||||
}, []);
|
||||
|
||||
return usernames;
|
||||
});
|
||||
}
|
||||
|
||||
async isSecurityEnabled() {
|
||||
|
@ -125,10 +123,9 @@ exports.NativeRealm = class NativeRealm {
|
|||
throw error;
|
||||
}
|
||||
|
||||
this._log.warning(
|
||||
'assuming [elastic] user not available yet, waiting 1.5 seconds and trying again'
|
||||
);
|
||||
await new Promise(resolve => setTimeout(resolve, 1500));
|
||||
const sec = 1.5 * attempt;
|
||||
this._log.warning(`assuming ES isn't initialized completely, trying again in ${sec} seconds`);
|
||||
await new Promise(resolve => setTimeout(resolve, sec * 1000));
|
||||
return await this._autoRetry(fn, attempt + 1);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue