Examples: SSH Keys
You can add SSH public keys to a Test Agent via the REST API. Using the corresponding private key you can then log in to the Test Agent via SSH.
The full list of available operations on SSH keys is as follows:
- Add an SSH key
- Modify an SSH key
- Inspect an SSH key
- List SSH keys
- Delete an SSH key.
Below, some of these operations are exemplified.
Adding an SSH Key
Here is how to create a new SSH key.
# Request settings
url = '{}/accounts/{}/ssh_keys/?test_agent_id={}'.format(args.ncc_url,
args.account,
args.test_agent_id)
# JSON content
json_data = json.dumps({
'key': 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCWDqRALdALDJARxa85',
'name': 'SSH key'
})
# Create the SSH key
response = requests.post(url=url, data=json_data, headers={
'API-Token': args.token,
'Accept': 'application/json; indent=4',
'Content-Type': 'application/json',
})Retrieving All SSH Keys
To list all SSH keys, proceed as follows:
# request settings
# NOTE: User is able to pass additional parameters as a query string ?limit=100&offset=111:
# limit: changes number of elements returned from api
# offset: changes element from which results will be returned
url = '{}/accounts/{}/ssh_keys/?test_agent_id={}'.format(args.ncc_url,
args.account,
args.test_agent_id)
# Get a list of SSH keys
response = requests.get(url=url, headers={'API-Token': args.token})Deleting an SSH Key
If you want to delete an SSH key, use the following command:
# request settings
url = '{}/accounts/{}/ssh_keys/{}/?test_agent_id={}'.format(args.ncc_url,
args.account,
args.ssh_key_id,
args.test_agent_id)
# Delete SSH key
response = requests.delete(url=url, headers={'API-Token': args.token})