From bf56017b3c58944edbeb5627a69be1512f94bcd9 Mon Sep 17 00:00:00 2001 From: kyorkJ1 Date: Tue, 24 Nov 2026 08:38:51 -0500 Subject: [PATCH] Docs: CFT dataset_id is the Dataset Name; README reads expiresIn (TD-9692) Customers were sending the wrong dataset_id because the Python client, example 09 and the README described it as an opaque "dataset ID" with placeholder values. The upload-URL resolver only issues a URL when datasetId exactly matches a config.entities[].id, which is the Dataset Name set on the CFT instance. - get_cft_upload_url / upload_cft_file docstrings: dataset_id is the Dataset Name, matched exactly; how to list valid names via get_integration_instance_details. - examples/09: help text, labels and placeholder use Dataset Name. - README: CFT section explains the exact match, shows the lookup, and reads upload_info['expiresIn'] (the mutation selects expiresIn, not expiresAt, so the old snippet raised KeyError). - tests: fixture returns expiresIn; new test_cft_docs.py discovers every upload_info[...] read in README, examples and the package and fails if one is not selected by the mutation, and asserts the docstring terms. No runtime behaviour change: the GraphQL string, variables and return statement are byte-identical. Co-Authored-By: Claude Haiku 5.5 --- README.md | 13 ++++- examples/09_custom_file_transfer_example.py | 12 ++-- jupiterone/client.py | 12 ++-- tests/test_cft_docs.py | 65 +++++++++++++++++++++ tests/test_cft_methods.py | 2 +- 5 files changed, 90 insertions(+), 14 deletions(-) create mode 100644 tests/test_cft_docs.py diff --git a/README.md b/README.md index 6de5960..9998d59 100644 --- a/README.md +++ b/README.md @@ -576,15 +576,22 @@ elif result['job']['status'] == 'FAILED': ##### Custom File Transfer (CFT) Integration Methods +`dataset_id` is the **Dataset Name** set on the CFT instance (the "Dataset name" field in the web app, e.g. `EuropaUsers`). It must match exactly, including case and spaces. To list the valid names: + +```python +instance = j1.get_integration_instance_details('') +print([e['id'] for e in instance['data']['integrationInstance']['config']['entities']]) +``` + ```python # Get a pre-signed URL for file upload upload_info = j1.get_cft_upload_url( integration_instance_id='', filename='data.csv', - dataset_id='' + dataset_id='EuropaUsers' ) print(f"Upload URL: {upload_info['uploadUrl']}") -print(f"Expires at: {upload_info['expiresAt']}") +print(f"Expires in: {upload_info['expiresIn']} seconds") # Upload a CSV file to the CFT integration upload_result = j1.upload_cft_file( @@ -628,7 +635,7 @@ def upload_and_process_data(j1, instance_id, dataset_id, file_path): print(f"Error in CFT workflow: {e}") # Usage -upload_and_process_data(j1, 'instance-123', 'dataset-456', '/path/to/data.csv') +upload_and_process_data(j1, 'instance-123', 'EuropaUsers', '/path/to/data.csv') ``` ##### Fetch Integration Instance Jobs diff --git a/examples/09_custom_file_transfer_example.py b/examples/09_custom_file_transfer_example.py index 5bbfacf..58e093a 100644 --- a/examples/09_custom_file_transfer_example.py +++ b/examples/09_custom_file_transfer_example.py @@ -59,7 +59,7 @@ def get_cft_upload_url_example(client, integration_instance_id, filename, datase client: JupiterOne client instance integration_instance_id: ID of the CFT integration instance filename: Name of the file to upload - dataset_id: Dataset ID for the upload + dataset_id: Dataset Name for the upload (exact match, e.g. "EuropaUsers") """ print("\n" + "="*60) print("1. GETTING CFT UPLOAD URL") @@ -69,7 +69,7 @@ def get_cft_upload_url_example(client, integration_instance_id, filename, datase print(f"Requesting upload URL for:") print(f" - Integration Instance ID: {integration_instance_id}") print(f" - Filename: {filename}") - print(f" - Dataset ID: {dataset_id}") + print(f" - Dataset Name: {dataset_id}") upload_info = client.get_cft_upload_url( integration_instance_id=integration_instance_id, @@ -186,7 +186,7 @@ def complete_workflow_example(client, integration_instance_id, file_path, datase client: JupiterOne client instance integration_instance_id: ID of the CFT integration instance file_path: Local path to the CSV file - dataset_id: Dataset ID for the upload + dataset_id: Dataset Name for the upload (exact match, e.g. "EuropaUsers") """ print("\n" + "="*60) print("COMPLETE CFT WORKFLOW") @@ -236,7 +236,7 @@ def main(): # Configuration - Replace these with your actual values INTEGRATION_INSTANCE_ID = os.getenv('J1_CFT_INSTANCE_ID', 'your-integration-instance-id') - DATASET_ID = os.getenv('J1_CFT_DATASET_ID', 'your-dataset-id') + DATASET_ID = os.getenv('J1_CFT_DATASET_ID', 'your-dataset-name') CSV_FILE_PATH = os.getenv('J1_CSV_FILE_PATH', 'examples/scanned_hosts.csv') # Check if we have the required configuration @@ -244,11 +244,11 @@ def main(): print("⚠️ Configuration required:") print("Set the following environment variables:") print(" - J1_CFT_INSTANCE_ID: Your CFT integration instance ID") - print(" - J1_CFT_DATASET_ID: Your dataset ID") + print(" - J1_CFT_DATASET_ID: The Dataset Name set on your CFT instance (exact match, e.g. EuropaUsers)") print(" - J1_CSV_FILE_PATH: Path to your CSV file (optional, defaults to examples/scanned_hosts.csv)") print("\nExample:") print("export J1_CFT_INSTANCE_ID='123e4567-e89b-12d3-a456-426614174000'") - print("export J1_CFT_DATASET_ID='dataset-123'") + print("export J1_CFT_DATASET_ID='EuropaUsers'") print("export J1_CSV_FILE_PATH='/path/to/your/file.csv'") print("\nOr update the variables in this script directly.") return diff --git a/jupiterone/client.py b/jupiterone/client.py index 37c7224..8741710 100644 --- a/jupiterone/client.py +++ b/jupiterone/client.py @@ -2155,16 +2155,20 @@ def get_cft_upload_url(self, integration_instance_id: str, filename: str, datase args: integration_instance_id (str): The integration instance ID filename (str): The filename to upload - dataset_id (str): The dataset ID for the upload + dataset_id (str): The Dataset Name of the CFT instance's dataset, matched exactly + (case and spaces count), e.g. "EuropaUsers". This is the "Dataset name" set when the + instance was configured, not an opaque ID. + To list the valid names, call get_integration_instance_details(integration_instance_id) + and read ["data"]["integrationInstance"]["config"]["entities"]; each entry's "id" is a Dataset Name. Returns: - Dict: Response containing uploadUrl and expiresIn + Dict: Response containing uploadUrl and expiresIn (seconds until the URL expires) Example: upload_info = j1_client.get_cft_upload_url( integration_instance_id="123e4567-e89b-12d3-a456-426614174000", filename="data.csv", - dataset_id="dataset-123" + dataset_id="EuropaUsers" ) upload_url = upload_info['uploadUrl'] """ @@ -2218,7 +2222,7 @@ def upload_cft_file(self, upload_url: str, file_path: str) -> Dict[str, Any]: upload_info = j1_client.get_cft_upload_url( integration_instance_id="123e4567-e89b-12d3-a456-426614174000", filename="data.csv", - dataset_id="dataset-123" + dataset_id="EuropaUsers" ) # Then upload the CSV file diff --git a/tests/test_cft_docs.py b/tests/test_cft_docs.py new file mode 100644 index 0000000..32a2f36 --- /dev/null +++ b/tests/test_cft_docs.py @@ -0,0 +1,65 @@ +"""Docs-drift guard for the Custom File Transfer (CFT) upload helpers (TD-9692). + +The docs and examples must only read keys of ``upload_info`` that the +``integrationFileTransferUploadUrl`` mutation actually selects, and the +``dataset_id`` docstring must say it is the instance's Dataset Name. +""" +import glob +import os +import re +from unittest.mock import patch + +from jupiterone.client import JupiterOneClient + +ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + +def _selected_fields(): + client = JupiterOneClient(account="test-account", token="test-token") + with patch("jupiterone.client.JupiterOneClient._execute_query") as mock_exec: + mock_exec.return_value = { + "data": {"integrationFileTransferUploadUrl": {}} + } + client.get_cft_upload_url("instance", "data.csv", "EuropaUsers") + query = mock_exec.call_args[0][0] + match = re.search( + r"integrationFileTransferUploadUrl\s*\(\s*integrationInstanceId:[^)]*\)\s*\{([^}]*)\}", query + ) + assert match, "could not find the selection set in the mutation" + return set(match.group(1).split()) + + +def _upload_info_reads(): + paths = [os.path.join(ROOT, "README.md")] + paths += sorted(glob.glob(os.path.join(ROOT, "examples", "*.py"))) + paths += sorted(glob.glob(os.path.join(ROOT, "jupiterone", "*.py"))) + pattern = re.compile(r"upload_info\[['\"](\w+)['\"]\]") + reads = [] + for path in paths: + with open(path, encoding="utf-8") as fh: + for lineno, line in enumerate(fh, 1): + for key in pattern.findall(line): + reads.append((os.path.relpath(path, ROOT), lineno, key)) + return reads + + +def test_selected_fields_found(): + assert {"uploadUrl", "expiresIn"} <= _selected_fields() + + +def test_docs_only_read_selected_upload_info_keys(): + selected = _selected_fields() + reads = _upload_info_reads() + assert reads, "no upload_info[...] reads found; the scan is not looking anywhere" + bad = [f"{p}:{n} reads '{k}'" for p, n, k in reads if k not in selected] + assert not bad, f"keys not selected by the mutation {sorted(selected)}: {bad}" + + +def test_get_cft_upload_url_docstring_says_dataset_name(): + doc = JupiterOneClient.get_cft_upload_url.__doc__ + assert "Dataset Name" in doc + + +def test_get_cft_upload_url_docstring_names_lookup(): + doc = JupiterOneClient.get_cft_upload_url.__doc__ + assert "get_integration_instance_details" in doc diff --git a/tests/test_cft_methods.py b/tests/test_cft_methods.py index 7f5930e..a4d25c5 100644 --- a/tests/test_cft_methods.py +++ b/tests/test_cft_methods.py @@ -26,7 +26,7 @@ def test_get_cft_upload_url_success(self, mock_execute_query): "data": { "integrationFileTransferUploadUrl": { "uploadUrl": "https://s3.amazonaws.com/test-bucket/test-file.csv", - "expiresAt": "2024-01-01T12:00:00Z" + "expiresIn": 900 } } }