go.temporal.io/server/components/callbacks/config.go
154 LOC · 52 covered · 102 uncovered · 25 ranges · 85 concepts · 20 introducers · 43 tests
File neighbourhood
The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.
Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file
In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.
Graph controls are ready.
Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.
package callbacks
import (
"net/url"
"regexp"
"strings"
"time"
"go.temporal.io/server/chasm"
"go.temporal.io/server/common/backoff"
"go.temporal.io/server/common/dynamicconfig"
"go.temporal.io/server/common/nexus"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
var RequestTimeout = dynamicconfig.NewDestinationDurationSetting(
"component.callbacks.request.timeout",
time.Second*10,
`RequestTimeout is the timeout for executing a single callback request.`,
)
var RetryPolicyInitialInterval = dynamicconfig.NewGlobalDurationSetting(
"component.callbacks.retryPolicy.initialInterval",
time.Second,
`The initial backoff interval between every callback request attempt for a given callback.`,
)
var RetryPolicyMaximumInterval = dynamicconfig.NewGlobalDurationSetting(
"component.callbacks.retryPolicy.maxInterval",
time.Hour,
`The maximum backoff interval between every callback request attempt for a given callback.`,
)
type Config struct {
RequestTimeout dynamicconfig.DurationPropertyFnWithDestinationFilter
RetryPolicy func() backoff.RetryPolicy
}
return &Config{
RequestTimeout: RequestTimeout.Get(dc),
RetryPolicy: func() backoff.RetryPolicy {
return backoff.NewExponentialRetryPolicy(
RetryPolicyInitialInterval.Get(dc)(),
).WithMaximumInterval(
RetryPolicyMaximumInterval.Get(dc)(),
).WithExpirationInterval(
backoff.NoInterval,
)
},
}
}
type AddressMatchRules struct {
Rules []AddressMatchRule
}
// Exact match only; no path, query, or fragment allowed for system URL
if rawURL == nexus.SystemCallbackURL || rawURL == chasm.NexusCompletionHandlerURL {
}
if err != nil {
return status.Errorf(codes.InvalidArgument, "invalid callback url: %v", err)
}
}
}
if err != nil {
}
}
}
return status.Errorf(codes.InvalidArgument, "invalid url: url does not match any configured callback address: %v", u)
config.go ×1
}
type AddressMatchRule struct {
Regexp *regexp.Regexp
AllowInsecure bool
}
// Allow validates the URL by:
// 1. true, nil if the provided url matches the rule and passed validation
// for the given rule.
// 2. false, nil if the URL does not match the rule.
// 3. It false, error if there is a match and the URL fails validation
if !a.Regexp.MatchString(u.Host) {
}
}
status.Errorf(codes.InvalidArgument,
"invalid url: callback address does not allow insecure connections: %v", u)
}
}
func allowedAddressConverter(val any) (AddressMatchRules, error) {
type entry struct {
Pattern string
AllowInsecure bool
}
intermediate, err := dynamicconfig.ConvertStructure[[]entry](nil)(val)
if err != nil {
return AddressMatchRules{}, err
}
configs := []AddressMatchRule{}
for _, e := range intermediate {
if e.Pattern == "" {
// Skip configs with missing / unparsable Pattern
continue
}
re, err := regexp.Compile(addressPatternToRegexp(e.Pattern))
if err != nil {
// Skip configs with malformed Pattern
continue
}
configs = append(configs, AddressMatchRule{
Regexp: re,
AllowInsecure: e.AllowInsecure,
})
}
return AddressMatchRules{Rules: configs}, nil
}
var result strings.Builder
result.WriteString("^")
first := true
for literal := range strings.SplitSeq(pattern, "*") {
if !first {
result.WriteString(".*")
}
first = false
}
return result.String()
}