Skip to content

Commit

Permalink
fix: enable unused and forcetypeassert rules and start fixing war…
Browse files Browse the repository at this point in the history
…nings
  • Loading branch information
superlinkx committed Jan 31, 2024
1 parent fee4256 commit 322dca4
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 81 deletions.
14 changes: 11 additions & 3 deletions .golangci.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"linters": {
"disable": [
"errcheck",
"unused"
"errcheck"
],
"enable": [
"gosimple",
"stylecheck"
"stylecheck",
"forcetypeassert"
]
},
"issues": {
Expand All @@ -26,6 +26,10 @@
"path": "foldr_test\\.go",
"text": "SA4000:",
"severity": "warning"
},
{
"path": "(dawgs/util/size/(.+)|dawgs/drivers/pg/statements.go)",
"linters": ["unused"]
}
]
},
Expand All @@ -41,6 +45,10 @@
"severity": {
"default-severity": "error",
"rules": [
{
"linters": ["unused"],
"severity": "warning"
},
{
"text": "(ST\\d{4}|S\\d{4}|SA1019)",
"severity": "warning"
Expand Down
9 changes: 4 additions & 5 deletions packages/go/crypto/argon2.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// Copyright 2023 Specter Ops, Inc.
//
//
// Licensed under the Apache License, Version 2.0
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//
// SPDX-License-Identifier: Apache-2.0

package crypto
Expand Down Expand Up @@ -78,7 +78,6 @@ type ComputerSpecs struct {

// Argon2 is a frontend implementation for the recommendations specified in https://tools.ietf.org/html/draft-irtf-cfrg-argon2-04
type Argon2 struct {
mcFormatRegex *regexp.Regexp
MemoryKibibytes uint32
NumIterations uint32
NumThreads uint8
Expand Down
11 changes: 5 additions & 6 deletions packages/go/cypher/frontend/literal.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// Copyright 2023 Specter Ops, Inc.
//
//
// Licensed under the Apache License, Version 2.0
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//
// SPDX-License-Identifier: Apache-2.0

package frontend
Expand Down Expand Up @@ -109,8 +109,7 @@ func (s *ListLiteralVisitor) ExitOC_Expression(ctx *parser.OC_ExpressionContext)
type LiteralVisitor struct {
BaseVisitor

Literal *model.Literal
propertyKey string
Literal *model.Literal
}

func NewLiteralVisitor() *LiteralVisitor {
Expand Down
14 changes: 2 additions & 12 deletions packages/go/cypher/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
package model

import (
"github.com/specterops/bloodhound/dawgs/graph"
"sort"
"strings"

"github.com/specterops/bloodhound/dawgs/graph"
)

type SortOrder string
Expand Down Expand Up @@ -1089,17 +1090,6 @@ func NewProperties() *Properties {
return &Properties{}
}

func (s *Properties) copy() *Properties {
if s == nil {
return nil
}

return &Properties{
Map: Copy(s.Map),
Parameter: Copy(s.Parameter),
}
}

// NodePattern Type
//
// Kinds is a conjunction of types for the given node.
Expand Down
22 changes: 2 additions & 20 deletions packages/go/dawgs/drivers/pg/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ package pg

import (
"errors"
"sync"

"github.com/jackc/pgx/v5"
"github.com/specterops/bloodhound/dawgs/drivers/pg/model"
"github.com/specterops/bloodhound/dawgs/drivers/pg/query"
"github.com/specterops/bloodhound/dawgs/graph"
"sync"
)

type KindMapper interface {
Expand Down Expand Up @@ -79,25 +80,6 @@ func (s *SchemaManager) defineKinds(tx graph.Transaction, kinds graph.Kinds) err
return nil
}

func (s *SchemaManager) defineGraphKinds(tx graph.Transaction, schemas []graph.Graph) error {
for _, schema := range schemas {
var (
_, missingNodeKinds = s.mapKinds(schema.Nodes)
_, missingEdgeKinds = s.mapKinds(schema.Edges)
)

if err := s.defineKinds(tx, missingNodeKinds); err != nil {
return err
}

if err := s.defineKinds(tx, missingEdgeKinds); err != nil {
return err
}
}

return nil
}

func (s *SchemaManager) mapKinds(kinds graph.Kinds) ([]int16, graph.Kinds) {
var (
missingKinds = make(graph.Kinds, 0, len(kinds))
Expand Down
22 changes: 3 additions & 19 deletions packages/go/dawgs/drivers/pg/query/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ package query

import (
"fmt"
"strconv"
"strings"

"github.com/specterops/bloodhound/dawgs/drivers/pg/model"
"github.com/specterops/bloodhound/dawgs/graph"
"github.com/specterops/bloodhound/graphschema/ad"
"strconv"
"strings"
)

func postgresIndexType(indexType graph.IndexType) string {
Expand Down Expand Up @@ -117,23 +118,6 @@ func formatConflictMatcher(propertyNames []string, defaultOnConflict string) str
return builder.String()
}

type idCounter struct {
current int
}

func newIDCounter() *idCounter {
return &idCounter{
current: 1,
}
}

func (s *idCounter) Next() string {
next := s.current
s.current += 1

return strconv.Itoa(next)
}

func FormatNodeUpsert(graphTarget model.Graph, identityProperties []string) string {
return join(
"insert into ", graphTarget.Partitions.Node.Name, " as n ",
Expand Down
7 changes: 1 addition & 6 deletions packages/go/dawgs/drivers/pg/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"bytes"
"context"
"fmt"

"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgconn"
"github.com/jackc/pgx/v5/pgxpool"
Expand Down Expand Up @@ -56,12 +57,6 @@ func (s inspectingDriver) QueryRow(ctx context.Context, sql string, arguments ..
return s.upstreamDriver.QueryRow(ctx, sql, arguments...)
}

func newInspectingDriver(upstreamDriver driver) driver {
return &inspectingDriver{
upstreamDriver: upstreamDriver,
}
}

type transaction struct {
schemaManager *SchemaManager
queryExecMode pgx.QueryExecMode
Expand Down
8 changes: 4 additions & 4 deletions packages/go/dawgs/query/neo4j/neo4j.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"bytes"
"errors"
"fmt"

"github.com/specterops/bloodhound/cypher/backend/cypher"
"github.com/specterops/bloodhound/cypher/model"
"github.com/specterops/bloodhound/dawgs/graph"
Expand All @@ -33,10 +34,9 @@ var (
type QueryBuilder struct {
Parameters map[string]any

query *model.RegularQuery
order *model.Order
relationshipPatternKinds graph.Kinds
prepared bool
query *model.RegularQuery
order *model.Order
prepared bool
}

func NewQueryBuilder(singleQuery *model.RegularQuery) *QueryBuilder {
Expand Down
6 changes: 0 additions & 6 deletions packages/go/dawgs/traversal/traversal.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,12 +267,6 @@ type Plan struct {
Driver Driver
}

type Service struct {
db graph.Database
workerWG *sync.WaitGroup
numWorkers int
}

type Traversal struct {
db graph.Database
numWorkers int
Expand Down

0 comments on commit 322dca4

Please sign in to comment.