github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/utils/parser/unsafe.go (about)

     1  package parser
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/lmorg/murex/lang/types"
     7  	"github.com/lmorg/murex/utils/json"
     8  )
     9  
    10  func isCmdUnsafe(f string) bool {
    11  	for _, sb := range safeCmds {
    12  		if f == sb {
    13  			return false
    14  		}
    15  	}
    16  
    17  	return true
    18  }
    19  
    20  // GetSafeCmds returns a slice of the safeCmds
    21  func GetSafeCmds() []string {
    22  	a := make([]string, len(safeCmds))
    23  	copy(a, safeCmds)
    24  	return a
    25  }
    26  
    27  // ReadSafeCmds returns an interface{} of the safeCmds.
    28  // This is only intended to be used by `config.Properties.GoFunc.Read()`
    29  func ReadSafeCmds() (interface{}, error) {
    30  	return GetSafeCmds(), nil
    31  }
    32  
    33  // WriteSafeCmds takes a JSON-encoded string and writes it to the safeCmds
    34  // slice.
    35  // This is only intended to be used by `config.Properties.GoFunc.Write()`
    36  func WriteSafeCmds(v interface{}) error {
    37  	switch v := v.(type) {
    38  	case string:
    39  		return json.Unmarshal([]byte(v), &safeCmds)
    40  
    41  	default:
    42  		return fmt.Errorf("invalid data-type. Expecting a %s encoded string", types.Json)
    43  	}
    44  }