definition

package
v0.40.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 21, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrSecretKeyMissing indicates an encrypted auth parameter was loaded
	// but vef.integration.secret_key is not configured, so it cannot be
	// decrypted.
	ErrSecretKeyMissing = errors.New("integration: encrypted auth parameter found but vef.integration.secret_key is not configured")

	// ErrMaskedSecretWithoutPrior indicates a save submitted the masked
	// placeholder for a sensitive parameter that has no stored value to keep.
	ErrMaskedSecretWithoutPrior = errors.New("integration: masked auth parameter has no stored value")

	// ErrEmptyCodeValue rejects an empty-string value in a code map entry.
	ErrEmptyCodeValue = errors.New("code value must not be empty")

	// ErrNonScalarCodeValue rejects a code map value outside the JSON scalar
	// types lookups can normalize.
	ErrNonScalarCodeValue = errors.New("code value must be a JSON string, number, or boolean")

	// ErrDuplicateCodeValue rejects a code map side reaching the same lookup
	// value through two entries — lookups would turn order-dependent.
	ErrDuplicateCodeValue = errors.New("duplicate code value")
)

Functions

func CompileEnvelopeRequestScript

func CompileEnvelopeRequestScript(script string) (*js.Program, error)

CompileEnvelopeRequestScript compiles a system-level request envelope script: the body sees the outgoing request as `request` and a top-level return statement yields the request to put on the wire. Unlike adapter scripts the wrapper is not invoked — it evaluates to a function the http library calls once per outbound request.

func CompileEnvelopeResponseScript

func CompileEnvelopeResponseScript(script string) (*js.Program, error)

CompileEnvelopeResponseScript compiles a system-level response envelope script: the body sees the completed response as `response` and a top-level return statement yields what the adapter's call returns.

func CompileSchema

func CompileSchema(raw json.RawMessage) (*jsonschema.Resolved, error)

CompileSchema parses and resolves raw as a self-contained JSON Schema (draft 2020-12). Remote $ref references are rejected — contract schemas live in the database and must validate deterministically and offline.

func CompileScript

func CompileScript(script string) (*js.Program, error)

CompileScript compiles an adapter script into the executable form the invoker runs: the body is wrapped in a function expression so a top-level return statement produces the invocation output. The wrapper shifts reported line numbers by one.

func DiagnoseRoutes

func DiagnoseRoutes(ctx context.Context, db orm.DB) (*integration.RouteDiagnostics, error)

DiagnoseRoutes analyses the routing table against contracts, systems, and adapters, reporting the configuration gaps that would otherwise surface only as runtime errors. Disabled routes are skipped — they are intentionally off. Definitions are config-scale, so the analysis loads them wholesale and walks them in memory.

func FindOne added in v0.40.0

func FindOne[T any](ctx context.Context, db orm.DB, notFound error, where func(orm.ConditionBuilder)) (*T, error)

FindOne loads the single definition row of T matched by where, mapping a missing row to notFound. Enabled-state handling stays at the call sites — what a disabled definition means is per-flow policy.

func MaskDataSource

MaskDataSource returns a copy of ds with a non-empty password replaced by MaskedSecret, for management API responses.

func MaskInboundAuth

func MaskInboundAuth(scheme secretScheme, auth *integration.InboundAuthConfig) *integration.InboundAuthConfig

MaskInboundAuth returns a copy of auth with every non-empty sensitive parameter value replaced by MaskedSecret, for management API responses. A nil scheme (no longer registered) masks every parameter — fail closed.

func MaskOutboundAuth

func MaskOutboundAuth(scheme secretScheme, auth *integration.OutboundAuthConfig) *integration.OutboundAuthConfig

MaskOutboundAuth returns a copy of auth with every non-empty sensitive parameter value replaced by MaskedSecret, for management API responses. A nil scheme (no longer registered) masks every parameter — fail closed. The signing script is code, not a secret; it passes through.

func NormalizeCodeValue added in v0.40.0

func NormalizeCodeValue(v any) (string, error)

NormalizeCodeValue folds a JSON scalar into the canonical string form lookups compare by, so 1 (number) and "1" (string) address the same entry regardless of how the value arrived (jsonb, API JSON, or a script value — goja exports integral numbers as int64).

func SensitiveValues

func SensitiveValues(scheme secretScheme, params map[string]string) []string

SensitiveValues returns the non-empty values of the parameters the scheme declares sensitive (a nil scheme selecting every parameter — fail closed). Wire captures scrub these values so a credential never lands in the invocation log or dry-run trace under whatever header or query name a scheme carries it — the point masking by a fixed name set cannot reach.

func ValidateAdapterScript

func ValidateAdapterScript(script string) error

ValidateAdapterScript rejects an adapter whose script does not compile.

func ValidateCodeMap added in v0.40.0

func ValidateCodeMap(m *integration.CodeMap) error

ValidateCodeMap rejects a code map whose identifier, unmapped policy, or entries would make lookups fail or turn non-deterministic at runtime. Building the lookup index is the entry validation: it normalizes every value and rejects per-side collisions.

func ValidateContract

func ValidateContract(contract *integration.Contract) error

ValidateContract rejects a contract whose input or output schema does not compile, so a broken schema fails at save time instead of on the first invocation.

func ValidateRouteRefs

func ValidateRouteRefs(ctx context.Context, db orm.DB, route *integration.Route) error

ValidateRouteRefs rejects a route referencing a missing contract or system. The contract reference is checked here because the column carries the empty-string wildcard sentinel and therefore has no foreign key.

func ValidateSystem

func ValidateSystem(scheme integration.OutboundAuthScheme, codec *SecretCodec, system *integration.System) error

ValidateSystem rejects a system whose base URL is not absolute or whose auth config fails the scheme's own parameter validation. Scheme is the resolved outbound scheme of system.OutboundAuth (nil when unresolved — the caller resolves once for validation and encryption alike). Auth params must already be in their persisted form (EncryptOutboundAuth applied) so masked placeholders have been resolved.

Types

type CodeMapIndex added in v0.40.0

type CodeMapIndex struct {
	// contains filtered or unexported fields
}

CodeMapIndex is a code map compiled for constant-time bidirectional lookup: each side's primary and aliases fold into one normalized-string key space pointing at the opposite side's primary value.

func BuildCodeMapIndex added in v0.40.0

func BuildCodeMapIndex(m *integration.CodeMap) (*CodeMapIndex, error)

BuildCodeMapIndex compiles m's entries into the bidirectional lookup index, rejecting non-scalar values and per-side collisions — a value reachable through two entries would make lookups order-dependent.

func (*CodeMapIndex) CanonicalFor added in v0.40.0

func (idx *CodeMapIndex) CanonicalFor(key string) (any, bool)

CanonicalFor returns the canonical primary value the normalized external-side key maps to.

func (*CodeMapIndex) Entries added in v0.40.0

func (idx *CodeMapIndex) Entries() []integration.CodeMapEntry

Entries returns the mapping pairs the index was built from.

func (*CodeMapIndex) ExternalFor added in v0.40.0

func (idx *CodeMapIndex) ExternalFor(key string) (any, bool)

ExternalFor returns the external primary value the normalized canonical-side key maps to.

func (*CodeMapIndex) FallbackCanonical added in v0.40.0

func (idx *CodeMapIndex) FallbackCanonical() any

FallbackCanonical returns the fallback value for the canonical side.

func (*CodeMapIndex) FallbackExternal added in v0.40.0

func (idx *CodeMapIndex) FallbackExternal() any

FallbackExternal returns the fallback value for the external side.

func (*CodeMapIndex) Policy added in v0.40.0

func (idx *CodeMapIndex) Policy() integration.UnmappedPolicy

Policy returns the map's unmapped policy, an empty value resolved to reject (fail closed).

type CodeMapIndexCache added in v0.40.0

type CodeMapIndexCache struct {
	// contains filtered or unexported fields
}

CodeMapIndexCache caches compiled lookup indexes keyed by the content that affects lookup semantics, so editing a code map invalidates its entry implicitly and unchanged maps never rebuild.

func NewCodeMapIndexCache added in v0.40.0

func NewCodeMapIndexCache() *CodeMapIndexCache

NewCodeMapIndexCache creates an empty compiled-index cache.

func (*CodeMapIndexCache) Get added in v0.40.0

Get returns the compiled index for m, building and caching it on first sight.

type ProgramCache

type ProgramCache struct {
	// contains filtered or unexported fields
}

ProgramCache caches compiled scripts keyed by content hash, so editing a script invalidates its entry implicitly and unchanged scripts never recompile. Each script wrapper owns an instance: adapter execution, script-scheme signing and verification, and the two envelope directions.

func NewProgramCache

func NewProgramCache(compile func(string) (*js.Program, error)) *ProgramCache

NewProgramCache creates an empty compiled-program cache backed by compile.

func (*ProgramCache) Get

func (c *ProgramCache) Get(script string) (*js.Program, error)

Get returns the compiled program for script, compiling and caching it on first sight.

type SecretCodec

type SecretCodec struct {
	// contains filtered or unexported fields
}

SecretCodec encrypts sensitive auth parameter values at rest with the key from vef.integration.secret_key, using the cipher selected by vef.integration.secret_algorithm (AES-GCM by default, SM4-GCM for 国密 deployments). Without a configured key it degrades to plaintext storage — NewSecretCodec logs the warning once at boot — but still refuses to load values a previous configuration encrypted.

func NewSecretCodec

func NewSecretCodec(cfg *config.IntegrationConfig) (*SecretCodec, error)

NewSecretCodec builds the codec from the configured secret key and algorithm, failing fast on a malformed key.

func (*SecretCodec) DecryptDataSource

DecryptDataSource returns a copy of ds with the password decrypted, ready for the datasource registry.

func (*SecretCodec) DecryptInboundAuth

func (c *SecretCodec) DecryptInboundAuth(scheme secretScheme, auth *integration.InboundAuthConfig) (*integration.InboundAuthConfig, error)

DecryptInboundAuth returns a copy of auth with every sensitive parameter decrypted, ready to hand to InboundAuthScheme.Verify.

func (*SecretCodec) DecryptOutboundAuth

func (c *SecretCodec) DecryptOutboundAuth(scheme secretScheme, auth *integration.OutboundAuthConfig) (*integration.OutboundAuthConfig, error)

DecryptOutboundAuth returns a copy of auth with every sensitive parameter decrypted, ready to hand to OutboundAuthScheme.Apply. A nil auth decrypts to an empty config so schemes never see a nil receiver.

func (*SecretCodec) EncryptDataSource

func (c *SecretCodec) EncryptDataSource(ds, prior *integration.DataSourceConfig) error

EncryptDataSource prepares a system's data source config for persistence, mutating it in place: the password is encrypted, and a submitted MaskedSecret placeholder is replaced by the prior stored value (prior is nil on create).

func (*SecretCodec) EncryptInboundAuth

func (c *SecretCodec) EncryptInboundAuth(scheme secretScheme, auth, prior *integration.InboundAuthConfig) error

EncryptInboundAuth prepares an inbound auth config for persistence, mutating its params in place with the same masked-placeholder resolution as EncryptOutboundAuth. The verification script is code, not a secret; it stays plaintext.

func (*SecretCodec) EncryptOutboundAuth

func (c *SecretCodec) EncryptOutboundAuth(scheme secretScheme, auth, prior *integration.OutboundAuthConfig) error

EncryptOutboundAuth prepares auth for persistence, mutating its params in place: every sensitive parameter is encrypted, and a submitted MaskedSecret placeholder is replaced by the prior stored value (prior is nil on create).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL