Methods
Instantiation
SdkAPI
Create a new Spire Linux Agent Client.
- Python
- C
from oort_sdk_client import SdkApi
agent = SdkApi()
#include "SdkAPI.h"
apiClient_t *client;
client = apiClient_create();
/* ... */
apiClient_free(client);
SendFile
Sends a file from the payload to the ground via the API.
- Python
- C
from oort_sdk_client.models import SendOptions, SendFileRequest, RetrieveFileRequest
ttl = TTLParams(urgent=9000, bulk=43200, surplus=172800)
# Where args are the parsed arguments send via payload_exec
tags = {"token": str(args.window_id)}
send_options = SendOptions(ttl_params=ttl, reliable=True, tags=tags)
req = SendFileRequest(
destination="ground",
topic="my-topic",
filepath="/path/to/file",
options=send_options)
resp = agent.send_file(req)
print("File sent successfully, UUID is {}".format(resp.uuid))
send_file_request_t *req;
send_options_t *send_opt;
send_file_response_t *resp;
ttl_params_t *ttl;
tags_t *tags;
char token[50];
/* where window_id is the int spire passes to the payload_exec for the customer via the payload_shim */
std::sprintf(token, "%lu", window_id);
ttl = ttl_params_create(urgent, bulk, surplus);
tags = tags_create(token);
send_opt = send_options_create(ttl, reliable, tags);
req = send_file_request_create(dest, filename, topic, send_opt);
resp = SdkAPI_sendFile(client, req);
if (resp != NULL) {
fprintf(stderr, "resp uuid = %s", resp->uuid);
send_file_response_free(resp);
}
send_file_request_free(req);
Arguments
Type | Description |
---|---|
SendFileRequest | SendFileRequest Object |
Return value
Type | Description |
---|---|
SendFileResponse | Contains the UUID assigned for this file transfer |
QueryAvailableFiles
Queries files that have been uplinked from the ground to the payload.
- Python
- C
from oort_sdk_client import SdkApi
agent = SdkApi()
topic = "my-topic"
available = agent.query_available_files(topic)
for item in available.files:
print("Available file: {item.id} -- {item.path}".format(item=item))
char *topic = NULL;
apiClient_t *client;
available_files_response_t *resp;
topic = strdup(argv[1]);
client = apiClient_create();
resp = SdkAPI_queryAvailableFiles(client, topic);
if (resp != NULL) {
listEntry_t *item;
fprintf(stderr, "Available files:\n");
list_ForEach(item, resp->files) {
file_info_t *finfo = (file_info_t *)item->data;
fprintf(stderr, "%s: %s\n", finfo->id, finfo->path);
}
available_files_response_free(resp);
}
apiClient_free(client);
Arguments
Type | Description |
---|---|
string | The topic to check for available files. |
Return value
Type | Description |
---|---|
AvailableFilesResponse | AvailableFilesResponse Object |
RetrieveFile
Retrieve a file returned from QueryAvailableFiles
- Python
- C
import os
from oort_sdk_client import SdkApi
from oort_sdk_client.models import RetrieveFileRequest
agent = SdkApi()
topic = "my-topic"
# download files that are available in the agent's inbox. Please note that this is not production-level code, and is
# typically done as part of the signaling configure step. Please refer to the examples in the customer documentation that
# has been provided separely
available_files = agent.query_available_files(topic).files
if not available.files:
print("No files available for retreival")
for new_file_info in available_files:
# Delivery Hints are set when uploading a file through the Tasking API
dest_path = new_file_info.delivery_hints.dest_path
mode = int(f"0o{new_file_info.delivery_hints.mode}", 8)
print(f"Retrieving {new_file.id} in {dest_path}")
# The oort agent will not create intermediate directories when extracting a file, so we need to create them ourselves
os.makedirs(os.path.dirname(dest_path), mode=0o755, exist_ok=True)
req = RetrieveFileRequest(
id=new_file_info.id,
save_path=dest_path)
rfinfo = agent.retrieve_file(req)
# We will set the file mode based on the delivery hints
os.chmod(dest_path, mode)
char *filename = NULL, *id = NULL;
apiClient_t *client;
retrieve_file_request_t *req;
file_info_t *finfo;
if (argc != 3) {
usage(argv[0]);
}
id = strdup(argv[1]);
filename = strdup(argv[2]);
client = apiClient_create();
req = retrieve_file_request_create(id, filename);
finfo = SdkAPI_retrieveFile(client, req);
if (finfo != NULL) {
fprintf(stderr, "retrieved id = %s to %s",
req->id, finfo->path);
file_info_free(finfo);
}
retrieve_file_request_free(req);
apiClient_free(client);
Retrieve an available file from the Data Pipeline API.
Arguments
Type | Description |
---|---|
RetrieveFileRequest | RetrieveFileRequest Object |
Return value
Type | Description |
---|---|
FileInfo | Details about the file retrieved |