Skip to content

Commit

Permalink
🧹 improve the sagemaker notebook instance & iam mfadevice resource (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
vjeffrey authored Aug 24, 2024
1 parent ff88599 commit e719a5a
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 33 deletions.
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

0 comments on commit e719a5a

Please sign in to comment.