Skip to content

Commit 63d542c

Browse files
committed
fixed api
1 parent 9a649f3 commit 63d542c

File tree

1 file changed

+31
-22
lines changed

1 file changed

+31
-22
lines changed

chipflow_lib/steps/silicon.py

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
from .. import ChipFlowError
1818
from ..platforms import SiliconPlatform, top_interfaces
19+
from urllib.parse import urlparse
1920

2021

2122
logger = logging.getLogger(__name__)
@@ -155,34 +156,42 @@ def submit(self, rtlil_path, *, dry_run=False):
155156
return
156157

157158
logger.info(f"Submitting {submission_name} for project {self.project_name}")
159+
endpoint = os.environ.get("CHIPFLOW_API_ENDPOINT", "https://build.chipflow.org/api/builds")
160+
host = urlparse(endpoint).netloc
158161

159162
resp = requests.post(
160-
os.environ.get("CHIPFLOW_API_ENDPOINT", "https://app.chipflow-infra.com/api/builds"),
163+
os.environ.get("CHIPFLOW_API_ENDPOINT", "https://build.chipflow.org/api/builds"),
161164
auth=(os.environ["CHIPFLOW_API_KEY_ID"], os.environ["CHIPFLOW_API_KEY_SECRET"]),
162165
data=data,
163166
files={
164167
"rtlil": open(rtlil_path, "rb"),
165168
"config": json.dumps(config),
166169
})
167-
resp_data = resp.json()
168-
if resp.status_code == 403:
169-
raise ChipFlowError(
170-
"Authentication failed; please verify the values of the the CHIPFLOW_API_KEY_ID "
171-
"and CHIPFLOW_API_KEY_SECRET environment variables, if the issue persists, "
172-
"contact support to resolve it")
173-
elif resp.status_code >= 400:
174-
raise ChipFlowError(
175-
f"Submission failed ({resp_data['statusCode']} {resp_data['error']}: "
176-
f"{resp_data['message']}); please contact support and provide this error message")
177-
elif resp.status_code >= 300:
178-
assert False, "3xx responses should not be returned"
179-
elif resp.status_code >= 200:
180-
if not resp_data["ok"]:
181-
raise ChipFlowError(
182-
f"Submission failed ({resp_data['msg']}); please contact support and provide "
183-
f"this error message")
184-
else:
185-
print(f"{resp_data['msg']} (#{resp_data['id']}: {resp_data['name']}); "
186-
f"{resp_data['url']}")
170+
171+
# Parse response body
172+
try:
173+
resp_data = resp.json()
174+
except ValueError:
175+
resp_data = resp.text
176+
177+
# Handle response based on status code
178+
if resp.status_code == 200:
179+
logger.info(f"Submitted design: {resp_data}")
180+
print(f"https://{host}/build/{resp_data["build_id"]}")
181+
187182
else:
188-
ChipFlowError(f"Unexpected response from API: {resp}")
183+
# Log detailed information about the failed request
184+
logger.error(f"Request failed with status code {resp.status_code}")
185+
logger.error(f"Request URL: {resp.request.url}")
186+
187+
# Log headers with auth information redacted
188+
headers = dict(resp.request.headers)
189+
if "Authorization" in headers:
190+
headers["Authorization"] = "REDACTED"
191+
logger.error(f"Request headers: {headers}")
192+
193+
logger.error(f"Request data: {data}")
194+
logger.error(f"Response headers: {dict(resp.headers)}")
195+
logger.error(f"Response body: {resp_data}")
196+
197+
raise ChipFlowError(f"Failed to submit design: {resp_data}")

0 commit comments

Comments
 (0)