Skip to content

Commit 8095d3e

Browse files
author
Adrian Willenbücher
committed
Include QNX toolchain credentials
1 parent 46494a6 commit 8095d3e

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

scripts/internal/qnx_creds.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/usr/bin/env python3
2+
3+
# *******************************************************************************
4+
# Copyright (c) 2025 Contributors to the Eclipse Foundation
5+
#
6+
# See the NOTICE file(s) distributed with this work for additional
7+
# information regarding copyright ownership.
8+
#
9+
# This program and the accompanying materials are made available under the
10+
# terms of the Apache License Version 2.0 which is available at
11+
# https://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# SPDX-License-Identifier: Apache-2.0
14+
# *******************************************************************************
15+
16+
import http.cookiejar
17+
import json
18+
import netrc
19+
import os
20+
import sys
21+
import urllib.parse
22+
import urllib.request
23+
24+
25+
def eprint(*args, **kwargs):
26+
print(*args, file=sys.stderr, **kwargs)
27+
28+
29+
if __name__ == "__main__":
30+
data = json.load(sys.stdin)
31+
32+
if "qnx.com" not in data["uri"]:
33+
eprint("Unsupported domain")
34+
sys.exit(1)
35+
36+
if "SCORE_QNX_USER" in os.environ and "SCORE_QNX_PASSWORD" in os.environ:
37+
login = os.environ["SCORE_QNX_USER"]
38+
password = os.environ["SCORE_QNX_PASSWORD"]
39+
else:
40+
try:
41+
nrc = netrc.netrc()
42+
auth = nrc.authenticators("qnx.com")
43+
if auth:
44+
login, _, password = auth
45+
else:
46+
raise Exception("No credential found for QNX")
47+
except Exception as excp:
48+
eprint(excp)
49+
eprint("Failed getting credentials from .netrc")
50+
sys.exit(1)
51+
52+
data = urllib.parse.urlencode({"userlogin": login, "password": password, "UseCookie": "1"})
53+
data = data.encode("ascii")
54+
55+
cookie_jar = http.cookiejar.CookieJar()
56+
cookie_processor = urllib.request.HTTPCookieProcessor(cookie_jar)
57+
opener = urllib.request.build_opener(cookie_processor)
58+
urllib.request.install_opener(opener)
59+
60+
r = urllib.request.urlopen("https://www.qnx.com/account/login.html", data)
61+
if r.status != 200:
62+
eprint("Failed to login to QNX")
63+
sys.exit(1)
64+
65+
cookies = {c.name: c.value for c in list(cookie_jar)}
66+
if not "myQNX" in cookies:
67+
eprint("Failed to get myQNX cookie from login page")
68+
sys.exit(1)
69+
70+
myQNX = cookies["myQNX"]
71+
print(
72+
json.dumps(
73+
{
74+
"headers": {
75+
"Cookie": [f"myQNX={myQNX}"],
76+
}
77+
}
78+
)
79+
)

0 commit comments

Comments
 (0)