-
Notifications
You must be signed in to change notification settings - Fork 1
fix: resolve vulnerabilities #50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
a069a33
d9a28fc
d7299ca
a799d6a
53d6be2
117a750
907fe2f
3388520
68a6b9b
67143f3
c90a739
2f130f3
440d7af
d196045
cb836ad
fdd861a
1bbb291
2b7441a
9cdb59b
70f0cb0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| name: Security Scan | ||
| on: | ||
| workflow_dispatch: | ||
| inputs: | ||
| target: | ||
| description: "Scan part" | ||
| required: true | ||
| default: "docker" | ||
| type: choice | ||
| options: | ||
| - docker | ||
| - source | ||
| image: | ||
| description: "Docker image (for 'docker' target). By default ghcr.io/<owner>/<repo>:latest" | ||
| required: false | ||
| default: "" | ||
| only-high-critical: | ||
| description: "Scan only HIGH + CRITICAL" | ||
| required: false | ||
| default: true | ||
| type: boolean | ||
| trivy-scan: | ||
| description: "Run Trivy scan" | ||
| required: false | ||
| default: true | ||
| type: boolean | ||
| grype-scan: | ||
| description: "Run Grype scan" | ||
| required: false | ||
| default: true | ||
| type: boolean | ||
| continue-on-error: | ||
| description: "Continue on error" | ||
| required: false | ||
| default: true | ||
| type: boolean | ||
| only-fixed: | ||
| description: "Show only fixable vulnerabilities" | ||
| required: false | ||
| default: true | ||
| type: boolean | ||
|
|
||
| permissions: | ||
| contents: read | ||
| security-events: write | ||
| actions: read | ||
| packages: read | ||
|
|
||
| jobs: | ||
| security-scan: | ||
| uses: netcracker/qubership-workflow-hub/.github/workflows/re-security-scan.yml@main | ||
| with: | ||
| target: ${{ github.event.inputs.target || 'source' }} | ||
| image: ${{ github.event.inputs.image || '' }} | ||
| only-high-critical: ${{ inputs.only-high-critical}} | ||
| trivy-scan: ${{ inputs.trivy-scan }} | ||
| grype-scan: ${{ inputs.grype-scan }} | ||
| only-fixed: ${{ inputs.only-fixed }} | ||
| continue-on-error: ${{ inputs.continue-on-error }} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ | |
| # limitations under the License. | ||
|
|
||
| import logging | ||
| import threading | ||
| import apsw | ||
|
|
||
|
|
||
|
|
@@ -29,6 +30,8 @@ class DbException(Exception): | |
|
|
||
|
|
||
| class DB: | ||
| _lock = threading.Lock() | ||
|
|
||
| def __init__(self, dbfile): | ||
| """ | ||
| Create a connection to sqlite database | ||
|
|
@@ -41,7 +44,7 @@ def __init__(self, dbfile): | |
| self.__dbfile = dbfile | ||
| try: | ||
| log.debug("Database file: %s" % self.__dbfile) | ||
| self.__cursor = DB.__create_connection(dbfile).cursor() | ||
| self.__conn = DB.__create_connection(dbfile) | ||
| except apsw.Error as err: | ||
| log.exception("Database error during init: %s" % err) | ||
| raise DbException("Database error during init") | ||
|
|
@@ -67,24 +70,27 @@ def __create_connection(db_file): | |
|
|
||
| def __create_table(self, query): | ||
| try: | ||
| self.__cursor.execute(query) | ||
| cursor = self.__conn.cursor() | ||
| with cursor: | ||
| cursor.execute(query) | ||
| except apsw.Error as err: | ||
| log.exception("Database Error: %s" % err) | ||
| return 0 | ||
|
|
||
| @staticmethod | ||
| def __log_and_execute(cursor, sql, args): | ||
| log.debug("SQL command: " + sql.replace('?', '%s') % args) | ||
| cursor.execute(sql, args) | ||
| with DB._lock: | ||
| log.debug("SQL command: " + sql.replace('?', '%s') % args) | ||
| cursor.execute(sql, args) | ||
|
Comment on lines
+82
to
+84
|
||
|
|
||
| def __insert_or_delete(self, query, params, login=False): | ||
| try: | ||
| if login: | ||
| cursor = DB.__create_connection(self.__dbfile).cursor() | ||
| else: | ||
| cursor = self.__cursor | ||
|
|
||
| DB.__log_and_execute(cursor, query, params) | ||
| cursor = self.__conn.cursor() | ||
| with cursor: | ||
| DB.__log_and_execute(cursor, query, params) | ||
|
Comment on lines
82
to
+93
|
||
| return 1 | ||
| except apsw.Error as err: | ||
| log.exception("Database Error: %s" % err) | ||
|
|
@@ -95,10 +101,10 @@ def __select(self, query, params, login=False): | |
| if login: | ||
| cursor = DB.__create_connection(self.__dbfile).cursor() | ||
| else: | ||
| cursor = self.__cursor | ||
|
|
||
| DB.__log_and_execute(cursor, query, params) | ||
| return cursor.fetchall() | ||
| cursor = self.__conn.cursor() | ||
| with cursor: | ||
| DB.__log_and_execute(cursor, query, params) | ||
| return cursor.fetchall() | ||
|
Comment on lines
95
to
+107
|
||
| except apsw.Error as err: | ||
| log.exception("Database Error: %s" % err) | ||
| return None | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The _lock is a class-level attribute shared across all DB instances. This means all database operations across different database files will compete for the same lock, which could cause unnecessary serialization and performance degradation. Consider using an instance-level lock (self._lock = threading.Lock() in init) if each DB instance operates on a separate database file.