mirror of
https://github.com/theupdateframework/python-tuf
synced 2026-05-24 10:08:28 +00:00
Merge pull request #1177 from joshuagl/ww/tuf-api-package
tuf/api: Expose tuf.api as a package (take 2)
This commit is contained in:
commit
a64a334cd4
5 changed files with 32 additions and 15 deletions
10
.travis.yml
10
.travis.yml
|
|
@ -20,11 +20,15 @@ matrix:
|
|||
env: TOXENV=py37
|
||||
- python: "3.8"
|
||||
env: TOXENV=py38
|
||||
- python: "3.6"
|
||||
- python: "3.8"
|
||||
env: TOXENV=with-sslib-master
|
||||
- python: "3.8"
|
||||
env: TOXENV=lint
|
||||
before_script: skip
|
||||
after_success: skip
|
||||
|
||||
allow_failures:
|
||||
- python: "3.6"
|
||||
- python: "3.8"
|
||||
env: TOXENV=with-sslib-master
|
||||
|
||||
install:
|
||||
|
|
@ -35,9 +39,9 @@ before_script:
|
|||
|
||||
script:
|
||||
- tox
|
||||
- fossa
|
||||
|
||||
after_success:
|
||||
- fossa
|
||||
# Workaround to get coverage reports with relative paths.
|
||||
# FIXME: Consider refactoring the tests to not require the test aggregation
|
||||
# script being invoked from the `tests` directory, so that `.coverage` is
|
||||
|
|
|
|||
10
tox.ini
10
tox.ini
|
|
@ -4,7 +4,7 @@
|
|||
# and then run "tox" from this directory.
|
||||
|
||||
[tox]
|
||||
envlist = py27, py35, py36, py37, py38
|
||||
envlist = lint,py{27,35,36,37,38}
|
||||
skipsdist = true
|
||||
|
||||
[testenv]
|
||||
|
|
@ -14,8 +14,6 @@ skipsdist = true
|
|||
changedir = tests
|
||||
|
||||
commands =
|
||||
pylint {toxinidir}/tuf
|
||||
bandit -r {toxinidir}/tuf
|
||||
coverage run aggregate_tests.py
|
||||
coverage report -m --fail-under 97
|
||||
|
||||
|
|
@ -39,3 +37,9 @@ deps =
|
|||
commands =
|
||||
coverage run aggregate_tests.py
|
||||
coverage report -m
|
||||
|
||||
[testenv:lint]
|
||||
commands =
|
||||
pylint {toxinidir}/tuf --ignore={toxinidir}/tuf/api
|
||||
pylint {toxinidir}/tuf/api --rcfile={toxinidir}/tuf/api/pylintrc
|
||||
bandit -r {toxinidir}/tuf
|
||||
|
|
|
|||
0
tuf/api/__init__.py
Normal file
0
tuf/api/__init__.py
Normal file
|
|
@ -10,7 +10,6 @@
|
|||
from typing import Any, Dict, Optional
|
||||
|
||||
import json
|
||||
import logging
|
||||
import tempfile
|
||||
|
||||
from securesystemslib.formats import encode_canonical
|
||||
|
|
@ -180,9 +179,9 @@ def to_json_file(
|
|||
The file cannot be written.
|
||||
|
||||
"""
|
||||
with tempfile.TemporaryFile() as f:
|
||||
f.write(self.to_json(compact).encode('utf-8'))
|
||||
persist_temp_file(f, filename, storage_backend)
|
||||
with tempfile.TemporaryFile() as temp_file:
|
||||
temp_file.write(self.to_json(compact).encode('utf-8'))
|
||||
persist_temp_file(temp_file, filename, storage_backend)
|
||||
|
||||
|
||||
# Signatures.
|
||||
|
|
@ -240,14 +239,14 @@ def verify(self, key: JsonDict) -> bool:
|
|||
raise tuf.exceptions.Error(
|
||||
f'no signature for key {key["keyid"]}.')
|
||||
|
||||
elif len(signatures_for_keyid) > 1:
|
||||
if len(signatures_for_keyid) > 1:
|
||||
raise tuf.exceptions.Error(
|
||||
f'{len(signatures_for_keyid)} signatures for key '
|
||||
f'{key["keyid"]}, not sure which one to verify.')
|
||||
else:
|
||||
return verify_signature(
|
||||
key, signatures_for_keyid[0],
|
||||
self.signed.to_canonical_bytes())
|
||||
|
||||
return verify_signature(
|
||||
key, signatures_for_keyid[0],
|
||||
self.signed.to_canonical_bytes())
|
||||
|
||||
|
||||
|
||||
|
|
@ -494,6 +493,10 @@ class Targets(Signed):
|
|||
}
|
||||
|
||||
"""
|
||||
# TODO: determine an appropriate value for max-args and fix places where
|
||||
# we violate that. This __init__ function takes 7 arguments, whereas the
|
||||
# default max-args value for pylint is 5
|
||||
# pylint: disable=too-many-arguments
|
||||
def __init__(
|
||||
self, _type: str, version: int, spec_version: str,
|
||||
expires: datetime, targets: JsonDict, delegations: JsonDict
|
||||
|
|
|
|||
6
tuf/api/pylintrc
Normal file
6
tuf/api/pylintrc
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
[MESSAGE_CONTROL]
|
||||
disable=fixme
|
||||
|
||||
[FORMAT]
|
||||
indent-string=" "
|
||||
max-line-length=79
|
||||
Loading…
Reference in a new issue