-
Notifications
You must be signed in to change notification settings - Fork 8.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EMT-248: add post action request handler and resources #60581
EMT-248: add post action request handler and resources #60581
Conversation
@elasticmachine merge upstream |
Pinging @elastic/ingest-management (Feature:EPM) |
…nnamdifrankie/kibana into EMT-248_add_post_action_request_handler
return async (context, request, response) => { | ||
const soClient = actionsService.getSavedObjectsClientContract(request); | ||
|
||
const res = APIKeyService.parseApiKey(request.headers); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This handler is not going to be consumed by the agent, but by kibana UI, we should not validate API key but rely on kibana authentication and use the builtin saved object client. (like the other crud actions we have in ingest manager)
{ | ||
path: AGENT_API_ROUTES.ACTIONS_PATTERN, | ||
validate: PostNewAgentActionRequestSchema, | ||
options: { tags: [] }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
options: { tags: [] }, | |
options: { tags: [`access:${PLUGIN_ID}-all`] }, |
@nnamdifrankie LGTM. One small question: Would there be a need for this API to accept an array of actions instead of just one? |
@paul-tavares perhaps no. Speaking with @nich07as I think we want one action at a time for now. |
|
||
Object.assign(agentAction, ...keys(newAgentAction).map(key => ({ [key]: newAgentAction[key] }))); | ||
|
||
return agentAction as AgentAction; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given the name/purpose of this function, I think it's important we don't lose the TS typing here.
I think we can keep it by doing something like
function createAgentAction(
createdAt: Date,
newAgentAction: NewAgentAction
): AgentAction {
const agentAction = { id: "uuid value", created_at: createdAt.toISOString() };
return Object.assign(agentAction, newAgentAction);
}
@@ -22,6 +22,8 @@ export interface AgentAction extends SavedObjectAttributes { | |||
sent_at?: string; | |||
} | |||
|
|||
export type NewAgentAction = Pick<AgentAction, 'type' | 'data' | 'sent_at'>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should follow the pattern used by AgentBase
/Agent
in this file and do something like
export interface NewAgentAction {
type: 'CONFIG_CHANGE' | 'DATA_DUMP' | 'RESUME' | 'PAUSE';
data?: string;
sent_at?: string;
}
export interface AgentAction extends NewAgentAction {
id: string;
created_at: string;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay will make this change, was limiting the changes to existing structures.
return agentAction as AgentAction; | ||
} | ||
|
||
function keys<O extends object>(obj: O): Array<keyof O> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we can drop this if we alter the way createAgentAction
uses Object.assign
}, | ||
postNewAgentActionHandlerBuilder({ | ||
getAgent: AgentService.getAgent, | ||
getSavedObjectsClientContract: getInternalUserSOClient, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually we want to use the SOClient that comme from the request directly
like this here const soClient = context.core.savedObjects.client;
and not the internal user one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay will make the change.
created_at: createdAt.toISOString(), | ||
}; | ||
|
||
return Object.assign(agentAction, newAgentAction); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just realized that this order will have the passed values will overwrite the agentAction
values
Is agentConfig the default values or final values?
Object.assign({}, newAgentConfig, agentAction)
will use agentConfig as final values
💚 Build SucceededHistory
To update your PR or re-run it, just comment with: |
… (#60705) [Ingest]EMT-248: add resource to allow to post new agent action.
* master: (52 commits) [SIEM] Fix types in rules tests (elastic#60736) [Alerting] prevent flickering when fields are updated in an alert (elastic#60666) License checks for actions plugin (elastic#59070) Implemented ability to clear and properly validate alert interval (elastic#60571) WebElementWrapper: add findByTestSubject/findAllByTestSubject to search with data-test-subj (elastic#60568) [Maps] Update layer dependencies to NP (elastic#59585) [Discover] Remove StateManagementConfigProvider (elastic#60221) [ML] Listing all categorization wizard checks (elastic#60502) [Upgrade Assistant] First iteration of batch reindex docs (elastic#59887) [SIEM] Export timeline (elastic#58368) [SIEM] Add support for actions and throttle in Rules (elastic#59641) Fix ace a11y listener (elastic#60639) Add addInfo toast to core notifications service (elastic#60574) fix test description (elastic#60638) [SIEM] Cypress screenshots upload to google cloud (elastic#60556) [canvas/shareable_runtime] sync sass loaders with kbn/optimizer (elastic#60653) [SIEM] Fixes Modification of ML Rules (elastic#60662) [SIEM] [Case] Bulk status update, add comment avatar, id => title in breadcrumbs (elastic#60410) [Alerting] add functional tests for index threshold alertType (elastic#60597) [Ingest]EMT-248: add post action request handler and resources (elastic#60581) ...
…o alerting/tls-warning * 'alerting/tls-warning' of github.com:gmmorris/kibana: (32 commits) [ML] Listing all categorization wizard checks (elastic#60502) [Upgrade Assistant] First iteration of batch reindex docs (elastic#59887) [SIEM] Export timeline (elastic#58368) [SIEM] Add support for actions and throttle in Rules (elastic#59641) Fix ace a11y listener (elastic#60639) Add addInfo toast to core notifications service (elastic#60574) fix test description (elastic#60638) [SIEM] Cypress screenshots upload to google cloud (elastic#60556) [canvas/shareable_runtime] sync sass loaders with kbn/optimizer (elastic#60653) [SIEM] Fixes Modification of ML Rules (elastic#60662) [SIEM] [Case] Bulk status update, add comment avatar, id => title in breadcrumbs (elastic#60410) [Alerting] add functional tests for index threshold alertType (elastic#60597) [Ingest]EMT-248: add post action request handler and resources (elastic#60581) Return incident's url (elastic#60617) [Endpoint] TEST: GET alert details - boundary test for first alert retrieval (elastic#60320) [ML] Transforms: Fix pivot preview table mapping. (elastic#60609) [Endpoint] Log random seed for sample data CLI to console (elastic#60646) Use common event model for determining if event is v0 or v1 (elastic#60667) Disables PR Project Assigner workflow [Reporting] Allow reports to be deleted in Management > Kibana > Reporting (elastic#60077) ...
Summary
https://github.com/elastic/endpoint-app-team/issues/248
The change creates a new resource for posting new actions for agents.
Request: - PostNewAgentActionRequest
Response - PostNewAgentActionResponse
Checklist
Delete any items that are not applicable to this PR.