-
Notifications
You must be signed in to change notification settings - Fork 672
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Rodney Osodo <[email protected]>
- Loading branch information
1 parent
615f097
commit 4282f24
Showing
41 changed files
with
2,757 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,278 @@ | ||
# Copyright (c) Abstract Machines | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
openapi: 3.0.3 | ||
info: | ||
title: Magistrala Event Logs Service | ||
description: | | ||
This is the Event Logs Server based on the OpenAPI 3.0 specification. It is the HTTP API for viewing event logs history. You can now help us improve the API whether it's by making changes to the definition itself or to the code. | ||
Some useful links: | ||
- [The Magistrala repository](https://github.com/absmach/magistrala) | ||
contact: | ||
email: [email protected] | ||
license: | ||
name: Apache 2.0 | ||
url: https://github.com/absmach/magistrala/blob/master/LICENSE | ||
version: 0.14.0 | ||
|
||
servers: | ||
- url: http://localhost:9021 | ||
- url: https://localhost:9021 | ||
|
||
tags: | ||
- name: event-logs | ||
description: Everything about your Event Logs | ||
externalDocs: | ||
description: Find out more about Event Logs | ||
url: http://docs.mainflux.io/ | ||
|
||
paths: | ||
/events/{id}{type}: | ||
get: | ||
tags: | ||
- event-logs | ||
summary: List event logs | ||
description: | | ||
Retrieves a list of events. Due to performance concerns, data | ||
is retrieved in subsets. The API must ensure that the entire | ||
dataset is consumed either by making subsequent requests, or by | ||
increasing the subset size of the initial request. | ||
parameters: | ||
- $ref: "#/components/parameters/id" | ||
- $ref: "#/components/parameters/type" | ||
- $ref: "#/components/parameters/limit" | ||
- $ref: "#/components/parameters/offset" | ||
- $ref: "#/components/parameters/operation" | ||
- $ref: "#/components/parameters/from" | ||
- $ref: "#/components/parameters/to" | ||
security: | ||
- bearerAuth: [] | ||
responses: | ||
"200": | ||
$ref: "#/components/responses/EventPageRes" | ||
"400": | ||
description: Failed due to malformed query parameters. | ||
"401": | ||
description: | | ||
Missing or invalid access token provided. | ||
This endpoint is available only for administrators. | ||
"404": | ||
description: A non-existent entity request. | ||
"422": | ||
description: Database can't process request. | ||
"500": | ||
$ref: "#/components/responses/ServiceError" | ||
|
||
/health: | ||
get: | ||
summary: Retrieves service health check info. | ||
tags: | ||
- health | ||
responses: | ||
"200": | ||
$ref: "#/components/responses/HealthRes" | ||
"500": | ||
$ref: "#/components/responses/ServiceError" | ||
|
||
components: | ||
schemas: | ||
Event: | ||
type: object | ||
properties: | ||
id: | ||
type: string | ||
format: uuid | ||
example: bb7edb32-2eac-4aad-aebe-ed96fe073879 | ||
description: Entity unique identifier. | ||
operation: | ||
type: string | ||
example: users.create | ||
description: Event operation. | ||
occurred_at: | ||
type: string | ||
format: date-time | ||
example: "2024-01-11T12:05:07.449053Z" | ||
description: Time when the event occurred. | ||
payload: | ||
type: object | ||
description: Event payload. | ||
example: | ||
{ | ||
"created_at": "2024-01-11T12:05:07.435357Z", | ||
"metadata": "e30=", | ||
"name": "Moors-Mlacak", | ||
"owner": "599a7f51-3f16-41b2-8224-3b1044cea83b", | ||
"status": "enabled", | ||
} | ||
xml: | ||
name: event | ||
|
||
EventPage: | ||
type: object | ||
properties: | ||
events: | ||
type: array | ||
minItems: 0 | ||
uniqueItems: true | ||
items: | ||
$ref: "#/components/schemas/Event" | ||
total: | ||
type: integer | ||
example: 1 | ||
description: Total number of items. | ||
offset: | ||
type: integer | ||
description: Number of items to skip during retrieval. | ||
limit: | ||
type: integer | ||
example: 10 | ||
description: Maximum number of items to return in one page. | ||
required: | ||
- events | ||
- total | ||
- offset | ||
|
||
Error: | ||
type: object | ||
properties: | ||
error: | ||
type: string | ||
description: Error message | ||
example: { "error": "malformed entity specification" } | ||
|
||
HealthRes: | ||
type: object | ||
properties: | ||
status: | ||
type: string | ||
description: Service status. | ||
enum: | ||
- pass | ||
version: | ||
type: string | ||
description: Service version. | ||
example: 0.14.0 | ||
commit: | ||
type: string | ||
description: Service commit hash. | ||
example: 7d6f4dc4f7f0c1fa3dc24eddfb18bb5073ff4f62 | ||
description: | ||
type: string | ||
description: Service description. | ||
example: <service_name> service | ||
build_time: | ||
type: string | ||
description: Service build time. | ||
example: 1970-01-01_00:00:00 | ||
|
||
parameters: | ||
id: | ||
name: id | ||
description: Unique identifier for an entity, e.g. user, group, domain, etc. | ||
in: path | ||
schema: | ||
type: string | ||
format: uuid | ||
required: true | ||
example: bb7edb32-2eac-4aad-aebe-ed96fe073879 | ||
|
||
type: | ||
name: type | ||
description: Type of entity, e.g. user, group, domain, etc. | ||
in: path | ||
schema: | ||
type: string | ||
enum: | ||
- user | ||
- group | ||
- domain | ||
- thing | ||
- platform | ||
- thing | ||
required: true | ||
example: user | ||
|
||
offset: | ||
name: offset | ||
description: Number of items to skip during retrieval. | ||
in: query | ||
schema: | ||
type: integer | ||
default: 0 | ||
minimum: 0 | ||
required: false | ||
example: "0" | ||
|
||
limit: | ||
name: limit | ||
description: Size of the subset to retrieve. | ||
in: query | ||
schema: | ||
type: integer | ||
default: 10 | ||
maximum: 10 | ||
minimum: 1 | ||
required: false | ||
example: "10" | ||
|
||
operation: | ||
name: operation | ||
description: Event operation. | ||
in: query | ||
schema: | ||
type: string | ||
required: false | ||
example: users.create | ||
|
||
from: | ||
name: from | ||
description: Start date in nanoseconds. | ||
in: query | ||
schema: | ||
type: string | ||
format: int64 | ||
required: false | ||
example: 1704974066014408296 | ||
|
||
to: | ||
name: to | ||
description: End date in nanoseconds. | ||
in: query | ||
schema: | ||
type: string | ||
format: int64 | ||
required: false | ||
example: 1704974066014408296 | ||
|
||
responses: | ||
EventPageRes: | ||
description: Data retrieved. | ||
content: | ||
application/json: | ||
schema: | ||
$ref: "#/components/schemas/EventPage" | ||
|
||
HealthRes: | ||
description: Service Health Check. | ||
content: | ||
application/health+json: | ||
schema: | ||
$ref: "#/components/schemas/HealthRes" | ||
|
||
ServiceError: | ||
description: Unexpected server-side error occurred. | ||
content: | ||
application/json: | ||
schema: | ||
$ref: "#/components/schemas/Error" | ||
|
||
securitySchemes: | ||
bearerAuth: | ||
type: http | ||
scheme: bearer | ||
bearerFormat: JWT | ||
description: | | ||
* User access: "Authorization: Bearer <user_access_token>" | ||
security: | ||
- bearerAuth: [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright (c) Abstract Machines | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package cli | ||
|
||
import ( | ||
mgxsdk "github.com/absmach/magistrala/pkg/sdk/go" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var cmdEvents = cobra.Command{ | ||
Use: "get <id> <entity_type> <user_auth_token>", | ||
Short: "Get events", | ||
Long: "Get events\n" + | ||
"Usage:\n" + | ||
"\tmagistrala-cli events get <id> <entity_type> <user_auth_token> - lists all events\n" + | ||
"\tmagistrala-cli events get <id> <entity_type> <user_auth_token> --offset <offset> --limit <limit> - lists all events with provided offset and limit\n", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if len(args) != 3 { | ||
logUsage(cmd.Use) | ||
return | ||
} | ||
|
||
pageMetadata := mgxsdk.PageMetadata{ | ||
Offset: Offset, | ||
Limit: Limit, | ||
} | ||
|
||
events, err := sdk.Events(pageMetadata, args[0], args[1], args[2]) | ||
if err != nil { | ||
logError(err) | ||
return | ||
} | ||
|
||
logJSON(events) | ||
}, | ||
} | ||
|
||
// NewEventsCmd returns invitations command. | ||
func NewEventsCmd() *cobra.Command { | ||
cmd := cobra.Command{ | ||
Use: "events get", | ||
Short: "events logs", | ||
Long: `events to read event history`, | ||
} | ||
|
||
cmd.AddCommand(&cmdEvents) | ||
|
||
return &cmd | ||
} |
Oops, something went wrong.