From 3c29daffa1a03d5414bca7a4bf2d6c5872817e55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ina=20Od=C3=A9n=20=C3=96sterbo?= Date: Tue, 31 Jan 2023 11:42:30 +0100 Subject: [PATCH 01/15] run ghcr publish manually --- .github/workflows/publish_and_trivyscan.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/publish_and_trivyscan.yml b/.github/workflows/publish_and_trivyscan.yml index 14089531a..a01157d0c 100644 --- a/.github/workflows/publish_and_trivyscan.yml +++ b/.github/workflows/publish_and_trivyscan.yml @@ -14,6 +14,7 @@ # Publish Docker Image to GHCR and run Trivy Security Scan name: GHCR and Trivy Scan on: + workflow_dispatch: pull_request: push: branches: From 2ae2f06284430152ae62ea2cc7a9c876e4304b19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ina=20Od=C3=A9n=20=C3=96sterbo?= Date: Tue, 31 Jan 2023 11:48:45 +0100 Subject: [PATCH 02/15] only dev + changelog --- .github/workflows/publish_and_trivyscan.yml | 1 + CHANGELOG.md | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/publish_and_trivyscan.yml b/.github/workflows/publish_and_trivyscan.yml index a01157d0c..4155bb8f3 100644 --- a/.github/workflows/publish_and_trivyscan.yml +++ b/.github/workflows/publish_and_trivyscan.yml @@ -15,6 +15,7 @@ name: GHCR and Trivy Scan on: workflow_dispatch: + branches: [dev] pull_request: push: branches: diff --git a/CHANGELOG.md b/CHANGELOG.md index bb371ca10..7841aff8c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -197,3 +197,4 @@ Please add a _short_ line describing the PR you make, if the PR implements a spe - Bug: Fix type issue in 0c9c237cced5 (latest) migration ([#1360](https://github.com/ScilifelabDataCentre/dds_web/pull/1360)) - Database: New `Reporting` table for saving unit / user stats every month ([#1363](https://github.com/ScilifelabDataCentre/dds_web/pull/1363)) - Version bump: 2.2.6 ([#1375](https://github.com/ScilifelabDataCentre/dds_web/pull/1375)) +- Workflox: Add option to publish dev image manually ([#1376](https://github.com/ScilifelabDataCentre/dds_web/pull/1376)) From 61161bc432e8a14e0fe5a2eb3be9bbcbdb34a590 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ina=20Od=C3=A9n=20=C3=96sterbo?= Date: Tue, 31 Jan 2023 11:42:30 +0100 Subject: [PATCH 03/15] run ghcr publish manually --- .github/workflows/publish_and_trivyscan.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/publish_and_trivyscan.yml b/.github/workflows/publish_and_trivyscan.yml index 14089531a..a01157d0c 100644 --- a/.github/workflows/publish_and_trivyscan.yml +++ b/.github/workflows/publish_and_trivyscan.yml @@ -14,6 +14,7 @@ # Publish Docker Image to GHCR and run Trivy Security Scan name: GHCR and Trivy Scan on: + workflow_dispatch: pull_request: push: branches: From 37a916dec20c9bd0827aa08a866676b020f9ea02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ina=20Od=C3=A9n=20=C3=96sterbo?= Date: Tue, 31 Jan 2023 11:48:45 +0100 Subject: [PATCH 04/15] only dev + changelog --- .github/workflows/publish_and_trivyscan.yml | 1 + CHANGELOG.md | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/publish_and_trivyscan.yml b/.github/workflows/publish_and_trivyscan.yml index a01157d0c..4155bb8f3 100644 --- a/.github/workflows/publish_and_trivyscan.yml +++ b/.github/workflows/publish_and_trivyscan.yml @@ -15,6 +15,7 @@ name: GHCR and Trivy Scan on: workflow_dispatch: + branches: [dev] pull_request: push: branches: diff --git a/CHANGELOG.md b/CHANGELOG.md index bb371ca10..7841aff8c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -197,3 +197,4 @@ Please add a _short_ line describing the PR you make, if the PR implements a spe - Bug: Fix type issue in 0c9c237cced5 (latest) migration ([#1360](https://github.com/ScilifelabDataCentre/dds_web/pull/1360)) - Database: New `Reporting` table for saving unit / user stats every month ([#1363](https://github.com/ScilifelabDataCentre/dds_web/pull/1363)) - Version bump: 2.2.6 ([#1375](https://github.com/ScilifelabDataCentre/dds_web/pull/1375)) +- Workflox: Add option to publish dev image manually ([#1376](https://github.com/ScilifelabDataCentre/dds_web/pull/1376)) From 057d595bcf35f408ce7d3bf32598e5e434301120 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ina=20Od=C3=A9n=20=C3=96sterbo?= Date: Tue, 31 Jan 2023 15:43:29 +0100 Subject: [PATCH 05/15] set existing units to have warning level 80 % --- CHANGELOG.md | 1 + migrations/versions/0c9c237cced5_unit_quota_and_warning.py | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7841aff8c..719e5bcda 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -198,3 +198,4 @@ Please add a _short_ line describing the PR you make, if the PR implements a spe - Database: New `Reporting` table for saving unit / user stats every month ([#1363](https://github.com/ScilifelabDataCentre/dds_web/pull/1363)) - Version bump: 2.2.6 ([#1375](https://github.com/ScilifelabDataCentre/dds_web/pull/1375)) - Workflox: Add option to publish dev image manually ([#1376](https://github.com/ScilifelabDataCentre/dds_web/pull/1376)) +- Bug: Add value to `Unit.warning_level` for existing units ([#1378](https://github.com/ScilifelabDataCentre/dds_web/pull/1379)) diff --git a/migrations/versions/0c9c237cced5_unit_quota_and_warning.py b/migrations/versions/0c9c237cced5_unit_quota_and_warning.py index f144bafaa..e1685a1ea 100644 --- a/migrations/versions/0c9c237cced5_unit_quota_and_warning.py +++ b/migrations/versions/0c9c237cced5_unit_quota_and_warning.py @@ -24,10 +24,13 @@ def upgrade(): # Update existing columns # 1. Load table - need to load columns in order to use - unit_table = sa.sql.table("units", sa.sql.column("quota", mysql.BIGINT)) + unit_table = sa.sql.table( + "units", sa.sql.column("quota", mysql.BIGINT), sa.sql.column("warning_level", mysql.FLOAT) + ) # 2. Update column value - set value to 100 TB op.execute(unit_table.update().values(quota=100 * (10**12))) - + # 3. Update column value - set value to 0.80 + op.execute(unit_table.update().values(warning_level=0.8)) # ### end Alembic commands ### From 6b5180be0338b1f56e0d372ed16198e4ed0a1edd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ina=20Od=C3=A9n=20=C3=96sterbo?= Date: Wed, 1 Feb 2023 08:50:05 +0100 Subject: [PATCH 06/15] same row instead --- migrations/versions/0c9c237cced5_unit_quota_and_warning.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/migrations/versions/0c9c237cced5_unit_quota_and_warning.py b/migrations/versions/0c9c237cced5_unit_quota_and_warning.py index e1685a1ea..46ab85d6b 100644 --- a/migrations/versions/0c9c237cced5_unit_quota_and_warning.py +++ b/migrations/versions/0c9c237cced5_unit_quota_and_warning.py @@ -27,10 +27,8 @@ def upgrade(): unit_table = sa.sql.table( "units", sa.sql.column("quota", mysql.BIGINT), sa.sql.column("warning_level", mysql.FLOAT) ) - # 2. Update column value - set value to 100 TB - op.execute(unit_table.update().values(quota=100 * (10**12))) - # 3. Update column value - set value to 0.80 - op.execute(unit_table.update().values(warning_level=0.8)) + # 2. Update column value - set value to 100 TB and 0.8 + op.execute(unit_table.update().values(quota=100 * (10**12), warning_level=0.8)) # ### end Alembic commands ### From b83c023b67a252ac3e08a280bd89b077ce00aea4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ina=20Od=C3=A9n=20=C3=96sterbo?= Date: Wed, 1 Feb 2023 10:47:07 +0100 Subject: [PATCH 07/15] wrong change to trigger black --- migrations/versions/0c9c237cced5_unit_quota_and_warning.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/migrations/versions/0c9c237cced5_unit_quota_and_warning.py b/migrations/versions/0c9c237cced5_unit_quota_and_warning.py index 46ab85d6b..6e8b0f060 100644 --- a/migrations/versions/0c9c237cced5_unit_quota_and_warning.py +++ b/migrations/versions/0c9c237cced5_unit_quota_and_warning.py @@ -28,7 +28,8 @@ def upgrade(): "units", sa.sql.column("quota", mysql.BIGINT), sa.sql.column("warning_level", mysql.FLOAT) ) # 2. Update column value - set value to 100 TB and 0.8 - op.execute(unit_table.update().values(quota=100 * (10**12), warning_level=0.8)) + op.execute(unit_table.update().values(quota=100 * (10**12), + warning_level=0.8)) # ### end Alembic commands ### From 8fb78f91e3c2040e2dc966d11412ca603143795b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ina=20Od=C3=A9n=20=C3=96sterbo?= Date: Wed, 1 Feb 2023 10:47:27 +0100 Subject: [PATCH 08/15] black --- migrations/versions/0c9c237cced5_unit_quota_and_warning.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/migrations/versions/0c9c237cced5_unit_quota_and_warning.py b/migrations/versions/0c9c237cced5_unit_quota_and_warning.py index 6e8b0f060..46ab85d6b 100644 --- a/migrations/versions/0c9c237cced5_unit_quota_and_warning.py +++ b/migrations/versions/0c9c237cced5_unit_quota_and_warning.py @@ -28,8 +28,7 @@ def upgrade(): "units", sa.sql.column("quota", mysql.BIGINT), sa.sql.column("warning_level", mysql.FLOAT) ) # 2. Update column value - set value to 100 TB and 0.8 - op.execute(unit_table.update().values(quota=100 * (10**12), - warning_level=0.8)) + op.execute(unit_table.update().values(quota=100 * (10**12), warning_level=0.8)) # ### end Alembic commands ### From 38281654bb4c34d9f91c0d527c70eed11c0a63e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ina=20Od=C3=A9n=20=C3=96sterbo?= Date: Wed, 1 Feb 2023 11:01:03 +0100 Subject: [PATCH 09/15] black, new version --- dds_web/api/db_tools.py | 1 - dds_web/api/dds_decorators.py | 9 +-------- dds_web/api/project.py | 2 +- dds_web/api/schemas/project_schemas.py | 1 - dds_web/api/user.py | 4 +--- dds_web/commands.py | 2 -- dds_web/errors.py | 12 ------------ dds_web/utils.py | 1 + dds_web/web/user.py | 3 --- tests/__init__.py | 1 + tests/api/test_superadmin_only.py | 1 + tests/test_auth.py | 1 + tests/test_commands.py | 1 + tests/test_errors.py | 1 - tests/test_files_new.py | 2 -- tests/test_project_info.py | 1 + tests/test_user_delete.py | 1 - 17 files changed, 9 insertions(+), 35 deletions(-) diff --git a/dds_web/api/db_tools.py b/dds_web/api/db_tools.py index 74113fa00..e76de6e25 100644 --- a/dds_web/api/db_tools.py +++ b/dds_web/api/db_tools.py @@ -23,7 +23,6 @@ def remove_user_self_deletion_request(user): - try: request_row = models.DeletionRequest.query.filter( models.DeletionRequest.requester_id == user.username diff --git a/dds_web/api/dds_decorators.py b/dds_web/api/dds_decorators.py index 57ba2bb0a..5bbeefb66 100644 --- a/dds_web/api/dds_decorators.py +++ b/dds_web/api/dds_decorators.py @@ -39,10 +39,9 @@ def handle_validation_errors(func): @functools.wraps(func) def handle_error(*args, **kwargs): - try: result = func(*args, **kwargs) - except (marshmallow.exceptions.ValidationError) as valerr: + except marshmallow.exceptions.ValidationError as valerr: if "_schema" in valerr.messages: return valerr.messages["_schema"][0], 400 else: @@ -56,7 +55,6 @@ def handle_error(*args, **kwargs): def json_required(func): @functools.wraps(func) def verify_json(*args, **kwargs): - if not flask.request.json: raise MissingJsonError(message="Required data missing from request!") @@ -68,7 +66,6 @@ def verify_json(*args, **kwargs): def args_required(func): @functools.wraps(func) def verify_args(*args, **kwargs): - if not flask.request.args: raise DDSArgumentError(message="Required information missing from request!") @@ -80,7 +77,6 @@ def verify_args(*args, **kwargs): def dbsession(func): @functools.wraps(func) def make_commit(*args, **kwargs): - # Run function, catch errors try: result = func(*args, **kwargs) @@ -106,7 +102,6 @@ def make_commit(*args, **kwargs): def handle_db_error(func): @functools.wraps(func) def perform_get(*args, **kwargs): - # Run function, catch errors try: result = func(*args, **kwargs) @@ -134,7 +129,6 @@ def connect_cloud(func): @functools.wraps(func) def init_resource(self, *args, **kwargs): - try: _, self.keys, self.url, self.bucketname = self.get_s3_info() # Connect to service @@ -190,7 +184,6 @@ def wrapper_logging_bind_request(*args, **kwargs): project=flask.request.args.get("project") if flask.request.args else None, user=get_username_or_request_ip(), ): - try: value = func(*args, **kwargs) diff --git a/dds_web/api/project.py b/dds_web/api/project.py index 15f7947e1..db7491509 100644 --- a/dds_web/api/project.py +++ b/dds_web/api/project.py @@ -46,6 +46,7 @@ from dds_web.security.auth import get_user_roles_common from dds_web.api.files import check_eligibility_for_deletion + #################################################################################################### # ENDPOINTS ############################################################################ ENDPOINTS # #################################################################################################### @@ -546,7 +547,6 @@ def format_project_dict(self, current_user): @staticmethod def project_usage(project): - # Calculate approximate cost per gbhour: kr per gb per month / (days * hours) cost_gbhour = 0.09 / (30 * 24) bhours = 0.0 diff --git a/dds_web/api/schemas/project_schemas.py b/dds_web/api/schemas/project_schemas.py index a5cfcfa08..3f1428d35 100644 --- a/dds_web/api/schemas/project_schemas.py +++ b/dds_web/api/schemas/project_schemas.py @@ -215,7 +215,6 @@ class ProjectContentSchema(ProjectRequiredSchema): get_all = marshmallow.fields.Boolean(required=False, default=False) def find_contents(self, project, contents): - # All contents all_contents_query = models.File.query.filter( models.File.project_id == sqlalchemy.func.binary(project.id) diff --git a/dds_web/api/user.py b/dds_web/api/user.py index 27c6e6b95..19a8a1187 100644 --- a/dds_web/api/user.py +++ b/dds_web/api/user.py @@ -44,6 +44,7 @@ # initiate bound logger action_logger = structlog.getLogger("actions") + #################################################################################################### # ENDPOINTS ############################################################################ ENDPOINTS # #################################################################################################### @@ -962,7 +963,6 @@ class SecondFactor(flask_restful.Resource): @auth.login_required @handle_validation_errors def get(self): - token_schemas.TokenSchema().load(flask.request.json) token_claims = dds_web.security.auth.obtain_current_encrypted_token_claims() @@ -1038,7 +1038,6 @@ class RequestHOTPActivation(flask_restful.Resource): # Using Basic auth since TOTP might have been lost, will still need access to email @basic_auth.login_required def post(self): - user = auth.current_user() json_info = flask.request.json @@ -1136,7 +1135,6 @@ def get(self): # Project (bucket) specific info usage = {} for p in unit_info.projects: - # Define fields in usage dict usage[p.public_id] = {"gbhours": 0.0, "cost": 0.0} diff --git a/dds_web/commands.py b/dds_web/commands.py index 5dae617c8..646dc6438 100644 --- a/dds_web/commands.py +++ b/dds_web/commands.py @@ -385,7 +385,6 @@ def set_available_to_expired(): ) .with_for_update() ): - if ( project.current_status == "Available" and project.current_deadline <= current_time() @@ -473,7 +472,6 @@ def set_expired_to_archived(): ) .with_for_update() ): - if ( project.current_status == "Expired" and project.current_deadline <= current_time() diff --git a/dds_web/errors.py b/dds_web/errors.py index ee82fedbf..8ac0087cf 100644 --- a/dds_web/errors.py +++ b/dds_web/errors.py @@ -159,7 +159,6 @@ def __init__( pass_message=False, project=None, ): - general_logger.error(message) if project: @@ -178,7 +177,6 @@ class EmptyProjectException(LoggedHTTPException): code = http.HTTPStatus.BAD_REQUEST def __init__(self, project, username=None, message="The project is empty."): - if not username: username = auth.current_user() structlog.threadlocal.bind_threadlocal(user=username) @@ -195,7 +193,6 @@ class DeletionError(LoggedHTTPException): code = http.HTTPStatus.INTERNAL_SERVER_ERROR def __init__(self, project, message, alt_message=None, pass_message=False): - if project: structlog.threadlocal.bind_threadlocal(project=project) @@ -209,7 +206,6 @@ class NoSuchProjectError(LoggedHTTPException): code = http.HTTPStatus.BAD_REQUEST # 400 def __init__(self, project, message="The specified project does not exist."): - if project: structlog.threadlocal.bind_threadlocal(project=project) @@ -271,7 +267,6 @@ class JwtTokenGenerationError(LoggedHTTPException): code = http.HTTPStatus.INTERNAL_SERVER_ERROR def __init__(self, message="Error during JWT Token generation.", pass_message=False): - general_logger.warning(message) super().__init__( @@ -366,7 +361,6 @@ class UserDeletionError(LoggedHTTPException): code = http.HTTPStatus.BAD_REQUEST def __init__(self, message="User deletion failed.", alt_message=None): - general_logger.warning(message) super().__init__(alt_message or message) @@ -394,28 +388,23 @@ def __init__(self, message="Specified file does not exist."): class TooManyRequestsError(LoggedHTTPException): - code = http.HTTPStatus.TOO_MANY_REQUESTS description = "Too many authentication requests in one hour" def __init__(self): - super().__init__(self.description) general_logger.warning(self.description) class RoleException(LoggedHTTPException): - code = http.HTTPStatus.FORBIDDEN def __init__(self, message="Invalid role."): - super().__init__(message) general_logger.warning(message) class VersionMismatchError(LoggedHTTPException): - code = http.HTTPStatus.FORBIDDEN def __init__( @@ -426,7 +415,6 @@ def __init__( class MaintenanceOngoingException(LoggedHTTPException): - code = http.HTTPStatus.SERVICE_UNAVAILABLE def __init__(self, message="Maintenance of DDS is ongoing."): diff --git a/dds_web/utils.py b/dds_web/utils.py index 295170a8b..a2895a32e 100644 --- a/dds_web/utils.py +++ b/dds_web/utils.py @@ -44,6 +44,7 @@ # General ################################################################################ General # + # Cannot have type hint for return due to models.Project giving circular import def collect_project(project_id: str): """Get project object from database.""" diff --git a/dds_web/web/user.py b/dds_web/web/user.py index aaddb9889..f8f3a0595 100644 --- a/dds_web/web/user.py +++ b/dds_web/web/user.py @@ -303,7 +303,6 @@ def confirm_2fa(): return flask.redirect(flask.url_for("auth_blueprint.login", next=next_target)) if form.validate_on_submit(): - if user.totp_enabled: twofactor_value = form.totp.data twofactor_verify = user.verify_TOTP @@ -637,7 +636,6 @@ def confirm_self_deletion(token): s = itsdangerous.URLSafeTimedSerializer(flask.current_app.config.get("SECRET_KEY")) try: - # Get email from token, overwrite the one from login if applicable email = s.loads(token, salt="email-delete", max_age=604800) @@ -655,7 +653,6 @@ def confirm_self_deletion(token): ).first() except itsdangerous.exc.SignatureExpired as exc: - email = db_tools.remove_user_self_deletion_request(flask_login.current_user) raise ddserr.UserDeletionError( message=f"Deletion request for {email} has expired. Please login to the DDS and request deletion anew." diff --git a/tests/__init__.py b/tests/__init__.py index 0b8a93735..06bd5aca7 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -43,6 +43,7 @@ DEFAULT_HEADER = {"X-CLI-Version": __version__} + ############################################################################### # CLASSES ########################################################### CLASSES # ############################################################################### diff --git a/tests/api/test_superadmin_only.py b/tests/api/test_superadmin_only.py index bc14da1b3..b60338b21 100644 --- a/tests/api/test_superadmin_only.py +++ b/tests/api/test_superadmin_only.py @@ -33,6 +33,7 @@ # TESTS #################################################################################### TESTS # #################################################################################################### + # Tools ############################################################################################ def get_token(username: str, client: flask.testing.FlaskClient) -> typing.Dict: return tests.UserAuth(tests.USER_CREDENTIALS[username]).token(client) diff --git a/tests/test_auth.py b/tests/test_auth.py index 12954321d..2437624ab 100644 --- a/tests/test_auth.py +++ b/tests/test_auth.py @@ -3,6 +3,7 @@ from dds_web.database import models from dds_web import db + # verify_token def test_verify_token_user_not_exists_after_deletion(client): """Log in, delete, log out. Should give exception.""" diff --git a/tests/test_commands.py b/tests/test_commands.py index 1fb4e74fa..71aaa4168 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -250,6 +250,7 @@ def test_update_uploaded_file_with_log_nonexisting_file(client, runner, fs: Fake # monitor_usage + # usage = 0 --> check log def test_monitor_usage_no_usage(client, cli_runner, capfd): """If a unit has no uploaded data, there's no need to do the calculations or send email warning.""" diff --git a/tests/test_errors.py b/tests/test_errors.py index 599258906..95a9edf16 100644 --- a/tests/test_errors.py +++ b/tests/test_errors.py @@ -10,7 +10,6 @@ class LoggedHTTPExceptionTest(errors.LoggedHTTPException): - code = http.HTTPStatus.INTERNAL_SERVER_ERROR diff --git a/tests/test_files_new.py b/tests/test_files_new.py index ea53ca7a3..336637f05 100644 --- a/tests/test_files_new.py +++ b/tests/test_files_new.py @@ -784,7 +784,6 @@ def test_new_file_publickey_wrong_length(client): def test_new_file_salt_wrong_length(client): - project_1 = project_row(project_id="file_testing_project") assert project_1 @@ -801,7 +800,6 @@ def test_new_file_salt_wrong_length(client): def test_new_file_checksum_wrong_length(client): - project_1 = project_row(project_id="file_testing_project") assert project_1 diff --git a/tests/test_project_info.py b/tests/test_project_info.py index ed252cbf1..cac738f9a 100644 --- a/tests/test_project_info.py +++ b/tests/test_project_info.py @@ -25,6 +25,7 @@ # TESTS #################################################################################### TESTS # + # Info listing def test_list_proj_info_no_token(client): """Token required to list project information""" diff --git a/tests/test_user_delete.py b/tests/test_user_delete.py index bfcea9bdc..858ac6654 100644 --- a/tests/test_user_delete.py +++ b/tests/test_user_delete.py @@ -65,7 +65,6 @@ def test_del_self_nouser(client): def test_del_self(client): """Request self deletion.""" with unittest.mock.patch.object(flask_mail.Mail, "send") as mock_mail_send: - response = client.delete( tests.DDSEndpoint.USER_DELETE_SELF, headers=tests.UserAuth(tests.USER_CREDENTIALS["delete_me_researcher"]).token(client), From a8818520ae969748c427ce0c01e6ed08709e58c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ina=20Od=C3=A9n=20=C3=96sterbo?= Date: Thu, 2 Feb 2023 13:22:18 +0100 Subject: [PATCH 10/15] workflow dispatch and cron for both dev and master --- .github/workflows/trivy.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/trivy.yml b/.github/workflows/trivy.yml index b1014c8e6..645d4714d 100644 --- a/.github/workflows/trivy.yml +++ b/.github/workflows/trivy.yml @@ -5,9 +5,17 @@ # --------------------------------- name: trivy on: + workflow_dispatch: + branches: + - master + - dev schedule: # - cron: "*/5 * * * *" - - cron: "0 7,13 * * *" + cron: "0 7,13 * * *" + branches: + - master + - dev + jobs: scan: permissions: From 3dad6e4d76ce56104f22c4a75d0f65a188191380 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ina=20Od=C3=A9n=20=C3=96sterbo?= Date: Thu, 2 Feb 2023 13:31:31 +0100 Subject: [PATCH 11/15] changelog --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 719e5bcda..b15ac8f0f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -197,5 +197,6 @@ Please add a _short_ line describing the PR you make, if the PR implements a spe - Bug: Fix type issue in 0c9c237cced5 (latest) migration ([#1360](https://github.com/ScilifelabDataCentre/dds_web/pull/1360)) - Database: New `Reporting` table for saving unit / user stats every month ([#1363](https://github.com/ScilifelabDataCentre/dds_web/pull/1363)) - Version bump: 2.2.6 ([#1375](https://github.com/ScilifelabDataCentre/dds_web/pull/1375)) -- Workflox: Add option to publish dev image manually ([#1376](https://github.com/ScilifelabDataCentre/dds_web/pull/1376)) +- Workflow: Add option to publish dev image manually ([#1376](https://github.com/ScilifelabDataCentre/dds_web/pull/1376)) - Bug: Add value to `Unit.warning_level` for existing units ([#1378](https://github.com/ScilifelabDataCentre/dds_web/pull/1379)) +- Workflow: Add option to run trivy on dev and master branches manually ([#1380](https://github.com/ScilifelabDataCentre/dds_web/pull/1380)) From 9442402f981c6c7398c0630b84d40b7364d66145 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ina=20Od=C3=A9n=20=C3=96sterbo?= Date: Thu, 2 Feb 2023 13:48:41 +0100 Subject: [PATCH 12/15] indent --- .github/workflows/trivy.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/trivy.yml b/.github/workflows/trivy.yml index 645d4714d..0570c1988 100644 --- a/.github/workflows/trivy.yml +++ b/.github/workflows/trivy.yml @@ -11,10 +11,10 @@ on: - dev schedule: # - cron: "*/5 * * * *" - cron: "0 7,13 * * *" - branches: - - master - - dev + - cron: "0 7,13 * * *" + branches: + - master + - dev jobs: scan: From 87f91719c76454d726b7873c9be3c59d23a69186 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ina=20Od=C3=A9n=20=C3=96sterbo?= Date: Thu, 2 Feb 2023 13:58:12 +0100 Subject: [PATCH 13/15] scheduled only run on default branch --- .github/workflows/trivy.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/trivy.yml b/.github/workflows/trivy.yml index 0570c1988..70f8f25b8 100644 --- a/.github/workflows/trivy.yml +++ b/.github/workflows/trivy.yml @@ -12,10 +12,6 @@ on: schedule: # - cron: "*/5 * * * *" - cron: "0 7,13 * * *" - branches: - - master - - dev - jobs: scan: permissions: From 2b659b731b8c6bc0cd741870154455970509aaf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ina=20Od=C3=A9n=20=C3=96sterbo?= Date: Thu, 2 Feb 2023 14:07:47 +0100 Subject: [PATCH 14/15] change yml file e.g. name --- .github/workflows/python-black.yml | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/.github/workflows/python-black.yml b/.github/workflows/python-black.yml index 74127ef6f..a3a7d09c1 100644 --- a/.github/workflows/python-black.yml +++ b/.github/workflows/python-black.yml @@ -3,20 +3,13 @@ # https://github.com/psf/black # This does not format the code, this only detects and informs on issues. # To format with black, run `black .` locally in the repository. -name: Lint Python -on: - push: - paths: - - "**.py" - pull_request: - paths: - - "**.py" +name: Black - Lint Python + +on: [push, pull_request] jobs: - PythonLint: + lint: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - - name: Check code lints with Black uses: psf/black@stable From 476c6d42353121692d1e3a6d2fd698c958d24e36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ina=20Od=C3=A9n=20=C3=96sterbo?= Date: Thu, 2 Feb 2023 14:09:45 +0100 Subject: [PATCH 15/15] syntax error --- .github/workflows/python-black.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-black.yml b/.github/workflows/python-black.yml index a3a7d09c1..7bdf6d299 100644 --- a/.github/workflows/python-black.yml +++ b/.github/workflows/python-black.yml @@ -12,4 +12,4 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: psf/black@stable + - uses: psf/black@stable