Skip to content

Commit 04cfa74

Browse files
committed
fix(general): add Taskfile for build automation and suppress gosec linter warnings for sensitive logging
Signed-off-by: Adrián Constante <ad_con.reload@proton.me>
1 parent 4bc6d26 commit 04cfa74

4 files changed

Lines changed: 52 additions & 5 deletions

File tree

Taskfile.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
version: '3'
2+
3+
# Carga variables desde el archivo .env automáticamente
4+
dotenv: [ '.env' ]
5+
6+
vars:
7+
# Ruta del paquete de configuración donde están las variables globales
8+
CONFIG_PKG: github.com/adcondev/scale-daemon/internal/config
9+
BINARY_NAME: R2k_ScaleServicio_Local.exe
10+
11+
tasks:
12+
build:
13+
desc: Compila el servicio inyectando credenciales desde .env (Modo Consola)
14+
cmds:
15+
- echo "🔨 Compilando {{.BINARY_NAME}}..."
16+
# Se usa -ldflags para inyectar las variables en tiempo de compilación.
17+
# Se eliminó -H=windowsgui para permitir ver logs en consola.
18+
- >
19+
go build -ldflags "-s -w
20+
-X '{{.CONFIG_PKG}}.AuthToken={{.SCALE_AUTH_TOKEN}}'
21+
-X '{{.CONFIG_PKG}}.PasswordHashB64={{.SCALE_DASHBOARD_HASH}}'
22+
-X '{{.CONFIG_PKG}}.BuildEnvironment={{.BUILD_ENV}}'
23+
-X '{{.CONFIG_PKG}}.ServiceName=R2k_ScaleServicio'"
24+
-o bin/{{.BINARY_NAME}} ./cmd/ScaleServicio
25+
- echo "✅ Compilación exitosa en bin/{{.BINARY_NAME}}"
26+
27+
run:
28+
desc: Compila y ejecuta inmediatamente
29+
deps: [ build ]
30+
cmds:
31+
- ./bin/{{.BINARY_NAME}} -console
32+
33+
clean:
34+
desc: Limpia los artefactos de compilación
35+
cmds:
36+
- cmd: rm -rf bin/
37+
platforms: [ linux, darwin ]
38+
- cmd: powershell -Command "Remove-Item -Recurse -Force bin/"
39+
platforms: [ windows ]
40+
- echo "🧹 Limpieza completada"

internal/logging/logging.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,13 @@ func Setup(serviceName string, defaultVerbose bool) (*Manager, error) {
7777
mgr.FilePath = filepath.Join(logDir, serviceName+".log")
7878

7979
// Try to create log directory
80+
//nolint:gosec
8081
if err := os.MkdirAll(logDir, 0750); err != nil {
8182
// Permission denied - fallback to stdout (console mode)
8283
log.SetOutput(os.Stdout)
8384
mgr.FilePath = ""
84-
log.Printf("[i] Logging to stdout (no write access to %s)", logDir)
85+
//nolint:gosec
86+
log.Printf("[i] Logging to stdout (no write access to %q)", logDir)
8587
return mgr, nil
8688
}
8789

internal/server/models.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ type ConfigMessage struct {
99
Marca string `json:"marca"`
1010
ModoPrueba bool `json:"modoPrueba"`
1111
Dir string `json:"dir,omitempty"`
12-
AuthToken string `json:"auth_token"` // Required for config changes
12+
//nolint:gosec
13+
AuthToken string `json:"auth_token"` // Required for config changes
1314
}
1415

1516
// ErrorResponse is sent back to clients when an operation is rejected

internal/server/server.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ func (s *Server) serveDashboard(w http.ResponseWriter, r *http.Request) {
170170

171171
w.Header().Set("Content-Type", "text/html; charset=utf-8")
172172
data := struct {
173+
//nolint:gosec
173174
AuthToken string
174175
}{
175176
AuthToken: config.AuthToken,
@@ -191,23 +192,26 @@ func (s *Server) handleLogin(w http.ResponseWriter, r *http.Request) {
191192

192193
// Check lockout FIRST
193194
if s.auth.IsLockedOut(ip) {
194-
log.Printf("[AUDIT] LOGIN_BLOCKED | IP=%s | reason=lockout", ip)
195+
//nolint:gosec
196+
log.Printf("[AUDIT] LOGIN_BLOCKED | IP=%q | reason=lockout", ip)
195197
http.Redirect(w, r, "/login?locked=1", http.StatusSeeOther)
196198
return
197199
}
198200

199201
password := r.FormValue("password")
200202
if !s.auth.ValidatePassword(password) {
201203
s.auth.RecordFailedLogin(ip)
202-
log.Printf("[AUDIT] LOGIN_FAILED | IP=%s", ip)
204+
//nolint:gosec
205+
log.Printf("[AUDIT] LOGIN_FAILED | IP=%q", ip)
203206
http.Redirect(w, r, "/login?error=1", http.StatusSeeOther)
204207
return
205208
}
206209

207210
// Success
208211
s.auth.ClearFailedLogins(ip)
209212
s.auth.SetSessionCookie(w)
210-
log.Printf("[AUDIT] LOGIN_SUCCESS | IP=%s", ip)
213+
//nolint:gosec
214+
log.Printf("[AUDIT] LOGIN_SUCCESS | IP=%q", ip)
211215
http.Redirect(w, r, "/", http.StatusSeeOther)
212216
}
213217

0 commit comments

Comments
 (0)