mirror of
https://github.com/open-policy-agent/opa.git
synced 2026-08-13 03:42:35 -06:00
b3f7c2cb30
### Why are the changes in this PR needed? The DAP debugger currently truncates variable values to a hardcoded limit of 100 characters, with no way for callers to configure it. Long values cannot be inspected or copied whole from a debugger UI. ### What are the changes in this PR? - Add a new `SetMaxVariableLength` Debugger option (in both `v1/debug` and the top-level `debug` package) - A value of 0 disables truncation; the default stays 100 characters for backward compatibility - Plumb the limit through `variableManager` and `namedVar`, so it applies to top-level and nested (object/array/set) variables alike - Relax `truncatedString` to return the original string unchanged when the limit is <= 0 - Add `TestTruncatedString` and `TestVariableValueLengthLimit` covering the default limit, unlimited (0), negative, custom limits, and boundary cases ### Notes - `go build ./...` and `go test ./v1/debug/...` both pass - Default behavior is unchanged; the new option is opt-in - This PR was developed with AI assistance (Claude Code) ### Further comments Refs #8890 --------- Signed-off-by: summy wu <summy.wu81@gmail.com>
60 lines
2.0 KiB
Go
60 lines
2.0 KiB
Go
// Copyright 2024 The OPA Authors. All rights reserved.
|
|
// Use of this source code is governed by an Apache2
|
|
// license that can be found in the LICENSE file.
|
|
|
|
// Package debug
|
|
// EXPERIMENTAL: This package is under active development and is subject to change.
|
|
package debug
|
|
|
|
import (
|
|
"github.com/open-policy-agent/opa/logging"
|
|
"github.com/open-policy-agent/opa/rego"
|
|
v1 "github.com/open-policy-agent/opa/v1/debug"
|
|
)
|
|
|
|
// Debugger is the interface for launching OPA debugger Session(s).
|
|
// This implementation is similar in structure to the Debug Adapter Protocol (DAP)
|
|
// to make such integrations easier, but is not intended to be a direct implementation.
|
|
// See: https://microsoft.github.io/debug-adapter-protocol/specification
|
|
//
|
|
// EXPERIMENTAL: These interfaces are under active development and is subject to change.
|
|
type Debugger = v1.Debugger
|
|
|
|
type Session = v1.Session
|
|
|
|
type DebuggerOption = v1.DebuggerOption
|
|
|
|
func NewDebugger(options ...DebuggerOption) Debugger {
|
|
return v1.NewDebugger(options...)
|
|
}
|
|
|
|
func SetLogger(logger logging.Logger) DebuggerOption {
|
|
return v1.SetLogger(logger)
|
|
}
|
|
|
|
func SetEventHandler(handler EventHandler) DebuggerOption {
|
|
return v1.SetEventHandler(handler)
|
|
}
|
|
|
|
// SetMaxVariableLength sets the maximum length of variable values displayed in the debugger.
|
|
// Values longer than this limit will be truncated. A value of 0 disables truncation.
|
|
// If not set, the default is 100 characters.
|
|
func SetMaxVariableLength(maxVariableLength int) DebuggerOption {
|
|
return v1.SetMaxVariableLength(maxVariableLength)
|
|
}
|
|
|
|
type LaunchEvalProperties = v1.LaunchEvalProperties
|
|
|
|
type LaunchTestProperties = v1.LaunchTestProperties
|
|
|
|
type LaunchProperties = v1.LaunchProperties
|
|
|
|
type LaunchOption = v1.LaunchOption
|
|
|
|
// RegoOption adds a rego option to the internal Rego instance.
|
|
// Options may be overridden by the debugger, and it is recommended to
|
|
// use LaunchEvalProperties for commonly used options.
|
|
func RegoOption(opt func(*rego.Rego)) LaunchOption {
|
|
return v1.RegoOption(opt)
|
|
}
|