Skip to content

Commit ddf9ae9

Browse files
committed
spec 2 support
1 parent 0b67941 commit ddf9ae9

File tree

3 files changed

+26
-21
lines changed

3 files changed

+26
-21
lines changed

README.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ A github action which is used in a combination with [torque-start-sb-action](htt
55
## Usage
66

77
```yaml
8-
- uses: QualiTorque/torque-end-sb-action@v0.0.3
8+
- uses: QualiTorque/torque-end-sb-action@v0.1
99
with:
1010
# The name of the Torque Space your repository is connected to
1111
space: TestSpace
@@ -54,7 +54,7 @@ jobs:
5454
steps:
5555
- name: Start Torque Sandbox
5656
id: start-sandbox
57-
uses: QualiTorque/torque-start-sb-action@v0.0.3
57+
uses: QualiTorque/torque-start-sb-action@v0.1
5858
with:
5959
space: Demo
6060
blueprint_name: WebApp
@@ -68,14 +68,10 @@ jobs:
6868
id: test-app
6969
run: |
7070
echo "Running tests against sandbox with id: ${{ steps.start-sandbox.outputs.sandbox_id }}"
71-
shortcuts=${{ steps.start-sandbox.outputs.sandbox_shortcuts }}
72-
readarray -t shortcuts <<< "$(jq '. | .flask-app[]' <<< '${{ steps.start-sandbox.outputs.sandbox_shortcuts }}')"
73-
for shortcut in ${shortcuts[@]}; do
74-
"Do something with this ${shortcut}."
75-
done
71+
echo "Do something with sandbox details json: ${{ steps.start-sandbox.outputs.sandbox_details }}"
7672
7773
- name: Stop sandbox
78-
uses: QualiTorque/torque-end-sb-action@v0.0.3
74+
uses: QualiTorque/torque-end-sb-action@v0.1
7975
with:
8076
space: Demo
8177
sandbox_id: ${{ steps.start-sandbox.outputs.sandbox_id }}

common.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,32 @@
11
import sys
22
import requests
3+
from constants import VERSION
34

45

56
class TorqueSession(requests.Session):
67
def __init__(self):
78
super(TorqueSession, self).__init__()
8-
self.headers.update({"Accept": "application/json", "Accept-Charset": "utf-8"})
9+
self.headers.update(
10+
{
11+
"Accept": "application/json",
12+
"Accept-Charset": "utf-8",
13+
"User-Agent": f"Torque-Plugin-Github-Actions/{VERSION}"
14+
}
15+
)
916

1017
def torque_auth(self, token: str) -> None:
1118
self.headers.update({"Authorization": f"Bearer {token}"})
1219

1320

1421
class TorqueClient:
15-
def __init__(self, space: str, token: str, session: TorqueSession = TorqueSession(), account: str = None):
22+
TORQUE_SERVER = "portal.qtorque.io"
23+
24+
def __init__(self, space: str, token: str, session: TorqueSession = TorqueSession()):
1625
self.token = token
1726
self.space = space
1827
self.session = session
1928
session.torque_auth(self.token)
20-
self.base_api_url = f"https://qtorque.io/api/spaces/{self.space}"
29+
self.base_api_url = f"https://{self.TORQUE_SERVER}/api/spaces/{self.space}"
2130

2231
def _request(self, endpoint: str, method: str = 'GET', params: dict = None) -> requests.Response:
2332
self._validate_creds()
@@ -56,23 +65,22 @@ def start_sandbox(
5665
sandbox_name: str,
5766
duration: int = 120,
5867
inputs: dict = None,
59-
artifacts: dict = None,
60-
branch: str = None) -> str:
68+
# branch: str = None
69+
) -> str:
6170

62-
path = "sandbox"
71+
path = "environments"
6372
iso_duration = f"PT{duration}M"
6473
params = {
6574
"sandbox_name": sandbox_name,
6675
"blueprint_name": blueprint_name,
6776
"duration": iso_duration,
6877
"inputs": inputs,
69-
"artifacts": artifacts,
7078
}
7179

72-
if branch:
73-
params["source"] = {
74-
"branch": branch,
75-
}
80+
# if branch:
81+
# params["source"] = {
82+
# "branch": branch,
83+
# }
7684

7785
res = self._request(path, method="POST", params=params)
7886
sandbox_id = res.json()["id"]
@@ -81,15 +89,15 @@ def start_sandbox(
8189

8290
def get_sandbox(self, sandbox_id: str) -> dict:
8391
"""Returns Sandbox as a json"""
84-
path = f"sandbox/{sandbox_id}"
92+
path = f"environments/{sandbox_id}"
8593

8694
res = self._request(path, method="GET")
8795

8896
return res.json()
8997

9098

9199
def end_sandbox(self, sandbox_id: str) -> None:
92-
path = f"sandbox/{sandbox_id}"
100+
path = f"environments/{sandbox_id}"
93101

94102
res = self._request(path, method="DELETE")
95103

constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
VERSION = "v0.1.0"

0 commit comments

Comments
 (0)