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

🐛 Change data conversion to allow for nil resources. Fix azure monitor as an example #2321

Closed
wants to merge 2 commits into from
Closed
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
9 changes: 7 additions & 2 deletions providers-sdk/v1/plugin/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,14 @@ func GetOrCompute[T any](cached *TValue[T], compute func() (T, error)) *TValue[T

x, err := compute()
if err != nil {
res := &TValue[T]{Data: x, Error: err}
// why do we always set to IsNull here?
res := &TValue[T]{State: StateIsSet | StateIsNull}
// Note: if we're getting back a NotReady error, it means the computed
// resource is not present and we should return nil.
// To avoid panics down the stack, we only set the data and err if it's anything other than a NotReady error
if err != NotReady {
res.State = StateIsSet | StateIsNull
res.Data = x
res.Error = err
}
return res
}
Expand Down
9 changes: 4 additions & 5 deletions providers/azure/resources/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package resources

import (
"context"
"errors"

"go.mondoo.com/cnquery/v9/llx"
"go.mondoo.com/cnquery/v9/providers-sdk/v1/plugin"
Expand Down Expand Up @@ -268,28 +267,28 @@ func (a *mqlAzureSubscriptionMonitorServiceActivityLog) alerts() ([]interface{},

func (a *mqlAzureSubscriptionMonitorServiceLogprofile) storageAccount() (*mqlAzureSubscriptionStorageServiceAccount, error) {
if a.StorageAccountId.IsNull() {
return nil, errors.New("diagnostic settings has no storage account")
return nil, plugin.NotReady
}
if a.StorageAccountId.Error != nil {
return nil, a.StorageAccountId.Error
}
storageAccId := a.StorageAccountId.Data
if storageAccId == "" {
return nil, errors.New("diagnostic settings has no storage account")
return nil, plugin.NotReady
}
return getStorageAccount(storageAccId, a.MqlRuntime, a.MqlRuntime.Connection.(*connection.AzureConnection))
}

func (a *mqlAzureSubscriptionMonitorServiceDiagnosticsetting) storageAccount() (*mqlAzureSubscriptionStorageServiceAccount, error) {
if a.StorageAccountId.IsNull() {
return nil, errors.New("diagnostic settings has no storage account")
return nil, plugin.NotReady
}
if a.StorageAccountId.Error != nil {
return nil, a.StorageAccountId.Error
}
storageAccId := a.StorageAccountId.Data
if storageAccId == "" {
return nil, errors.New("diagnostic settings has no storage account")
return nil, plugin.NotReady
}
return getStorageAccount(storageAccId, a.MqlRuntime, a.MqlRuntime.Connection.(*connection.AzureConnection))
}
Expand Down
Loading