Skip to content

Pulse Helper Libraries

Orcasio Pulse provides a set of helper libraries that can be used in the go lambda snippets. The helper libraries can be used without a need to import them.

Note

While we showcase these functions in examples using transformer: |, please note that all of these functions are also applicable within Rule definitions.

Pulse HTTP

The "pulsehttp" library simplifies making HTTP calls from Go Lambda snippets and is built upon the standard Go http library.

Function Signatures

pulsehttp.Get

  • pulsehttp.Get(url string, header http.Header, body io.Reader, tlsVerify bool) (string, int, error)
    • url: URL for the HTTP GET request.
    • header: HTTP headers to include in the request.
    • body: HTTP body to send with the request.
    • tlsVerify: Indicates whether to verify the TLS certificate.
    • Returns:
      • string: HTTP response body.
      • int: HTTP response status code.
      • error: Error object.
    • Example:

      transformer: |
        # golang
        url := "https://api.example.com/data"
        headers := make(http.Header)
        headers.Add("Authorization", "Bearer YOUR_ACCESS_TOKEN")
      
        response, statusCode, err := pulsehttp.Get(url, headers, nil, true)
      
        if err != nil {
          pulselog.Error("Error while making GET request: %v", err)
        } else {
          pulselog.Info("GET request successful. Status code: %d", statusCode)
          pulselog.Debug("Response body: %s", response)
        }
      

pulsehttp.Post

  • pulsehttp.Post(url string, header http.Header, body io.Reader, tlsVerify bool) (string, int, error)
    • url: URL for the HTTP POST request.
    • header: HTTP headers to include in the request.
    • body: HTTP body to send with the request.
    • tlsVerify: Indicates whether to verify the TLS certificate.
    • Returns:
      • string: HTTP response body.
      • int: HTTP response status code.
      • error: Error object.
    • Example:

      transformer: |
        # golang
        url := "https://api.example.com/create"
        headers := make(http.Header)
        headers.Add("Authorization", "Bearer YOUR_ACCESS_TOKEN")
      
        requestBody := []byte(`{"name": "John", "age": 30}`)
        bodyReader := bytes.NewReader(requestBody)
      
        response, statusCode, err := pulsehttp.Post(url, headers, bodyReader, true)
      
        if err != nil {
          pulselog.Error("Error while making POST request: %v", err)
        } else {
          pulselog.Info("POST request successful. Status code: %d", statusCode)
          pulselog.Debug("Response body: %s", response)
        }
      

Pulse JSON

The "pulsejson" library provides utilities to parse JSON strings within Go Lambda snippets.

Function Signatures

pulsejson.Get

  • pulsejson.Get(path string, input any) any
    • path: JSON path used to retrieve a specific value within the JSON data. The path should begin with one of the supported separator characters: $, ., #, or _, and subsequent keys or indices should also use the same separator.
    • input: JSON data from which to retrieve the value.
    • Returns:
      • any: value under path. If it does not find any value it will return an empty string ""
    • Example:
      transformer: |
          # golang
          address := pulsejson.Get(".user.address", signal)
      

pulsejson.Delete

  • pulsejson.Delete(path string, input any)
    • path: JSON path used to delete a specific value within the JSON data. The path should start with one of the supported separator characters: $, ., #, or _, and subsequent keys or indices should follow the same separator.
    • input: JSON data from which to delete the value.
    • Example:
      transformer: |
          # golang
          pulsejson.Delete("user.address", userData)
      

pulsejson.Transcode

  • pulsejson.Transcode(in any, out any)
    • in: JSON to transcode.
    • out: Pointer to the transcoded Map object.
    • Example:
      transformer: |
          # golang
          var result map[string]interface{}
          pulsejson.Transcode(signal, &result)
      

pulsejson.Print

  • pulsejson.Print(data any)
    • data: JSON Transcoded Map object to be printed.
    • Example:
      transformer: |
          # golang
          pulsejson.Print(signal)
      

Pulse Log

The "pulselog" library facilitates logging messages from Go Lambda snippets. It provides utilities to interact with the Pulse engine and sensor logger objects, allowing you to write log messages with appropriate log levels.

Function Signatures

pulselog.Trace

  • pulselog.Trace(format string, v ...interface{})
    • format: Format string for the log message.
    • v: Arguments for the format string.
    • Example:
      transformer: |
          # golang
          pulselog.Trace("This is a Trace log message with arguments: %s, %d", arg1, arg2)
      

pulselog.Debug

  • pulselog.Debug(format string, v ...interface{})
    • format: Format string for the log message.
    • v: Arguments for the format string.
    • Example:
      transformer: |
          # golang
          pulselog.Debug("This is a Debug log message with arguments: %s, %d", arg1, arg2)
      

pulselog.Info

  • pulselog.Info(format string, v ...interface{})
    • format: Format string for the log message.
    • v: Arguments for the format string.
    • Example:
      transformer: |
          # golang
          pulselog.Info("This is a Info log message with arguments: %s, %d", arg1, arg2)
      

pulselog.Warn

  • pulselog.Warn(format string, v ...interface{})
    • format: Format string for the log message.
    • v: Arguments for the format string.
    • Example:
      transformer: |
          # golang
          pulselog.Warn("This is a Warn log message with arguments: %s, %d", arg1, arg2)
      

pulselog.Error

  • pulselog.Error(format string, v ...interface{})
    • format: Format string for the log message.
    • v: Arguments for the format string.
    • Example:
      transformer: |
          # golang
          pulselog.Error("This is a Error log message with arguments: %s, %d", arg1, arg2)
      

Pulse Number

The "pulsenum" library facilitates number casting operations from Go Lambda snippets.

Function Signatures

pulsenum.ToInt

  • pulsenum.ToInt(in any) (int, bool)
    • in: Input object to be casted to an integer.
    • Returns:
      • int: Casted integer value.
      • bool: Flag indicating the success of the cast.
    • Example:
      transformer: |
          # golang
          value, success := pulsenum.ToInt(inputValue)
      

pulsenum.ToFloat

  • pulsenum.ToFloat(in any) (float64, bool)
    • in: Input object to be casted to a float64.
    • Returns:
      • float64: Casted float64 value.
      • bool: Flag indicating the success of the cast.
    • Example:
      transformer: |
          # golang
          value, success := pulsenum.ToFloat(inputValue)
      

Pulse String

The "pulsestr" library assists in performing string operations within Go Lambda snippets.

Function Signatures

pulsestr.HasString

  • pulsestr.HasString(list []string, str string) bool
    • list: List of strings to search within.
    • str: String to search for within the list.
    • Returns:
      • bool: Flag indicating whether the string was found in the list.
    • Example:
      transformer: |
          # golang
          found := pulsestr.HasString(stringList, searchString)
      

Specific Helper Functions

The are some helper functions that are specific to either transformer or rules.

Transforemer Functions

appendSignals

  • appendSignals(signals ...(map[string]any))
    • str: New signals that want to be sent to the stream.
    • Example:
      transformer: |
          #! golang
      
          out1 := make(map[string]any)
          pulsejson.Transcode(signal, &out1)
          out1["apiVersion"] = "xyz"
      
          out2 := make(map[string]any)
          pulsejson.Transcode(signal, &out2)
          out2["apiVersion"] = "a123"
      
          pulsejson.Delete("spec", signal)
      
          // Append signals to the existing signal
          appendSignals(out1, out2, signal)