Edit artifact
Example - Edit an artifact from your connector
Last update: 2024-02-02
This request edits an artifact on a custom connector using a connection to the connector. It uses a pre-established connection from the examples request to our connector.
The following operations are demonstrated:
Load environment variables (your connector configs) from a .env file.
Establish a connection to your TSG connector.
Edits an artifact from your connector.
Important
Ensure that the required environment variables (Your Connector API_KEY, CONNECTOR_ID, ACCESS_URL and AGENT_ID) are set in the .env file before using this request.
The connector API_KEY can be retrieved by loging into the TSG connector UI and navigating to the ‘API Keys’ tab.
Execute the code below to publish a data artifact on your connector.
Ensure that the required parameters are specified before executing the request:
artifact_id: Id of the artifact.
artifact_path: The path to the data artifact.
artifact_description: The description of the data artifact.
artifact_title: The title of the data artifact.
contract_offer_path: The path to the contract offer file.
1if __name__ == "__main__":
2 from loguru import logger
3 from dotenv import dotenv_values
4 from tsg_client.controllers import TSGController
5
6 # Comment the line below to enable internal logger:
7 logger.disable("")
8
9 # Load environment variables:
10 config = dotenv_values('.env')
11
12 # Connect to our TSG connector:
13 conn = TSGController(
14 api_key=config['API_KEY'],
15 connector_id=config['CONNECTOR_ID'],
16 access_url=config['ACCESS_URL'],
17 agent_id=config['AGENT_ID']
18 )
19
20 # Specify the required parameters:
21 artifact_id = "<artifact_id>"
22 artifact_path = "<artifact_path>"
23 artifact_description = "<description>"
24 artifact_title = "<title>"
25 contract_offer_path = "./files/contracts/default.json"
26
27 # Read the contract offer content from the file:
28 with open(contract_offer_path, 'r') as file:
29 contract_offer_content = file.read()
30
31 # Post artifact on our connector:
32 updated_data_artifact = conn.edit_artifact(
33 artifact_id=artifact_id,
34 artifact=artifact_path,
35 contract_offer=contract_offer_content,
36 description=artifact_description,
37 title=artifact_title
38 )
39
40 print("-" * 79)
41 print("Updated Data Artifact:")
42 print(updated_data_artifact)