c2cciutils 1.7.0.dev174__py3-none-any.whl → 1.8.0.dev45__py3-none-any.whl

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.

Potentially problematic release.


This version of c2cciutils might be problematic. Click here for more details.

Files changed (35) hide show
  1. c2cciutils/__init__.py +15 -230
  2. c2cciutils/applications-versions.yaml +3 -3
  3. c2cciutils/applications_definition.py +20 -22
  4. c2cciutils/configuration.py +83 -554
  5. c2cciutils/env.py +8 -31
  6. c2cciutils/lib/docker.py +2 -8
  7. c2cciutils/lib/oidc.py +188 -0
  8. c2cciutils/package-lock.json +115 -127
  9. c2cciutils/package.json +1 -1
  10. c2cciutils/publish.py +26 -44
  11. c2cciutils/schema.json +3 -230
  12. c2cciutils/scripts/__init__.py +1 -3
  13. c2cciutils/scripts/clean.py +4 -11
  14. c2cciutils/scripts/docker_logs.py +4 -4
  15. c2cciutils/scripts/docker_versions_gen.py +0 -1
  16. c2cciutils/scripts/download_applications.py +0 -2
  17. c2cciutils/scripts/env.py +2 -6
  18. c2cciutils/scripts/k8s/__init__.py +1 -3
  19. c2cciutils/scripts/k8s/wait.py +2 -2
  20. c2cciutils/scripts/main.py +4 -16
  21. c2cciutils/scripts/publish.py +45 -31
  22. c2cciutils/scripts/trigger_image_update.py +3 -8
  23. c2cciutils/scripts/version.py +5 -4
  24. {c2cciutils-1.7.0.dev174.dist-info → c2cciutils-1.8.0.dev45.dist-info}/LICENSE +1 -1
  25. {c2cciutils-1.7.0.dev174.dist-info → c2cciutils-1.8.0.dev45.dist-info}/METADATA +29 -58
  26. c2cciutils-1.8.0.dev45.dist-info/RECORD +37 -0
  27. {c2cciutils-1.7.0.dev174.dist-info → c2cciutils-1.8.0.dev45.dist-info}/WHEEL +1 -1
  28. {c2cciutils-1.7.0.dev174.dist-info → c2cciutils-1.8.0.dev45.dist-info}/entry_points.txt +0 -3
  29. c2cciutils/audit.py +0 -229
  30. c2cciutils/pr_checks.py +0 -286
  31. c2cciutils/scripts/audit.py +0 -41
  32. c2cciutils/scripts/docker_versions_update.py +0 -85
  33. c2cciutils/scripts/pr_checks.py +0 -78
  34. c2cciutils/security.py +0 -59
  35. c2cciutils-1.7.0.dev174.dist-info/RECORD +0 -42
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: c2cciutils
3
- Version: 1.7.0.dev174
3
+ Version: 1.8.0.dev45
4
4
  Summary: Common utilities for Camptocamp CI
5
5
  Home-page: https://github.com/camptocamp/c2cciutils
6
6
  License: FreeBSD
@@ -18,29 +18,28 @@ Classifier: Programming Language :: Python
18
18
  Classifier: Programming Language :: Python :: 3
19
19
  Classifier: Programming Language :: Python :: 3.9
20
20
  Classifier: Programming Language :: Python :: 3.10
21
+ Classifier: Programming Language :: Python :: 3.11
22
+ Classifier: Programming Language :: Python :: 3.12
23
+ Classifier: Programming Language :: Python :: 3.13
21
24
  Classifier: Typing :: Typed
22
25
  Provides-Extra: audit
23
26
  Provides-Extra: checks
24
- Provides-Extra: pr_checks
27
+ Provides-Extra: pr-checks
25
28
  Provides-Extra: publish
26
- Provides-Extra: publish_plugins
29
+ Provides-Extra: publish-plugins
27
30
  Provides-Extra: version
28
- Requires-Dist: Markdown (>=3.0.0,<4.0.0)
29
31
  Requires-Dist: PyYAML (>=6.0.0,<7.0.0)
30
- Requires-Dist: codespell (==2.2.6); extra == "pr_checks"
31
32
  Requires-Dist: debian-inspector (>=31.0.0,<32.0.0)
32
33
  Requires-Dist: defusedxml (>=0.0.0,<1.0.0)
33
- Requires-Dist: google-api-python-client (>=2.0.0,<3.0.0); extra == "publish"
34
- Requires-Dist: google-auth-httplib2 (>=0.0.0,<1.0.0); extra == "publish"
35
- Requires-Dist: google-auth-oauthlib (>=1.0.0,<2.0.0); extra == "publish"
36
- Requires-Dist: markdown-table (>=2020.0.0,<2021.0.0)
37
- Requires-Dist: multi-repo-automation (>=1.0.0,<2.0.0); extra == "version"
38
- Requires-Dist: python-magic (>=0.0.0,<1.0.0)
34
+ Requires-Dist: google-api-python-client (>=2.0.0,<3.0.0) ; extra == "publish"
35
+ Requires-Dist: google-auth-httplib2 (>=0.0.0,<1.0.0) ; extra == "publish"
36
+ Requires-Dist: google-auth-oauthlib (>=1.0.0,<2.0.0) ; extra == "publish"
37
+ Requires-Dist: id (>=1.0.0,<2.0.0) ; extra == "publish"
38
+ Requires-Dist: multi-repo-automation (>=1.0.0,<2.0.0) ; extra == "version"
39
39
  Requires-Dist: requests (>=2.0.0,<3.0.0)
40
40
  Requires-Dist: ruamel.yaml (>=0.0.0,<1.0.0)
41
- Requires-Dist: toml (>=0.0.0,<1.0.0)
42
- Requires-Dist: tomlkit (>=0.0.0,<1.0.0); extra == "publish"
43
- Requires-Dist: twine (>=5.0.0,<6.0.0); extra == "publish"
41
+ Requires-Dist: security-md (>=1.0.0,<2.0.0)
42
+ Requires-Dist: twine (>=6.0.0,<7.0.0) ; extra == "publish"
44
43
  Project-URL: Repository, https://github.com/camptocamp/c2cciutils
45
44
  Description-Content-Type: text/markdown
46
45
 
@@ -48,47 +47,14 @@ Description-Content-Type: text/markdown
48
47
 
49
48
  ## Publishing
50
49
 
51
- The main goals of C2C CI utils is to offer the commands and the workflows to have the following project structure:
52
-
53
- Have stabilization branches named by default `<major>.<minor>`.
54
- Have the release named by default `<major>.<minor>.<patch>`.
55
-
56
- With C2C CI utils you can publish a python package and a Docker image from the same repository.
57
-
58
- The default publishing are:
59
-
60
- - Push on the `<major>.<minor>` branch will publish Docker images.
61
- - Create the tag `<major>.<minor>.<patch>` will publish the Docker images, and the Python package.
62
- - Push on a feature branch (whatever other name) will publish the Docker images.
63
- - Delete a feature branch will delete the Docker images.
64
- - Push on the `master` branch will publish the Docker images with the master tag (Publishing a python package is also possible).
65
- - The version at the last line of the `SECURITY.md` of the `master` branch will be also published using the `latest` tag,
66
- this will respect the `tags` present in the configuration
67
- - In the `SECURITY.md` file of the `master` branch we can also add a column `Alternate Tag` to publish the Docker images with another tag,
68
- this will respect the `tags` present in the configuration (only for Docker).
69
-
70
- The Docker images are published on Docker Hub and GitHub Container Registry.
71
-
72
- You can run the publishing locally in dry-run mode:
73
-
74
- ```bash
75
- GITHUB_REF=... c2cciutils-publish --dry-run ...
76
- ```
50
+ The main goals of C2C CI utils is to offer the commands to publish the project,
51
+ see the [documentation](https://github.com/camptocamp/c2cciutils/wiki/Publishing).
77
52
 
78
53
  ## Changelog
79
54
 
80
55
  When we create a tag by default with the `changelog` workflow a release is created on GitHub, a changelog is
81
56
  generated and added to the release.
82
57
 
83
- ## Security
84
-
85
- The security is managed by the `c2cciutils-audit` command with Snyk, it will audit the dependencies of the project on every
86
- stabilization branches, if possible a pull request is created automatically to update the dependencies.
87
-
88
- When we publish a Docker image the generated image is monitored by Snyk, this means that Snyk will search
89
- for all the dependencies and send the list to the Snyk web site to be monitored.
90
- We also do a test of the image and log the result (This will never cause the build to fail).
91
-
92
58
  ## Checks
93
59
 
94
60
  C2C CI utils will no more provide a tool to do a check of the project, this is replaced by `pre-commit`,
@@ -123,21 +89,16 @@ workflow will delete the workflows older than 500 days.
123
89
 
124
90
  C2cciutils make easier to have those workflows in a project:
125
91
 
126
- - `audit.yaml`: Audit the stabilization branches of the application against vulnerabilities in the python and node dependency
127
92
  - `auto-review.yaml`: Auto review the Renovate pull requests
128
93
  - `backport.yaml`: Trigger the backports (work with labels)
129
94
  - `clean.yaml`: Clean the Docker images related on a deleted feature branch
130
95
  - `main.yaml`: Main workflow especially with the c2cciutils-checks command
131
- - `changelog.yaml`: Generate the changelog and create the release on GitHub
132
- - `delete-old-workflows-run.yaml`: Delete the old workflows
133
- - `pr-checks.yaml`: Run the checks on the pull requests
134
96
 
135
97
  All the provided commands used in the workflow:
136
98
 
137
99
  - `c2cciutils`: some generic tools.
138
100
  - `c2cciutils-version`: Create a new version of the project.
139
- - `c2cciutils-checks`: Run the checks on the code (those checks don't need any project dependencies).
140
- - `c2cciutils-audit`: Do the audit, the main difference with checks is that it can change between runs on the same code.
101
+ - `c2cciutils-env`: Print some environment information.
141
102
  - `c2cciutils-publish`: Publish the project.
142
103
  - `c2cciutils-clean`: Delete Docker images on Docker Hub after corresponding branch have been deleted.
143
104
 
@@ -198,7 +159,6 @@ You can override the configuration with the file `ci/config.yaml`.
198
159
  At the base of the configuration you have:
199
160
 
200
161
  - `version`: Contains some regular expressions to find the versions branches and tags, and to convert them into application versions.
201
- - `audit`: The audit configuration, see `c2cciutils/audit.py` for more information.
202
162
  - `publish`: The publishing configuration, see `c2cciutils/publish.py` for more information.
203
163
 
204
164
  Many actions can be disabled by setting the corresponding configuration part to `False`.
@@ -294,11 +254,22 @@ Then by default:
294
254
  - Commit on `master` branch after the tag 1.3.0 => release `1.4.0.dev1`
295
255
  - Commit on `1.3` branch after the tag 1.3.0 => release `1.3.1.dev1`
296
256
 
257
+ #### Authentication
258
+
259
+ If the file `~/.pypirc` exists we consider that we ar already logged in also
260
+ we will do the login with the `pypi` server with OpenID Connect (OIDC).
261
+
262
+ The OIDC login is recommended because it didn't needs any additional secrets,
263
+ but it need some configuration on pypi in the package,
264
+ see the [GitHub Documentation](https://docs.github.com/en/actions/security-for-github-actions/security-hardening-your-deployments/configuring-openid-connect-in-pypi#adding-the-identity-provider-to-pypi).
265
+
266
+ #### Integration if the package directly in a Docker image
267
+
297
268
  To make it working in the `Dockerfile` you should have in the `poetry` stage:
298
269
 
299
270
  ```Dockerfile
300
271
  ENV POETRY_DYNAMIC_VERSIONING_BYPASS=dev
301
- RUN poetry export --extras=checks --extras=publish --extras=audit --output=requirements.txt \
272
+ RUN poetry export --extras=checks --extras=publish --output=requirements.txt \
302
273
  && poetry export --with=dev --output=requirements-dev.txt
303
274
  ```
304
275
 
@@ -336,7 +307,7 @@ repository:
336
307
  # List of kinds of versions you want to publish, that can be: rebuild (specified using --type),
337
308
  # version_tag, version_branch, feature_branch, feature_tag (for pull request)
338
309
  version:
339
- # List of tags we want to publish interpreted with `template(version=version)`
310
+ # List of tags we want to publish interpreted with `format(version=version)`
340
311
  # e.g. if you use `{version}-lite` when you publish the version `1.2.3` the source tag
341
312
  # (that should be built by the application build) is `latest-lite`, and it will be published
342
313
  # with the tag `1.2.3-lite`.
@@ -0,0 +1,37 @@
1
+ c2cciutils/__init__.py,sha256=-J6_XPwyZ3Xbix6AhmAONbltSf9okJsXwQvBj6TuP_U,13353
2
+ c2cciutils/applications-versions.yaml,sha256=uTCcyFKt2GJIhUNxrOl3hEZo-6ee0x5ftb9Zncci6dk,224
3
+ c2cciutils/applications.yaml,sha256=yn0XRi08cS29A_jXPofcBPxsGBv7PEBliztjRC3WtfM,504
4
+ c2cciutils/applications_definition.py,sha256=inAh3vJitu3S9n62Ntv6N-avNUQlUd5FatNvDq4VpxM,1305
5
+ c2cciutils/branches.graphql,sha256=UZrj1RO-H527M1SKqWm1VnkWtNsuKTnPTf4BCU2YcOU,358
6
+ c2cciutils/commits.graphql,sha256=3HAuIEig5V7j1L-6mqBaOkiTD3Fb8_gl1ilpZjPJf74,308
7
+ c2cciutils/configuration.py,sha256=LwJw-l9zB3zy7LtjjrWHFATIuxdRVMJZ-mLbTbFiug8,17062
8
+ c2cciutils/default_branch.graphql,sha256=CaP3rRsNiyg_7RvqbMk0tOJr0aqWd8cOeSV-ZKgvKY4,131
9
+ c2cciutils/env.py,sha256=daNqFY-6-X7PGuPz5OaN634KqYtsawj9Dj-Zt-bxctw,3338
10
+ c2cciutils/lib/docker.py,sha256=ULklJgc-8sfy1vI8p_cbYYEq_u73BKNIGorMxzEKA2I,5663
11
+ c2cciutils/lib/oidc.py,sha256=inulioX8__IJEF-yJO8pJNJb-CnU1zdSLdXrD7uP2Qc,6297
12
+ c2cciutils/package-lock.json,sha256=3m-e-2KYk1OBfeUJ1ICuYXx1Z9sEgX7YUW4xSI7QiIM,13406
13
+ c2cciutils/package.json,sha256=M-ah0GP5yl-tipGXquiCD9m6wBPqUwonCrmHLG9JwT4,134
14
+ c2cciutils/publish.py,sha256=Pc8BdEMZiqDiNIP3tlysNf1nxc-0ZM0lnymfKcqapg8,17158
15
+ c2cciutils/schema-applications.json,sha256=Tus-s9NB7uwKhTrQwhWQM4_oJygF_yHUqShtZhN1IxE,1551
16
+ c2cciutils/schema.json,sha256=G0WbvTVn9zdDjilFr28uZqF7zDVADl7uQus12_TVnSs,14559
17
+ c2cciutils/scripts/__init__.py,sha256=YvySYhMJ9eUqBc9FgH6hNbZHbTU25D7z6FIbYJiRW_U,34
18
+ c2cciutils/scripts/clean.py,sha256=oB4A4TvSNoo7vGWzy5m0p2QDyGM-ix0FepxPIqqNlyg,2987
19
+ c2cciutils/scripts/docker_logs.py,sha256=-_LeoavnKqNNeDJMwkAMKrH91JBUiJuAScMpCA6VfTA,1766
20
+ c2cciutils/scripts/docker_versions_gen.py,sha256=yp1I_UqxyIABKxHek3q3UYWh0YR8tqKWzliC2kqZOa0,1315
21
+ c2cciutils/scripts/download_applications.py,sha256=x0SPm4MCWCIYMp1AWekIpbOicwUixitEAJ69quMq698,4488
22
+ c2cciutils/scripts/env.py,sha256=YZwV39D_vQ454ytHByI84gXP6VrtTW3eM8MdFLUBCw0,363
23
+ c2cciutils/scripts/k8s/__init__.py,sha256=m8_lELJYRmzbAW7aGZL_T3tNwuFi1t8ot8F271HZp9E,67
24
+ c2cciutils/scripts/k8s/db.py,sha256=GK1tzzyCqrCyIJzcBdIXjyNJUXrBPFNa-9fdtwxyrlU,3268
25
+ c2cciutils/scripts/k8s/install.py,sha256=OIQ8KHA3Pst2pjO2E-J5FYNaBHW-i-fqCXlAUcG1tw0,933
26
+ c2cciutils/scripts/k8s/logs.py,sha256=-xJYu8BBUmSmMrPEwiTBKZjJBRyIlMp1depCB04_NWs,2655
27
+ c2cciutils/scripts/k8s/wait.py,sha256=mZyQbmSwuC2BZuJlfJDjkLSKWXz4WkIkihOjRzdBa6Y,5689
28
+ c2cciutils/scripts/main.py,sha256=DfljDzEGCWwP7FZG0RRZaXD6PmOVaXMJjnNBQ0-rAWM,785
29
+ c2cciutils/scripts/pin_pipenv.py,sha256=jBTwlolcEL0MUyq6VYzO-adkcL1gqN7B3kBb3UjTo2k,2150
30
+ c2cciutils/scripts/publish.py,sha256=wzXSBn_60DzMJVdO8i2NjjO6Vwg6L6efH_T6ZR6LRsU,20513
31
+ c2cciutils/scripts/trigger_image_update.py,sha256=kEQHs71ymRNFh5VpKt0UMJILxcRPFZupl24iJ2EA3Bs,2772
32
+ c2cciutils/scripts/version.py,sha256=Srk22CQudxT8JixS-ZBsxeJvWryYVzN_NiWpcJvgrWI,8931
33
+ c2cciutils-1.8.0.dev45.dist-info/LICENSE,sha256=K_e76Y2cY12AHvtanvNmIEJ0nWsNh_WFMDK020TxMcY,1307
34
+ c2cciutils-1.8.0.dev45.dist-info/METADATA,sha256=v7iKCTMwlIgCjTOxcdxPPonwrlQgTIXfl9yunTXi3FU,17852
35
+ c2cciutils-1.8.0.dev45.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
36
+ c2cciutils-1.8.0.dev45.dist-info/entry_points.txt,sha256=54llpn1q67tS78NbLwA8rwSDWnEQ6aE3FaqMN0ctNN8,918
37
+ c2cciutils-1.8.0.dev45.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 1.2.0
2
+ Generator: poetry-core 1.9.1
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -1,11 +1,9 @@
1
1
  [console_scripts]
2
2
  c2cciutils=c2cciutils.scripts.main:main
3
- c2cciutils-audit=c2cciutils.scripts.audit:main
4
3
  c2cciutils-checks=c2cciutils.scripts.env:main
5
4
  c2cciutils-clean=c2cciutils.scripts.clean:main
6
5
  c2cciutils-docker-logs=c2cciutils.scripts.docker_logs:main
7
6
  c2cciutils-docker-versions-gen=c2cciutils.scripts.docker_versions_gen:main
8
- c2cciutils-docker-versions-update=c2cciutils.scripts.docker_versions_update:main
9
7
  c2cciutils-download-applications=c2cciutils.scripts.download_applications:main
10
8
  c2cciutils-env=c2cciutils.scripts.env:main
11
9
  c2cciutils-google-calendar=c2cciutils.publish:main_calendar
@@ -15,7 +13,6 @@ c2cciutils-k8s-logs=c2cciutils.scripts.k8s.logs:main
15
13
  c2cciutils-k8s-wait=c2cciutils.scripts.k8s.wait:main
16
14
  c2cciutils-pin-pipenv=c2cciutils.scripts.pin_pipenv:main
17
15
  c2cciutils-publish=c2cciutils.scripts.publish:main
18
- c2cciutils-pull-request-checks=c2cciutils.scripts.pr_checks:main
19
16
  c2cciutils-trigger-image-update=c2cciutils.scripts.trigger_image_update:main
20
17
  c2cciutils-version=c2cciutils.scripts.version:main
21
18
 
c2cciutils/audit.py DELETED
@@ -1,229 +0,0 @@
1
- """
2
- The auditing functions.
3
- """
4
-
5
- import datetime
6
- import json
7
- import os.path
8
- import subprocess # nosec
9
- import sys
10
- from argparse import Namespace
11
-
12
- import c2cciutils
13
- import c2cciutils.configuration
14
- import c2cciutils.security
15
-
16
-
17
- def print_versions(
18
- config: c2cciutils.configuration.PrintVersions,
19
- full_config: c2cciutils.configuration.Configuration,
20
- args: Namespace,
21
- ) -> bool:
22
- """
23
- Print the versions.
24
-
25
- Arguments:
26
- config: The audit section config
27
- full_config: All the CI config
28
- args: The parsed command arguments
29
- """
30
- del full_config, args
31
-
32
- print("::group::Versions")
33
- c2cciutils.print_versions(config)
34
- print("::endgroup::")
35
-
36
- return True
37
-
38
-
39
- def snyk(
40
- config: c2cciutils.configuration.AuditSnykConfig,
41
- full_config: c2cciutils.configuration.Configuration,
42
- args: Namespace,
43
- ) -> bool:
44
- """
45
- Audit the code with Snyk.
46
- """
47
- del full_config
48
-
49
- one_done = False
50
- install_success = True
51
- test_success = True
52
-
53
- for file in (
54
- subprocess.run(
55
- ["git", "ls-files", "requirements.txt", "*/requirements.txt"], stdout=subprocess.PIPE, check=True
56
- )
57
- .stdout.decode()
58
- .strip()
59
- .split("\n")
60
- ):
61
- if not file:
62
- continue
63
- if file in config.get(
64
- "files_no_install", c2cciutils.configuration.AUDIT_SNYK_FILES_NO_INSTALL_DEFAULT
65
- ):
66
- continue
67
- print(f"::notice::Install from: {file}")
68
- if not one_done:
69
- print("::group::Install dependencies")
70
- one_done = True
71
- sys.stdout.flush()
72
- sys.stderr.flush()
73
- proc = subprocess.run( # pylint: disable=subprocess-run-check
74
- [
75
- "pip",
76
- "install",
77
- *config.get(
78
- "pip_install_arguments", c2cciutils.configuration.AUDIT_SNYK_PIP_INSTALL_ARGUMENTS_DEFAULT
79
- ),
80
- f"--requirement={file}",
81
- ]
82
- )
83
- if proc.returncode != 0:
84
- print(f"::error::With error from: {file}")
85
- install_success &= proc.returncode == 0
86
-
87
- for file in (
88
- subprocess.run(["git", "ls-files", "Pipfile", "*/Pipfile"], stdout=subprocess.PIPE, check=True)
89
- .stdout.decode()
90
- .strip()
91
- .split("\n")
92
- ):
93
- if not file:
94
- continue
95
- if file in config.get(
96
- "files_no_install", c2cciutils.configuration.AUDIT_SNYK_FILES_NO_INSTALL_DEFAULT
97
- ):
98
- continue
99
- if not one_done:
100
- print("::group::Install dependencies")
101
- one_done = True
102
- print(f"::notice::Install from: {file}")
103
- directory = os.path.dirname(os.path.abspath(file))
104
-
105
- sys.stdout.flush()
106
- sys.stderr.flush()
107
- proc = subprocess.run( # pylint: disable=subprocess-run-check
108
- [
109
- "pipenv",
110
- "sync",
111
- *config.get(
112
- "pipenv_sync_arguments", c2cciutils.configuration.AUDIT_SNYK_PIPENV_SYNC_ARGUMENTS_DEFAULT
113
- ),
114
- ],
115
- cwd=directory,
116
- )
117
- if proc.returncode != 0:
118
- print(f"::error::With error from: {file}")
119
- install_success &= proc.returncode == 0
120
-
121
- if one_done:
122
- print("::endgroup::")
123
- if not install_success:
124
- print("::error::Error while installing the dependencies")
125
-
126
- snyk_exec, env = c2cciutils.snyk_exec()
127
- if not args.fix:
128
- command = [snyk_exec, "monitor", f"--target-reference={args.branch}"] + config.get(
129
- "monitor_arguments", c2cciutils.configuration.AUDIT_SNYK_MONITOR_ARGUMENTS_DEFAULT
130
- )
131
- print(f"::group::Run: {' '.join(command)}")
132
- sys.stdout.flush()
133
- sys.stderr.flush()
134
- subprocess.run(command, env=env) # pylint: disable=subprocess-run-check
135
- print("::endgroup::")
136
-
137
- command = [snyk_exec, "test"] + config.get(
138
- "test_arguments", c2cciutils.configuration.AUDIT_SNYK_TEST_ARGUMENTS_DEFAULT
139
- )
140
- print(f"::group::Run: {' '.join(command)}")
141
- sys.stdout.flush()
142
- sys.stderr.flush()
143
- test_proc = subprocess.run(command, env=env) # pylint: disable=subprocess-run-check
144
- print("::endgroup::")
145
- if test_proc.returncode != 0:
146
- test_success = False
147
- print("::error::With error")
148
-
149
- # Clean all the changes to isolate the fix diff
150
- subprocess.run(["git", "reset", "--hard"], check=True)
151
-
152
- command = [snyk_exec, "fix"] + config.get(
153
- "fix_arguments", c2cciutils.configuration.AUDIT_SNYK_FIX_ARGUMENTS_DEFAULT
154
- )
155
- print(f"::group::Run: {' '.join(command)}")
156
- sys.stdout.flush()
157
- sys.stderr.flush()
158
- snyk_fix_proc = subprocess.run( # pylint: disable=subprocess-run-check
159
- command, env={**env, "FORCE_COLOR": "false"}, stdout=subprocess.PIPE, encoding="utf-8"
160
- )
161
- snyk_fix_message = snyk_fix_proc.stdout.strip()
162
- print("::endgroup::")
163
-
164
- if not args.fix:
165
- current_branch = c2cciutils.get_branch(args.branch)
166
- fix_github_create_pull_request_arguments = config.get(
167
- "fix_github_create_pull_request_arguments",
168
- c2cciutils.configuration.AUDIT_SNYK_FIX_PULL_REQUEST_ARGUMENTS_DEFAULT,
169
- )
170
- has_diff = c2cciutils.create_pull_request_if_needed(
171
- current_branch,
172
- f"snyk-fix/{current_branch}",
173
- "Snyk auto fix",
174
- [f"--body={snyk_fix_message}", *fix_github_create_pull_request_arguments],
175
- )
176
-
177
- return install_success and test_success and not has_diff
178
-
179
-
180
- def outdated_versions(
181
- config: None,
182
- full_config: c2cciutils.configuration.Configuration,
183
- args: Namespace,
184
- ) -> bool:
185
- """
186
- Check that the versions from the SECURITY.md are not outdated.
187
-
188
- Arguments:
189
- config: The audit section config
190
- full_config: All the CI config
191
- args: The parsed command arguments
192
- """
193
- del config, full_config
194
-
195
- repo = c2cciutils.get_repository().split("/")
196
- json_response = c2cciutils.graphql(
197
- "default_branch.graphql",
198
- {"name": repo[1], "owner": repo[0]},
199
- )
200
-
201
- if "errors" in json_response:
202
- raise RuntimeError(json.dumps(json_response["errors"], indent=2))
203
- if json_response["repository"]["defaultBranchRef"]["name"] != c2cciutils.get_branch(args.branch):
204
- return True
205
-
206
- success = True
207
-
208
- if not os.path.exists("SECURITY.md"):
209
- return True
210
-
211
- with open("SECURITY.md", encoding="utf-8") as security_file:
212
- security = c2cciutils.security.Security(security_file.read())
213
-
214
- version_index = security.headers.index("Version")
215
- date_index = security.headers.index("Supported Until")
216
-
217
- for row in security.data:
218
- str_date = row[date_index]
219
- if str_date not in ("Unsupported", "Best effort", "To be defined"):
220
- date = datetime.datetime.strptime(row[date_index], "%d/%m/%Y")
221
- if date < datetime.datetime.now():
222
- c2cciutils.error(
223
- "versions",
224
- f"The version '{row[version_index]}' is outdated, it can be set to "
225
- "'Unsupported', 'Best effort' or 'To be defined'",
226
- "SECURITY.md",
227
- )
228
- success = False
229
- return success