Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ repos:
- id: check-docstring-first
- id: requirements-txt-fixer


- repo: https://github.com/Bahjat/pre-commit-golang
rev: v1.0.5
hooks:
- id: go-fmt-import
- id: go-static-check # install https://staticcheck.io/docs/
- id: golangci-lint # requires github.com/golangci/golangci-lint
args: [--config=.golangci.yml, --allow-parallel-runners] # optional
- id: go-unit-tests

- repo: https://github.com/golangci/golangci-lint
rev: v1.62.2
hooks:
- id: golangci-lint
args: [--config=.golangci.yml]
4 changes: 2 additions & 2 deletions cmd/admin/handlers/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
"encoding/json"
"fmt"
"net/http"
"strconv"
"strings"
"time"
"strconv"

"github.com/jmpsec/osctrl/pkg/config"
"github.com/jmpsec/osctrl/pkg/environments"
Expand Down Expand Up @@ -58,7 +58,7 @@ func randomForNames() string {
b := make([]byte, 32)
_, _ = rand.Read(b)
hasher := md5.New()
_, _ = hasher.Write([]byte(fmt.Sprintf("%x", b)))
_, _ = fmt.Fprintf(hasher, "%x", b)
return hex.EncodeToString(hasher.Sum(nil))
}

Expand Down
6 changes: 3 additions & 3 deletions cmd/admin/sessions/sessions.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func (sm *SessionManager) New(r *http.Request, username string) (UserSession, er
}
session.Cookie = cookie
if err := sm.db.Create(&session).Error; err != nil {
return UserSession{}, fmt.Errorf("Create UserSession %w", err)
return UserSession{}, fmt.Errorf("create UserSession %w", err)
}
return session, nil
}
Expand All @@ -162,7 +162,7 @@ func (sm *SessionManager) Destroy(r *http.Request) error {
return err
}
if err := sm.db.Model(&s).Update("expires_at", time.Now().Add(-1*time.Second)).Error; err != nil {
return fmt.Errorf("Update %w", err)
return fmt.Errorf("update %w", err)
}
}
return nil
Expand All @@ -185,7 +185,7 @@ func (sm *SessionManager) Save(r *http.Request, w http.ResponseWriter, user user
}
}
if s.Username != user.Username {
return s, fmt.Errorf("Invalid user session (%s)", s.Username)
return s, fmt.Errorf("invalid user session (%s)", s.Username)
}
}
http.SetCookie(w, sessions.NewCookie(sm.CookieName, s.Cookie, sm.Options))
Expand Down
8 changes: 4 additions & 4 deletions cmd/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,20 +110,20 @@ func listQueries(ctx context.Context, cmd *cli.Command) error {
"Expiration",
}
// Prepare output
switch {
case formatFlag == jsonFormat:
switch formatFlag {
case jsonFormat:
jsonRaw, err := json.Marshal(qs)
if err != nil {
return fmt.Errorf("❌ error json marshal - %w", err)
}
fmt.Println(string(jsonRaw))
case formatFlag == csvFormat:
case csvFormat:
data := queriesToData(qs, header)
w := csv.NewWriter(os.Stdout)
if err := w.WriteAll(data); err != nil {
return fmt.Errorf("❌ error csv writeall - %w", err)
}
case formatFlag == prettyFormat:
case prettyFormat:
table := tablewriter.NewWriter(os.Stdout)
table.Header(stringSliceToAnySlice(header)...)
if len(qs) > 0 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/auditlog/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type AuditLogManager struct {

// CreateAuditLogManager to initialize the audit log struct and tables
func CreateAuditLogManager(backend *gorm.DB, service string, enabled bool) (*AuditLogManager, error) {
var t *AuditLogManager = &AuditLogManager{
t := &AuditLogManager{
DB: backend,
Service: service,
Enabled: enabled,
Expand Down
2 changes: 1 addition & 1 deletion pkg/carves/carves.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ type Carves struct {

// CreateFileCarves to initialize the carves struct and tables
func CreateFileCarves(backend *gorm.DB, carverType string, s3 *CarverS3) *Carves {
var c *Carves = &Carves{DB: backend, Carver: carverType, S3: s3}
c := &Carves{DB: backend, Carver: carverType, S3: s3}
// table carved_files
if err := backend.AutoMigrate(&CarvedFile{}); err != nil {
log.Fatal().Msgf("Failed to AutoMigrate table (carved_files): %v", err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/environments/environments.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ type EnvManager struct {

// CreateEnvironment to initialize the environment struct and tables
func CreateEnvironment(backend *gorm.DB) *EnvManager {
var e *EnvManager = &EnvManager{DB: backend}
e := &EnvManager{DB: backend}
// table tls_environments
if err := backend.AutoMigrate(&TLSEnvironment{}); err != nil {
log.Fatal().Msgf("Failed to AutoMigrate table (tls_environments): %v", err)
Expand Down
6 changes: 2 additions & 4 deletions pkg/logging/logstash.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ const (
LogstashMethod = "POST"
// LogstashContentType Content Type for requests
LogstashContentType = "application/json"
// LogstashConnStr Connection string for Logstash
LogstashConnStr = "%s:%s"
)

// LogstashMessage to handle log format to be sent to Logstash
Expand Down Expand Up @@ -111,7 +109,7 @@ func (logLS *LoggerLogstash) SendUDP(logType string, data []byte, environment, u
if debug {
log.Debug().Msgf("Sending %d bytes to Logstash TCP for %s - %s", len(data), environment, uuid)
}
connAddr := fmt.Sprintf(LogstashConnStr, logLS.Configuration.Host, logLS.Configuration.Port)
connAddr := net.JoinHostPort(logLS.Configuration.Host, logLS.Configuration.Port)
conn, err := net.Dial("udp", connAddr)
if err != nil {
log.Err(err).Msg("Error connecting to Logstash")
Expand All @@ -134,7 +132,7 @@ func (logLS *LoggerLogstash) SendTCP(logType string, data []byte, environment, u
if debug {
log.Debug().Msgf("Sending %d bytes to Logstash UDP for %s - %s", len(data), environment, uuid)
}
connAddr := fmt.Sprintf(LogstashConnStr, logLS.Configuration.Host, logLS.Configuration.Port)
connAddr := net.JoinHostPort(logLS.Configuration.Host, logLS.Configuration.Port)
conn, err := net.Dial("tcp", connAddr)
if err != nil {
log.Err(err).Msg("Error connecting to Logstash")
Expand Down
2 changes: 1 addition & 1 deletion pkg/nodes/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type NodeManager struct {

// CreateNodes to initialize the nodes struct and its tables
func CreateNodes(backend *gorm.DB) *NodeManager {
var n *NodeManager = &NodeManager{
n := &NodeManager{
DB: backend,
}
// table osquery_nodes
Expand Down
2 changes: 1 addition & 1 deletion pkg/settings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ var ValidServices = map[string]struct{}{

// NewSettings to initialize the access to settings and table
func NewSettings(backend *gorm.DB) *Settings {
var s *Settings = &Settings{DB: backend}
s := &Settings{DB: backend}
// table setting_values
if err := backend.AutoMigrate(&SettingValue{}); err != nil {
log.Fatal().Msgf("Failed to AutoMigrate table (setting_values): %v", err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/tags/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ type TagManager struct {

// CreateTagManager to initialize the tags struct and tables
func CreateTagManager(backend *gorm.DB) *TagManager {
var t *TagManager = &TagManager{DB: backend}
t := &TagManager{DB: backend}
// table admin_tags
if err := backend.AutoMigrate(&AdminTag{}); err != nil {
log.Fatal().Msgf("Failed to AutoMigrate table (admin_tags): %v", err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/users/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func CreateUserManager(backend *gorm.DB, jwtconfig *config.YAMLConfigurationJWT)
if jwtconfig.JWTSecret == "" {
log.Fatal().Msgf("JWT Secret can not be empty")
}
var u *UserManager = &UserManager{DB: backend, JWTConfig: jwtconfig}
u := &UserManager{DB: backend, JWTConfig: jwtconfig}
// table admin_users
if err := backend.AutoMigrate(&AdminUser{}); err != nil {
log.Fatal().Msgf("Failed to AutoMigrate table (admin_users): %v", err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func RandomForNames() string {
b := make([]byte, 32)
_, _ = rand.Read(b)
hasher := md5.New()
_, _ = hasher.Write([]byte(fmt.Sprintf("%x", b)))
_, _ = fmt.Fprintf(hasher, "%x", b)
return hex.EncodeToString(hasher.Sum(nil))
}

Expand Down
Loading