Skip to content

Commit f303878

Browse files
authored
Merge pull request #2 from eclipse-score/lt_qnx_credentials_helper
Add credential helper for QNX
2 parents 3a7e062 + 767303c commit f303878

File tree

4 files changed

+110
-2
lines changed

4 files changed

+110
-2
lines changed

Diff for: README.md

+25
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,28 @@ The archive of this directory is the input for the toolchain_qcc extension.
4040

4141
It is currently assumed that the license is deployed to ```/opt/score_qnx/license/licenses```.
4242
By default QNX tooling installs the license in ```~/.qnx/license/licenses```.
43+
44+
## Using pre-packaged QNX 8.0 SDP
45+
46+
Pre-packaged SDP requires authentication with ones QNX login and password.
47+
For this the ```tools/qnx_credential_helper.py``` needs to be used.
48+
49+
The credential helper is a standalone application and cannot be referenced as Bazel target.
50+
For this the credential helper needs to be put:
51+
52+
- as an absolute path:
53+
```
54+
common --credential_helper=*.qnx.com=/path/to/qnx_credential_helper.py
55+
```
56+
57+
- in $PATH and referenced as:
58+
```
59+
common --credential_helper=*.qnx.com=qnx_credential_helper.py
60+
```
61+
62+
- in your module source and referenced as:
63+
```
64+
common --credential_helper=*.qnx.com=%worksapce%/path/to/qnx_credential_helper.py
65+
```
66+
67+
The credentials are taken from .netrc or from enviroment variables ```SCORE_QNX_LOGIN``` and ```SCORE_QNX_PASSWORD```.

Diff for: extensions.bzl

+3
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ def _impl(mctx):
2222
name = sdp.name
2323
url = sdp.url
2424
sha256 = sdp.sha256
25+
strip_prefix = sdp.strip_prefix
2526

2627
http_archive(
2728
name = "%s_sdp" % name,
2829
urls = [url],
2930
build_file = "@score_toolchains_qnx//toolchain:sdp.BUILD",
3031
sha256 = sha256,
32+
strip_prefix = strip_prefix,
3133
)
3234

3335
qnx_toolchain(
@@ -42,6 +44,7 @@ toolchain_qcc = module_extension(
4244
attrs = {
4345
"name": attr.string(default = "toolchain_qcc"),
4446
"url": attr.string(mandatory = True),
47+
"strip_prefix": attr.string(default = ""),
4548
"sha256": attr.string(mandatory = True),
4649
},
4750
),

Diff for: tests/MODULE.bazel

+3-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ local_path_override(
2424

2525
toolchain_qcc = use_extension("@score_toolchains_qnx//:extensions.bzl", "toolchain_qcc")
2626
toolchain_qcc.sdp(
27-
sha256 = "559d40a5c9306d091bff43fc3ef169650d2579838829c3b039ad4d60dc507598",
28-
url = "file:///opt/score_qnx/qnx800.tar.gz",
27+
sha256 = "f2e0cb21c6baddbcb65f6a70610ce498e7685de8ea2e0f1648f01b327f6bac63",
28+
url = "https://www.qnx.com/download/download/79858/installation.tgz",
29+
strip_prefix = "installation",
2930
)
3031
use_repo(toolchain_qcc, "toolchain_qcc_sdp")
3132
use_repo(toolchain_qcc, "toolchain_qcc")

Diff for: tools/qnx_credential_helper.py

+79
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_LOGIN" in os.environ and "SCORE_QNX_PASSWORD" in os.environ:
37+
login = os.environ["SCORE_QNX_LOGIN"]
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({
53+
"userlogin": login,
54+
"password": password,
55+
"UseCookie": "1"
56+
})
57+
data = data.encode("ascii")
58+
59+
cookie_jar = http.cookiejar.CookieJar()
60+
cookie_processor = urllib.request.HTTPCookieProcessor(cookie_jar)
61+
opener = urllib.request.build_opener(cookie_processor)
62+
urllib.request.install_opener(opener)
63+
64+
r = urllib.request.urlopen("https://www.qnx.com/account/login.html", data)
65+
if r.status != 200:
66+
eprint("Failed to login to QNX")
67+
sys.exit(1)
68+
69+
cookies = {c.name: c.value for c in list(cookie_jar)}
70+
if not "myQNX" in cookies:
71+
eprint("Failed to get myQNX cookie from login page")
72+
sys.exit(1)
73+
74+
myQNX = cookies["myQNX"]
75+
print(json.dumps({
76+
"headers": {
77+
"Cookie": [f"myQNX={myQNX}"],
78+
}
79+
}))

0 commit comments

Comments
 (0)