Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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('<id-of-integration-instance>')
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='<id-of-integration-instance>',
filename='data.csv',
dataset_id='<id-of-dataset>'
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(
Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions examples/09_custom_file_transfer_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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,
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -236,19 +236,19 @@ 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
if INTEGRATION_INSTANCE_ID == 'your-integration-instance-id':
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
Expand Down
12 changes: 8 additions & 4 deletions jupiterone/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
"""
Expand Down Expand Up @@ -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
Expand Down
65 changes: 65 additions & 0 deletions tests/test_cft_docs.py
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion tests/test_cft_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down
Loading