Skip to content

Commit

Permalink
resolve golint issue
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffhuang4704 committed Oct 13, 2024
1 parent 186b972 commit cb468e5
Show file tree
Hide file tree
Showing 37 changed files with 561 additions and 578 deletions.
18 changes: 9 additions & 9 deletions controller/access/access_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -620,17 +620,17 @@ func TestDualAccess(t *testing.T) {

// --

type readObject struct {
members []string
}
// type readObject struct {
// members []string
// }

func newReadObject(members []string) *readObject {
return &readObject{members: members}
}
// func newReadObject(members []string) *readObject {
// return &readObject{members: members}
// }

func (o *readObject) GetDomain(f share.GetAccessObjectFunc) ([]string, []string) {
return o.members, nil
}
// func (o *readObject) GetDomain(f share.GetAccessObjectFunc) ([]string, []string) {
// return o.members, nil
// }

// --

Expand Down
26 changes: 13 additions & 13 deletions controller/api/log_apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,19 +199,19 @@ const (
EventNameAwsLambdaScan = "AwsLambda.Scan"
)

var incidentNameList []string = []string{
EventNameHostPrivilEscalate,
EventNameContainerPrivilEscalate,
EventNameHostSuspiciousProcess,
EventNameContainerSuspiciousProcess,
EventNameHostFileAccessViolation,
EventNameContainerFileAccessViolation,
EventNameHostPackageUpdated,
EventNameContainerPackageUpdated,
EventNameHostTunnelDetected,
EventNameProcessProfileViolation,
EventNameHostProcessProfileViolation,
}
// var incidentNameList []string = []string{
// EventNameHostPrivilEscalate,
// EventNameContainerPrivilEscalate,
// EventNameHostSuspiciousProcess,
// EventNameContainerSuspiciousProcess,
// EventNameHostFileAccessViolation,
// EventNameContainerFileAccessViolation,
// EventNameHostPackageUpdated,
// EventNameContainerPackageUpdated,
// EventNameHostTunnelDetected,
// EventNameProcessProfileViolation,
// EventNameHostProcessProfileViolation,
// }

const (
EventCatREST = "RESTFUL"
Expand Down
2 changes: 1 addition & 1 deletion controller/atmo/atmo.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type automode_ctx struct {
m2p_life int

// callbacks
probefn probeFunc
// probefn probeFunc

// test functions
testfn testFunc
Expand Down
170 changes: 80 additions & 90 deletions controller/atmo/atmo_test.go
Original file line number Diff line number Diff line change
@@ -1,101 +1,91 @@
package atmo

import (
"fmt"
"os"
"testing"
"time"
// Temporarily commented out since this test function is not currently in use.

log "github.com/sirupsen/logrus"
// func my_test_func(mover int, group string, probeDuration time.Duration) (bool, error) {
// // log.WithFields(log.Fields{"group": group, "mover": mover}).Debug("ATMO:")
// switch mover {
// case Discover2Monitor:
// return true, nil
// case Monitor2Protect:
// return true, nil
// }
// return false, common.ErrUnsupported
// }

"github.com/neuvector/neuvector/controller/common"
"github.com/neuvector/neuvector/share/utils"
)
// func my_decision_func(mover int, group string, err error) error {
// log.WithFields(log.Fields{"group": group, "mover": mover, "error": err}).Debug("ATMO:")
// if err != nil {
// log.WithFields(log.Fields{"mover": mover, "error": err}).Debug("ATMO: member left")
// return nil
// }

func my_test_func(mover int, group string, probeDuration time.Duration) (bool, error) {
// log.WithFields(log.Fields{"group": group, "mover": mover}).Debug("ATMO:")
switch mover {
case Discover2Monitor:
return true, nil
case Monitor2Protect:
return true, nil
}
return false, common.ErrUnsupported
}
// switch mover {
// case Discover2Monitor:
// return nil
// case Monitor2Protect:
// return nil
// }
// return common.ErrUnsupported
// }

func my_decision_func(mover int, group string, err error) error {
log.WithFields(log.Fields{"group": group, "mover": mover, "error": err}).Debug("ATMO:")
if err != nil {
log.WithFields(log.Fields{"mover": mover, "error": err}).Debug("ATMO: member left")
return nil
}
// func my_completed(mover int, group string, err error) bool {
// log.WithFields(log.Fields{"group": group, "mover": mover, "error": err}).Debug("ATMO:")
// switch mover {
// case Discover2Monitor:
// return true // promote Discover to Monitor
// case Monitor2Protect:
// return true // promote Monitor to Protect
// }
// return false
// }

switch mover {
case Discover2Monitor:
return nil
case Monitor2Protect:
return nil
}
return common.ErrUnsupported
}
// func initEnv() *automode_ctx {
// log.SetOutput(os.Stdout)
// log.SetLevel(log.DebugLevel) // change it later: log.InfoLevel
// log.SetFormatter(&utils.LogFormatter{Module: "ATMO"})
// timerWheel := utils.NewTimerWheel()
// timerWheel.Start()
// ctx := Init(timerWheel, my_test_func, my_decision_func)
// // testing purpose
// ctx.ConfigProbeTime(Discover2Monitor, time.Second*5)
// ctx.ConfigProbeTime(Monitor2Protect, time.Second*5)
// return ctx
// }

func my_completed(mover int, group string, err error) bool {
log.WithFields(log.Fields{"group": group, "mover": mover, "error": err}).Debug("ATMO:")
switch mover {
case Discover2Monitor:
return true // promote Discover to Monitor
case Monitor2Protect:
return true // promote Monitor to Protect
}
return false
}
// func testAddGroups(t *testing.T) {
// ctx := initEnv()
// ctx.ConfigureCompleteDuration(Discover2Monitor, time.Second*30)
// ctx.ConfigureCompleteDuration(Monitor2Protect, time.Second*60)

func initEnv() *automode_ctx {
log.SetOutput(os.Stdout)
log.SetLevel(log.DebugLevel) // change it later: log.InfoLevel
log.SetFormatter(&utils.LogFormatter{Module: "ATMO"})
timerWheel := utils.NewTimerWheel()
timerWheel.Start()
ctx := Init(timerWheel, my_test_func, my_decision_func)
// testing purpose
ctx.ConfigProbeTime(Discover2Monitor, time.Second*5)
ctx.ConfigProbeTime(Monitor2Protect, time.Second*5)
return ctx
}
// for i := 0; i < 2; i++ {
// name := fmt.Sprintf("m2d%d", i)
// if ok := ctx.AddGroup(Monitor2Protect, name, ProfileMode); !ok {
// t.Errorf("Error: failed to add %s\n", name)
// break
// }
// time.Sleep(time.Second * 10)
// }

func testAddGroups(t *testing.T) {
ctx := initEnv()
ctx.ConfigureCompleteDuration(Discover2Monitor, time.Second*30)
ctx.ConfigureCompleteDuration(Monitor2Protect, time.Second*60)
// for i := 0; i < 5; i++ {
// name := fmt.Sprintf("d2m%d", i)
// if ok := ctx.AddGroup(Discover2Monitor, name, ProfileMode); !ok {
// t.Errorf("Error: failed to add %s\n", name)
// break
// }
// time.Sleep(time.Second * 10)
// }

for i := 0; i < 2; i++ {
name := fmt.Sprintf("m2d%d", i)
if ok := ctx.AddGroup(Monitor2Protect, name, ProfileMode); !ok {
t.Errorf("Error: failed to add %s\n", name)
break
}
time.Sleep(time.Second * 10)
}

for i := 0; i < 5; i++ {
name := fmt.Sprintf("d2m%d", i)
if ok := ctx.AddGroup(Discover2Monitor, name, ProfileMode); !ok {
t.Errorf("Error: failed to add %s\n", name)
break
}
time.Sleep(time.Second * 10)
}

cnt := 12
for {
time.Sleep(time.Second * 10)
if ctx.Counts(Discover2Monitor) == 0 && ctx.Counts(Monitor2Protect) == 0 {
break
}
cnt--
if cnt == 0 {
t.Errorf("Error: failed to stop\n")
break
}
}
}
// cnt := 12
// for {
// time.Sleep(time.Second * 10)
// if ctx.Counts(Discover2Monitor) == 0 && ctx.Counts(Monitor2Protect) == 0 {
// break
// }
// cnt--
// if cnt == 0 {
// t.Errorf("Error: failed to stop\n")
// break
// }
// }
// }
2 changes: 1 addition & 1 deletion controller/common/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func (s *Syslogger) makeDial(prio syslog.Priority, timeout time.Duration) (*sysl

// --

const webhookInfo = "Neuvector webhook is configured."
// const webhookInfo = "Neuvector webhook is configured."
const requestTimeout = time.Duration(5 * time.Second)
const ctypeText = "text/plain; charset=us-ascii"
const ctypeJSON = "application/json"
Expand Down
4 changes: 2 additions & 2 deletions controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ var Host share.CLUSHost = share.CLUSHost{
var Ctrler, parentCtrler share.CLUSController

type ctrlEnvInfo struct {
startsAt time.Time
procDir string
startsAt time.Time
// procDir string
cgroupMemory string
cgroupCPUAcct string
runInContainer bool
Expand Down
6 changes: 3 additions & 3 deletions controller/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
"github.com/neuvector/neuvector/share/utils"
)

const scanImageDataTimeout = time.Second * 45
// const scanImageDataTimeout = time.Second * 45
const repoScanTimeout = time.Minute * 20

type ScanService struct {
Expand Down Expand Up @@ -398,8 +398,8 @@ func (s *CapService) IsGRPCCompressed(ctx context.Context, v *share.RPCVoid) (*s
type UpgradeService struct {
}

const tmpDir string = "/tmp/"
const dstDir string = "/etc/neuvector/db/"
// const tmpDir string = "/tmp/"
// const dstDir string = "/etc/neuvector/db/"

func (s *UpgradeService) SupportUpgradeDB(context.Context, *share.RPCVoid) (*share.CLUSBoolean, error) {
return &share.CLUSBoolean{Value: false}, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ var allowedNamespaces utils.Set // all effectively allowed namespaces that d
var allowedNamespacesWild utils.Set // all effectively allowed namespaces that contain wildcard character
var nsSelectorValue string

var allSetOps = []string{share.CriteriaOpContainsAll, share.CriteriaOpContainsAny, share.CriteriaOpNotContainsAny, share.CriteriaOpContainsOtherThan}
// var allSetOps = []string{share.CriteriaOpContainsAll, share.CriteriaOpContainsAny, share.CriteriaOpNotContainsAny, share.CriteriaOpContainsOtherThan}

func InitK8sNsSelectorInfo(allowedNS, allowedNsWild, defAllowedNS utils.Set, selectorValue string, admCtrlEnabled bool) {
nsSelectorValue = selectorValue
Expand Down
2 changes: 1 addition & 1 deletion controller/resource/kubernetes_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
)

const (
openshiftServer = "openshift"
// openshiftServer = "openshift"

openshiftOAuthDiscoverURL = "%s/.well-known/oauth-authorization-server"
openshiftOAuthDefaultURL = "%s/oauth/authorize"
Expand Down
38 changes: 19 additions & 19 deletions controller/resource/kubernetes_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -1154,25 +1154,25 @@ func xlateConfigMap(obj metav1.Object) (string, interface{}) {
return "", nil
}

func xlateMutatingWebhookConfiguration(obj metav1.Object) (string, interface{}) {
var name string
var guid string
if o, ok := obj.(*admregv1.MutatingWebhookConfiguration); ok {
name = o.GetName()
guid = string(o.GetUID())
} else if o, ok := obj.(*admregv1b1.MutatingWebhookConfiguration); ok {
name = o.GetName()
guid = string(o.GetUID())
}
if name != "" {
r := &AdmissionWebhookConfiguration{
AdmType: nvAdmMutateType,
Name: name,
}
return guid, r
}
return "", nil
}
// func xlateMutatingWebhookConfiguration(obj metav1.Object) (string, interface{}) {
// var name string
// var guid string
// if o, ok := obj.(*admregv1.MutatingWebhookConfiguration); ok {
// name = o.GetName()
// guid = string(o.GetUID())
// } else if o, ok := obj.(*admregv1b1.MutatingWebhookConfiguration); ok {
// name = o.GetName()
// guid = string(o.GetUID())
// }
// if name != "" {
// r := &AdmissionWebhookConfiguration{
// AdmType: nvAdmMutateType,
// Name: name,
// }
// return guid, r
// }
// return "", nil
// }

func xlateValidatingWebhookConfiguration(obj metav1.Object) (string, interface{}) {
var name string
Expand Down
10 changes: 5 additions & 5 deletions controller/resource/kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ import (
"github.com/neuvector/neuvector/share/utils"
)

func preTestDebug() {
log.SetOutput(os.Stdout)
log.SetFormatter(&utils.LogFormatter{Module: "TEST"})
log.SetLevel(log.DebugLevel)
}
// func preTestDebug() {
// log.SetOutput(os.Stdout)
// log.SetFormatter(&utils.LogFormatter{Module: "TEST"})
// log.SetLevel(log.DebugLevel)
// }

func preTest() {
log.SetOutput(os.Stdout)
Expand Down
22 changes: 11 additions & 11 deletions controller/resource/noop.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ type noop struct {
lock sync.RWMutex
}

func (d *noop) locateResourceCache(rt string, id string) interface{} {
d.lock.RLock()
defer d.lock.RUnlock()
if cache, ok := d.resCaches[rt]; !ok {
return nil
} else if old, ok := cache[id]; !ok {
return nil
} else {
return old
}
}
// func (d *noop) locateResourceCache(rt string, id string) interface{} {
// d.lock.RLock()
// defer d.lock.RUnlock()
// if cache, ok := d.resCaches[rt]; !ok {
// return nil
// } else if old, ok := cache[id]; !ok {
// return nil
// } else {
// return old
// }
// }

// Return if object is created or modified, and the old object if exists.
func (d *noop) updateResourceCache(rt string, id string, obj interface{}) (string, interface{}) {
Expand Down
Loading

0 comments on commit cb468e5

Please sign in to comment.