go.mondoo.com/cnquery@v0.0.0-20231005093811-59568235f6ea/providers/os/resources/asset_eol.go (about) 1 // Copyright (c) Mondoo, Inc. 2 // SPDX-License-Identifier: BUSL-1.1 3 4 package resources 5 6 import ( 7 "context" 8 "errors" 9 "time" 10 11 "github.com/rs/zerolog/log" 12 "go.mondoo.com/cnquery/llx" 13 "go.mondoo.com/cnquery/providers-sdk/v1/inventory" 14 "go.mondoo.com/cnquery/providers-sdk/v1/plugin" 15 "go.mondoo.com/cnquery/providers-sdk/v1/resources" 16 "go.mondoo.com/cnquery/providers-sdk/v1/upstream/mvd" 17 "go.mondoo.com/cnquery/providers/os/connection/shared" 18 ) 19 20 // convertPlatform2VulnPlatform converts the motor platform.Platform to the 21 // platform object we use for vulnerability data 22 // TODO: we need to harmonize the platform objects 23 func convertPlatform2VulnPlatform(pf *inventory.Platform) *mvd.Platform { 24 if pf == nil { 25 return nil 26 } 27 return &mvd.Platform{ 28 Name: pf.Name, 29 Release: pf.Version, 30 Build: pf.Build, 31 Arch: pf.Arch, 32 Title: pf.Title, 33 Labels: pf.Labels, 34 } 35 } 36 37 // FIXME: DEPRECATED, update in v10.0 vv 38 func initPlatformEol(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) { 39 res, cache, err := initAssetEol(runtime, args) 40 if err != nil || res != nil || cache == nil { 41 return res, nil, err 42 } 43 44 acache := cache.(*mqlAssetEol) 45 cres := mqlPlatformEol{ 46 MqlRuntime: acache.MqlRuntime, 47 DocsUrl: acache.DocsUrl, 48 ProductUrl: acache.ProductUrl, 49 Date: acache.Date, 50 } 51 52 return nil, &cres, nil 53 } 54 55 // ^^ 56 57 func initAssetEol(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) { 58 conn := runtime.Connection.(shared.Connection) 59 platform := conn.Asset().Platform 60 eolPlatform := convertPlatform2VulnPlatform(platform) 61 62 mcc := runtime.Upstream 63 if mcc == nil || mcc.ApiEndpoint == "" { 64 return nil, nil, resources.MissingUpstreamError{} 65 } 66 67 // get new advisory report 68 // start scanner client 69 70 scannerClient, err := newAdvisoryScannerHttpClient(mcc.ApiEndpoint, mcc.Plugins, mcc.HttpClient) 71 if err != nil { 72 return nil, nil, err 73 } 74 75 eolInfo, err := scannerClient.IsEol(context.Background(), eolPlatform) 76 if err != nil { 77 return nil, nil, err 78 } 79 80 log.Debug().Str("name", eolPlatform.Name).Str("release", eolPlatform.Release).Str("title", eolPlatform.Title).Msg("search for eol information") 81 if eolInfo == nil { 82 return nil, nil, errors.New("no platform eol information available") 83 } 84 85 var eolDate *time.Time 86 if eolInfo.EolDate != "" { 87 parsedEolDate, err := time.Parse(time.RFC3339, eolInfo.EolDate) 88 if err != nil { 89 return nil, nil, errors.New("could not parse eol date: " + eolInfo.EolDate) 90 } 91 eolDate = &parsedEolDate 92 } else { 93 eolDate = &llx.NeverFutureTime 94 } 95 96 res := mqlAssetEol{ 97 MqlRuntime: runtime, 98 DocsUrl: plugin.TValue[string]{Data: eolInfo.DocsUrl, State: plugin.StateIsSet}, 99 ProductUrl: plugin.TValue[string]{Data: eolInfo.ProductUrl, State: plugin.StateIsSet}, 100 Date: plugin.TValue[*time.Time]{Data: eolDate, State: plugin.StateIsSet}, 101 } 102 103 return nil, &res, nil 104 }