Skip to content

Commit

Permalink
chore(internal,pkg): fixup some linting issues.
Browse files Browse the repository at this point in the history
Signed-off-by: Federico Di Pierro <[email protected]>
  • Loading branch information
FedeDP committed Nov 3, 2023
1 parent 61f5e7a commit df3d709
Show file tree
Hide file tree
Showing 15 changed files with 39 additions and 17 deletions.
3 changes: 2 additions & 1 deletion cmd/driver/driver_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ package driver

import (
"context"
"github.com/falcosecurity/falcoctl/cmd/driver/prepare"

driverprepare "github.com/falcosecurity/falcoctl/cmd/driver/prepare"
driverselect "github.com/falcosecurity/falcoctl/cmd/driver/select"
"github.com/falcosecurity/falcoctl/internal/config"
commonoptions "github.com/falcosecurity/falcoctl/pkg/options"
Expand Down
1 change: 1 addition & 0 deletions cmd/driver/prepare/prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package driverprepare
import (
"errors"
"fmt"

"github.com/falcosecurity/falcoctl/internal/config"
driverdistro "github.com/falcosecurity/falcoctl/pkg/driver/distro"
driverkernel "github.com/falcosecurity/falcoctl/pkg/driver/kernel"
Expand Down
1 change: 1 addition & 0 deletions cmd/driver/select/select.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package driverselect

import (
"fmt"

"github.com/falcosecurity/falcoctl/internal/config"
driverdistro "github.com/falcosecurity/falcoctl/pkg/driver/distro"
driverkernel "github.com/falcosecurity/falcoctl/pkg/driver/kernel"
Expand Down
1 change: 1 addition & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@ func Driverer() (Driver, error) {
}, nil
}

// SelectDriver stores a driver as selected in config file.
func SelectDriver(driverType, configFile string) error {
if err := UpdateConfigFile(DriverSelectedKey, driverType, configFile); err != nil {
return fmt.Errorf("unable to update selected driver in the config file %q: %w", configFile, err)
Expand Down
15 changes: 8 additions & 7 deletions pkg/driver/distro/amzn.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package driverdistro

import (
"fmt"

"github.com/falcosecurity/falcoctl/pkg/output"
"gopkg.in/ini.v1"
)
Expand All @@ -14,23 +15,23 @@ type amzn struct {
*generic
}

func (a *amzn) init(printer *output.Printer, id string, cfg *ini.File) error {
func (a *amzn) init(printer *output.Printer, _ string, cfg *ini.File) error {
idKey := cfg.Section("").Key("VERSION_ID")
if idKey == nil {
// OS-release without `VERSION_ID` (can it happen?)
return fmt.Errorf("no VERSION_ID present for amzn")
}
// overwrite id
newId := ""
newID := ""
switch idKey.String() {
case "2":
newId = "amazonlinux2"
newID = "amazonlinux2"
case "2022":
newId = "amazonlinux2022"
newID = "amazonlinux2022"
case "2023":
newId = "amazonlinux2023"
newID = "amazonlinux2023"
default:
newId = "amazonlinux"
newID = "amazonlinux"
}
return a.generic.init(printer, newId, cfg)
return a.generic.init(printer, newID, cfg)
}
3 changes: 2 additions & 1 deletion pkg/driver/distro/bottlerocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package driverdistro

import (
"fmt"
"strings"

driverkernel "github.com/falcosecurity/falcoctl/pkg/driver/kernel"
"github.com/falcosecurity/falcoctl/pkg/output"
"gopkg.in/ini.v1"
"strings"
)

func init() {
Expand Down
3 changes: 2 additions & 1 deletion pkg/driver/distro/debian.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package driverdistro

import (
"fmt"
driverkernel "github.com/falcosecurity/falcoctl/pkg/driver/kernel"
"os"
"regexp"

driverkernel "github.com/falcosecurity/falcoctl/pkg/driver/kernel"
)

func init() {
Expand Down
8 changes: 7 additions & 1 deletion pkg/driver/distro/distro.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,22 @@ package driverdistro

import (
"fmt"
"strings"

driverkernel "github.com/falcosecurity/falcoctl/pkg/driver/kernel"
drivertype "github.com/falcosecurity/falcoctl/pkg/driver/type"
"github.com/falcosecurity/falcoctl/pkg/options"
"github.com/falcosecurity/falcoctl/pkg/output"
"gopkg.in/ini.v1"
"strings"
)

var distros = map[string]Distro{}

// ErrUnsupported is the error returned when the target distro is not supported.
var ErrUnsupported = fmt.Errorf("failed to determine distro")

// Distro is the common interface used by distro-specific implementations.
// Most of the distro-specific only partially override the default `generic` implementation.
type Distro interface {
init(printer *output.Printer, id string, cfg *ini.File) error // private
GetTargetID(i driverkernel.Info) string
Expand All @@ -27,6 +31,8 @@ type checker interface {
check(hostRoot string) bool // private
}

// DiscoverDistro tries to fetch the correct Distro by looking at /etc/os-release or
// by cycling on all supported distros and checking them one by one.
func DiscoverDistro(printer *output.Printer, hostRoot string) (Distro, error) {
distro, err := getOSReleaseDistro(printer, hostRoot)
if err == nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/driver/distro/flatcar.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package driverdistro

import (
"fmt"

driverkernel "github.com/falcosecurity/falcoctl/pkg/driver/kernel"
"github.com/falcosecurity/falcoctl/pkg/output"
"gopkg.in/ini.v1"
Expand Down
7 changes: 4 additions & 3 deletions pkg/driver/distro/generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ package driverdistro

import (
"fmt"
"io"
"net/http"
"os"

"github.com/docker/docker/pkg/homedir"
driverkernel "github.com/falcosecurity/falcoctl/pkg/driver/kernel"
drivertype "github.com/falcosecurity/falcoctl/pkg/driver/type"
"github.com/falcosecurity/falcoctl/pkg/options"
"github.com/falcosecurity/falcoctl/pkg/output"
"gopkg.in/ini.v1"
"io"
"net/http"
"os"
)

type generic struct {
Expand Down
3 changes: 2 additions & 1 deletion pkg/driver/distro/minikube.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package driverdistro

import (
"fmt"
driverkernel "github.com/falcosecurity/falcoctl/pkg/driver/kernel"
"io"
"os"
"regexp"

driverkernel "github.com/falcosecurity/falcoctl/pkg/driver/kernel"
)

func init() {
Expand Down
1 change: 1 addition & 0 deletions pkg/driver/distro/talos.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package driverdistro

import (
"fmt"

driverkernel "github.com/falcosecurity/falcoctl/pkg/driver/kernel"
"github.com/falcosecurity/falcoctl/pkg/output"
"gopkg.in/ini.v1"
Expand Down
3 changes: 2 additions & 1 deletion pkg/driver/distro/ubuntu.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package driverdistro

import (
driverkernel "github.com/falcosecurity/falcoctl/pkg/driver/kernel"
"regexp"
"strings"

driverkernel "github.com/falcosecurity/falcoctl/pkg/driver/kernel"
)

func init() {
Expand Down
4 changes: 3 additions & 1 deletion pkg/driver/kernel/kernel.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package driverkernel

import (
"bytes"
"golang.org/x/sys/unix"
"strings"

"golang.org/x/sys/unix"
)

// Info is the struct that holds all the kernel related information that are needed.
type Info struct {
Architecture string
KernelRelease string
Expand Down
2 changes: 2 additions & 0 deletions pkg/driver/type/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import "fmt"

var driverTypes = map[string]DriverType{}

// DriverType is the interface that wraps driver types.
type DriverType interface {
String() string
Prepare() error
Extension() string
HasArtifacts() bool
}

// Parse parses a driver type string and returns the corresponding DriverType object or an error.
func Parse(driverType string) (DriverType, error) {
if dType, ok := driverTypes[driverType]; ok {
return dType, nil
Expand Down

0 comments on commit df3d709

Please sign in to comment.