Skip to content

Commit

Permalink
refactor: run pre-commit for all
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomáš Sasák committed Jun 27, 2023
1 parent 4698ac0 commit c2b1cdf
Show file tree
Hide file tree
Showing 58 changed files with 56 additions and 71 deletions.
1 change: 0 additions & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,3 @@ pipeline {
}
}
}

4 changes: 1 addition & 3 deletions database/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ This is a quick step-by-step of how to add a database schema upgrade.

* add a CREATE USER command to database/schema/ve_db_user_create_postgresql.sql
* add SELECT privileges for all tables for this user at the bottom of database/schema/ve_db_postgresql.sql
* throughout the database/schema/ve_db_postgresql.sql file, for each table to which the user should have write privileges, add a GRANT INSERT, UPDATE, DELETE statement under the CREATE TABLE statement to give these privileges to the user. If there is a sequence, also add a GRANT USAGE, SELECT, UPDATE on the sequence as well.
* throughout the database/schema/ve_db_postgresql.sql file, for each table to which the user should have write privileges, add a GRANT INSERT, UPDATE, DELETE statement under the CREATE TABLE statement to give these privileges to the user. If there is a sequence, also add a GRANT USAGE, SELECT, UPDATE on the sequence as well.
* add a new envirnment variable to database/Dockerfile to hold the password for the new user.
* in the database/schema/init_schema.sh file, add an addition psql command to alter the new user and provide the user's password using the environment variable defined in the previous step.
* add an upgrade script (see section above) to create the new user and grant permissions to existing database instances.
Expand Down Expand Up @@ -55,5 +55,3 @@ This is a quick step-by-step of how to add a database schema upgrade.
#### Command to open shell in container

```docker exec -it ve_db_ctr bash```


1 change: 0 additions & 1 deletion database/schema/upgrade_scripts/001-db-upgrade-support.sql
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,3 @@ GRANT USAGE, SELECT ON db_upgrade_log_id_seq TO ve_db_user_listener;
-- user for UI manager component
GRANT SELECT ON db_version TO ve_db_user_manager;
GRANT SELECT ON db_upgrade_log TO ve_db_user_manager;

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
DO $$
BEGIN
ALTER TABLE cve_affected_systems_cache ADD direct_systems_affected INT NOT NULL DEFAULT 0;
EXCEPTION
EXCEPTION
WHEN duplicate_column THEN
RAISE NOTICE 'Column direct_systems_affected already exists.';
END$$;
Expand Down Expand Up @@ -146,8 +146,8 @@ DO $$
BEGIN
CREATE TRIGGER system_platform_satellite_managed_cache
AFTER UPDATE OF satellite_managed ON system_platform
FOR EACH ROW EXECUTE PROCEDURE satellite_managed_system_update_cache();
EXCEPTION
FOR EACH ROW EXECUTE PROCEDURE satellite_managed_system_update_cache();
EXCEPTION
WHEN others THEN
RAISE NOTICE 'Trigger system_platform_satellite_managed_cache already exists.';
END$$;
Expand All @@ -156,4 +156,4 @@ END$$;
GRANT UPDATE (direct_systems_affected) ON cve_affected_systems_cache TO ve_db_user_listener;

-- refresh cached counts in order to populate direct_systems_affected
SELECT refresh_all_cached_counts();
SELECT refresh_all_cached_counts();
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ ALTER USER ve_db_user_vmaas_sync WITH PASSWORD 've_db_user_vmaas_sync_pwd';

GRANT SELECT ON ALL TABLES IN SCHEMA public TO ve_db_user_vmaas_sync;
GRANT SELECT, INSERT, UPDATE, DELETE ON cve_metadata TO ve_db_user_vmaas_sync;

2 changes: 1 addition & 1 deletion database/schema/upgrade_scripts/006-fix-refresh-caches.sql
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ $refresh_system_cached_counts$
) WHERE sp.inventory_id = inventory_id_in;
END;
$refresh_system_cached_counts$
LANGUAGE 'plpgsql';
LANGUAGE 'plpgsql';
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,4 @@ DROP FUNCTION IF EXISTS satellite_managed_system_update_cache;

ALTER TABLE system_platform DROP COLUMN IF EXISTS satellite_managed;

ALTER TABLE cve_affected_systems_cache DROP COLUMN IF EXISTS direct_systems_affected;
ALTER TABLE cve_affected_systems_cache DROP COLUMN IF EXISTS direct_systems_affected;
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ cad.rh_account_id = casc.rh_account_id;
INSERT INTO cve_account_data (cve_id, rh_account_id, systems_affected)
SELECT casc.cve_id, casc.rh_account_id, casc.systems_affected
FROM cve_affected_systems_cache casc
WHERE (casc.cve_id, casc.rh_account_id) NOT IN
WHERE (casc.cve_id, casc.rh_account_id) NOT IN
(SELECT cad2.cve_id, cad2.rh_account_id FROM cve_account_data cad2);

DROP TABLE cve_affected_systems_cache;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
GRANT INSERT, UPDATE ON rh_account TO ve_db_user_manager;
GRANT USAGE, SELECT ON rh_account_id_seq TO ve_db_user_manager;
GRANT USAGE, SELECT ON rh_account_id_seq TO ve_db_user_manager;
2 changes: 1 addition & 1 deletion database/schema/upgrade_scripts/030-fqdn.sql
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ALTER TABLE system_platform ADD display_name TEXT;
ALTER TABLE system_platform ADD display_name TEXT;
2 changes: 1 addition & 1 deletion database/schema/upgrade_scripts/031-stale-dates.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
ALTER TABLE system_platform ADD stale_timestamp TIMESTAMP WITH TIME ZONE;
ALTER TABLE system_platform ADD stale_warning_timestamp TIMESTAMP WITH TIME ZONE;
ALTER TABLE system_platform ADD culled_timestamp TIMESTAMP WITH TIME ZONE;
ALTER TABLE system_platform ADD culled_timestamp TIMESTAMP WITH TIME ZONE;
2 changes: 1 addition & 1 deletion database/schema/upgrade_scripts/034-stale-flag.sql
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,4 @@ $opt_out_system_update_cache$
RETURN NEW;
END;
$opt_out_system_update_cache$
LANGUAGE 'plpgsql';
LANGUAGE 'plpgsql';
2 changes: 1 addition & 1 deletion database/schema/upgrade_scripts/040-rules-table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA public TO ve_db_user_manager;
GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA public TO ve_db_user_vmaas_sync;
GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA public TO ve_db_user_metrics;
GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA public TO ve_db_user_taskomatic;
GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA public TO ve_db_user_advisor_listener;
GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA public TO ve_db_user_advisor_listener;
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
GRANT SELECT, INSERT, UPDATE, DELETE ON rh_account TO ve_db_user_advisor_listener;
GRANT SELECT, INSERT, UPDATE, DELETE ON system_platform TO ve_db_user_advisor_listener;
GRANT SELECT, INSERT, UPDATE, DELETE ON cve_metadata TO ve_db_user_advisor_listener;
GRANT SELECT, INSERT, UPDATE, DELETE ON cve_metadata TO ve_db_user_advisor_listener;
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
ALTER TABLE system_vulnerabilities ADD rule_id INT;

GRANT SELECT, INSERT, UPDATE, DELETE ON system_vulnerabilities TO ve_db_user_advisor_listener;
GRANT SELECT, INSERT, UPDATE, DELETE ON system_vulnerabilities TO ve_db_user_advisor_listener;
Original file line number Diff line number Diff line change
@@ -1 +1 @@
GRANT UPDATE ON insights_rule TO ve_db_user_advisor_listener;
GRANT UPDATE ON insights_rule TO ve_db_user_advisor_listener;
2 changes: 1 addition & 1 deletion database/schema/upgrade_scripts/044-rule_id-constraint.sql
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ALTER TABLE system_vulnerabilities ADD CONSTRAINT rule_id FOREIGN KEY (rule_id) REFERENCES insights_rule (id);
ALTER TABLE system_vulnerabilities ADD CONSTRAINT rule_id FOREIGN KEY (rule_id) REFERENCES insights_rule (id);
Original file line number Diff line number Diff line change
@@ -1 +1 @@
GRANT SELECT, INSERT, UPDATE, DELETE ON cve_account_data TO ve_db_user_advisor_listener;
GRANT SELECT, INSERT, UPDATE, DELETE ON cve_account_data TO ve_db_user_advisor_listener;
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,4 @@ $opt_out_system_update_cache$
RETURN NEW;
END;
$opt_out_system_update_cache$
LANGUAGE 'plpgsql';
LANGUAGE 'plpgsql';
2 changes: 1 addition & 1 deletion database/schema/upgrade_scripts/047-refresh_counts.sql
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,4 @@ $refresh_system_cached_counts$
) WHERE sp.inventory_id = inventory_id_in;
END;
$refresh_system_cached_counts$
LANGUAGE 'plpgsql';
LANGUAGE 'plpgsql';
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ALTER TABLE system_platform ADD advisor_evaluated TIMESTAMP WITH TIME ZONE;
ALTER TABLE system_platform ADD advisor_evaluated TIMESTAMP WITH TIME ZONE;
Original file line number Diff line number Diff line change
Expand Up @@ -264,4 +264,4 @@ $refresh_cve_account_cached_counts$
AND rh_account_id = rh_account_id_in;
END;
$refresh_cve_account_cached_counts$
LANGUAGE 'plpgsql';
LANGUAGE 'plpgsql';
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ ALTER TABLE insights_rule ADD playbook_count INT;
ALTER TABLE insights_rule ADD change_risk INT;
ALTER TABLE insights_rule ADD kbase_node_id INT;

GRANT UPDATE (description_text, summary_text, generic_text, reboot_required, playbook_count, change_risk, kbase_node_id) ON insights_rule TO ve_db_user_taskomatic;
GRANT UPDATE (description_text, summary_text, generic_text, reboot_required, playbook_count, change_risk, kbase_node_id) ON insights_rule TO ve_db_user_taskomatic;
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
ALTER TABLE insights_rule ADD active BOOLEAN NOT NULL DEFAULT FALSE;

GRANT UPDATE (active) ON insights_rule TO ve_db_user_taskomatic;
GRANT UPDATE (active) ON insights_rule TO ve_db_user_taskomatic;
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ALTER TABLE cve_rule_mapping ADD CONSTRAINT cve_rule_mapping_cve_id_rule_id_key UNIQUE (cve_id, rule_id);
ALTER TABLE cve_rule_mapping ADD CONSTRAINT cve_rule_mapping_cve_id_rule_id_key UNIQUE (cve_id, rule_id);
Original file line number Diff line number Diff line change
Expand Up @@ -288,4 +288,4 @@ $refresh_system_cached_counts$
) WHERE sp.inventory_id = inventory_id_in;
END;
$refresh_system_cached_counts$
LANGUAGE 'plpgsql';
LANGUAGE 'plpgsql';
2 changes: 1 addition & 1 deletion database/schema/upgrade_scripts/055-rule_hit_details.sql
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ALTER TABLE system_vulnerabilities ADD rule_hit_details TEXT;
ALTER TABLE system_vulnerabilities ADD rule_hit_details TEXT;
2 changes: 1 addition & 1 deletion database/schema/upgrade_scripts/056-dont-refresh-stale.sql
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,4 @@ $refresh_cve_account_cached_counts$
AND rh_account_id = rh_account_id_in;
END;
$refresh_cve_account_cached_counts$
LANGUAGE 'plpgsql';
LANGUAGE 'plpgsql';
2 changes: 1 addition & 1 deletion database/schema/upgrade_scripts/057-rules_more_info.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ ALTER TABLE insights_rule ADD reason_text TEXT;
ALTER TABLE insights_rule ADD resolution_text TEXT;
ALTER TABLE insights_rule ADD more_info_text TEXT;

GRANT UPDATE (reason_text, resolution_text, more_info_text) ON insights_rule TO ve_db_user_taskomatic;
GRANT UPDATE (reason_text, resolution_text, more_info_text) ON insights_rule TO ve_db_user_taskomatic;
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ DROP INDEX IF EXISTS system_platform_stale_timestamp_idx;

CREATE INDEX ON system_platform(stale);

CREATE INDEX ON system_platform(stale_warning_timestamp);
CREATE INDEX ON system_platform(stale_warning_timestamp);
Original file line number Diff line number Diff line change
Expand Up @@ -298,4 +298,3 @@ $refresh_system_cached_counts$
END;
$refresh_system_cached_counts$
LANGUAGE 'plpgsql';

2 changes: 1 addition & 1 deletion database/schema/upgrade_scripts/077-use-account-id.sql
Original file line number Diff line number Diff line change
Expand Up @@ -272,4 +272,4 @@ $delete_system$
RETURN QUERY DELETE FROM system_platform WHERE id = system_id_in RETURNING inventory_id;
END;
$delete_system$
LANGUAGE 'plpgsql';
LANGUAGE 'plpgsql';
8 changes: 4 additions & 4 deletions database/schema/upgrade_scripts/078-system-platform-uuid.sql
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
-- Vanish non-uuid systems from DB
CREATE OR REPLACE FUNCTION try_cast_uuid(uuid_in TEXT)
CREATE OR REPLACE FUNCTION try_cast_uuid(uuid_in TEXT)
RETURNS uuid AS
$$
BEGIN
RETURN uuid_in::UUID;
EXCEPTION WHEN invalid_text_representation THEN
EXCEPTION WHEN invalid_text_representation THEN
RETURN NULL;
END;
$$ LANGUAGE 'plpgsql';
Expand All @@ -30,10 +30,10 @@ BEGIN
RETURN;
END IF;

PERFORM * FROM system_platform
PERFORM * FROM system_platform
WHERE id BETWEEN low AND high FOR UPDATE;

UPDATE system_platform
UPDATE system_platform
SET inventory_id_new = try_cast_uuid(inventory_id)
WHERE id BETWEEN low AND high;

Expand Down
2 changes: 1 addition & 1 deletion database/schema/upgrade_scripts/085-content_version.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ GRANT SELECT ON content_version TO ve_db_user_manager;
GRANT SELECT ON content_version TO ve_db_user_vmaas_sync;
GRANT SELECT ON content_version TO ve_db_user_metrics;
GRANT SELECT ON content_version TO ve_db_user_taskomatic;
GRANT SELECT ON content_version TO ve_db_user_advisor_listener;
GRANT SELECT ON content_version TO ve_db_user_advisor_listener;
2 changes: 1 addition & 1 deletion database/schema/upgrade_scripts/086-cve_name.sql
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ALTER TABLE cve_metadata ADD celebrity_name TEXT;
ALTER TABLE cve_metadata ADD celebrity_name TEXT;
1 change: 0 additions & 1 deletion doc/schema.md
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
![engine](https://user-images.githubusercontent.com/6339153/120200721-eade9900-c224-11eb-85d7-0e4c4d765e43.jpg)

2 changes: 1 addition & 1 deletion doc/vulnerability_engine_diagram.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docker-compose-dbdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ services:
- ./conf/database.env
ports:
- 5432:5432

schema_spy:
container_name: schema-spy
privileged: true
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.devel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ services:
- label=disable
working_dir: /git
command: ["sleep", "infinity"]

ve_manager_admin:
volumes:
- .:/git
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ services:
depends_on:
- ve_database
- platform_mock

ve_manager_admin:
command: /engine/entrypoint.sh manager-admin
container_name: vulnerability-engine-manager-admin
Expand Down
2 changes: 1 addition & 1 deletion manager.spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,7 @@ components:
type: string
description: Datetime string
example: '2017-09-18T00:00:00+00:00'

advisory_available:
in: query
name: advisory_available
Expand Down
4 changes: 2 additions & 2 deletions manager/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ def _filter_system_cve_by_rule_presence(query, args, _kwargs):
def bool_expr(presence_bool):
if presence_bool:
return InsightsRule.active == True # noqa: E712
return (InsightsRule.active == False) | (InsightsRule.active == None) # noqa: E712
return (InsightsRule.active == False) | (InsightsRule.active == None) # noqa: E712,E711

if True in args["rule_presence"] and False in args["rule_presence"]:
return query
Expand Down Expand Up @@ -446,7 +446,7 @@ def _filter_system_cve_by_rule(query, args, _kwargs):
if "rule" in args and args["rule"]:
def eval_expr(value):
if value.lower() == "false":
return (InsightsRule.active == False) | (InsightsRule.active == None) # noqa: E712
return (InsightsRule.active == False) | (InsightsRule.active == None) # noqa: E712,E711
if value.lower() == "affected_not_vulnerable":
return (InsightsRule.active == True) & \
(SystemVulnerabilities.when_mitigated.is_null(True)) & \
Expand Down
2 changes: 1 addition & 1 deletion notificator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ account_number: rh account number of customer
org_id: rh org id of customer
notif_events: array of notification types, to which customer should be notified
```
There are two queues, the unknown cves queue and known cves queue.
There are two queues, the unknown cves queue and known cves queue.
Since we have both sources of data, where the results can be mutually exclusive (vmaas can mark system as vulnerable to cve, but advisor listener can set it as non vulnerable) the notificator queue resolver needs to wait for evaluation from both components.
Queue resolver process runs every 3 minutes and checks both queues, for normal cve queue:
* Checks if `system_vulnerabilities` id row exists.
Expand Down
1 change: 0 additions & 1 deletion platform_mock/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,3 @@ done

# run upload mock
exec python3 -m platform_mock.platform_mock

1 change: 0 additions & 1 deletion pr_check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,3 @@ then
echo "PR check failed"
make_results_xml
fi

2 changes: 1 addition & 1 deletion scripts/3scale-mock
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ if __name__ == "__main__":
if options.command == 'print':
if remaining:
print('Unexpected args %s' % remaining)
sys.exit(1)
sys.exit(1)
print(encoded_identity)
sys.exit(0)

Expand Down
10 changes: 5 additions & 5 deletions scripts/db_docs_generator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ then
fi

if [[ "$VULNERABILITY_DOCS_TOKEN" == "" ]]
then
then
echo "Cannot find github token for pushing into docs repo."
exit 1
fi
Expand All @@ -24,8 +24,8 @@ echo "Current branch of git: ${BRANCH_NAME}"

echo "Calculating checksum for ${VE_DB_SCHEMA}"
cd scripts
git clone https://github.com/RedHatInsights/vulnerability-docs.git $GIT_DOCS
sha1sum ../database/schema/$VE_DB_SCHEMA > $TEMP_CSUM
git clone https://github.com/RedHatInsights/vulnerability-docs.git $GIT_DOCS
sha1sum ../database/schema/$VE_DB_SCHEMA > $TEMP_CSUM
DIFF_RESULT=0

if [[ "$BRANCH_NAME" == "stable" ]]
Expand All @@ -41,7 +41,7 @@ if [[ "$DIFF_RESULT" == "1" ]]
then
echo "Commit has new changes in schema, regenerating docs"
echo "Creating output directory for docs"
mkdir $DB_DOCS_OUTPUT
mkdir $DB_DOCS_OUTPUT
sudo chmod -R 777 $DB_DOCS_OUTPUT

echo "Starting schemaspy container and creating docs"
Expand All @@ -66,7 +66,7 @@ then
COMMIT_MESSAGE="Updating VE master docs for commit $(git rev-parse --short HEAD)"
rm -rf $VE_DB_MASTER/*
mv ./$DB_DOCS_OUTPUT/* $VE_DB_MASTER
mv -f $TEMP_CSUM $VE_DB_MASTER/$ORIGINAL_CSUM
mv -f $TEMP_CSUM $VE_DB_MASTER/$ORIGINAL_CSUM
fi

git config --global user.name "vmaas-bot"
Expand Down
2 changes: 1 addition & 1 deletion scripts/db_upgrade_local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# This script runs the dbupgrade script in local development.
# You can specify your OCI runtime as first argument if not docker.
# Second argument can be the name of the specific container
# Second argument can be the name of the specific container
# where must be dbupgrade.sh script.
# Script must be started from root directory, where the docker-compose
# yaml is located.
Expand Down
1 change: 0 additions & 1 deletion scripts/openshift-devel-container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ warning="WARNING: This script will OVERRIDE container entrypoint of following de
filter="$1"

. $(dirname $0)/openshift-common.sh "$warning" "$filter" "devel-container"

1 change: 0 additions & 1 deletion scripts/openshift-remove-required-resources.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ warning="WARNING: This script will REMOVE resource requests/limits from followin
filter="$1"

. $(dirname $0)/openshift-common.sh "$warning" "$filter" "remove-resources"

Loading

0 comments on commit c2b1cdf

Please sign in to comment.