Skip to content

Commit

Permalink
fix(server): Improve validation for RunWfRequest wf_spec_name and…
Browse files Browse the repository at this point in the history
… `id`
  • Loading branch information
Snarr committed Feb 21, 2025
1 parent 77b4db7 commit 34469fc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,20 @@ public boolean hasResponse() {

@Override
public WfRun process(ProcessorExecutionContext processorContext, LHServerConfig config) {
if (wfSpecName.equals("")) {
throw new LHApiException(Status.INVALID_ARGUMENT, "Missing required argument 'wf_spec_name'");
}

if ((id != null && id.equals("")) || !LHUtil.isValidLHName(id)) {
throw new LHApiException(Status.INVALID_ARGUMENT, "Optional argument 'id' must be a valid hostname");
}

GetableManager getableManager = processorContext.getableManager();
WfSpecModel spec = processorContext.service().getWfSpec(wfSpecName, majorVersion, revision);
if (spec == null) {
throw new LHApiException(Status.NOT_FOUND, "Couldn't find specified WfSpec");
}

if (!LHUtil.isValidLHName(id)) {
throw new LHApiException(Status.INVALID_ARGUMENT, "WfRunId must be a valid hostname");
}

// TODO: Add WfRun Start Metrics

WfRunModel oldWfRun = getableManager.get(new WfRunIdModel(id));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -592,11 +592,11 @@ public void searchScheduledWfRun(SearchScheduledWfRunRequest req, StreamObserver
@Authorize(resources = ACLResource.ACL_WORKFLOW, actions = ACLAction.RUN)
public void runWf(RunWfRequest req, StreamObserver<WfRun> ctx) {
if (req.getWfSpecName().equals("")) {
throw new LHApiException(Status.INVALID_ARGUMENT, "Missing required parameter 'wf_spec_name'");
throw new LHApiException(Status.INVALID_ARGUMENT, "Missing required argument 'wf_spec_name'");
}

if (!req.getId().equals("") && !LHUtil.isValidLHName(req.getId())) {
throw new LHApiException(Status.INVALID_ARGUMENT, "WfRunId must be a valid hostname");
if ((req.hasId() && req.getId().equals("")) || !LHUtil.isValidLHName(req.getId())) {
throw new LHApiException(Status.INVALID_ARGUMENT, "Optional argument 'id' must be a valid hostname");
}

RunWfRequestModel reqModel = LHSerializable.fromProto(req, RunWfRequestModel.class, requestContext());
Expand Down

0 comments on commit 34469fc

Please sign in to comment.