Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigozhou committed Aug 27, 2024
1 parent ae9bcfe commit 6ee5334
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
4 changes: 2 additions & 2 deletions internal/internal_nexus_task_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,15 +169,15 @@ func (h *nexusTaskHandler) handleStartOperation(
if callbackHeader == nil {
callbackHeader = make(map[string]string)
}
var nexusLinks []nexus.Link
nexusLinks := make([]nexus.Link, 0, len(req.GetLinks()))
for _, link := range req.GetLinks() {
if link == nil {
continue
}
linkURL, err := url.Parse(link.GetUrl())
if err != nil {
nctx.Log.Error("failed to parse link url: %s", link.GetUrl(), tagError, err)
return nil, h.internalError(fmt.Errorf("failed to parse link url: %w", err)), nil
return nil, nexusHandlerError(nexus.HandlerErrorTypeBadRequest, "failed to parse link url"), nil
}
nexusLinks = append(nexusLinks, nexus.Link{
URL: linkURL,
Expand Down
28 changes: 17 additions & 11 deletions converter/link_converter.go → temporalnexus/link_converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ const (
)

var (
rePatternNamespace = fmt.Sprintf(`(?P<%s>[a-z0-9-.]+)`, urlPathNamespaceKey)
rePatternNamespace = fmt.Sprintf(`(?P<%s>[^/]+)`, urlPathNamespaceKey)
rePatternWorkflowID = fmt.Sprintf(`(?P<%s>[^/]+)`, urlPathWorkflowIDKey)
rePatternRunID = fmt.Sprintf(`(?P<%s>[a-zA-Z0-9-]+)`, urlPathRunIDKey)
rePatternRunID = fmt.Sprintf(`(?P<%s>[^/]+)`, urlPathRunIDKey)
urlPathRE = regexp.MustCompile(fmt.Sprintf(
`^/+namespaces/+%s/+workflows/+%s/+%s/+history/*$`,
`^/namespaces/%s/workflows/%s/%s/history/?$`,
rePatternNamespace,
rePatternWorkflowID,
rePatternRunID,
Expand Down Expand Up @@ -91,41 +91,47 @@ func ConvertNexusLinkToLinkWorkflowEvent(link nexus.Link) (*commonpb.Link_Workfl
}

if link.URL.Scheme != urlSchemeTemporalKey {
return nil, fmt.Errorf("failed to parse link to Link_WorkflowEvent")
return nil, fmt.Errorf(
"failed to parse link to Link_WorkflowEvent: invalid scheme: %s",
link.URL.Scheme,
)
}

matches := urlPathRE.FindStringSubmatch(link.URL.EscapedPath())
if len(matches) != 4 {
return nil, fmt.Errorf("failed to parse link to Link_WorkflowEvent")
return nil, fmt.Errorf("failed to parse link to Link_WorkflowEvent: malformed URL path")
}

var err error
we.Namespace, err = url.PathUnescape(matches[urlPathRE.SubexpIndex(urlPathNamespaceKey)])
if err != nil {
return nil, fmt.Errorf("failed to parse link to Link_WorkflowEvent")
return nil, fmt.Errorf("failed to parse link to Link_WorkflowEvent: %w", err)
}

we.WorkflowId, err = url.PathUnescape(matches[urlPathRE.SubexpIndex(urlPathWorkflowIDKey)])
if err != nil {
return nil, fmt.Errorf("failed to parse link to Link_WorkflowEvent")
return nil, fmt.Errorf("failed to parse link to Link_WorkflowEvent: %w", err)
}

we.RunId, err = url.PathUnescape(matches[urlPathRE.SubexpIndex(urlPathRunIDKey)])
if err != nil {
return nil, fmt.Errorf("failed to parse link to Link_WorkflowEvent")
return nil, fmt.Errorf("failed to parse link to Link_WorkflowEvent: %w", err)
}

switch link.URL.Query().Get(linkWorkflowEventReferenceTypeKey) {
switch refType := link.URL.Query().Get(linkWorkflowEventReferenceTypeKey); refType {
case string((&commonpb.Link_WorkflowEvent_EventReference{}).ProtoReflect().Descriptor().Name()):
eventRef, err := convertURLQueryToLinkWorkflowEventEventReference(link.URL.Query())
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to parse link to Link_WorkflowEvent: %w", err)
}
we.Reference = &commonpb.Link_WorkflowEvent_EventRef{
EventRef: eventRef,
}
default:
// TODO(rodrigozhou): do we want to return an error here?
return nil, fmt.Errorf(
"failed to parse link to Link_WorkflowEvent: unknown reference type: %q",
refType,
)
}

return we, nil
Expand Down
File renamed without changes.

0 comments on commit 6ee5334

Please sign in to comment.