Skip to content

Commit

Permalink
Update openapi.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexRuiz7 committed Dec 3, 2024
1 parent 17a2b82 commit 8ae4425
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 47 deletions.
21 changes: 16 additions & 5 deletions plugins/command-manager/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,40 @@ paths:
post:
tags:
- "authentication"
summary: Add a new command to the queue.
description: Add a new command to the queue.
summary: Mock of the Wazuh Server M_API authentication endpoint.
description: Returns a JWT.
responses:
"200":
description: OK
/commands:
post:
tags:
- "commands"
summary: Add a new command to the queue.
description: Add a new command to the queue.
summary: Add commands.
description: Receives and processes an array of commands.
requestBody:
required: true
content:
"application/json":
schema:
$ref: "#/components/schemas/Command"
$ref: "#/components/schemas/Commands"
responses:
"200":
description: OK
"400":
description: parsing_exception
"500":
description: Internal server error (boom!)

components:
schemas:
Commands:
type: object
properties:
commands:
type: array
items:
$ref: '#/components/schemas/Command'
Command:
type: object
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public CommandIndex(Client client, ClusterService clusterService, ThreadPool thr
* @param document instance of the document model to persist in the index.
* @return A CompletableFuture with the RestStatus response from the operation
*/
@Deprecated
public CompletableFuture<RestStatus> asyncCreate(Document document) {
CompletableFuture<RestStatus> future = new CompletableFuture<>();
ExecutorService executor = this.threadPool.executor(ThreadPool.Names.WRITE);
Expand All @@ -84,7 +85,10 @@ public CompletableFuture<RestStatus> asyncCreate(Document document) {
RestStatus restStatus = client.index(request).actionGet().status();
future.complete(restStatus);
} catch (Exception e) {
log.error("Error indexing command with id [{}] due to {}", document.getId(), e.getMessage());
log.error(
"Error indexing command with id [{}] due to {}",
document.getId(),
e.getMessage());
future.completeExceptionally(e);
}
});
Expand Down Expand Up @@ -113,7 +117,7 @@ public CompletableFuture<RestStatus> asyncBulkCreate(ArrayList<Document> documen

BulkRequest bulkRequest = new BulkRequest();
for (Document document : documents) {
log.info("Indexing command with id [{}]", document.getId());
log.info("Adding command with id [{}] to the bulk request", document.getId());
try {
bulkRequest.add(createIndexRequest(document));
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ private RestChannelConsumer handlePost(RestRequest request) throws IOException {
XContentParser parser = request.contentParser();
List<Command> commands = new ArrayList<>();
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser);
// The array of commands is inside the "commands" JSON object.
// This line moves the parser pointer into this object.
parser.nextToken();
if (parser.nextToken() == XContentParser.Token.START_ARRAY) {
commands = Command.parseToArray(parser);
Expand All @@ -128,7 +130,8 @@ private RestChannelConsumer handlePost(RestRequest request) throws IOException {
// Note: needs to be decoupled from the Rest handler (job scheduler task).
try {
String payload =
document.toXContent(XContentFactory.jsonBuilder(), ToXContent.EMPTY_PARAMS)
documents
.toXContent(XContentFactory.jsonBuilder(), ToXContent.EMPTY_PARAMS)
.toString();
SimpleHttpResponse response =
HttpRestClientDemo.runWithResponse(payload, document.getId());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
---
"Create command":
- do:
_plugins._command_manager:
body:
commands:
[
{ source: "Users/Services",
user: "user13",
target: {
id: "target4",
type: "agent"
},
action: {
name: "change_group",
args: [ "/path/to/executable/arg8" ],
version: "v4"
},
timeout: 100 },
- do:
_plugins._command_manager:
body:
commands:
[
{
source: "Users/Services",
user: "user13",
target: { id: "target4", type: "agent" },
action:
{
name: "change_group",
args: ["/path/to/executable/arg8"],
version: "v4",
},
timeout: 100,
},

{ source: "Users/Services",
user: "user54",
target: {
id: "target5",
type: "agent"
},
action: {
name: "stop",
args: [ "/path/to/executable/arg7" ],
version: "v4"
},
timeout: 30 }
]
{
source: "Users/Services",
user: "user54",
target: { id: "target5", type: "agent" },
action:
{
name: "stop",
args: ["/path/to/executable/arg7"],
version: "v4",
},
timeout: 30,
},
]

- match: { _index: .commands }
- match: { result: "OK" }
- match: { _index: .commands }
- match: { result: "OK" }

- do:
indices.refresh:
index: [ .commands ]
- do:
indices.refresh:
index: [.commands]

- do:
count:
index: .commands
- do:
count:
index: .commands

- match: { count: 2 }
- match: { count: 2 }

0 comments on commit 8ae4425

Please sign in to comment.