Views:

How to use the Go SDK for Trend Vision One File Security

After initializing the Go SDK for File Security, you can start using it to interact with File Security. Here are some basic examples of how to use the SDK.

Procedure

  • Scan a file.
    filePath := "path/to/your/file.txt"
    tags := []string{"tag1", "tag2"}
    
    response, err := client.ScanFile(filePath, tags)
    if err != nil {
        // Handle scanning error
        panic(err)
    }
    
    // Use the 'response' as needed
  • Scan a buffer. You can use up to eight tags each with a maximum length of 63 characters.
    filePath := "path/to/your/file.txt"
    tags := []string{"tag1", "tag2"}
    
    response, err := client.ScanFile(filePath, tags)
    if err != nil {
        // Handle scanning error
        panic(err)
    }
    
    // Use the 'response' as needed

Using advanced functions Parent topic

The Go SDK provides additional functions for advanced use such as enabling PML, dumping the configuration, and cleaning up resources.

Procedure

  • Dump the configuration.
    You can dump the current configuration for debugging purposes.
    configDump := client.DumpConfig()
    fmt.Println("SDK Configuration:\n", configDump)
  • Clean up resources.
    You can destroy the SDK client when you are done to release any allocated resources.
    client.Destroy()
  • Enable Predictive Machine Learning (PML)
    client.SetPMLEnable()
  • Enable SPN feedback
    client.SetFeedbackEnable()

Viewing Examples Parent topic

The tools/ directory of the SDK package contains two important files with code examples.

Procedure

  • Refer to these examples for a deeper understanding of how to integrate and use the SDK with File Security.
    • client.go: This file contains the main client initialization logic and functions for scanning a single file.
    • scanfiles.go: This file provides examples of how to scan multiple files using the SDK.

Using client tools Parent topic

Procedure

  • Execute make build in the root directory to build the client tools.
    The build process produces the following client tools in the tools/directory:
    • client
      This program supports servers with Google™ remote procedure call (gRPC).
      client [command-line flags]
      This program supports the following flags:

      Client Supported Flags

      Flag
      Use
      -tls
      Specify to enable server authentication by client for gRPC.
      -region <string>
      Specify the region to connect to for gRPC.
      -addr <string>
      Set the address to connect to for gRPC. The default is localhost:50051.
      -filename <string>
      Indicate the path of file to scan.
      -apikey <string>
      Use the API key for service authentication if authentication is enabled.
      -pml
      Specify to enable Predictive Machine Learning (PML) detection.
      -feedback
      Specify to enable SPN feedback.
      tag <string>
      Specify the tags to be used for scanning, separated by commas. The maximum number tags that you can use is 8, and the length of each tag cannot exceed 63.
    • scanfiles
      This is another program that uses the gRPC client library to communicate with the File Security server. When the -good flag is specified, this program shows whether testing was successful and the files are non-malicious. So, for example, if File Security indicates a file is malicious, the program output indicates the testing failed.
      This program supports the following flags:

      Scanfiles Supported Flags

      Flag
      Use
      -path <string>
      Indicate the directory or file to scan. This flag must be specified in all scenarios.
      -good
      Specify if scanning non-malicious files.
      -parallel
      Specify to scan multiple files simultaneously instead of sequentially.
      -tls
      Specify to enable server authentication by client for gRPC.
      -region <string>
      Specify the region to connect to for gRPC.
      -addr <string>
      Set the address to connect to for gRPC. The default is localhost:50051.
      -apikey <string>
      Use the API key for service authentication if authentication is enabled.
      -pml
      Specify to enable Predictive Machine Learning (PML) detection.
      -feedback
      Specify to enable SPN feedback.
      -tag <string>
      Specify the tags to be used for scanning, separated by commas. The maximum number tags that you can use is 8, and the length of each tag cannot exceed 63.