Skip to content

Commit f001b71

Browse files
committed
feat: add log warning to instances response
1 parent 9a785a7 commit f001b71

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

internal/controller/instances_controller.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@ type InstancesController struct {
2424
database *gorm.DB
2525
router *gin.RouterGroup
2626
rateLimit RateLimit
27+
warn string
2728
}
2829

29-
func NewInstancesController(router *gin.RouterGroup, database *gorm.DB, rateLimit RateLimit) *InstancesController {
30+
func NewInstancesController(router *gin.RouterGroup, database *gorm.DB, rateLimit RateLimit, warn string) *InstancesController {
3031
return &InstancesController{
3132
database: database,
3233
router: router,
3334
rateLimit: rateLimit,
35+
warn: warn,
3436
}
3537
}
3638

@@ -58,6 +60,7 @@ func (ic *InstancesController) listAllInstances(c *gin.Context) {
5860
"status": 200,
5961
"total": len(instances),
6062
"instances": instances,
63+
"warning": ic.warn,
6164
})
6265
}
6366

@@ -105,6 +108,7 @@ func (ic *InstancesController) heartbeat(c *gin.Context) {
105108
c.JSON(201, gin.H{
106109
"status": 201,
107110
"message": "Instance created",
111+
"warning": ic.warn,
108112
})
109113
return
110114
}
@@ -126,5 +130,6 @@ func (ic *InstancesController) heartbeat(c *gin.Context) {
126130
c.JSON(200, gin.H{
127131
"status": 200,
128132
"message": "Instance updated",
133+
"warning": ic.warn,
129134
})
130135
}

main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,15 @@ func main() {
5050
log.Fatal().Err(err).Msg("failed to parse config")
5151
}
5252

53+
warn := "no warning"
54+
5355
switch conf.LogLevel {
5456
case "trace":
5557
log.Logger = log.Level(zerolog.TraceLevel)
58+
warn = "log level set to trace, this may expose sensitive information like IP addresses to the server owner"
5659
case "debug":
5760
log.Logger = log.Level(zerolog.DebugLevel)
61+
warn = "log level set to trace, this may expose sensitive information like IP addresses to the server owner"
5862
case "info":
5963
log.Logger = log.Level(zerolog.InfoLevel)
6064
case "warn":
@@ -99,7 +103,7 @@ func main() {
99103

100104
rateLimitMiddleware := middleware.NewRateLimitMiddleware(db, cacheSvc, conf.RateLimitCount)
101105

102-
instancesCtrl := controller.NewInstancesController(api, db, rateLimitMiddleware)
106+
instancesCtrl := controller.NewInstancesController(api, db, rateLimitMiddleware, warn)
103107

104108
instancesCtrl.SetupRoutes()
105109

0 commit comments

Comments
 (0)