Skip to content

Commit

Permalink
[Fleet] Fix api key creation
Browse files Browse the repository at this point in the history
  • Loading branch information
nchaulet committed Jan 13, 2020
1 parent 08d1df5 commit 030a249
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
4 changes: 0 additions & 4 deletions x-pack/legacy/plugins/fleet/server/libs/policy_update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ export function makePolicyUpdateHandler(libs: FleetServerLib) {
const internalUser = libs.framework.getInternalUser();

if (action === 'created') {
if (policyId === 'default') {
// TODO wait for #53111 to be fixed
return;
}
await libs.apiKeys.generateEnrollmentApiKey(internalUser, {
policyId,
});
Expand Down
41 changes: 23 additions & 18 deletions x-pack/legacy/plugins/ingest/server/libs/policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,24 +258,29 @@ export class PolicyLib {
if (info === null) {
throw new Error('Could not get version information about Kibana from xpack');
}
const newDefaultPolicy: StoredPolicy = {
name: 'Default policy',
description: 'Default policy created by Kibana',
status: Status.Active,
datasources: [],
updated_on: new Date().toISOString(),
updated_by: 'Fleet (system action)',
};

await this.adapter.create(this.libs.framework.internalUser, newDefaultPolicy, {
id: DEFAULT_POLICY_ID,
});

await this._triggerPolicyUpdatedEvent(
this.libs.framework.internalUser,
'created',
DEFAULT_POLICY_ID
);
try {
const newDefaultPolicy: StoredPolicy = {
name: 'Default policy',
description: 'Default policy created by Kibana',
status: Status.Active,
datasources: [],
updated_on: new Date().toISOString(),
updated_by: 'Fleet (system action)',
};

await this.adapter.create(this.libs.framework.internalUser, newDefaultPolicy, {
id: DEFAULT_POLICY_ID,
});

await this._triggerPolicyUpdatedEvent(
this.libs.framework.internalUser,
'created',
DEFAULT_POLICY_ID
);
} catch (err) {
// Log error but do not stop kbn to boot
this.libs.framework.log(err);
}
}
}

Expand Down

0 comments on commit 030a249

Please sign in to comment.