Skip to content

Commit

Permalink
🧹 safe guard connections that should implement the Closer interface (#…
Browse files Browse the repository at this point in the history
…3302)

Signed-off-by: Ivan Milchev <[email protected]>
  • Loading branch information
imilchev authored Feb 14, 2024
1 parent f9ac865 commit 9179ae5
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 11 deletions.
2 changes: 2 additions & 0 deletions providers/aws/connection/awsec2ebsconn/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ const (
EBSConnectionType shared.ConnectionType = "ebs"
)

var _ plugin.Closer = (*AwsEbsConnection)(nil)

type AwsEbsConnection struct {
plugin.Connection
asset *inventory.Asset
Expand Down
3 changes: 3 additions & 0 deletions providers/azure/connection/azureinstancesnapshot/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/rs/zerolog/log"
"go.mondoo.com/cnquery/v10/mrn"
"go.mondoo.com/cnquery/v10/providers-sdk/v1/inventory"
"go.mondoo.com/cnquery/v10/providers-sdk/v1/plugin"
"go.mondoo.com/cnquery/v10/providers-sdk/v1/vault"
"go.mondoo.com/cnquery/v10/providers/azure/connection/auth"
"go.mondoo.com/cnquery/v10/providers/azure/connection/shared"
Expand Down Expand Up @@ -246,6 +247,8 @@ func NewAzureSnapshotConnection(id uint32, conf *inventory.Config, asset *invent
return c, nil
}

var _ plugin.Closer = (*AzureSnapshotConnection)(nil)

type AzureSnapshotConnection struct {
*fs.FileSystemConnection
opts map[string]string
Expand Down
3 changes: 3 additions & 0 deletions providers/gcp/connection/gcpinstancesnapshot/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/rs/zerolog/log"
"go.mondoo.com/cnquery/v10/mrn"
"go.mondoo.com/cnquery/v10/providers-sdk/v1/inventory"
"go.mondoo.com/cnquery/v10/providers-sdk/v1/plugin"
"go.mondoo.com/cnquery/v10/providers/gcp/connection/shared"
"go.mondoo.com/cnquery/v10/providers/os/connection/fs"
"go.mondoo.com/cnquery/v10/providers/os/connection/local"
Expand Down Expand Up @@ -252,6 +253,8 @@ func NewGcpSnapshotConnection(id uint32, conf *inventory.Config, asset *inventor
return c, nil
}

var _ plugin.Closer = (*GcpSnapshotConnection)(nil)

type GcpSnapshotConnection struct {
*fs.FileSystemConnection
opts map[string]string
Expand Down
5 changes: 4 additions & 1 deletion providers/os/connection/fs/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ import (
"go.mondoo.com/cnquery/v10/providers/os/fs"
)

var _ shared.Connection = &FileSystemConnection{}
var (
_ shared.Connection = (*FileSystemConnection)(nil)
_ plugin.Closer = (*FileSystemConnection)(nil)
)

func NewFileSystemConnectionWithClose(id uint32, conf *inventory.Config, asset *inventory.Asset, closeFN func()) (*FileSystemConnection, error) {
path, ok := conf.Options["path"]
Expand Down
4 changes: 0 additions & 4 deletions providers/os/connection/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,6 @@ func (p *LocalConnection) FileInfo(path string) (shared.FileInfoDetails, error)
}, nil
}

func (p *LocalConnection) Close() {
// TODO: we need to close all commands and file handles
}

type CommandRunner struct {
shared.Command
cmdExecutor *exec.Cmd
Expand Down
5 changes: 4 additions & 1 deletion providers/os/connection/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ import (
"golang.org/x/crypto/ssh/knownhosts"
)

var _ shared.Connection = (*SshConnection)(nil)
var (
_ shared.Connection = (*SshConnection)(nil)
_ plugin.Closer = (*SshConnection)(nil)
)

type SshConnection struct {
plugin.Connection
Expand Down
5 changes: 4 additions & 1 deletion providers/os/connection/tar.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ const (
FLATTENED_IMAGE = "flattened_path"
)

var _ shared.Connection = (*TarConnection)(nil)
var (
_ shared.Connection = (*TarConnection)(nil)
_ plugin.Closer = (*TarConnection)(nil)
)

type TarConnection struct {
plugin.Connection
Expand Down
4 changes: 0 additions & 4 deletions providers/os/connection/winrm.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,3 @@ func (p *WinrmConnection) FileSystem() afero.Fs {
}
return p.fs
}

func (p *WinrmConnection) Close() {
// nothing to do yet
}
2 changes: 2 additions & 0 deletions providers/terraform/connection/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (

type ConnectionType string

var _ plugin.Closer = (*Connection)(nil)

// References:
// - https://www.terraform.io/docs/language/syntax/configuration.html
// - https://github.com/hashicorp/hcl/blob/main/hclsyntax/spec.md
Expand Down

0 comments on commit 9179ae5

Please sign in to comment.