-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 Fix docker/container registry scanning. Clean the container code a …
…bit (#3701) * 🐛 Fix docker/container registry scanning. Start cleaning code up. Signed-off-by: Preslav <preslav@mondoo.com> * Use type.String() for the container connection. Signed-off-by: Preslav <preslav@mondoo.com> --------- Signed-off-by: Preslav <preslav@mondoo.com>
- Loading branch information
1 parent
0dfbdd3
commit 467ed2b
Showing
10 changed files
with
197 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright (c) Mondoo, Inc. | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
|
||
package auth | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestConstructKeychain(t *testing.T) { | ||
t.Run("default keychain only", func(t *testing.T) { | ||
keychain := getKeychains("test") | ||
require.Equal(t, 1, len(keychain)) | ||
}) | ||
t.Run("default keychain and ecr keychain", func(t *testing.T) { | ||
keychain := getKeychains("0000000000.dkr.ecr.us-east-1.amazonaws.com/test") | ||
require.Equal(t, 2, len(keychain)) | ||
}) | ||
|
||
t.Run("default keychain and acr keychain", func(t *testing.T) { | ||
keychain := getKeychains("test.azurecr.io") | ||
require.Equal(t, 2, len(keychain)) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Copyright (c) Mondoo, Inc. | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
|
||
package container | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/spf13/afero" | ||
"go.mondoo.com/cnquery/v10/providers-sdk/v1/inventory" | ||
"go.mondoo.com/cnquery/v10/providers-sdk/v1/plugin" | ||
"go.mondoo.com/cnquery/v10/providers/os/connection/shared" | ||
"go.mondoo.com/cnquery/v10/providers/os/resources/discovery/container_registry" | ||
) | ||
|
||
var _ shared.Connection = &RegistryConnection{} | ||
|
||
type RegistryConnection struct { | ||
plugin.Connection | ||
asset *inventory.Asset | ||
} | ||
|
||
func (r *RegistryConnection) Capabilities() shared.Capabilities { | ||
return shared.Capabilities(0) | ||
} | ||
|
||
func (r *RegistryConnection) FileInfo(path string) (shared.FileInfoDetails, error) { | ||
return shared.FileInfoDetails{}, plugin.ErrFileInfoNotImplemented | ||
} | ||
|
||
func (r *RegistryConnection) FileSystem() afero.Fs { | ||
panic("unimplemented") | ||
} | ||
|
||
func (r *RegistryConnection) RunCommand(command string) (*shared.Command, error) { | ||
return nil, errors.New("unimplemented") | ||
} | ||
|
||
func (r *RegistryConnection) Type() shared.ConnectionType { | ||
return shared.Type_ContainerRegistry | ||
} | ||
|
||
func (r *RegistryConnection) UpdateAsset(asset *inventory.Asset) { | ||
r.asset = asset | ||
} | ||
|
||
func NewRegistryConnection(id uint32, asset *inventory.Asset) (*RegistryConnection, error) { | ||
conn := &RegistryConnection{ | ||
Connection: plugin.NewConnection(id, asset), | ||
asset: asset, | ||
} | ||
|
||
return conn, nil | ||
} | ||
|
||
func (r *RegistryConnection) Name() string { | ||
return "container-registry" | ||
} | ||
|
||
func (r *RegistryConnection) ID() uint32 { | ||
return r.Connection.ID() | ||
} | ||
|
||
func (r *RegistryConnection) ParentID() uint32 { | ||
return r.Connection.ParentID() | ||
} | ||
|
||
func (r *RegistryConnection) Close() error { | ||
return nil | ||
} | ||
|
||
func (r *RegistryConnection) Asset() *inventory.Asset { | ||
return r.asset | ||
} | ||
|
||
func (r *RegistryConnection) DiscoverImages() (*inventory.Inventory, error) { | ||
resolver := container_registry.NewContainerRegistryResolver() | ||
host := r.asset.Connections[0].Host | ||
assets, err := resolver.ListRegistry(host) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return inventory.New(inventory.WithAssets(assets...)), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.