This repository was archived by the owner on Jan 23, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
corellium driver #351
Merged
Merged
corellium driver #351
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| # Corellium Jumpstarter Driver | ||
|
|
||
| A Jumpstarter driver that manages virtual devices in [Corellium](https://corellium.com). | ||
|
|
||
| It implements the following interfaces: | ||
|
|
||
| * PowerInterface | ||
|
|
||
| ## Usage | ||
|
|
||
| Check the [examples folder](./examples) for example files. | ||
|
|
||
| ### Config Exporter | ||
|
|
||
| You can run an exporter by running: `jmp exporter shell -c $file`: | ||
|
|
||
| ```yml | ||
| apiVersion: jumpstarter.dev/v1alpha1 | ||
| kind: ExporterConfig | ||
| # endpoint and token are intentionally left empty | ||
| metadata: | ||
| namespace: default | ||
| name: corellium-demo | ||
| endpoint: "" | ||
| token: "" | ||
| export: | ||
| rd1ae: | ||
| type: jumpstarter_driver_corellium.driver.Corellium | ||
| config: | ||
| project_id: "778f00af-5e9b-40e6-8e7f-c4f14b632e9c" | ||
| device_name: "jmp-rd1ae" | ||
| device_flavor: "kronos" | ||
| ``` | ||
|
|
||
| ```yml | ||
| apiVersion: jumpstarter.dev/v1alpha1 | ||
| kind: ExporterConfig | ||
| # endpoint and token are intentionally left empty | ||
| metadata: | ||
| namespace: default | ||
| name: corellium-demo | ||
| endpoint: "" | ||
| token: "" | ||
| export: | ||
| rd1ae: | ||
| type: jumpstarter_driver_corellium.driver.Corellium | ||
| config: | ||
| project_id: "778f00af-5e9b-40e6-8e7f-c4f14b632e9c" | ||
| device_name: "jmp-rd1ae" | ||
| device_flavor: "kronos" | ||
| device_os: "1.0" | ||
| device_build: "Critical Application Monitor (Baremetal)" | ||
| ``` |
18 changes: 18 additions & 0 deletions
18
packages/jumpstarter-driver-corellium/examples/exporter.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| apiVersion: jumpstarter.dev/v1alpha1 | ||
| kind: ExporterConfig | ||
| # endpoint and token are intentionally left empty | ||
| metadata: | ||
| namespace: default | ||
| name: corellium-demo | ||
| endpoint: "" | ||
| token: "" | ||
| export: | ||
| rd1ae: | ||
| type: jumpstarter_driver_corellium.driver.Corellium | ||
| config: | ||
| project_id: "778f00af-5e9b-40e6-8e7f-c4f14b632e9c" | ||
| device_name: "jmp-rd1ae" | ||
| device_flavor: "kronos" | ||
| # optional | ||
| device_os: "1.1.1" | ||
| device_build: "Critical Application Monitor (Baremetal)" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "error": "Invalid or missing authorization token", | ||
| "errorID": "PermissionDenied", | ||
| "originalError": "Invalid or missing authorization token" | ||
| } |
3 changes: 3 additions & 0 deletions
3
packages/jumpstarter-driver-corellium/fixtures/http/create-instance-200.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "id": "7f4f241c-821f-4219-905f-c3b50b0db5dd" | ||
| } |
5 changes: 5 additions & 0 deletions
5
packages/jumpstarter-driver-corellium/fixtures/http/create-instance-400.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "error": "Unsupported device model", | ||
| "errorID": "UserError", | ||
| "field": "flavor" | ||
| } |
8 changes: 8 additions & 0 deletions
8
packages/jumpstarter-driver-corellium/fixtures/http/delete-instance-404.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "error": "Instance with instanceId=7f4f241c-821f-4219-905f-c3b50b0db5dd not found", | ||
| "errorID": "InstanceNotFound", | ||
| "name": "Instance", | ||
| "params": { | ||
| "instanceId": "7f4f241c-821f-4219-905f-c3b50b0db5dd" | ||
| } | ||
| } |
1 change: 1 addition & 0 deletions
1
packages/jumpstarter-driver-corellium/fixtures/http/get-instance-state-200.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| on |
5 changes: 5 additions & 0 deletions
5
packages/jumpstarter-driver-corellium/fixtures/http/get-instance-state-404.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "error": "No instance associated with this value", | ||
| "errorID": "UserError", | ||
| "field": "InstanceId" | ||
| } |
14 changes: 14 additions & 0 deletions
14
packages/jumpstarter-driver-corellium/fixtures/http/get-models-200.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| [ | ||
| { | ||
| "type": "iot", | ||
| "name": "rpi4b", | ||
| "flavor": "rpi4b", | ||
| "description": "Raspberry Pi 4", | ||
| "model": "rpi4b", | ||
| "peripherals": false, | ||
| "quotas": { | ||
| "cores": 4, | ||
| "cpus": 4 | ||
| } | ||
| } | ||
| ] |
40 changes: 40 additions & 0 deletions
40
packages/jumpstarter-driver-corellium/fixtures/http/get-projects-200.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| [ | ||
| { | ||
| "id": "d59db33d-27bd-4b22-878d-49e4758a648e", | ||
| "name": "Default Project", | ||
| "settings": { | ||
| "internet-access": true, | ||
| "dhcp": true | ||
| }, | ||
| "quotas": { | ||
| "cores": 30, | ||
| "instances": 75, | ||
| "ram": 184320 | ||
| }, | ||
| "quotasUsed": { | ||
| "cores": 2, | ||
| "instances": 7, | ||
| "ram": 2048, | ||
| "gpu": 0 | ||
| } | ||
| }, | ||
| { | ||
| "id": "e2fdb33c-37ae-4b22-878d-49e4758a51f0", | ||
| "name": "OtherProject", | ||
| "settings": { | ||
| "internet-access": true, | ||
| "dhcp": true | ||
| }, | ||
| "quotas": { | ||
| "cores": 30, | ||
| "instances": 75, | ||
| "ram": 184320 | ||
| }, | ||
| "quotasUsed": { | ||
| "cores": 2, | ||
| "instances": 7, | ||
| "ram": 2048, | ||
| "gpu": 0 | ||
| } | ||
| } | ||
| ] |
5 changes: 5 additions & 0 deletions
5
packages/jumpstarter-driver-corellium/fixtures/http/get-projects-404.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "error": "Found no matching Projects", | ||
| "errorID": "UserError", | ||
| "field": "Project" | ||
| } |
1 change: 1 addition & 0 deletions
1
packages/jumpstarter-driver-corellium/fixtures/http/json-error.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| {"token": "a} | ||
4 changes: 4 additions & 0 deletions
4
packages/jumpstarter-driver-corellium/fixtures/http/login-200.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "token": "session-token", | ||
| "expiration": "2022-03-20T01:50:10.000Z" | ||
| } |
Empty file.
5 changes: 5 additions & 0 deletions
5
packages/jumpstarter-driver-corellium/jumpstarter_driver_corellium/client.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| from jumpstarter_driver_composite.client import CompositeClient | ||
|
|
||
|
|
||
| class CorelliumClient(CompositeClient): | ||
| pass |
Empty file.
173 changes: 173 additions & 0 deletions
173
packages/jumpstarter-driver-corellium/jumpstarter_driver_corellium/corellium/api.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,173 @@ | ||
| from typing import Optional | ||
|
|
||
| import requests | ||
|
|
||
| from .exceptions import CorelliumApiException | ||
| from .types import Device, Instance, Project, Session | ||
|
|
||
|
|
||
| class ApiClient: | ||
| """ | ||
| Corellium ReST API client used by the Corellium driver. | ||
| """ | ||
| session: Session | ||
| req: requests.Session | ||
|
|
||
| def __init__(self, host: str, token: str) -> None: | ||
| """ | ||
| Initializes a new client, containing a | ||
| """ | ||
| self.host = host | ||
| self.token = token | ||
| self.session = None | ||
| self.req = requests.Session() | ||
|
|
||
| @property | ||
| def baseurl(self) -> str: | ||
| """ | ||
| Return the baseurl path for API calls. | ||
| """ | ||
| return f'https://{self.host}/api' | ||
|
|
||
| def login(self) -> None: | ||
| """ | ||
| Login against Corellium's ReST API. | ||
|
|
||
| Set an internal Session object instance to be used | ||
| in other API calls that require authentication. | ||
|
|
||
| It uses the global requests objects so a new session can be generated. | ||
| """ | ||
| data = { | ||
| 'apiToken': self.token | ||
| } | ||
|
|
||
| try: | ||
| res = requests.post(f'{self.baseurl}/v1/auth/login', json=data) | ||
| data = res.json() | ||
| res.raise_for_status() | ||
| except (requests.exceptions.RequestException, requests.exceptions.HTTPError) as e: | ||
| raise CorelliumApiException(data.get('error', str(e))) from e | ||
|
|
||
| self.session = Session(**data) | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| self.req.headers.update(self.session.as_header()) | ||
|
|
||
| def get_project(self, project_ref: str = 'Default Project') -> Optional[Project]: | ||
| """ | ||
| Retrieve a project based on project_ref, which is either its id or name. | ||
| """ | ||
| try: | ||
| res = self.req.get(f'{self.baseurl}/v1/projects') | ||
| data = res.json() | ||
| res.raise_for_status() | ||
| except requests.exceptions.RequestException as e: | ||
| raise CorelliumApiException(data.get('error', str(e))) from e | ||
|
|
||
| for project in data: | ||
| if project['name'] == project_ref or project['id'] == project_ref: | ||
| return Project(id=project['id'], name=project['name']) | ||
|
|
||
| return None | ||
|
|
||
| def get_device(self, model: str) -> Optional[Device]: | ||
| """ | ||
| Get a device spec from Corellium's list based on the model name. | ||
|
|
||
| A device object is used to create a new virtual instance. | ||
| """ | ||
| try: | ||
| res = self.req.get(f'{self.baseurl}/v1/models') | ||
| data = res.json() | ||
| res.raise_for_status() | ||
| except requests.exceptions.RequestException as e: | ||
| raise CorelliumApiException(data.get('error', str(e))) from e | ||
|
|
||
| for device in data: | ||
| if device['model'] == model: | ||
| return Device(**device) | ||
|
|
||
| return None | ||
|
|
||
| def create_instance(self, name: str, project: Project, device: Device, os_version: str, os_build: str) -> Instance: | ||
| """ | ||
| Create a new virtual instance from a device spec. | ||
| """ | ||
| data = { | ||
| 'name': name, | ||
| 'project': project.id, | ||
| 'flavor': device.flavor, | ||
| 'os': os_version, | ||
| 'osbuild': os_build, | ||
| } | ||
|
|
||
| try: | ||
| res = self.req.post(f'{self.baseurl}/v1/instances', json=data) | ||
| data = res.json() | ||
| res.raise_for_status() | ||
| except requests.exceptions.RequestException as e: | ||
| raise CorelliumApiException(data.get('error', str(e))) from e | ||
|
|
||
| return Instance(**data) | ||
|
|
||
| def get_instance(self, instance_ref: str) -> Optional[Instance]: | ||
| """ | ||
| Retrieve an existing instance by its name. | ||
|
|
||
| Return None if it does not exist. | ||
| """ | ||
| try: | ||
| res = self.req.get(f'{self.baseurl}/v1/instances') | ||
| data = res.json() | ||
| res.raise_for_status() | ||
| except requests.exceptions.RequestException as e: | ||
| raise CorelliumApiException(data.get('error', str(e))) from e | ||
|
|
||
| for instance in data: | ||
| if instance['name'] == instance_ref or instance['id'] == instance_ref: | ||
| return Instance(id=instance['id'], state=instance['state']) | ||
|
|
||
| return None | ||
|
|
||
| def set_instance_state(self, instance: Instance, instance_state: str) -> None: | ||
| """ | ||
| Set the virtual instance state from corellium. | ||
|
|
||
| Valid instance state values: | ||
|
|
||
| - on | ||
| - off | ||
| - booting | ||
| - deleting | ||
| - creating | ||
| - restoring | ||
| - paused | ||
| - rebooting | ||
| - error | ||
| """ | ||
| data = { | ||
| 'state': instance_state | ||
| } | ||
|
|
||
| try: | ||
| res = self.req.put(f'{self.baseurl}/v1/instances/{instance.id}/state', json=data) | ||
| data = res.json() if res.status_code != 204 else None | ||
| res.raise_for_status() | ||
| except requests.exceptions.RequestException as e: | ||
| msgerr = data if data is not None else str(e) | ||
|
|
||
| raise CorelliumApiException(msgerr) from e | ||
|
|
||
| def destroy_instance(self, instance: Instance) -> None: | ||
| """ | ||
| Delete a virtual instance. | ||
|
|
||
| Does not return anything since Corellium's API return a HTTP 204 response. | ||
| """ | ||
| try: | ||
| res = self.req.delete(f'{self.baseurl}/v1/instances/{instance.id}') | ||
| data = res.json() if res.status_code != 204 else None | ||
| res.raise_for_status() | ||
| except requests.exceptions.RequestException as e: | ||
| msgerr = data if data is not None else str(e) | ||
|
|
||
| raise CorelliumApiException(msgerr) from e | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix invalid JSON syntax in test fixture.
The JSON file contains syntax errors: the string value for "token" is missing a closing quotation mark, and the JSON object is missing a closing brace. This will cause parsing errors when used.
Apply this diff to correct the JSON syntax:
📝 Committable suggestion
🧰 Tools
🪛 Biome (1.9.4)
[error] 1-1: Missing closing quote
The closing quote must be on the same line.
(parse)
[error] 1-1: expected
}but instead the file endsthe file ends here
(parse)