From 06e53f30d47e641045fbacf0ed9e605d3edae2ca Mon Sep 17 00:00:00 2001 From: Dominik Richter Date: Sun, 17 Sep 2023 22:51:50 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20revert=20error=20on=20non-existe?= =?UTF-8?q?nt=20package,=20service,=20and=20kernel.module?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is in line with v8 and would otherwise break a number of existing queries. It is inconsistent with a few other resources (like `user`) and needs further alignment (as descriped in https://github.com/mondoohq/cnquery/issues/1622) Signed-off-by: Dominik Richter --- providers/os/resources/kernel.go | 7 ++++++- providers/os/resources/packages.go | 19 +++++++++++++++---- providers/os/resources/services.go | 16 ++++++++++++---- 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/providers/os/resources/kernel.go b/providers/os/resources/kernel.go index 19904a1175..1c89eb7807 100644 --- a/providers/os/resources/kernel.go +++ b/providers/os/resources/kernel.go @@ -322,7 +322,12 @@ func initKernelModule(runtime *plugin.Runtime, args map[string]*llx.RawData) (ma if res, ok := kernel.moduleByName[name]; ok { return nil, res, nil } - return args, nil, nil + + res := &mqlKernelModule{} + res.Name = plugin.TValue[string]{Data: name, State: plugin.StateIsSet} + res.Size.State = plugin.StateIsSet | plugin.StateIsNull + res.Loaded = plugin.TValue[bool]{Data: false, State: plugin.StateIsSet} + return nil, res, nil } func (k *mqlKernelModule) id() (string, error) { diff --git a/providers/os/resources/packages.go b/providers/os/resources/packages.go index 9bfe4b759a..b2aaa5681c 100644 --- a/providers/os/resources/packages.go +++ b/providers/os/resources/packages.go @@ -46,12 +46,23 @@ func initPackage(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[str return nil, nil, err } - x, found := packages.packagesByName[name] - if !found { - return nil, nil, errors.New("cannot find package " + name) + if res, ok := packages.packagesByName[name]; ok { + return nil, res, nil } - return nil, x, nil + res := &mqlPackage{} + res.Name = plugin.TValue[string]{Data: name, State: plugin.StateIsSet} + res.Installed = plugin.TValue[bool]{Data: false, State: plugin.StateIsSet} + res.Outdated = plugin.TValue[bool]{Data: false, State: plugin.StateIsSet} + res.Version.State = plugin.StateIsSet | plugin.StateIsNull + res.Epoch.State = plugin.StateIsSet | plugin.StateIsNull + res.Available.State = plugin.StateIsSet | plugin.StateIsNull + res.Description.State = plugin.StateIsSet | plugin.StateIsNull + res.Arch.State = plugin.StateIsSet | plugin.StateIsNull + res.Format.State = plugin.StateIsSet | plugin.StateIsNull + res.Origin.State = plugin.StateIsSet | plugin.StateIsNull + res.Status.State = plugin.StateIsSet | plugin.StateIsNull + return nil, res, nil } func (p *mqlPackage) status() (string, error) { diff --git a/providers/os/resources/services.go b/providers/os/resources/services.go index 163c4801c0..bbddcd81f0 100644 --- a/providers/os/resources/services.go +++ b/providers/os/resources/services.go @@ -39,12 +39,20 @@ func initService(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[str return nil, nil, err } - srv := services.namedServices[name] - if srv == nil { - return nil, nil, errors.New("service '" + name + "' does not exist") + if srv, ok := services.namedServices[name]; ok { + return nil, srv, nil } - return nil, srv, nil + res := &mqlService{} + res.Name = plugin.TValue[string]{Data: name, State: plugin.StateIsSet} + res.Description.State = plugin.StateIsSet | plugin.StateIsNull + res.Installed = plugin.TValue[bool]{Data: false, State: plugin.StateIsSet} + res.Running = plugin.TValue[bool]{Data: false, State: plugin.StateIsSet} + res.Enabled = plugin.TValue[bool]{Data: false, State: plugin.StateIsSet} + res.Type.State = plugin.StateIsSet | plugin.StateIsNull + res.Enabled = plugin.TValue[bool]{Data: false, State: plugin.StateIsSet} + res.Masked = plugin.TValue[bool]{Data: false, State: plugin.StateIsSet} + return nil, res, nil } func (x *mqlService) id() (string, error) {