go.mondoo.com/cnquery@v0.0.0-20231005093811-59568235f6ea/providers/os/resources/privatekey.go (about)

     1  // Copyright (c) Mondoo, Inc.
     2  // SPDX-License-Identifier: BUSL-1.1
     3  
     4  package resources
     5  
     6  import (
     7  	"errors"
     8  
     9  	"go.mondoo.com/cnquery/llx"
    10  	"go.mondoo.com/cnquery/providers-sdk/v1/plugin"
    11  )
    12  
    13  func initPrivatekey(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) {
    14  	if x, ok := args["path"]; ok {
    15  		path, ok := x.Value.(string)
    16  		if !ok {
    17  			return nil, nil, errors.New("wrong type for 'path' in privatekey initialization, it must be a string")
    18  		}
    19  		f, err := CreateResource(runtime, "file", map[string]*llx.RawData{
    20  			"path": llx.StringData(path),
    21  		})
    22  		if err != nil {
    23  			return nil, nil, err
    24  		}
    25  		args["file"] = llx.ResourceData(f, "file")
    26  	}
    27  
    28  	return args, nil, nil
    29  }
    30  
    31  func (r *mqlPrivatekey) id() (string, error) {
    32  	// TODO: use path or hash depending on initialization
    33  
    34  	file := r.GetFile()
    35  	if file.Error != nil {
    36  		return "", file.Error
    37  	}
    38  	if file.Data == nil {
    39  		return "", errors.New("no file provided")
    40  	}
    41  
    42  	return "privatekey:" + file.Data.Path.Data, nil
    43  }