Skip to content

Commit

Permalink
Merge pull request neuvector#1606 from jeffhuang4704/NVSHAS-9525_Reso…
Browse files Browse the repository at this point in the history
…lve_existing_Go_linter_issues

fix: NVSHAS-9525 fix lint issue in controller, gofmt category
  • Loading branch information
williamlin-suse authored Oct 14, 2024
2 parents 8d68aed + 05ac6f6 commit 03c8975
Show file tree
Hide file tree
Showing 73 changed files with 960 additions and 1,050 deletions.
18 changes: 9 additions & 9 deletions controller/access/access.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ func getRestRolePermitValues(roleName, domain string) map[string]rwPermit {
}
for _, option := range PermissionOptions {
// need to check fed/nv_resource permissions as well
permit, _ := rolePermits[option.ID]
permit := rolePermits[option.ID]
optionReadValue, optionWriteValue := option.Value, option.Value
if domain == AccessDomainGlobal {
optionReadValue &= share.PERMS_FED_READ
Expand Down Expand Up @@ -521,7 +521,7 @@ func getDomainPermissions(domain string, roles []string, extraPermits []share.Nv
} else {
for id, rw := range rolePermits {
if rw.read || rw.write {
rwFound, _ := allPermits[id]
rwFound := allPermits[id]
allPermits[id] = rwPermit{read: rwFound.read || rw.read, write: rwFound.write || rw.write}
}
}
Expand All @@ -544,7 +544,7 @@ func getDomainPermissions(domain string, roles []string, extraPermits []share.Nv
}
for _, permit := range GetTopLevelPermitsList(scope, dExtraPermits) { // iterate thru []*api.RESTRolePermission from extra permissions
if permit.Read || permit.Write {
rw, _ := allPermits[permit.ID]
rw := allPermits[permit.ID]
allPermits[permit.ID] = rwPermit{read: rw.read || permit.Read, write: rw.write || permit.Write}
}
}
Expand Down Expand Up @@ -584,7 +584,7 @@ func GetUserPermissions(role string, roleDomains map[string][]string, extraPermi
}
for _, domain := range domains {
if domain != AccessDomainGlobal {
roles, _ := domainRoles[domain]
roles := domainRoles[domain]
domainRoles[domain] = append(roles, role)
allDomains[domain] = nil
}
Expand All @@ -599,7 +599,7 @@ func GetUserPermissions(role string, roleDomains map[string][]string, extraPermi
}
for _, domain := range permitsDomains.Domains {
if domain != AccessDomainGlobal {
permits, _ := domainPermits[domain]
permits := domainPermits[domain]
domainPermits[domain] = append(permits, permitsDomains.Permits)
allDomains[domain] = nil
}
Expand All @@ -608,9 +608,9 @@ func GetUserPermissions(role string, roleDomains map[string][]string, extraPermi

// 2-3. merge #2-1 & #2-2 to get the top-level permissions list for each domain
dPermitsList := make(map[string][]*api.RESTRolePermission, len(allDomains)) // domain -> list of permissions
for domain, _ := range allDomains {
roles, _ := domainRoles[domain]
extraPermits, _ := domainPermits[domain]
for domain := range allDomains {
roles := domainRoles[domain]
extraPermits := domainPermits[domain]
if permitsList := getDomainPermissions(domain, roles, extraPermits); len(permitsList) > 0 {
dPermitsList[domain] = permitsList
}
Expand Down Expand Up @@ -672,7 +672,7 @@ func getRequiredPermissions(r *http.Request) (int8, uint32) {
}
}
}
requiredPermissions, _ := apiPermissions[apiCategoryID]
requiredPermissions := apiPermissions[apiCategoryID]

return apiCategoryID, requiredPermissions
}
Expand Down
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
2 changes: 1 addition & 1 deletion controller/api/access.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (o *Event) GetDomain(f share.GetAccessObjectFunc) ([]string, []string) {
return []string{o.WorkloadDomain}, nil
} else if o.UserRoles != nil {
list := make([]string, 0, len(o.UserRoles))
for domain, _ := range o.UserRoles {
for domain := range o.UserRoles {
list = append(list, domain)
}
return list, nil
Expand Down
30 changes: 15 additions & 15 deletions controller/api/internal_apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,16 @@ type RESTRiskScoreMetricsWL struct {
}

type RESTRiskScoreMetricsGroup struct {
Groups int `json:"groups"`
DiscoverGroups int `json:"discover_groups"`
MonitorGroups int `json:"monitor_groups"`
ProtectGroups int `json:"protect_groups"`
ProfileDiscoverGroups int `json:"profile_discover_groups"`
ProfileMonitorGroups int `json:"profile_monitor_groups"`
ProfileProtectGroups int `json:"profile_protect_groups"`
DiscoverGroupsZD int `json:"discover_groups_zero_drift"`
MonitorGroupsZD int `json:"monitor_groups_zero_drift"`
ProtectGroupsZD int `json:"protect_groups_zero_drift"`
Groups int `json:"groups"`
DiscoverGroups int `json:"discover_groups"`
MonitorGroups int `json:"monitor_groups"`
ProtectGroups int `json:"protect_groups"`
ProfileDiscoverGroups int `json:"profile_discover_groups"`
ProfileMonitorGroups int `json:"profile_monitor_groups"`
ProfileProtectGroups int `json:"profile_protect_groups"`
DiscoverGroupsZD int `json:"discover_groups_zero_drift"`
MonitorGroupsZD int `json:"monitor_groups_zero_drift"`
ProtectGroupsZD int `json:"protect_groups_zero_drift"`
}

type RESTRiskScoreMetricsCVE struct {
Expand Down Expand Up @@ -229,9 +229,9 @@ type RESTK8sNvAcceptableAlerts struct {
}

type RESTNvAlerts struct {
NvUpgradeInfo *RESTCheckUpgradeInfo `json:"neuvector_upgrade_info"`
AcceptableAlerts *RESTNvAcceptableAlerts `json:"acceptable_alerts,omitempty"` // acceptable controller-generated alerts
AcceptedAlerts []string `json:"accepted_alerts,omitempty"` // keys of accepted manager-generated/user alerts
NvUpgradeInfo *RESTCheckUpgradeInfo `json:"neuvector_upgrade_info"`
AcceptableAlerts *RESTNvAcceptableAlerts `json:"acceptable_alerts,omitempty"` // acceptable controller-generated alerts
AcceptedAlerts []string `json:"accepted_alerts,omitempty"` // keys of accepted manager-generated/user alerts
}

type RESTNvAcceptableAlerts struct {
Expand All @@ -257,8 +257,8 @@ type RESTNvAlertGroup struct {
}

type RESTNvAlert struct {
ID string `json:"id"` // ID is md5 of the English message
Message string `json:"message"`
ID string `json:"id"` // ID is md5 of the English message
Message string `json:"message"`
}

type RESTAcceptedAlerts struct {
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
Loading

0 comments on commit 03c8975

Please sign in to comment.