Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

postmanlabs/postman-sdk-go

Repository files navigation

Warning

This package is DEPRECATED! It is no longer maintained

Postman

About

This SDK instruments web frameworks to capture http requests and auto-generates Postman Live Collections.

Installation Process

go get github.com/postmanlabs/postman-sdk-go

Initializing the SDK

import (
    pm "github.com/postmanlabs/postman-sdk-go/postmansdk"
)

func main() {
	router := gin.Default()
	sdk, err := pm.Initialize("<POSTMAN-COLLECTION-ID>", "<POSTMAN-API-KEY>")

	if err == nil {
      // Registers a custom middleware
	    sdk.Integrations.Gin(router)
	}
}

For full working example see: Gin instrumented example

Configuration

Required Params

  • CollectionId: Postman collectionId where requests will be added. This is the id for your live collection.

    • Type: string
  • ApiKey: Postman api key needed for authentication.

    • Type: string

Configuration example

import (
	pm "github.com/postmanlabs/postman-sdk-go/postmansdk"
)

sdk, err := pm.Initialize(
    "<POSTMAN-COLLECTION-ID>",
    "<POSTMAN-API-KEY>",
    pm.WithDebug(false),
    pm.WithEnable(true),
    // ...Other configuration options
)

Configuration Options

  • WithDebug: Enable/Disable debug logs.

    • Type: func(bool)
    • Default: false
  • WithEnable: Enable/Disable the SDK.

    • Disabled SDK does not capture any new traces, nor does it use up system resources.
    • Type: func(bool)
    • Default: true
  • WithTruncateData: Truncate the request and response body so that no PII data is sent to Postman.

    • Disabling it sends actual request and response payloads.

    • Type: func(bool)

    • Default: true

    • Example:

      Sample payload or non-truncated payload:

      {
          "first_name": "John",
          "age": 30
      }

      Truncated payload:

      {
          "first_name": {
              "type": "string"
          },
          "age": {
              "type": "float64"
          }
      }
  • WithRedactSensitiveData: Redact sensitive data such as api_keys and auth tokens, before they leave the sdk. When this is enabled, below redaction rules are applied by default (they are not case-sensitive):

    • Default regex rules applied are

      "pmPostmanAPIKey":    `PMAK-[a-f0-9]{24}-[a-f0-9]{34}`,
      "pmPostmanAccessKey": `PMAT-[0-9a-z]{26}`,
      "pmBasicAuth":        `Basic [a-zA-Z0-9]{3,1000}(?:[^a-z0-9+({})!@#$%^&|*=]{0,2})`,
      "pmBearerToken":      `Bearer [a-z0-9A-Z-._~+/]{15,1000}`,
    • Example:

      WithRedactSensitiveData(
          true,
          map[string]string{
              "<rule name>": "<regex to match the rule>",
              "key": `PMAT-[0-9a-z]{26}`,
          }
      )
      
      // To enable default redactions
      WithRedactSensitiveData(
          true,
          map[string]string{}
      )
    • Type: func(bool, map[string][string])

  • WithIgnoreIncomingRequests: List of regexes to be ignored from instrumentation.

    • This rule only applies to endpoints that are served by the application/server.

    • Example:

          WithIgnoreIncomingRequests(
            []string{"knockknock", "^get.*"}
          )

      Ignore any incoming request endpoints matching the two regexes.

    • Type: func([]string)

  • WithBufferIntervalInMilliseconds: Interval between SDK data push to backend

    • Type: func(int)
    • Default: 5000 milliseconds

About

[DEPRECATED] Go SDK powering Live Collections

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages