python-utility-scripts 2.0.5__tar.gz → 2.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {python_utility_scripts-2.0.5 → python_utility_scripts-2.1.0}/.gitignore +7 -0
- {python_utility_scripts-2.0.5 → python_utility_scripts-2.1.0}/PKG-INFO +3 -2
- python_utility_scripts-2.1.0/apps/jira_utils/README.md +459 -0
- python_utility_scripts-2.1.0/apps/jira_utils/jira_information.py +1679 -0
- {python_utility_scripts-2.0.5 → python_utility_scripts-2.1.0}/apps/unused_code/README.md +3 -1
- {python_utility_scripts-2.0.5 → python_utility_scripts-2.1.0}/apps/unused_code/unused_code.py +126 -120
- {python_utility_scripts-2.0.5 → python_utility_scripts-2.1.0}/apps/utils.py +26 -7
- {python_utility_scripts-2.0.5 → python_utility_scripts-2.1.0}/pyproject.toml +2 -1
- python_utility_scripts-2.0.5/apps/jira_utils/README.md +0 -62
- python_utility_scripts-2.0.5/apps/jira_utils/jira_information.py +0 -288
- {python_utility_scripts-2.0.5 → python_utility_scripts-2.1.0}/LICENSE +0 -0
- {python_utility_scripts-2.0.5 → python_utility_scripts-2.1.0}/README.md +0 -0
- {python_utility_scripts-2.0.5 → python_utility_scripts-2.1.0}/apps/__init__.py +0 -0
- {python_utility_scripts-2.0.5 → python_utility_scripts-2.1.0}/apps/jira_utils/__init__.py +0 -0
- {python_utility_scripts-2.0.5 → python_utility_scripts-2.1.0}/apps/polarion/README.md +0 -0
- {python_utility_scripts-2.0.5 → python_utility_scripts-2.1.0}/apps/polarion/__init__.py +0 -0
- {python_utility_scripts-2.0.5 → python_utility_scripts-2.1.0}/apps/polarion/polarion_set_automated.py +0 -0
- {python_utility_scripts-2.0.5 → python_utility_scripts-2.1.0}/apps/polarion/polarion_utils.py +0 -0
- {python_utility_scripts-2.0.5 → python_utility_scripts-2.1.0}/apps/polarion/polarion_verify_tc_requirements.py +0 -0
- {python_utility_scripts-2.0.5 → python_utility_scripts-2.1.0}/apps/unused_code/__init__.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
2
|
Name: python-utility-scripts
|
|
3
|
-
Version: 2.0
|
|
3
|
+
Version: 2.1.0
|
|
4
4
|
Summary: Python utility scripts
|
|
5
5
|
Project-URL: Homepage, https://github.com/RedHatQE/python-utility-scripts
|
|
6
6
|
Project-URL: Repository, https://github.com/RedHatQE/python-utility-scripts
|
|
@@ -19,6 +19,7 @@ Requires-Dist: pylero<0.3,>=0.2
|
|
|
19
19
|
Requires-Dist: pytest-mock<4,>=3.14.0
|
|
20
20
|
Requires-Dist: python-simple-logger<3,>=2.0.4
|
|
21
21
|
Requires-Dist: pyyaml<7,>=6.0.1
|
|
22
|
+
Requires-Dist: requests<3,>=2.32
|
|
22
23
|
Requires-Dist: tenacity<10,>=9.0.0
|
|
23
24
|
Description-Content-Type: text/markdown
|
|
24
25
|
|
|
@@ -0,0 +1,459 @@
|
|
|
1
|
+
# pyutils-jira
|
|
2
|
+
Helper to identify wrong jira card references in a repository files. e.g. closed tickets or tickets with not relevant target versions in a test repository branch would be identified.
|
|
3
|
+
It looks for following patterns in files of a pytest repository:
|
|
4
|
+
```text
|
|
5
|
+
- jira_id=ABC-12345 # When jira id is present in a function call
|
|
6
|
+
- <jira url>/browse/ABC-12345 # when jira is in a link in comments; see "Browse link matching"
|
|
7
|
+
- pytest.mark.jira_utils(ABC-12345) # when jira is in a marker
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
The scan skips a directory by its **name**, never by a path substring, so a checkout living under e.g.
|
|
11
|
+
`/tmp/build-tools/` is still scanned. Excluded names: `.git`, `.tox`, `.venv`, `venv`, `.pytest_cache`,
|
|
12
|
+
`site-packages`, `.mypy_cache`, `.worktrees`, `.pi`, `node_modules`, `build`, `dist`.
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
pyutils-jira
|
|
18
|
+
pyutils-jira --help
|
|
19
|
+
|
|
20
|
+
# verify the credential before a scan; quote the values, unquoted <...> is a shell redirection
|
|
21
|
+
export JIRA_CLOUD_ID="<cloud-id>"
|
|
22
|
+
export JIRA_TOKEN="<token>"
|
|
23
|
+
pyutils-jira --check-auth
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Authentication
|
|
27
|
+
Three authentication modes are supported (the service-account mode has two credential flavours, described
|
|
28
|
+
below), selected by the config file, CLI option or environment variable:
|
|
29
|
+
|
|
30
|
+
| Mode | Selection | Client |
|
|
31
|
+
|---|---|---|
|
|
32
|
+
| Data Center PAT (default) | url + token | `JIRA(token_auth=token, options={"server": url})` |
|
|
33
|
+
| Atlassian Cloud, basic auth | `--cloud` / `cloud: true` + url + user + token (there is no env var for `cloud`) | `JIRA(server=url, basic_auth=(user, token))` |
|
|
34
|
+
| Atlassian Cloud service account, pre-minted token | `--cloud-id` / `JIRA_CLOUD_ID` / `cloud_id`, or a gateway `url` (see below) | `JIRA(server=https://api.atlassian.com/ex/jira/<cloud_id>, token_auth=token)` |
|
|
35
|
+
| Atlassian Cloud service account, OAuth 2.0 client credentials | `--cloud-id` (required) + `--client-id` + `--client-secret` | `JIRA(server=https://api.atlassian.com/ex/jira/<cloud_id>, token_auth=<minted token>)` |
|
|
36
|
+
|
|
37
|
+
Service-account (Bearer) mode is selected in two ways: by setting `cloud_id`, or by setting `url` to the API
|
|
38
|
+
gateway URL `https://api.atlassian.com/ex/jira/<cloud_id>`. The gateway URL is itself a service-account selector,
|
|
39
|
+
so either one is enough and `cloud` and `user` are then ignored. A credential is still required: `token`, or the
|
|
40
|
+
OAuth 2.0 `client_id` + `client_secret` pair.
|
|
41
|
+
|
|
42
|
+
`cloud_id` wins over `url`, `cloud` and `user`:
|
|
43
|
+
|
|
44
|
+
- the client always talks to `https://api.atlassian.com/ex/jira/<cloud_id>`, rebuilt from `cloud_id`;
|
|
45
|
+
- it must be the Atlassian cloud id itself - letters, digits and dashes, 8 to 64 characters, not the site host
|
|
46
|
+
(`https://example.atlassian.net` is wrong). An invalid value is rejected before any request is made, so the
|
|
47
|
+
token is never sent anywhere. The run exits `1` with a message that names the source and masks the value (the
|
|
48
|
+
placeholder is printed, not the rejected id):
|
|
49
|
+
`Invalid Jira cloud id (from --cloud-id/JIRA_CLOUD_ID/ATLASSIAN_OAUTH_CLOUD_ID/config 'cloud_id'): <cloud-id>. Pass --cloud-id "" to ignore it.`
|
|
50
|
+
Passing an explicit empty `--cloud-id ""` wins over `JIRA_CLOUD_ID`/`ATLASSIAN_OAUTH_CLOUD_ID` and the `cloud_id`
|
|
51
|
+
config key, and the utility falls back to `url` + `token`. Service-account auth is only fully off when `url` is
|
|
52
|
+
not a gateway url either;
|
|
53
|
+
- a gateway `url` selects Bearer auth because it carries the cloud id (`https://api.atlassian.com/ex/jira/<cloud_id>`).
|
|
54
|
+
A bare gateway url (`https://api.atlassian.com/ex/jira/`, no id) - and the bare gateway host
|
|
55
|
+
`https://api.atlassian.com` itself, with or without its trailing slash, which is recognised as a gateway url too -
|
|
56
|
+
is rejected with no cloud id resolved: the run
|
|
57
|
+
exits `1` before any request is made, with
|
|
58
|
+
`The supplied Jira API gateway url is missing its cloud id: append it, or pass --cloud-id (expected https://api.atlassian.com/ex/jira/<cloud-id>).`
|
|
59
|
+
An id segment that is present but the wrong shape (`/ex/jira/abc123`, an account id) gets its own message instead:
|
|
60
|
+
`Invalid Jira cloud id in the supplied gateway url: expected letters, digits and dashes, 8-64 characters.`
|
|
61
|
+
A path below the cloud id (`.../ex/jira/<cloud-id>/rest/api/2`) is ignored: the server is rebuilt as the canonical
|
|
62
|
+
gateway url, so the path python-jira appends itself is never doubled.
|
|
63
|
+
With a `cloud_id` set the bare prefix costs nothing for the API calls - `cloud_id` rebuilds the full gateway url
|
|
64
|
+
anyway - but it still decides browse-link matching: a bare gateway prefix, with or without its trailing slash, is
|
|
65
|
+
recognised as a gateway url, so links are then matched host-agnostically as `/browse/<KEY>` (see
|
|
66
|
+
"Browse link matching");
|
|
67
|
+
- a non-gateway `url` supplied together with `cloud_id` is discarded and the discard is logged at `INFO`
|
|
68
|
+
(`cloud_id provided, discarding supplied Jira url ... in favor of the API gateway url`);
|
|
69
|
+
- `cloud: true` plus `user` does not switch the mode away from Bearer auth.
|
|
70
|
+
|
|
71
|
+
A service-account scoped API token (`ATST...`) is sent as `Authorization: Bearer` and only works against the
|
|
72
|
+
API gateway URL `https://api.atlassian.com/ex/jira/<cloud_id>`. Against the site URL (for example
|
|
73
|
+
`https://redhat.atlassian.net`) it returns HTTP 403 `Failed to parse Connect Session Auth Token`, and it does
|
|
74
|
+
not work with basic auth either. Because of that, when `cloud_id` is set the utility builds the gateway URL
|
|
75
|
+
itself and discards a site URL supplied via `url`/`--url` for the API calls (it still affects link matching, see
|
|
76
|
+
"Browse link matching").
|
|
77
|
+
|
|
78
|
+
In service-account mode `url` and `user` are optional; only `token`, or the OAuth 2.0 `client_id` + `client_secret`
|
|
79
|
+
pair, is required.
|
|
80
|
+
|
|
81
|
+
Environment variables: `JIRA_SERVER_URL` (or `JIRA_URL`), `JIRA_TOKEN`, `JIRA_USER`, `JIRA_CLOUD_ID` (or
|
|
82
|
+
`ATLASSIAN_OAUTH_CLOUD_ID`), `JIRA_SA_CLIENT_ID`, `JIRA_SA_CLIENT_SECRET`. `url`, `token` and `user` are
|
|
83
|
+
`os.getenv()` defaults of their CLI option, so their environment variable also overrides the config file entry for
|
|
84
|
+
the same key. `cloud_id` and the OAuth 2.0 pair are resolved per key instead, where the environment beats the config
|
|
85
|
+
file but an explicitly empty option beats both (see "Precedence is per key"). `cloud` has no environment variable,
|
|
86
|
+
only `--cloud` or `cloud: true`. The two OAuth 2.0 credential variables
|
|
87
|
+
also accept the older aliases `ATLASSIAN_OAUTH_CLIENT_ID` and `JIRA_OAUTH_CLIENT_SECRET`; the `JIRA_SA_*` pair wins
|
|
88
|
+
when both are set. The aliases keep the older mixed prefixes for compatibility with the existing rootcoz/tooling
|
|
89
|
+
convention, while the primary `JIRA_SA_*` names follow this repo's scheme.
|
|
90
|
+
|
|
91
|
+
### The two service-account flavours
|
|
92
|
+
|
|
93
|
+
Both flavours select the same mode, send `Authorization: Bearer` to `https://api.atlassian.com/ex/jira/<cloud_id>`
|
|
94
|
+
and ignore `cloud`/`user`. They differ only in where the bearer value comes from:
|
|
95
|
+
|
|
96
|
+
| | A - pre-minted scoped token | B - OAuth 2.0 client credentials |
|
|
97
|
+
|---|---|---|
|
|
98
|
+
| Credential | `--token` (`ATST...`) minted by an Atlassian admin | `--client-id` + `--client-secret` (`ATOA...`) created by an Atlassian admin for the service account |
|
|
99
|
+
| Environment | `JIRA_TOKEN` | `JIRA_SA_CLIENT_ID` / `JIRA_SA_CLIENT_SECRET` (aliases: `ATLASSIAN_OAUTH_CLIENT_ID` / `JIRA_OAUTH_CLIENT_SECRET`) |
|
|
100
|
+
| Config keys | `token` | `client_id` / `client_secret` |
|
|
101
|
+
| Lifetime | expires, so it must be re-minted by hand | ~1 hour access token, minted once per run and reused for the whole run, so no manual re-minting |
|
|
102
|
+
| Log line | `Using Jira service-account (pre-minted scoped API token) authentication against ...` | `Using Jira service-account (OAuth 2.0 client credentials) authentication against ...` |
|
|
103
|
+
|
|
104
|
+
In service-account mode a healthy scan logs exactly one `INFO` line naming the resolved flavour and the server - the
|
|
105
|
+
`Log line` above. The cloud id is masked in every log line and message: only the resolved flavour and the masked
|
|
106
|
+
gateway url `https://api.atlassian.com/ex/jira/<cloud-id>` are printed, never the id itself - the real id and url are
|
|
107
|
+
still what the utility uses to talk to Jira. A `user:password@` component is stripped the same way, with one split:
|
|
108
|
+
a url passed on its own (`--url`, a server named in a message, the probe url) always loses its userinfo - parsed
|
|
109
|
+
whole, or, when the authority does not parse at all (an unmatched bracket), matched over the authority alone - while
|
|
110
|
+
inside free-form text (a log line, an error body) a url ends at whitespace or at a quote/bracket, so a credential
|
|
111
|
+
containing one of those cannot be delimited there and is not stripped from that text. The `jira`/`urllib3`
|
|
112
|
+
transport logs - which quote the request url verbatim - are filtered too, in
|
|
113
|
+
message and traceback alike. The configured (or minted) bearer token is redacted there as `***`, and only when it is
|
|
114
|
+
at least 8 characters long so a dummy value cannot corrupt words. The filter is installed once at start-up, when any
|
|
115
|
+
of the three is present: a resolved cloud id, a real token, or a url carrying a userinfo.
|
|
116
|
+
Flavour B adds a second `INFO` line when it mints (`Minted an Atlassian OAuth 2.0 access token, valid for <n> seconds`).
|
|
117
|
+
A site `url` discarded because `cloud_id` is set is also logged at `INFO`. An OAuth 2.0 credential that is ignored
|
|
118
|
+
(incomplete pair, or a complete pair with no resolvable cloud id) yields one `WARNING`, naming both what was ignored
|
|
119
|
+
and the credential actually used; none of these notices is an error.
|
|
120
|
+
|
|
121
|
+
With flavour B the utility exchanges the pair at `https://auth.atlassian.com/oauth/token`
|
|
122
|
+
(`grant_type=client_credentials`), keeps the resulting access token in-process for the whole run and never logs the
|
|
123
|
+
client secret. `token` is not needed then; if it is set as well, the minted access token replaces it.
|
|
124
|
+
|
|
125
|
+
The pair is validated before any request is made. Only a completely empty invocation (no config file, no
|
|
126
|
+
credential, no cloud id) is rejected earlier, by the pre-flight guard:
|
|
127
|
+
|
|
128
|
+
```text
|
|
129
|
+
No Jira configuration supplied: pass --config-file-path, or a credential (--token with --url or --cloud-id, or --client-id plus --client-secret with --cloud-id).
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Every credential combination then gets its own message:
|
|
133
|
+
|
|
134
|
+
- a lone `client_id` or `client_secret` **together with another complete credential** (`token` plus `url` or
|
|
135
|
+
`cloud_id`) is logged at `WARNING` and the run continues on that credential; the message names the credential
|
|
136
|
+
actually used (`the pre-minted scoped API token`, `cloud basic auth (user email plus API token)` or
|
|
137
|
+
`the Data Center personal access token (PAT)`):
|
|
138
|
+
`Incomplete OAuth 2.0 service-account credential (both --client-id and --client-secret are required): ignoring it and authenticating with <credential> instead.`
|
|
139
|
+
- a lone pair member as the **only** credential exits `1`:
|
|
140
|
+
`Both --client-id and --client-secret are required for the OAuth 2.0 service-account credential.`
|
|
141
|
+
- a complete pair without a resolvable cloud id, with `token` and `url` set, is logged at `WARNING` and the run
|
|
142
|
+
continues on that credential, again naming it:
|
|
143
|
+
`OAuth 2.0 service-account credential ignored for lack of a cloud id (pass --cloud-id or set JIRA_CLOUD_ID): authenticating with <credential> instead.`
|
|
144
|
+
- a complete pair without a cloud id as the **only** credential exits `1`, naming the opt-out:
|
|
145
|
+
`A Jira cloud id is required for OAuth service-account authentication: pass --cloud-id (or set JIRA_CLOUD_ID), or opt out of the OAuth credential with --client-id "" --client-secret "".`
|
|
146
|
+
|
|
147
|
+
An invalid or disabled credential never reaches Jira: the exchange at `https://auth.atlassian.com/oauth/token`
|
|
148
|
+
rejects it first, so the mint failure exits `1` before any Jira API call and `/myself` is never called. The message
|
|
149
|
+
carries whatever status the token endpoint answered with, for example
|
|
150
|
+
`Jira authentication failed: could not mint an Atlassian access token from the OAuth 2.0 credential (HTTP 401 - check the client id and secret)`.
|
|
151
|
+
The same prefix covers the other mint failures: a network error appends the `requests` exception text, a non-JSON
|
|
152
|
+
body renders `... (HTTP <status> - malformed response payload)`, and a payload without a usable `access_token`
|
|
153
|
+
renders `... (HTTP <status> - the response payload has no access_token)`.
|
|
154
|
+
|
|
155
|
+
> **Known limitation:** the access token is minted once per run and reused for the whole run, so a scan that runs
|
|
156
|
+
> longer than the token lifetime (~1 hour) is not refreshed mid-run — it simply starts failing with `401`. Re-run
|
|
157
|
+
> the scan, or split it into shorter runs.
|
|
158
|
+
>
|
|
159
|
+
> The 120 second margin in `mint_atlassian_token` bounds only its in-process token cache (a second mint inside the
|
|
160
|
+
> margin re-mints instead of reusing). The CLI mints once, before it builds the client, so that margin never acts
|
|
161
|
+
> at run time.
|
|
162
|
+
|
|
163
|
+
#### Where the cloud id comes from
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
curl "https://<site>.atlassian.net/_edge/tenant_info" # -> {"cloudId": "4a4f8f8f-1234-5678-9abc-def012345678", ...}
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
That `cloudId` is a plain UUID. `ATLASSIAN_OAUTH_CLOUD_ID` is accepted as an alternative to `JIRA_CLOUD_ID` for
|
|
170
|
+
this value.
|
|
171
|
+
|
|
172
|
+
> **Not a cloud id:** an Atlassian *account id* (shape `digits:uuid`, for example `712020:f0a60b32-...`, as seen
|
|
173
|
+
> in profile URLs) is a user identity. As `--cloud-id` it fails the validation above (no colons allowed), and
|
|
174
|
+
> behind a gateway `url` the run exits `1` before any request is made with
|
|
175
|
+
> `Invalid Jira cloud id in the supplied gateway url: expected letters, digits and dashes, 8-64 characters.` - the
|
|
176
|
+
> id segment of a gateway url must itself be a valid cloud id. `JIRA_SA_CLIENT_ID` likewise must be
|
|
177
|
+
> the OAuth client id of the service account, not an account id.
|
|
178
|
+
|
|
179
|
+
### Verify the credential with `--check-auth`
|
|
180
|
+
|
|
181
|
+
`--check-auth` performs no scan. It builds the client, calls `/myself` and prints the resolved mode, server URL
|
|
182
|
+
and identity (`displayName`, `emailAddress`, `accountId`) without revealing the token, so it can be used as a
|
|
183
|
+
pre-flight check before a long scan.
|
|
184
|
+
|
|
185
|
+
| Exit | Meaning | Line it prints |
|
|
186
|
+
|---|---|---|
|
|
187
|
+
| `0` | The credential is verified: `/myself` answered, or the project endpoint returned a non-empty list that the same request without an `Authorization` header does not also return | `Jira authentication OK - ...` |
|
|
188
|
+
| `1` | The credential is rejected: a `401`/`403` from `/myself` (Data Center PAT, cloud basic auth), or from **both** probe endpoints (Bearer) | `Jira authentication failed (mode: ..., server: ...): <status> <detail>` plus the credential hint |
|
|
189
|
+
| `1` | The probe could not decide: an outage, an unreachable API, an empty project list, or a project list that is also readable anonymously | `Jira credential check failed (<ErrorType>, status: <status>): <detail>` or `Jira credential could not be verified: ...` |
|
|
190
|
+
|
|
191
|
+
Service-account credentials - the pre-minted scoped API token as much as the OAuth 2.0 pair - usually carry only
|
|
192
|
+
`read:jira-work`/`write:jira-work`, and `/myself` is not part of those scopes. When `/myself` answers `401`/`403`
|
|
193
|
+
the check falls back to the project endpoint, for either flavour and without needing a client secret. A non-empty
|
|
194
|
+
project list only verifies the credential when the same request without a credential does not return it as well, in
|
|
195
|
+
which case the success log reports the project visibility instead of an identity:
|
|
196
|
+
|
|
197
|
+
```text
|
|
198
|
+
Jira authentication OK - mode: service-account, server: https://api.atlassian.com/ex/jira/<cloud-id>, service account: project visibility verified; the current-user endpoint (/myself) is unavailable for this credential's scopes
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
The fallback is a second opinion rather than a certainty, so it can be inconclusive in two ways.
|
|
202
|
+
|
|
203
|
+
In service-account mode a non-empty project list is only evidence when the same request without the credential does
|
|
204
|
+
not return it as well, so the check repeats the call once with no `Authorization` header, against the same project
|
|
205
|
+
path and API version the authenticated call used. Only a genuinely different answer counts as evidence: an empty
|
|
206
|
+
list, a non-OK status or a non-JSON body all mean "not anonymously readable", so the authenticated non-empty list
|
|
207
|
+
stands and the check exits `0`. If that header-less call returns a non-empty project list instead, the outcome is
|
|
208
|
+
inconclusive - a dead bearer would look exactly as healthy - and the check exits `1`:
|
|
209
|
+
|
|
210
|
+
```text
|
|
211
|
+
Jira credential could not be verified: the project endpoint returns the same non-empty project list without an Authorization header, so a non-empty list does not prove this credential is honoured.
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
That cross-check is a tripwire rather than the general verdict: in service-account mode the server is always the
|
|
215
|
+
canonical API gateway url, so the header-less probe can only ever ask the gateway's project path - it cannot fire
|
|
216
|
+
against Atlassian with the current server resolution, and the tests reach the branch by mocking the premise. Every
|
|
217
|
+
scope-limited `--check-auth` still pays one extra header-less request for it, which a proxy or a
|
|
218
|
+
TLS-intercepting environment may turn into a `WARNING` (a probe that could not run counts as no evidence).
|
|
219
|
+
|
|
220
|
+
In service-account mode an empty project list verifies nothing either (the project endpoint is also readable
|
|
221
|
+
anonymously), so it exits `1` without claiming success:
|
|
222
|
+
|
|
223
|
+
```text
|
|
224
|
+
Jira credential could not be verified: the current-user endpoint (/myself) is out of this credential's scopes and no projects are visible, so neither endpoint proves the credential is valid.
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
When the probe fails for a non-auth reason - any status that is not `401`/`403` (a `5xx`, a `404`, a throttled
|
|
228
|
+
`429`) or an unreachable API (a connection error or a timeout, which surfaces as a `requests` exception rather than
|
|
229
|
+
a `JIRAError`) - the outage is reported as an outage, not as a rejected credential, and the check exits `1` without
|
|
230
|
+
the credential-failure hint:
|
|
231
|
+
|
|
232
|
+
```text
|
|
233
|
+
Jira credential check failed (<ErrorType>, status: <status>): <detail>
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
`<ErrorType>` is the exception class name (`JIRAError`, `ConnectionError`, `Timeout`, ...) and `<status>` is the HTTP
|
|
237
|
+
status of the answer, or `None` when the request never got one (a connection error, a timeout). The client
|
|
238
|
+
construction path reports an unreachable server the same way, under `Jira client construction failed (...)`. A server
|
|
239
|
+
url that cannot be parsed at all is rejected before that, on one line
|
|
240
|
+
(`Invalid Jira server url (unparseable, e.g. an unbracketed IPv6 host): <url>`), so a genuine `ValueError` from inside
|
|
241
|
+
the client keeps its traceback instead of being reported as an outage.
|
|
242
|
+
|
|
243
|
+
An unreachable anonymous probe counts as no evidence of anonymous readability, so it does not undo a
|
|
244
|
+
project-visibility verdict, and a probe that could not run at all is logged at `WARNING` (a degraded guard is not a
|
|
245
|
+
detail). The header-less probe itself is built to stay header-less: the url it sends has its `user:password@`
|
|
246
|
+
component stripped, the `Authorization` header requests adds from a `~/.netrc` entry for the host is dropped once the
|
|
247
|
+
request is prepared, and a redirect is not followed (a redirect hop runs `rebuild_auth()`, which would re-inject that
|
|
248
|
+
credential). The request still merges the environment, so `REQUESTS_CA_BUNDLE`/`CURL_CA_BUNDLE` and the proxy
|
|
249
|
+
variables are honoured: discarding them would silently turn the guard into a no-op behind a mandatory proxy or an
|
|
250
|
+
env CA bundle.
|
|
251
|
+
|
|
252
|
+
In service-account (Bearer) mode - the only mode with two probe endpoints - a `401`/`403` from **both** endpoints
|
|
253
|
+
means Jira rejected the credential itself, and only then is the credential-failure hint printed. Data Center PAT and
|
|
254
|
+
cloud basic auth have no project-endpoint fallback, so a `401`/`403` from `/myself` is the verdict there. Common
|
|
255
|
+
causes:
|
|
256
|
+
|
|
257
|
+
- a `cloud_id` that does not match the site the credential is scoped to;
|
|
258
|
+
- a token or credential without the scopes the utility needs to read issues;
|
|
259
|
+
- an expired token - **pre-minted scoped API token only**: scoped API tokens expire, so re-mint it. An OAuth 2.0
|
|
260
|
+
credential is exchanged for a fresh access token on every run, so it never presents an expired access token.
|
|
261
|
+
|
|
262
|
+
An invalid or disabled OAuth 2.0 client id/secret is not in this list: it fails at the token endpoint before any
|
|
263
|
+
Jira call (see the mint-failure paragraph above), so it never produces a `/myself` response.
|
|
264
|
+
|
|
265
|
+
Pass the token through the environment rather than on the command line:
|
|
266
|
+
|
|
267
|
+
```bash
|
|
268
|
+
export JIRA_CLOUD_ID="<cloud-id>"
|
|
269
|
+
export JIRA_TOKEN="<token>"
|
|
270
|
+
pyutils-jira --check-auth
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
Command-line arguments are visible to other users in `ps` output and are appended to your shell history, so use
|
|
274
|
+
`--token` only when the environment is not an option.
|
|
275
|
+
|
|
276
|
+
During a scan a single issue returning `401`/`403` is not taken as proof: the utility runs the same credential
|
|
277
|
+
probe (the verdict is cached per client and flavour, so repeated failures reuse it instead of re-probing). The
|
|
278
|
+
first per-issue `401` clears that cache, once per scan: the scan re-probes at most once, which is enough to catch a
|
|
279
|
+
bearer that expired mid-scan without probing again for every failing issue, and the fresh verdict is reused for the
|
|
280
|
+
rest of the scan.
|
|
281
|
+
|
|
282
|
+
A per-issue transport failure (a connection error, a timeout, an exhausted retry) does not abort the scan either: it
|
|
283
|
+
is rendered as one finding of its own, `"<KEY> Jira connection failed (<ErrorType>): <detail>"`, and every such
|
|
284
|
+
finding reaches the aggregate report. A scan retries a `5xx` and a `JIRAError` that carries no status code at all (the
|
|
285
|
+
shape python-jira wraps a connection error in); a raw `requests.Timeout`/`ConnectionError` that reaches the scan
|
|
286
|
+
without that wrapper is not retried by this layer and is reported per issue straight away. A `429` is left to
|
|
287
|
+
python-jira's `ResilientSession`, which retries a `429` (and a `503` carrying `Retry-After`) internally with its own
|
|
288
|
+
backoff and jitter, honouring `Retry-After` best-effort - how long it sleeps depends on the installed python-jira
|
|
289
|
+
version, so no fixed formula and no minimum wait is promised here. That is also why there is no second layer: it
|
|
290
|
+
would add tens of seconds to minutes per throttled issue, serially. A `503` carrying `Retry-After` is still retried by
|
|
291
|
+
both layers here; a `503` without one is a `5xx`, so it is retried by this layer.
|
|
292
|
+
|
|
293
|
+
In service-account (Bearer) mode - the only mode with two probe endpoints - a `401`/`403` from **both** of them means
|
|
294
|
+
the credential is genuinely rejected. A Data Center PAT or cloud basic auth has no project-endpoint fallback: its
|
|
295
|
+
probe is called without the service-account path, so a single `401`/`403` from `/myself` is already the verdict.
|
|
296
|
+
Either way the hint is logged once at `ERROR` and the run exits `1` without a per-issue report.
|
|
297
|
+
|
|
298
|
+
Otherwise the failure is treated as a per-issue permission problem: the scan continues, the failures are
|
|
299
|
+
aggregated at the end and the run still exits `1`. That covers a probe that succeeds and an inconclusive one alike
|
|
300
|
+
(a project endpoint outage or an empty project list): inconclusive is not verification, but it does not abort a
|
|
301
|
+
scan either. The scan runs the same two-endpoint probe `--check-auth` uses, including the project-endpoint fallback
|
|
302
|
+
for a scope-limited service-account credential (either flavour) but not its extra anonymous cross-check, so a
|
|
303
|
+
credential that passes `--check-auth` does not abort a scan. An unreachable API during that probe is an outage rather
|
|
304
|
+
than a rejection (it is logged at `WARNING`), so it likewise does not abort the scan with a credential hint.
|
|
305
|
+
|
|
306
|
+
### Example: Data Center PAT (default)
|
|
307
|
+
|
|
308
|
+
```yaml
|
|
309
|
+
pyutils-jira:
|
|
310
|
+
url: https://jira.example.com
|
|
311
|
+
token: mytoken
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
### Example: Atlassian Cloud, basic auth
|
|
315
|
+
|
|
316
|
+
```yaml
|
|
317
|
+
pyutils-jira:
|
|
318
|
+
cloud: true
|
|
319
|
+
url: https://example.atlassian.net
|
|
320
|
+
user: myuser@example.com
|
|
321
|
+
token: mytoken
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
### Example: Atlassian Cloud service account
|
|
325
|
+
|
|
326
|
+
```yaml
|
|
327
|
+
pyutils-jira:
|
|
328
|
+
cloud_id: 4a4f8f8f-1234-5678-9abc-def012345678
|
|
329
|
+
token: ATST...
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
Equivalent from the CLI:
|
|
333
|
+
|
|
334
|
+
```bash
|
|
335
|
+
export JIRA_CLOUD_ID="4a4f8f8f-1234-5678-9abc-def012345678"
|
|
336
|
+
export JIRA_TOKEN="<ATST-token>"
|
|
337
|
+
pyutils-jira --check-auth
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
### Example: Atlassian Cloud service account, OAuth 2.0 client credentials
|
|
341
|
+
|
|
342
|
+
```yaml
|
|
343
|
+
pyutils-jira:
|
|
344
|
+
cloud_id: 4a4f8f8f-1234-5678-9abc-def012345678
|
|
345
|
+
client_id: <oauth client id>
|
|
346
|
+
client_secret: ATOA...
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
Equivalent from the CLI. The secret is exported into the environment rather than passed on the command line, so it
|
|
350
|
+
stays out of `ps` output (the `export` line itself still lands in your shell history):
|
|
351
|
+
|
|
352
|
+
```bash
|
|
353
|
+
export JIRA_CLOUD_ID="4a4f8f8f-1234-5678-9abc-def012345678"
|
|
354
|
+
export JIRA_SA_CLIENT_ID="<oauth-client-id>"
|
|
355
|
+
export JIRA_SA_CLIENT_SECRET="<atoa-client-secret>"
|
|
356
|
+
pyutils-jira --check-auth
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
## Browse link matching
|
|
360
|
+
`<jira url>/browse/<key>` links are matched differently per mode, because the API gateway URL never appears in
|
|
361
|
+
source code:
|
|
362
|
+
|
|
363
|
+
| Mode | Matched prefix |
|
|
364
|
+
|---|---|
|
|
365
|
+
| Data Center PAT, Cloud basic auth | the configured `url` must prefix the link (a trailing `/` is ignored) |
|
|
366
|
+
| Service account (`cloud_id` or gateway `url`) | `/browse/<KEY>` on any `http(s)` host, e.g. `https://example.atlassian.net/browse/KEY` |
|
|
367
|
+
|
|
368
|
+
Relative links such as `/browse/KEY` are never matched, and outside service-account mode a link to a host other
|
|
369
|
+
than the configured `url` is not matched either.
|
|
370
|
+
|
|
371
|
+
In service-account mode the match is host-agnostic only while no site `url` is supplied: when `cloud_id` and a
|
|
372
|
+
site `url` are both set, that `url` is still used as the link prefix - it is discarded only for the API calls.
|
|
373
|
+
|
|
374
|
+
## Config file
|
|
375
|
+
A config file with the jira connection parameters like url, token, resolved_statuses, skip_project_ids,
|
|
376
|
+
target_versions can be passed to the command line option `--config-file-path`.
|
|
377
|
+
|
|
378
|
+
`--config-file-path` is optional: `pyutils-jira` also runs on `token` plus `url` or `cloud_id` alone, which is
|
|
379
|
+
why the environment-variable usage above needs no config file. Unlike `pyutils-unusedcode` and the Polarion
|
|
380
|
+
utilities it defines no `~/.config/python-utility-scripts/config.yaml` default, so without the option nothing is
|
|
381
|
+
read from disk.
|
|
382
|
+
|
|
383
|
+
Precedence is per key:
|
|
384
|
+
|
|
385
|
+
- `url`, `token`, `user`, `cloud_id`, `target_versions` and `skip_project_ids` fall back to the config file only
|
|
386
|
+
when the CLI option is not set (`target_versions` is read from the file when `--target-versions` is not passed;
|
|
387
|
+
`skip_project_ids` resolves as `skip_projects or config_dict.get("skip_project_ids", [])` with a click default of
|
|
388
|
+
`None`: an unset `--skip-projects` falls back to the config key, but an explicitly empty value becomes `[""]`
|
|
389
|
+
(truthy, and its empty prefix matches every issue), so it silently disables the target-version check - omit it);
|
|
390
|
+
- `client_id` and `client_secret` resolve per key, and the option state decides - the same shape as `--cloud-id`:
|
|
391
|
+
an explicitly passed `--client-id`/`--client-secret` wins **even when it is empty** (the empty pair is the
|
|
392
|
+
documented opt-out, and it beats the environment and the config file alike); otherwise the environment variable
|
|
393
|
+
(`JIRA_SA_CLIENT_ID`/`JIRA_SA_CLIENT_SECRET`, or the aliases `ATLASSIAN_OAUTH_CLIENT_ID`/`JIRA_OAUTH_CLIENT_SECRET`,
|
|
394
|
+
the `JIRA_SA_*` name winning when both are set); otherwise the config key. Unlike `token`/`url`, the OAuth pair is
|
|
395
|
+
therefore *not* an `os.getenv()` option default - both defaults are `None`, so "option not passed" stays
|
|
396
|
+
distinguishable from "option passed empty";
|
|
397
|
+
- `cloud` resolves as `cloud if cloud is not None else config_dict.get("cloud", False)`. `--cloud` is a flag whose
|
|
398
|
+
default is `None` and it has no environment variable, so it can enable cloud basic auth but cannot disable a
|
|
399
|
+
`cloud: true` coming from the config file;
|
|
400
|
+
- `version_string_not_targeted_jiras` is the exception - it resolves as `config_dict.get(key, cli_value)`, so a
|
|
401
|
+
value in the config file wins even over an explicitly passed `--version-string-not-targeted-jiras` flag;
|
|
402
|
+
- the target version key is `target_versions`; `jira_target_versions` is not read;
|
|
403
|
+
- `resolved_statuses` and `issue_pattern` are accepted but currently overridden by the non-empty CLI defaults
|
|
404
|
+
(see `config.example.yaml`).
|
|
405
|
+
|
|
406
|
+
### Example:
|
|
407
|
+
|
|
408
|
+
```yaml
|
|
409
|
+
pyutils-jira:
|
|
410
|
+
# Data Center PAT: url + token. Cloud basic auth: also set cloud: true and fill user.
|
|
411
|
+
# Service-account auth: set cloud_id and token, or cloud_id with client_id + client_secret for OAuth 2.0.
|
|
412
|
+
# url and user may then be removed or left empty: both are optional, cloud and user are ignored in this mode,
|
|
413
|
+
# and a leftover site url is only used for browse-link matching (never for the API calls).
|
|
414
|
+
url: <jira_url>
|
|
415
|
+
token: mytoken
|
|
416
|
+
user: <jira_user_email>
|
|
417
|
+
cloud: false
|
|
418
|
+
cloud_id: ""
|
|
419
|
+
resolved_statuses:
|
|
420
|
+
- verified
|
|
421
|
+
- release pending
|
|
422
|
+
- closed
|
|
423
|
+
skip_project_ids:
|
|
424
|
+
- ABC
|
|
425
|
+
- DEF
|
|
426
|
+
# target_versions is read from this file when --target-versions is not passed
|
|
427
|
+
target_versions:
|
|
428
|
+
- 1.0.0
|
|
429
|
+
- 2.0.1
|
|
430
|
+
- 3.0.z
|
|
431
|
+
issue_pattern: "([A-Z]+-[0-9]+)"
|
|
432
|
+
version_string_not_targeted_jiras: "vfuture"
|
|
433
|
+
```
|
|
434
|
+
This would skip version checks on any jira ids associated with project ABC and DEF
|
|
435
|
+
This would also check if the current repository branch is pointing to any jira card that is not targeted for 1.0.0 or 2.0.1 version
|
|
436
|
+
|
|
437
|
+
To run from CLI with `--target-versions`
|
|
438
|
+
|
|
439
|
+
```bash
|
|
440
|
+
pyutils-jira --target-versions '1.0.0,2.0.1'
|
|
441
|
+
```
|
|
442
|
+
#### Note:
|
|
443
|
+
To mark to skip a jira from these checks, one can add `<skip-jira-utils-check>` as a comment to the same line containing the specific jira
|
|
444
|
+
|
|
445
|
+
Example:
|
|
446
|
+
```text
|
|
447
|
+
#https://issues.redhat.com/browse/OSD-5716 <skip-jira-utils-check>
|
|
448
|
+
```
|
|
449
|
+
The effective default for resolved statuses is the `--resolved-statuses` CLI default, because that option is
|
|
450
|
+
always non-empty and therefore shadows the `resolved_statuses` config key:
|
|
451
|
+
|
|
452
|
+
```text
|
|
453
|
+
verified, release pending, closed, resolved
|
|
454
|
+
```
|
|
455
|
+
|
|
456
|
+
The config key has no effect until that CLI default is changed to `None`.
|
|
457
|
+
|
|
458
|
+
Default value for `version_string_not_targeted_jiras` is `vfuture`; a value in the config file wins over both
|
|
459
|
+
this default and an explicitly passed flag.
|