Skip to content

Commit 36e02b3

Browse files
authored
🐛 aws: fetch asset name via instance-connect (#5484)
This change fixes fetching the instance name from the instance tags, before this change we weren't able to run `DescribeTags()` from the `awsec2` package. Signed-off-by: Salim Afiune Maya <afiune@mondoo.com>
1 parent 58d5752 commit 36e02b3

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

providers/os/id/awsec2/awsec2.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package awsec2
66
import (
77
"context"
88

9+
"github.com/aws/aws-sdk-go-v2/aws"
910
"github.com/aws/aws-sdk-go-v2/config"
1011
"github.com/cockroachdb/errors"
1112
"go.mondoo.com/cnquery/v11/providers-sdk/v1/inventory"
@@ -25,7 +26,7 @@ type InstanceIdentifier interface {
2526
}
2627

2728
func Resolve(conn shared.Connection, pf *inventory.Platform) (InstanceIdentifier, error) {
28-
cfg, err := config.LoadDefaultConfig(context.Background())
29+
cfg, err := awsConfig(conn)
2930
if err != nil {
3031
// for local environments we must have a config, or it won't work
3132
if conn.Type() == shared.Type_Local {
@@ -47,3 +48,22 @@ func Resolve(conn shared.Connection, pf *inventory.Platform) (InstanceIdentifier
4748
}
4849
return NewCommandInstanceMetadata(conn, pf, &cfg), nil
4950
}
51+
52+
// awsConfig looks at the connection to see if it has additional options that need
53+
// to be used to create an AWS configuration.
54+
func awsConfig(conn shared.Connection) (aws.Config, error) {
55+
awsConfigOptions := []func(*config.LoadOptions) error{}
56+
57+
if asset := conn.Asset(); asset != nil && len(asset.Connections) != 0 {
58+
for key, value := range asset.Connections[0].Options {
59+
switch key {
60+
case "region":
61+
awsConfigOptions = append(awsConfigOptions, config.WithRegion(value))
62+
case "profile":
63+
awsConfigOptions = append(awsConfigOptions, config.WithSharedConfigProfile(value))
64+
}
65+
}
66+
}
67+
68+
return config.LoadDefaultConfig(context.Background(), awsConfigOptions...)
69+
}

0 commit comments

Comments
 (0)