Completed implementing a vulnerability checker based on the data of the Safety DB. eric7

Tue, 15 Mar 2022 17:35:35 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 15 Mar 2022 17:35:35 +0100
branch
eric7
changeset 8981
fa03fe1fd672
parent 8980
f49ab2441e1f
child 8982
afec1a04aed9

Completed implementing a vulnerability checker based on the data of the Safety DB.

eric7/Preferences/ConfigurationPages/PipPage.py file | annotate | diff | comparison | revisions
eric7/Preferences/ConfigurationPages/PipPage.ui file | annotate | diff | comparison | revisions
eric7/Preferences/__init__.py file | annotate | diff | comparison | revisions
--- a/eric7/Preferences/ConfigurationPages/PipPage.py	Tue Mar 15 17:29:43 2022 +0100
+++ b/eric7/Preferences/ConfigurationPages/PipPage.py	Tue Mar 15 17:35:35 2022 +0100
@@ -29,11 +29,26 @@
         
         self.indexLabel.setText(self.tr(
             '<b>Note:</b> Leave empty to use the default index URL ('
-            '<a href="{0}">{0}</a>).')
-            .format(Pip.DefaultPyPiUrl))
+            '<a href="{0}">{0}</a>).'
+        ).format(Pip.DefaultPyPiUrl))
+        self.safetyDbMirrorLabel.setText(self.tr(
+            '<b>Note:</b> Leave empty to use the default Safety DB URL ({0}).'
+        ).format(Preferences.Prefs.pipDefaults["VulnerabilityDbMirror"]))
         
         # set initial values
         self.indexEdit.setText(Preferences.getPip("PipSearchIndex"))
+        
+        safetyDbUrl = Preferences.getPip("VulnerabilityDbMirror")
+        if (
+            safetyDbUrl ==
+            Preferences.Prefs.pipDefaults["VulnerabilityDbMirror"]
+        ):
+            safetyDbUrl = ""
+        self.safetyDbMirrorEdit.setText(safetyDbUrl)
+        self.validitySpinBox.setValue(
+            Preferences.getPip("VulnerabilityDbCacheValidity") // 3600)
+        # seconds converted to hours
+        
         self.noCondaCheckBox.setChecked(
             Preferences.getPip("ExcludeCondaEnvironments"))
     
@@ -41,10 +56,24 @@
         """
         Public slot to save the pip configuration.
         """
-        Preferences.setPip(
-            "PipSearchIndex", self.indexEdit.text().strip())
-        Preferences.setPip(
-            "ExcludeCondaEnvironments", self.noCondaCheckBox.isChecked())
+        safetyDbUrl = self.safetyDbMirrorEdit.text().strip()
+        if not safetyDbUrl:
+            safetyDbUrl = Preferences.Prefs.pipDefaults[
+                "VulnerabilityDbMirror"]
+        safetyDbUrl = safetyDbUrl.replace("\\", "/")
+        if not safetyDbUrl.endswith("/"):
+            safetyDbUrl += "/"
+        
+        Preferences.setPip("PipSearchIndex",
+                           self.indexEdit.text().strip())
+        
+        Preferences.setPip("VulnerabilityDbMirror", safetyDbUrl)
+        Preferences.setPip("VulnerabilityDbCacheValidity",
+                           self.validitySpinBox.value() * 3600)
+        # hours converted to seconds
+        
+        Preferences.setPip("ExcludeCondaEnvironments",
+                           self.noCondaCheckBox.isChecked())
 
 
 def create(dlg):
--- a/eric7/Preferences/ConfigurationPages/PipPage.ui	Tue Mar 15 17:29:43 2022 +0100
+++ b/eric7/Preferences/ConfigurationPages/PipPage.ui	Tue Mar 15 17:35:35 2022 +0100
@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>402</width>
-    <height>247</height>
+    <width>532</width>
+    <height>393</height>
    </rect>
   </property>
   <layout class="QVBoxLayout" name="verticalLayout_3">
@@ -42,6 +42,9 @@
         <property name="toolTip">
          <string>Enter the URL of the package index or leave empty to use the default</string>
         </property>
+        <property name="clearButtonEnabled">
+         <bool>true</bool>
+        </property>
        </widget>
       </item>
       <item>
@@ -49,6 +52,9 @@
         <property name="text">
          <string/>
         </property>
+        <property name="wordWrap">
+         <bool>true</bool>
+        </property>
         <property name="openExternalLinks">
          <bool>true</bool>
         </property>
@@ -58,6 +64,81 @@
     </widget>
    </item>
    <item>
+    <widget class="QGroupBox" name="groupBox_3">
+     <property name="title">
+      <string>Vulnerability Checks</string>
+     </property>
+     <layout class="QGridLayout" name="gridLayout">
+      <item row="0" column="0">
+       <widget class="QLabel" name="label">
+        <property name="text">
+         <string>Safety DB URL:</string>
+        </property>
+       </widget>
+      </item>
+      <item row="0" column="1" colspan="2">
+       <widget class="QLineEdit" name="safetyDbMirrorEdit">
+        <property name="toolTip">
+         <string>Enter the base URL for the Safety DB mirror to be used</string>
+        </property>
+        <property name="clearButtonEnabled">
+         <bool>true</bool>
+        </property>
+       </widget>
+      </item>
+      <item row="1" column="0" colspan="3">
+       <widget class="QLabel" name="safetyDbMirrorLabel">
+        <property name="wordWrap">
+         <bool>true</bool>
+        </property>
+        <property name="openExternalLinks">
+         <bool>true</bool>
+        </property>
+       </widget>
+      </item>
+      <item row="2" column="0">
+       <widget class="QLabel" name="label_2">
+        <property name="text">
+         <string>Cache Validity:</string>
+        </property>
+       </widget>
+      </item>
+      <item row="2" column="1">
+       <widget class="QSpinBox" name="validitySpinBox">
+        <property name="toolTip">
+         <string>Enter the Safetty DB cache validity time in hours (2 hours up to 7 days)</string>
+        </property>
+        <property name="alignment">
+         <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+        </property>
+        <property name="suffix">
+         <string> hours</string>
+        </property>
+        <property name="minimum">
+         <number>2</number>
+        </property>
+        <property name="maximum">
+         <number>168</number>
+        </property>
+       </widget>
+      </item>
+      <item row="2" column="2">
+       <spacer name="horizontalSpacer">
+        <property name="orientation">
+         <enum>Qt::Horizontal</enum>
+        </property>
+        <property name="sizeHint" stdset="0">
+         <size>
+          <width>330</width>
+          <height>20</height>
+         </size>
+        </property>
+       </spacer>
+      </item>
+     </layout>
+    </widget>
+   </item>
+   <item>
     <widget class="QGroupBox" name="groupBox">
      <property name="title">
       <string>Environment</string>
@@ -93,6 +174,9 @@
  </widget>
  <tabstops>
   <tabstop>indexEdit</tabstop>
+  <tabstop>safetyDbMirrorEdit</tabstop>
+  <tabstop>validitySpinBox</tabstop>
+  <tabstop>noCondaCheckBox</tabstop>
  </tabstops>
  <resources/>
  <connections/>
--- a/eric7/Preferences/__init__.py	Tue Mar 15 17:29:43 2022 +0100
+++ b/eric7/Preferences/__init__.py	Tue Mar 15 17:35:35 2022 +0100
@@ -1439,7 +1439,6 @@
         "VulnerabilityDbMirror":
             "https://raw.githubusercontent.com/pyupio/safety-db/master/data/",
         "VulnerabilityDbCacheValidity": 60 * 60 * 6     # 6 hours
-        # TODO: make these entries configurable
     }
     
     # defaults for MicroPython

eric ide

mercurial