Skip to content

Commit 7811071

Browse files
committed
[logs] add empty /logs endpoint
1 parent 9ada820 commit 7811071

File tree

9 files changed

+269
-9
lines changed

9 files changed

+269
-9
lines changed

Diff for: api/local.http

+4-1
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,14 @@ Content-Type: application/json
6969

7070
{
7171
"id": "LreFUt-Z3sSq0JufY9uWB",
72-
"url": "https://webhook.site/280a6655-eb68-40b9-b857-af5be37c5303",
72+
"url": "https://webhook.site/7598bc37-8765-4e7d-89e0-01e7f5ea5346",
7373
"event": "sms:received"
7474
}
7575

7676
###
7777
DELETE {{localUrl}}/webhooks/LreFUt-Z3sSq0JufY9uWB HTTP/1.1
7878
Authorization: Basic {{localCredentials}}
7979

80+
###
81+
GET {{localUrl}}/logs?from=2024-08-01T13:19:02.093%2B07:00 HTTP/1.1
82+
Authorization: Basic {{localCredentials}}

Diff for: api/requests.http

+4
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ Content-Type: application/json
7777
DELETE {{baseUrl}}/api/3rdparty/v1/webhooks/MYofX8bTd5Bov0wWFZLRP HTTP/1.1
7878
Authorization: Basic {{credentials}}
7979

80+
###
81+
GET {{baseUrl}}/api/3rdparty/v1/logs HTTP/1.1
82+
Authorization: Basic {{credentials}}
83+
8084
###
8185
GET http://localhost:3000/metrics HTTP/1.1
8286

Diff for: api/swagger.json

+115-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"host": "sms.capcom.me",
1616
"basePath": "/api",
1717
"paths": {
18-
"/3rdparty/v1/device": {
18+
"/3rdparty/v1/devices": {
1919
"get": {
2020
"security": [
2121
{
@@ -87,6 +87,69 @@
8787
}
8888
}
8989
},
90+
"/3rdparty/v1/logs": {
91+
"get": {
92+
"security": [
93+
{
94+
"ApiAuth": []
95+
}
96+
],
97+
"description": "Retrieve a list of log entries within a specified time range.",
98+
"produces": [
99+
"application/json"
100+
],
101+
"tags": [
102+
"System",
103+
"Logs"
104+
],
105+
"summary": "Get logs",
106+
"parameters": [
107+
{
108+
"type": "string",
109+
"format": "date-time",
110+
"description": "The start of the time range for the logs to retrieve. Logs created after this timestamp will be included.",
111+
"name": "from",
112+
"in": "query"
113+
},
114+
{
115+
"type": "string",
116+
"format": "date-time",
117+
"description": "The end of the time range for the logs to retrieve. Logs created before this timestamp will be included.",
118+
"name": "to",
119+
"in": "query"
120+
}
121+
],
122+
"responses": {
123+
"200": {
124+
"description": "Log entries",
125+
"schema": {
126+
"type": "array",
127+
"items": {
128+
"$ref": "#/definitions/smsgateway.LogEntry"
129+
}
130+
}
131+
},
132+
"401": {
133+
"description": "Unauthorized",
134+
"schema": {
135+
"$ref": "#/definitions/smsgateway.ErrorResponse"
136+
}
137+
},
138+
"500": {
139+
"description": "Internal server error",
140+
"schema": {
141+
"$ref": "#/definitions/smsgateway.ErrorResponse"
142+
}
143+
},
144+
"501": {
145+
"description": "Not implemented",
146+
"schema": {
147+
"$ref": "#/definitions/smsgateway.ErrorResponse"
148+
}
149+
}
150+
}
151+
}
152+
},
90153
"/3rdparty/v1/message": {
91154
"get": {
92155
"security": [
@@ -773,6 +836,57 @@
773836
"HealthStatusFail"
774837
]
775838
},
839+
"smsgateway.LogEntry": {
840+
"type": "object",
841+
"properties": {
842+
"context": {
843+
"description": "Additional context information related to the log entry, typically including data relevant to the log event.",
844+
"type": "object",
845+
"additionalProperties": {
846+
"type": "string"
847+
}
848+
},
849+
"createdAt": {
850+
"description": "The timestamp when this log entry was created.",
851+
"type": "string"
852+
},
853+
"id": {
854+
"description": "A unique identifier for the log entry.",
855+
"type": "integer"
856+
},
857+
"message": {
858+
"description": "A message describing the log event.",
859+
"type": "string"
860+
},
861+
"module": {
862+
"description": "The module or component of the system that generated the log entry.",
863+
"type": "string"
864+
},
865+
"priority": {
866+
"description": "The priority level of the log entry.",
867+
"allOf": [
868+
{
869+
"$ref": "#/definitions/smsgateway.LogEntryPriority"
870+
}
871+
]
872+
}
873+
}
874+
},
875+
"smsgateway.LogEntryPriority": {
876+
"type": "string",
877+
"enum": [
878+
"DEBUG",
879+
"INFO",
880+
"WARN",
881+
"ERROR"
882+
],
883+
"x-enum-varnames": [
884+
"LogEntryPriorityDebug",
885+
"LogEntryPriorityInfo",
886+
"LogEntryPriorityWarn",
887+
"LogEntryPriorityError"
888+
]
889+
},
776890
"smsgateway.Message": {
777891
"type": "object",
778892
"required": [

Diff for: api/swagger.yaml

+82-1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,44 @@ definitions:
9292
- HealthStatusPass
9393
- HealthStatusWarn
9494
- HealthStatusFail
95+
smsgateway.LogEntry:
96+
properties:
97+
context:
98+
additionalProperties:
99+
type: string
100+
description: Additional context information related to the log entry, typically
101+
including data relevant to the log event.
102+
type: object
103+
createdAt:
104+
description: The timestamp when this log entry was created.
105+
type: string
106+
id:
107+
description: A unique identifier for the log entry.
108+
type: integer
109+
message:
110+
description: A message describing the log event.
111+
type: string
112+
module:
113+
description: The module or component of the system that generated the log
114+
entry.
115+
type: string
116+
priority:
117+
allOf:
118+
- $ref: '#/definitions/smsgateway.LogEntryPriority'
119+
description: The priority level of the log entry.
120+
type: object
121+
smsgateway.LogEntryPriority:
122+
enum:
123+
- DEBUG
124+
- INFO
125+
- WARN
126+
- ERROR
127+
type: string
128+
x-enum-varnames:
129+
- LogEntryPriorityDebug
130+
- LogEntryPriorityInfo
131+
- LogEntryPriorityWarn
132+
- LogEntryPriorityError
95133
smsgateway.Message:
96134
properties:
97135
id:
@@ -329,7 +367,7 @@ info:
329367
title: SMS Gateway for Android™ API
330368
version: '{APP_VERSION}'
331369
paths:
332-
/3rdparty/v1/device:
370+
/3rdparty/v1/devices:
333371
get:
334372
description: Returns list of registered devices
335373
produces:
@@ -375,6 +413,49 @@ paths:
375413
summary: Health check
376414
tags:
377415
- System
416+
/3rdparty/v1/logs:
417+
get:
418+
description: Retrieve a list of log entries within a specified time range.
419+
parameters:
420+
- description: The start of the time range for the logs to retrieve. Logs created
421+
after this timestamp will be included.
422+
format: date-time
423+
in: query
424+
name: from
425+
type: string
426+
- description: The end of the time range for the logs to retrieve. Logs created
427+
before this timestamp will be included.
428+
format: date-time
429+
in: query
430+
name: to
431+
type: string
432+
produces:
433+
- application/json
434+
responses:
435+
"200":
436+
description: Log entries
437+
schema:
438+
items:
439+
$ref: '#/definitions/smsgateway.LogEntry'
440+
type: array
441+
"401":
442+
description: Unauthorized
443+
schema:
444+
$ref: '#/definitions/smsgateway.ErrorResponse'
445+
"500":
446+
description: Internal server error
447+
schema:
448+
$ref: '#/definitions/smsgateway.ErrorResponse'
449+
"501":
450+
description: Not implemented
451+
schema:
452+
$ref: '#/definitions/smsgateway.ErrorResponse'
453+
security:
454+
- ApiAuth: []
455+
summary: Get logs
456+
tags:
457+
- System
458+
- Logs
378459
/3rdparty/v1/message:
379460
get:
380461
description: Returns message state by ID

Diff for: go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ go 1.22.0
44

55
require (
66
firebase.google.com/go/v4 v4.12.1
7-
github.com/android-sms-gateway/client-go v1.0.1
7+
github.com/android-sms-gateway/client-go v1.0.2
88
github.com/ansrivas/fiberprometheus/v2 v2.6.1
99
github.com/capcom6/go-helpers v0.0.0-20240521035631-865ee2879fa3
1010
github.com/capcom6/go-infra-fx v0.0.2
1111
github.com/go-playground/validator/v10 v10.16.0
12+
github.com/go-sql-driver/mysql v1.7.1
1213
github.com/gofiber/fiber/v2 v2.52.5
1314
github.com/jaevor/go-nanoid v1.3.0
1415
github.com/nyaruka/phonenumbers v1.3.0
@@ -35,7 +36,6 @@ require (
3536
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
3637
github.com/go-playground/locales v0.14.1 // indirect
3738
github.com/go-playground/universal-translator v0.18.1 // indirect
38-
github.com/go-sql-driver/mysql v1.7.1 // indirect
3939
github.com/gofiber/adaptor/v2 v2.2.1 // indirect
4040
github.com/gofiber/contrib/fiberzap/v2 v2.1.2 // indirect
4141
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect

Diff for: go.sum

+2-4
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,8 @@ github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migc
2626
github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
2727
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 h1:TngWCqHvy9oXAN6lEVMRuU21PR1EtLVZJmdB18Gu3Rw=
2828
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5/go.mod h1:lmUJ/7eu/Q8D7ML55dXQrVaamCz2vxCfdQBasLZfHKk=
29-
github.com/android-sms-gateway/client-go v1.0.1-0.20240610222412-894fc9370287 h1:4Q6TuWQcTrKb+nyMrdBTBIV0b4R/xQgmOJhOygHWIkg=
30-
github.com/android-sms-gateway/client-go v1.0.1-0.20240610222412-894fc9370287/go.mod h1:DQsReciU1xcaVW3T5Z2bqslNdsAwCFCtghawmA6g6L4=
31-
github.com/android-sms-gateway/client-go v1.0.1 h1:ZqLMJ0MlpYPafU1Vxc2MoEvggzJFtH8wqmk+wpwRmyE=
32-
github.com/android-sms-gateway/client-go v1.0.1/go.mod h1:DQsReciU1xcaVW3T5Z2bqslNdsAwCFCtghawmA6g6L4=
29+
github.com/android-sms-gateway/client-go v1.0.2 h1:kXWzVeSgBu2bM1yN4ac8tTEm0fX2Tqsn+yr9mMNjNfI=
30+
github.com/android-sms-gateway/client-go v1.0.2/go.mod h1:DQsReciU1xcaVW3T5Z2bqslNdsAwCFCtghawmA6g6L4=
3331
github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M=
3432
github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY=
3533
github.com/ansrivas/fiberprometheus/v2 v2.6.1 h1:wac3pXaE6BYYTF04AC6K0ktk6vCD+MnDOJZ3SK66kXM=

Diff for: internal/sms-gateway/handlers/3rdparty.go

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/android-sms-gateway/client-go/smsgateway"
88
"github.com/capcom6/sms-gateway/internal/sms-gateway/handlers/base"
99
devicesCtrl "github.com/capcom6/sms-gateway/internal/sms-gateway/handlers/devices"
10+
"github.com/capcom6/sms-gateway/internal/sms-gateway/handlers/logs"
1011
"github.com/capcom6/sms-gateway/internal/sms-gateway/handlers/webhooks"
1112
"github.com/capcom6/sms-gateway/internal/sms-gateway/models"
1213
"github.com/capcom6/sms-gateway/internal/sms-gateway/modules/auth"
@@ -30,6 +31,7 @@ type ThirdPartyHandlerParams struct {
3031
HealthHandler *healthHandler
3132
WebhooksHandler *webhooks.ThirdPartyController
3233
DevicesHandler *devicesCtrl.ThirdPartyController
34+
LogsHandler *logs.ThirdPartyController
3335

3436
AuthSvc *auth.Service
3537
MessagesSvc *messages.Service
@@ -45,6 +47,7 @@ type thirdPartyHandler struct {
4547
healthHandler *healthHandler
4648
webhooksHandler *webhooks.ThirdPartyController
4749
devicesHandler *devicesCtrl.ThirdPartyController
50+
logsHandler *logs.ThirdPartyController
4851

4952
authSvc *auth.Service
5053
messagesSvc *messages.Service
@@ -170,6 +173,7 @@ func (h *thirdPartyHandler) Register(router fiber.Router) {
170173
h.devicesHandler.Register(router.Group("/device")) // TODO: remove after 2025-07-11
171174
h.devicesHandler.Register(router.Group("/devices"))
172175
h.webhooksHandler.Register(router.Group("/webhooks"))
176+
h.logsHandler.Register(router.Group("/logs"))
173177
}
174178

175179
func newThirdPartyHandler(params ThirdPartyHandlerParams) *thirdPartyHandler {
@@ -178,6 +182,7 @@ func newThirdPartyHandler(params ThirdPartyHandlerParams) *thirdPartyHandler {
178182
healthHandler: params.HealthHandler,
179183
webhooksHandler: params.WebhooksHandler,
180184
devicesHandler: params.DevicesHandler,
185+
logsHandler: params.LogsHandler,
181186
authSvc: params.AuthSvc,
182187
messagesSvc: params.MessagesSvc,
183188
devicesSvc: params.DevicesSvc,

Diff for: internal/sms-gateway/handlers/logs/3rdparty.go

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package logs
2+
3+
import (
4+
"github.com/capcom6/sms-gateway/internal/sms-gateway/handlers/base"
5+
"github.com/capcom6/sms-gateway/internal/sms-gateway/models"
6+
"github.com/capcom6/sms-gateway/internal/sms-gateway/modules/auth"
7+
"github.com/go-playground/validator/v10"
8+
"github.com/gofiber/fiber/v2"
9+
"go.uber.org/fx"
10+
"go.uber.org/zap"
11+
)
12+
13+
type thirdPartyControllerParams struct {
14+
fx.In
15+
16+
Validator *validator.Validate
17+
Logger *zap.Logger
18+
}
19+
20+
type ThirdPartyController struct {
21+
base.Handler
22+
}
23+
24+
// @Summary Get logs
25+
// @Description Retrieve a list of log entries within a specified time range.
26+
// @Security ApiAuth
27+
// @Tags System, Logs
28+
// @Produce json
29+
// @Param from query string false "The start of the time range for the logs to retrieve. Logs created after this timestamp will be included." Format(date-time)
30+
// @Param to query string false "The end of the time range for the logs to retrieve. Logs created before this timestamp will be included." Format(date-time)
31+
// @Success 200 {object} smsgateway.GetLogsResponse "Log entries"
32+
// @Failure 401 {object} smsgateway.ErrorResponse "Unauthorized"
33+
// @Failure 500 {object} smsgateway.ErrorResponse "Internal server error"
34+
// @Failure 501 {object} smsgateway.ErrorResponse "Not implemented"
35+
// @Router /3rdparty/v1/logs [get]
36+
//
37+
// List webhooks
38+
func (h *ThirdPartyController) get(user models.User, c *fiber.Ctx) error {
39+
return fiber.NewError(fiber.StatusNotImplemented, "For privacy reasons, device's logs are not accessible through Cloud server")
40+
}
41+
42+
func (h *ThirdPartyController) Register(router fiber.Router) {
43+
router.Get("", auth.WithUser(h.get))
44+
}
45+
46+
func NewThirdPartyController(params thirdPartyControllerParams) *ThirdPartyController {
47+
return &ThirdPartyController{
48+
Handler: base.Handler{
49+
Logger: params.Logger.Named("logs"),
50+
Validator: params.Validator,
51+
},
52+
}
53+
}

0 commit comments

Comments
 (0)