Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🧹 improve the sagemaker notebook instance & iam mfadevice resource #4587

Merged
merged 2 commits into from
Aug 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion providers/aws/resources/aws.lr
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@ private aws.iam.virtualmfadevice @defaults("serialNumber") {
// Time when the MFA device was enabled
enableDate time
// User associated with the MFA device
user aws.iam.user
user() aws.iam.user
}

// AWS IAM Access Analyzer resource (for assessing the configuration of AWS IAM Access Analyzer)
Expand Down
18 changes: 15 additions & 3 deletions providers/aws/resources/aws.lr.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 24 additions & 16 deletions providers/aws/resources/aws_iam.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,38 +303,46 @@ func (a *mqlAwsIam) virtualMfaDevices() ([]interface{}, error) {
for i := range devicesResp.VirtualMFADevices {
device := devicesResp.VirtualMFADevices[i]

var mqlAwsIamUser plugin.Resource
args := map[string]*llx.RawData{
"serialNumber": llx.StringDataPtr(device.SerialNumber),
"enableDate": llx.TimeDataPtr(device.EnableDate),
}

usr := device.User
if usr != nil {
mqlAwsIamUser, err = NewResource(a.MqlRuntime, "aws.iam.user", map[string]*llx.RawData{
"arn": llx.StringDataPtr(usr.Arn),
"name": llx.StringDataPtr(usr.UserName),
})
if err == nil {
args["user"] = llx.ResourceData(mqlAwsIamUser, "aws.iam.user")
}
}

if usr == nil || err != nil {
args["user"] = llx.NilData
}

mqlAwsIamMfaDevice, err := CreateResource(a.MqlRuntime, "aws.iam.virtualmfadevice", args)
if err != nil {
return nil, err
}

res = append(res, mqlAwsIamMfaDevice)
if device.User != nil {
mqlAwsIamMfaDevice.(*mqlAwsIamVirtualmfadevice).cacheUserArn = device.User.Arn
mqlAwsIamMfaDevice.(*mqlAwsIamVirtualmfadevice).cacheUserName = device.User.UserName
}
}

return res, nil
}

func (a *mqlAwsIamVirtualmfadevice) user() (*mqlAwsIamUser, error) {
if a.cacheUserArn != nil && a.cacheUserName != nil {
awsIamUser, err := NewResource(a.MqlRuntime, "aws.iam.user", map[string]*llx.RawData{
"arn": llx.StringDataPtr(a.cacheUserArn),
"name": llx.StringDataPtr(a.cacheUserName),
})
if err != nil {
return nil, err
}
return awsIamUser.(*mqlAwsIamUser), nil
}
a.User.State = plugin.StateIsNull | plugin.StateIsSet
return nil, nil
}

type mqlAwsIamVirtualmfadeviceInternal struct {
cacheUserName *string
cacheUserArn *string
}

func (a *mqlAwsIam) mqlPolicies(policies []iamtypes.Policy) ([]interface{}, error) {
res := []interface{}{}
for i := range policies {
Expand Down
29 changes: 16 additions & 13 deletions providers/aws/resources/aws_sagemaker.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,27 +238,30 @@ func (a *mqlAwsSagemakerNotebookinstance) details() (*mqlAwsSagemakerNotebookins
"directInternetAccess": llx.StringData(string(instanceDetails.DirectInternetAccess)),
}

if instanceDetails.KmsKeyId != nil && *instanceDetails.KmsKeyId != "" {
mqlKeyResource, err := NewResource(a.MqlRuntime, "aws.kms.key",
map[string]*llx.RawData{"arn": llx.StringData(convert.ToString(instanceDetails.KmsKeyId))},
)
if err != nil {
log.Error().Err(err).Msg("cannot create kms key resource")
} else {
args["kmsKey"] = llx.ResourceData(mqlKeyResource, mqlKeyResource.MqlName())
}
} else {
args["kmsKey"] = llx.NilData
}
mqlInstanceDetails, err := CreateResource(a.MqlRuntime, "aws.sagemaker.notebookinstance.details", args)
if err != nil {
return nil, err
}
mqlInstanceDetails.(*mqlAwsSagemakerNotebookinstanceDetails).cacheKmsKey = instanceDetails.KmsKeyId
return mqlInstanceDetails.(*mqlAwsSagemakerNotebookinstanceDetails), nil
}

type mqlAwsSagemakerNotebookinstanceDetailsInternal struct {
cacheKmsKey *string
}

func (a *mqlAwsSagemakerNotebookinstanceDetails) kmsKey() (*mqlAwsKmsKey, error) {
return &mqlAwsKmsKey{}, nil
if a.cacheKmsKey != nil && *a.cacheKmsKey != "" {
mqlKeyResource, err := NewResource(a.MqlRuntime, "aws.kms.key",
map[string]*llx.RawData{"arn": llx.StringData(convert.ToString(a.cacheKmsKey))},
)
if err != nil {
return nil, err
}
return mqlKeyResource.(*mqlAwsKmsKey), nil
}
a.KmsKey.State = plugin.StateIsNull | plugin.StateIsSet
return nil, nil
}

func (a *mqlAwsSagemakerEndpoint) id() (string, error) {
Expand Down
Loading