Skip to content

Filesharing Resolve Git URL Task¤

task api name: resolve_git_url

The resolve_git_url task validates a git:// file URL, synchronizes its configured remote, and returns the file's published nf:// URL. The task does not stream file content. NFPClient.fetch_file() calls it automatically before using the existing File Sharing transfer flow.

Output¤

Returns results keyed by original Git URL. Each entry contains failed, errors, and result; successful results contain the file's published nf:// URL using its remote's configured mount. Missing files, invalid paths, and failed remotes produce individual failures. Each valid referenced remote is synchronized once per request. The url argument accepts a string or list. A string retains the original single-file result containing the published URL directly, or a failed result.

Examples¤

Use the client-level file command, which resolves the URL automatically:

nf#file copy url git://network-assets/templates/base.j2 read

Direct task invocation:

from norfab.core.nfapi import NorFab

with NorFab(inventory="./inventory.yaml") as nf:
    client = nf.make_client()
    result = client.run_job(
        service="filesharing",
        task="resolve_git_url",
        workers="filesharing-worker-1",
        kwargs={"url": ["git://network-assets/templates/base.j2"]},
    )
    print(result)

Normal file retrieval:

from norfab.core.nfapi import NorFab

with NorFab(inventory="./inventory.yaml") as nf:
    client = nf.make_client()
    result = client.fetch_file(
        "git://network-assets/templates/base.j2",
        read=True,
    )
    print(result["content"])

Notes¤

  • The remote must already be configured or registered with create_remote_git.
  • Resolution synchronizes the complete configured branch before returning.
  • The returned URL uses the configured mount, which may differ from the remote name.
  • Git access and credentials remain inside the File Sharing worker.

Python API Reference¤

Synchronize remotes and resolve a batch of Git URLs.

Parameters:

Name Type Description Default
job Job

Active worker job used for synchronization events.

required
url str | list[str]

A git:// URL or list of URLs. An empty list returns no entries.

required

Returns:

Type Description
Result

For string input, a published nf:// URL or a failed result. For list

Result

input, per-URL results containing published URLs or individual errors.

Result

Each referenced valid remote is synchronized once per request. A

Result

remote synchronization failure affects only that remote's entries.

Result

Entry errors are also collected in the outer result errors list.

Source code in norfab\workers\filesharing_worker\git_tasks.py
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
@Task(
    input=ResolveGitUrlInput,
    output=ResolveGitUrlResult,
    fastapi={"methods": ["POST"]},
    agent={"enabled": False},
    mcp={
        "annotations": {
            "title": "Resolve Git URL",
            "readOnlyHint": False,
            "destructiveHint": False,
            "idempotentHint": True,
            "openWorldHint": True,
        }
    },
)
def resolve_git_url(self, job: Job, url: str | list[str]) -> Result:
    """Synchronize remotes and resolve a batch of Git URLs.

    Args:
        job: Active worker job used for synchronization events.
        url: A git:// URL or list of URLs. An empty list returns no entries.

    Returns:
        For string input, a published nf:// URL or a failed result. For list
        input, per-URL results containing published URLs or individual errors.
        Each referenced valid remote is synchronized once per request. A
        remote synchronization failure affects only that remote's entries.
        Entry errors are also collected in the outer result errors list.
    """
    urls = [url] if isinstance(url, str) else url
    synced = {}
    ret = Result(result={})
    for item in urls:
        try:
            remote_path = item.removeprefix("git://").replace("\\", "/")
            name, separator, file_path = remote_path.partition("/")
            if (
                not item.startswith("git://")
                or not name
                or not separator
                or not file_path
            ):
                raise ValueError(f"'{item}' - invalid Git URL format")

            remote = self.remotes.get(name)
            if remote is None:
                raise ValueError(f"Remote '{name}' is not configured")
            if remote["type"] != "git":
                raise ValueError(f"Remote '{name}' is not a git remote")

            mount_path = self.safe_path(remote["mount"])
            resolved_path = os.path.abspath(
                os.path.join(mount_path, *file_path.split("/"))
            )
            if os.path.commonpath([mount_path, resolved_path]) != mount_path:
                raise ValueError(f"'{item}' - invalid Git URL path")

            # Share one synchronization across all files from this remote.
            if name not in synced:
                synced[name] = self.git_clone(job, name)
            sync_result = synced[name]
            if sync_result.failed:
                entry = Result(failed=True, errors=sync_result.errors)
            elif not os.path.isfile(resolved_path):
                entry = Result(failed=True, errors=[f"'{item}' file not found"])
            else:
                published_path = os.path.relpath(resolved_path, mount_path).replace(
                    os.sep, "/"
                )
                resolved_url = f"{remote['mount'].rstrip('/')}/{published_path}"
                entry = Result(result=resolved_url)
        except (OSError, ValueError) as exc:
            entry = Result(failed=True, errors=[str(exc)])
        ret.errors.extend(entry.errors)
        ret.result[item] = entry.model_dump()
    if isinstance(url, str):
        return entry
    return ret

Batch entry errors are also collected in the outer result's errors list, while successful entries remain available.