Skip to content

Commit

Permalink
Merge pull request #91 from unpoller/linting
Browse files Browse the repository at this point in the history
Apply Linting, Improve Release Process
  • Loading branch information
platinummonkey committed Jul 27, 2023
2 parents 1203f11 + 637233d commit cb0eebf
Show file tree
Hide file tree
Showing 26 changed files with 530 additions and 312 deletions.
19 changes: 5 additions & 14 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Build

on:
on:
- pull_request

permissions:
Expand All @@ -14,8 +14,8 @@ jobs:
test:
strategy:
matrix:
go: [1.19]
os: [ubuntu-latest]
go: ["1.20"]
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
Expand All @@ -33,7 +33,7 @@ jobs:
lint:
strategy:
matrix:
go: [1.19]
go: ["1.20"]
os: [ubuntu-latest]
name: lint
runs-on: ${{ matrix.os }}
Expand All @@ -47,13 +47,4 @@ jobs:
uses: golangci/golangci-lint-action@v3
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.50.1
# Optional: working directory, useful for monorepos
# working-directory: somedir

# Optional: golangci-lint command line arguments.
# args: --issues-exit-code=0
args: --timeout=3m

# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true
version: v1.53
35 changes: 35 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Release

on:
push:
# run only against tags
tags:
- '*'

permissions:
contents: write
packages: write

jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- run: git fetch --force --tags
- uses: actions/setup-go@v3
with:
go-version: '>=1.20.5'
cache: true
- uses: goreleaser/goreleaser-action@v4
with:
# either 'goreleaser' (default) or 'goreleaser-pro':
distribution: goreleaser-pro
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Your GoReleaser Pro key, if you are using the 'goreleaser-pro'
# distribution:
GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}
27 changes: 27 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
run:
timeout: 3m

linters:
enable:
- wsl
- nlreturn
- tagalign
- revive
- testpackage
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- unused

output:
sort-results: true

issues:
# disable the default limit so we see everything
max-same-issues: 0
max-issues-per-linter: 0

# default enable fix where the linter supports
fix: true
2 changes: 2 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
builds:
- skip: true
26 changes: 13 additions & 13 deletions alarms.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,44 @@ import (

type Alarm struct {
Archived FlexBool `json:"archived"`
DestPort int `json:"dest_port" fake:"{port}"`
SrcPort int `json:"src_port" fake:"{port}"`
DestPort int `fake:"{port}" json:"dest_port"`
SrcPort int `fake:"{port}" json:"src_port"`
FlowID int64 `json:"flow_id"`
InnerAlertGID int64 `json:"inner_alert_gid"`
InnerAlertRev int64 `json:"inner_alert_rev"`
InnerAlertSeverity int64 `json:"inner_alert_severity"`
InnerAlertSignatureID int64 `json:"inner_alert_signature_id"`
Time int64 `json:"time" fake:"{timestamp}"`
Timestamp int64 `json:"timestamp" fake:"{timestamp}"`
Time int64 `fake:"{timestamp}" json:"time"`
Timestamp int64 `fake:"{timestamp}" json:"timestamp"`
Datetime time.Time `json:"datetime"`
HandledTime time.Time `json:"handled_time,omitempty"`
AppProto string `json:"app_proto,omitempty"`
Catname string `json:"catname"`
DestIP string `json:"dest_ip" fake:"{ipv4address}"`
DstMAC string `json:"dst_mac" fake:"{macaddress}"`
DestIP string `fake:"{ipv4address}" json:"dest_ip"`
DstMAC string `fake:"{macaddress}" json:"dst_mac"`
DstIPASN string `json:"dstipASN,omitempty"`
DstIPCountry string `json:"dstipCountry,omitempty"`
EventType string `json:"event_type"`
HandledAdminID string `json:"handled_admin_id,omitempty"`
Host string `json:"host"`
ID string `json:"_id" fake:"{uuid}"`
InIface string `json:"in_iface" fake:"{randomstring:[eth0,eth1,lan1,wan1,wan2]}"`
ID string `fake:"{uuid}" json:"_id"`
InIface string `fake:"{randomstring:[eth0,eth1,lan1,wan1,wan2]}" json:"in_iface"`
InnerAlertAction string `json:"inner_alert_action"`
InnerAlertCategory string `json:"inner_alert_category"`
InnerAlertSignature string `json:"inner_alert_signature"`
Key string `json:"key"`
Msg string `json:"msg" fake:"{sentence:5}"`
Msg string `fake:"{sentence:5}" json:"msg"`
Proto string `json:"proto"`
SiteID string `json:"site_id" fake:"{uuid}"`
SiteID string `fake:"{uuid}" json:"site_id"`
SiteName string `json:"-"`
SourceName string `json:"-"`
SrcIP string `json:"src_ip" fake:"{ipv4address}"`
SrcIP string `fake:"{ipv4address}" json:"src_ip"`
SrcIPASN string `json:"srcipASN,omitempty"`
SrcIPCountry string `json:"srcipCountry,omitempty"`
SrcMAC string `json:"src_mac" fake:"{macaddress}"`
SrcMAC string `fake:"{macaddress}" json:"src_mac"`
Subsystem string `json:"subsystem"`
UniqueAlertID string `json:"unique_alertid"`
USGIP string `json:"usgip" fake:"{ipv4address}"`
USGIP string `fake:"{ipv4address}" json:"usgip"`
USGIPASN string `json:"usgipASN"`
USGIPCountry string `json:"usgipCountry"`
TxID FlexInt `json:"tx_id,omitempty"`
Expand Down
4 changes: 2 additions & 2 deletions anomalies.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
// anomaly is the type UniFi returns, but not the type this library returns.
type anomaly struct {
Anomaly string `json:"anomaly"`
MAC string `json:"mac" fake:"{macaddress}"`
Timestamps []int64 `json:"timestamps" fake:"{timestamps}"`
MAC string `fake:"{macaddress}" json:"mac"`
Timestamps []int64 `fake:"{timestamps}" json:"timestamps"`
}

// Anomaly is the reformatted data type that this library returns.
Expand Down
28 changes: 14 additions & 14 deletions clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ func (u *Unifi) GetClientsDPI(sites []*Site) ([]*DPITable, error) {
type Client struct {
SourceName string `json:"-"`
Anomalies FlexInt `json:"anomalies,omitempty"`
ApMac string `json:"ap_mac" fake:"{macaddress}"`
ApMac string `fake:"{macaddress}" json:"ap_mac"`
ApName string `json:"-"`
AssocTime FlexInt `json:"assoc_time"`
Blocked bool `json:"blocked,omitempty"`
Bssid string `json:"bssid" fake:"{macaddress}"`
Bssid string `fake:"{macaddress}" json:"bssid"`
BytesR FlexInt `json:"bytes-r"`
Ccq FlexInt `json:"ccq"`
Channel FlexInt `json:"channel"`
Expand All @@ -81,14 +81,14 @@ type Client struct {
DevVendor FlexInt `json:"dev_vendor,omitempty"`
DhcpendTime FlexInt `json:"dhcpend_time,omitempty"`
Satisfaction FlexInt `json:"satisfaction,omitempty"`
Essid string `json:"essid" fake:"{macaddress}"`
Essid string `fake:"{macaddress}" json:"essid"`
FirstSeen FlexInt `json:"first_seen"`
FixedIP string `json:"fixed_ip" fake:"{ipv4address}"`
GwMac string `json:"gw_mac" fake:"{macaddress}"`
FixedIP string `fake:"{ipv4address}" json:"fixed_ip"`
GwMac string `fake:"{macaddress}" json:"gw_mac"`
GwName string `json:"-"`
Hostname string `json:"hostname"`
ID string `json:"_id" fake:"{uuid}"`
IP string `json:"ip" fake:"{ipv4address}"`
ID string `fake:"{uuid}" json:"_id"`
IP string `fake:"{ipv4address}" json:"ip"`
IdleTime FlexInt `json:"idle_time"`
Is11R FlexBool `json:"is_11r"`
IsGuest FlexBool `json:"is_guest"`
Expand All @@ -101,12 +101,12 @@ type Client struct {
LastSeenByUGW FlexInt `json:"_last_seen_by_ugw"`
LastSeenByUSW FlexInt `json:"_last_seen_by_usw"`
LatestAssocTime FlexInt `json:"latest_assoc_time"`
Mac string `json:"mac" fake:"{macaddress}"`
Mac string `fake:"{macaddress}" json:"mac"`
Name string `json:"name"`
Network string `json:"network"`
NetworkID string `json:"network_id" fake:"{uuid}"`
NetworkID string `fake:"{uuid}" json:"network_id"`
Noise FlexInt `json:"noise"`
Note string `json:"note" fake:"{sentence 20}"`
Note string `fake:"{sentence 20}" json:"note"`
Noted FlexBool `json:"noted"`
OsClass FlexInt `json:"os_class"`
OsName FlexInt `json:"os_name"`
Expand All @@ -124,10 +124,10 @@ type Client struct {
RxPackets FlexInt `json:"rx_packets"`
RxRate FlexInt `json:"rx_rate"`
Signal FlexInt `json:"signal"`
SiteID string `json:"site_id" fake:"{uuid}"`
SiteID string `fake:"{uuid}" json:"site_id"`
SiteName string `json:"-"`
SwDepth int `json:"sw_depth"`
SwMac string `json:"sw_mac" fake:"{macaddress}"`
SwMac string `fake:"{macaddress}" json:"sw_mac"`
SwName string `json:"-"`
SwPort FlexInt `json:"sw_port"`
TxBytes FlexInt `json:"tx_bytes"`
Expand All @@ -141,8 +141,8 @@ type Client struct {
UptimeByUGW FlexInt `json:"_uptime_by_ugw"`
UptimeByUSW FlexInt `json:"_uptime_by_usw"`
UseFixedIP FlexBool `json:"use_fixedip"`
UserGroupID string `json:"usergroup_id" fake:"{uuid}"`
UserID string `json:"user_id" fake:"{uuid}"`
UserGroupID string `fake:"{uuid}" json:"usergroup_id"`
UserID string `fake:"{uuid}" json:"user_id"`
Vlan FlexInt `json:"vlan"`
WifiTxAttempts FlexInt `json:"wifi_tx_attempts"`
WiredRxBytes FlexInt `json:"wired-rx_bytes"`
Expand Down
1 change: 1 addition & 0 deletions devices.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ func (u *Unifi) parseDevices(data []json.RawMessage, site *Site) *Devices {
var o minimalUnmarshalInfo
if u.unmarshalDevice("map", r, &o) != nil {
u.ErrorLog("unknown asset type - cannot find asset type in payload - skipping")

continue
}

Expand Down
7 changes: 4 additions & 3 deletions devmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ const (
// devMgrCmd is the type marshalled and sent to APIDevMgrPath.
type devMgrCmd struct {
Cmd string `json:"cmd"` // Required.
Mac string `json:"mac" fake:"{macaddress}"` // Device MAC (required for most, but not all).
URL string `json:"url,omitempty" fake:"{url}"` // External Upgrade only.
Inform string `json:"inform_url,omitempty" fake:"{url}"` // Migration only.
Mac string `fake:"{macaddress}" json:"mac"` // Device MAC (required for most, but not all).
URL string `fake:"{url}" json:"url,omitempty"` // External Upgrade only.
Inform string `fake:"{url}" json:"inform_url,omitempty"` // Migration only.
Port int `json:"port_idx,omitempty"` // Power Cycle only.
}

Expand All @@ -51,6 +51,7 @@ func (s *Site) devMgrCommandReply(cmd *devMgrCmd) ([]byte, error) {
// devMgrCommandSimple is for commands with no return value.
func (s *Site) devMgrCommandSimple(cmd *devMgrCmd) error {
_, err := s.devMgrCommandReply(cmd)

return err
}

Expand Down
10 changes: 5 additions & 5 deletions dpi.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ type DPITable struct {
SourceName string `json:"-"`
SiteName string `json:"-"`
Name string `json:"-"`
MAC string `json:"mac" fake:"{macaddress}"`
ByCat []DPIData `json:"by_cat" fakesize:"5"`
ByApp []DPIData `json:"by_app" fakesize:"5"`
MAC string `fake:"{macaddress}" json:"mac"`
ByCat []DPIData `fakesize:"5" json:"by_cat"`
ByApp []DPIData `fakesize:"5" json:"by_app"`
LastUpdated FlexInt `json:"last_updated"`
}

Expand All @@ -21,13 +21,13 @@ type DPIData struct {
TxBytes FlexInt `json:"tx_bytes"`
RxPackets FlexInt `json:"rx_packets"`
TxPackets FlexInt `json:"tx_packets"`
Clients []*DPIClient `json:"clients,omitempty" fakesize:"5"`
Clients []*DPIClient `fakesize:"5" json:"clients,omitempty"`
KnownClients FlexInt `json:"known_clients,omitempty"`
}

// DPIClient data is sometimes included in ByApp output.
type DPIClient struct {
Mac string `json:"mac" fake:"{macaddress}"`
Mac string `fake:"{macaddress}" json:"mac"`
RxBytes FlexInt `json:"rx_bytes"`
TxBytes FlexInt `json:"tx_bytes"`
RxPackets FlexInt `json:"rx_packets"`
Expand Down
Loading

0 comments on commit cb0eebf

Please sign in to comment.