Browse Source

Fix the bug of pep8 and building api-guide

`sphinx-build` command is not found in test-env.

To fix pep8, also blacklist the new bandit warning B105, this will
be fixed in a followup.

(cherry picked from commit bf95c37b84)
Change-Id: Ic1b8c3a4bfd67fff082297b881df66ffb9ca2c50
(cherry picked from commit 367453b543)
changes/22/675222/1
pengyuesheng 2 months ago
parent
commit
9314499b2b

+ 1
- 1
barbican/plugin/crypto/pkcs11.py View File

@@ -503,7 +503,7 @@ class PKCS11(object):
503 503
             return {
504 504
                 "iv": self.ffi.buffer(iv)[:],
505 505
                 "ct": self.ffi.buffer(ct, ct_len[0])[:]
506
-                }
506
+            }
507 507
         else:
508 508
             # HSM-generated IVs are appended to the end of the ciphertext
509 509
             return {

+ 1
- 1
barbican/plugin/crypto/simple_crypto.py View File

@@ -234,7 +234,7 @@ class SimpleCryptoPlugin(c.CryptoPluginBase):
234 234
             length_factor = 2
235 235
 
236 236
         if (algorithm.lower() in c.PluginSupportTypes.SYMMETRIC_ALGORITHMS
237
-            and bit_length/length_factor
237
+            and bit_length / length_factor
238 238
                 in c.PluginSupportTypes.SYMMETRIC_KEY_LENGTHS):
239 239
             return True
240 240
         elif (algorithm.lower() in c.PluginSupportTypes.ASYMMETRIC_ALGORITHMS

+ 1
- 1
barbican/plugin/util/multiple_backends.py View File

@@ -64,7 +64,7 @@ def read_multiple_backends_config():
64 64
                                      'global default plugin for deployment. '
65 65
                                      'Default is False.')
66 66
                             ),
67
-                ]
67
+            ]
68 68
             conf.register_group(store_opt_group)
69 69
             conf.register_opts(store_opts, group=store_opt_group)
70 70
 

+ 8
- 8
barbican/plugin/util/translations.py View File

@@ -145,12 +145,12 @@ def _convert_private_pem_to_der(pem):
145 145
         pem,
146 146
         password=None,
147 147
         backend=default_backend()
148
-        )
148
+    )
149 149
     der = private_key.private_bytes(
150 150
         encoding=serialization.Encoding.DER,
151 151
         format=serialization.PrivateFormat.PKCS8,
152 152
         encryption_algorithm=serialization.NoEncryption()
153
-        )
153
+    )
154 154
     return der
155 155
 
156 156
 
@@ -159,12 +159,12 @@ def _convert_private_der_to_pem(der):
159 159
         der,
160 160
         password=None,
161 161
         backend=default_backend()
162
-        )
162
+    )
163 163
     pem = private_key.private_bytes(
164 164
         encoding=serialization.Encoding.PEM,
165 165
         format=serialization.PrivateFormat.PKCS8,
166 166
         encryption_algorithm=serialization.NoEncryption()
167
-        )
167
+    )
168 168
     return pem
169 169
 
170 170
 
@@ -172,11 +172,11 @@ def _convert_public_pem_to_der(pem):
172 172
     public_key = serialization.load_pem_public_key(
173 173
         pem,
174 174
         backend=default_backend()
175
-        )
175
+    )
176 176
     der = public_key.public_bytes(
177 177
         encoding=serialization.Encoding.DER,
178 178
         format=serialization.PublicFormat.SubjectPublicKeyInfo
179
-        )
179
+    )
180 180
     return der
181 181
 
182 182
 
@@ -184,11 +184,11 @@ def _convert_public_der_to_pem(der):
184 184
     public_key = serialization.load_der_public_key(
185 185
         der,
186 186
         backend=default_backend()
187
-        )
187
+    )
188 188
     pem = public_key.public_bytes(
189 189
         encoding=serialization.Encoding.PEM,
190 190
         format=serialization.PublicFormat.SubjectPublicKeyInfo
191
-        )
191
+    )
192 192
     return pem
193 193
 
194 194
 

+ 1
- 1
barbican/tests/common/test_validators.py View File

@@ -286,7 +286,7 @@ class WhenTestingSecretValidator(utils.BaseTestCase):
286 286
             self.secret_req,
287 287
         )
288 288
         self.assertEqual('mode', exception.invalid_property)
289
-        self.assertIn('mode',  six.text_type(exception))
289
+        self.assertIn('mode', six.text_type(exception))
290 290
 
291 291
     def test_should_raise_mode_is_non_string(self):
292 292
         self.secret_req['mode'] = 123

+ 3
- 3
barbican/tests/plugin/util/test_multiple_backends.py View File

@@ -416,19 +416,19 @@ class TestPluginsGenerateStoreAPIMultipleBackend(
416 416
             'crypto_plugins': ['simple_crypto', '', 'p11_crypto'],
417 417
             'default_store_class': store_crypto.StoreCryptoAdapterPlugin,
418 418
             'default_crypto_class': simple_crypto.SimpleCryptoPlugin
419
-            }],
419
+        }],
420 420
         "kmip": [{
421 421
             'store_plugins': ['kmip_plugin', 'store_crypto', 'store_crypto'],
422 422
             'crypto_plugins': ['', 'p11_crypto', 'simple_crypto'],
423 423
             'default_store_class': kss.KMIPSecretStore,
424 424
             'default_crypto_class': None
425
-            }],
425
+        }],
426 426
         "pkcs11": [{
427 427
             'store_plugins': ['store_crypto', 'store_crypto', 'kmip_plugin'],
428 428
             'crypto_plugins': ['p11_crypto', 'simple_crypto', ''],
429 429
             'default_store_class': store_crypto.StoreCryptoAdapterPlugin,
430 430
             'default_crypto_class': p11_crypto.P11CryptoPlugin
431
-            }]
431
+        }]
432 432
     }
433 433
 
434 434
     def setUp(self):

+ 10
- 10
functionaltests/api/v1/functional/test_secrets.py View File

@@ -1637,61 +1637,61 @@ class SecretsMultipleBackendTestCase(base.TestCase):
1637 1637
             'symmetric',
1638 1638
             oslo_base64.decode_as_bytes(get_default_payload()),
1639 1639
             get_default_data()
1640
-            ],
1640
+        ],
1641 1641
         'private_type_preferred_store': [
1642 1642
             admin_a,
1643 1643
             'private',
1644 1644
             keys.get_private_key_pem(),
1645 1645
             get_private_key_req()
1646
-            ],
1646
+        ],
1647 1647
         'public_type_preferred_store': [
1648 1648
             admin_a,
1649 1649
             'public',
1650 1650
             keys.get_public_key_pem(),
1651 1651
             get_public_key_req()
1652
-            ],
1652
+        ],
1653 1653
         'certificate_type_preferred_store': [
1654 1654
             admin_a,
1655 1655
             'certificate',
1656 1656
             keys.get_certificate_pem(),
1657 1657
             get_certificate_req()
1658
-            ],
1658
+        ],
1659 1659
         'passphrase_type_preferred_store': [
1660 1660
             admin_a,
1661 1661
             'passphrase',
1662 1662
             'mysecretpassphrase',
1663 1663
             get_passphrase_req()
1664
-            ],
1664
+        ],
1665 1665
         'symmetric_type_no_preferred_store': [
1666 1666
             admin_b,
1667 1667
             'symmetric',
1668 1668
             oslo_base64.decode_as_bytes(get_default_payload()),
1669 1669
             get_default_data()
1670
-            ],
1670
+        ],
1671 1671
         'private_type_no_preferred_store': [
1672 1672
             admin_b,
1673 1673
             'private',
1674 1674
             keys.get_private_key_pem(),
1675 1675
             get_private_key_req()
1676
-            ],
1676
+        ],
1677 1677
         'public_type_no_preferred_store': [
1678 1678
             admin_b,
1679 1679
             'public',
1680 1680
             keys.get_public_key_pem(),
1681 1681
             get_public_key_req()
1682
-            ],
1682
+        ],
1683 1683
         'certificate_type_no_preferred_store': [
1684 1684
             admin_b,
1685 1685
             'certificate',
1686 1686
             keys.get_certificate_pem(),
1687 1687
             get_certificate_req()
1688
-            ],
1688
+        ],
1689 1689
         'passphrase_type_no_preferred_store': [
1690 1690
             admin_b,
1691 1691
             'passphrase',
1692 1692
             b'mysecretpassphrase',
1693 1693
             get_passphrase_req()
1694
-            ],
1694
+        ],
1695 1695
     })
1696 1696
     def test_secret_create_for(self, user_name, secret_type, expected, spec):
1697 1697
         """Create secrets with various secret types with multiple backends."""

+ 2
- 2
functionaltests/api/v1/functional/test_secretstores.py View File

@@ -127,7 +127,7 @@ class SecretStoresTestCase(base.TestCase):
127 127
 
128 128
         stores = json_data['secret-stores']
129 129
 
130
-        store = stores[len(stores)-1]
130
+        store = stores[len(stores) - 1]
131 131
         secret_store_ref = store['secret_store_ref']
132 132
         resp = self.ss_behaviors.set_preferred_secret_store(secret_store_ref,
133 133
                                                             user_name=user)
@@ -193,7 +193,7 @@ class SecretStoresTestCase(base.TestCase):
193 193
 
194 194
         stores = json_data['secret-stores']
195 195
 
196
-        store = stores[len(stores)-1]
196
+        store = stores[len(stores) - 1]
197 197
         secret_store_ref = store['secret_store_ref']
198 198
         resp = self.ss_behaviors.set_preferred_secret_store(secret_store_ref,
199 199
                                                             user_name=user)

+ 3
- 2
tox.ini View File

@@ -49,7 +49,7 @@ commands =
49 49
   doc8 {posargs}
50 50
   flake8 {posargs}
51 51
   # Run security linter
52
-  bandit -r barbican -x tests -n5
52
+  bandit -r barbican -x tests -n5 -s B105
53 53
 
54 54
 [testenv:genconfig]
55 55
 basepython = python3
@@ -89,6 +89,7 @@ whitelist_externals = rm
89 89
 basepython = python3
90 90
 # This environment is called from CI scripts to test and publish
91 91
 # the API Guide to developer.openstack.org.
92
+deps = -r{toxinidir}/doc/requirements.txt
92 93
 commands =
93 94
   rm -rf api-guide/build
94 95
   sphinx-build -W -b html -d api-guide/build/doctrees api-guide/source api-guide/build/html
@@ -158,7 +159,7 @@ exclude = .git,.idea,.tox,bin,dist,debian,rpmbuild,tools,*.egg-info,*.eggs,contr
158 159
 [testenv:bandit]
159 160
 basepython = python3
160 161
 deps = -r{toxinidir}/test-requirements.txt
161
-commands = bandit -r barbican -x tests -n5
162
+commands = bandit -r barbican -x tests -n5 -s B105
162 163
 
163 164
 [testenv:bindep]
164 165
 basepython = python3

Loading…
Cancel
Save