multisign option

This commit is contained in:
2021-03-11 01:39:45 +03:00
parent fd2049b334
commit 262d8d8647
12 changed files with 23 additions and 79 deletions

View File

@ -21,7 +21,7 @@ import configparser
import os
from logging.config import fileConfig
from typing import List, Optional
from typing import List, Optional, Set
# built-in configparser extension

View File

@ -1,26 +0,0 @@
#
# Copyright (c) 2021 Evgenii Alekseev.
#
# This file is part of ahriman
# (see https://github.com/arcan1s/ahriman).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from ahriman.core.report.report import Report
class Dummy(Report):
def generate(self, path: str) -> None:
pass

View File

@ -39,10 +39,8 @@ class HTML(Report):
self.template_path = config.get(section, 'template_path')
# base template vars
if SignSettings.from_option(config.get('sign', 'enabled')) != SignSettings.Disabled:
self.pgp_key = config.get('sign', 'key', fallback=None)
else:
self.pgp_key = None
self.sign_targets = [SignSettings.from_option(opt) for opt in config.get_list('sign', 'target')]
self.pgp_key = config.get('sign', 'key', fallback=None)
self.homepage = config.get(section, 'homepage', fallback=None)
self.repository = config.get('repository', 'name')
@ -62,6 +60,8 @@ class HTML(Report):
html = template.render(
homepage=self.homepage,
link_path=self.link_path,
has_package_signed=SignSettings.SignPackages in self.sign_targets,
has_repo_signed=SignSettings.SignRepository in self.sign_targets,
packages=packages,
pgp_key=self.pgp_key,
repository=self.repository)

View File

@ -38,8 +38,7 @@ class Report:
from ahriman.core.report.html import HTML
report: Report = HTML(architecture, config)
else:
from ahriman.core.report.dummy import Dummy
report = Dummy(architecture, config)
report = Report(architecture, config)
try:
report.generate(path)
@ -47,4 +46,4 @@ class Report:
raise ReportFailed(e) from e
def generate(self, path: str) -> None:
raise NotImplementedError
pass

View File

@ -33,12 +33,12 @@ class GPGWrapper:
def __init__(self, config: Configuration) -> None:
self.logger = logging.getLogger('build_details')
self.key = config.get('sign', 'key', fallback=None)
self.sign = SignSettings.from_option(config.get('sign', 'enabled'))
self.target = [SignSettings.from_option(opt) for opt in config.get_list('sign', 'target')]
self.key = config.get('sign', 'key') if self.target else None
@property
def repository_sign_args(self) -> List[str]:
if self.sign != SignSettings.SignRepository:
if SignSettings.SignRepository not in self.target:
return []
return ['--sign', '--key', self.key] if self.key else ['--sign']
@ -58,11 +58,11 @@ class GPGWrapper:
return cmd
def sign_package(self, path: str) -> List[str]:
if self.sign != SignSettings.SignPackages:
if SignSettings.SignPackages not in self.target:
return [path]
return self.process(path)
def sign_repository(self, path: str) -> List[str]:
if self.sign != SignSettings.SignRepository:
if SignSettings.SignRepository not in self.target:
return [path]
return self.process(path)

View File

@ -1,26 +0,0 @@
#
# Copyright (c) 2021 Evgenii Alekseev.
#
# This file is part of ahriman
# (see https://github.com/arcan1s/ahriman).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from ahriman.core.upload.uploader import Uploader
class Dummy(Uploader):
def sync(self, path: str) -> None:
pass

View File

@ -41,8 +41,7 @@ class Uploader:
from ahriman.core.upload.s3 import S3
uploader = S3(architecture, config)
else:
from ahriman.core.upload.dummy import Dummy
uploader = Dummy(architecture, config)
uploader = Uploader(architecture, config)
try:
uploader.sync(path)
@ -50,4 +49,4 @@ class Uploader:
raise SyncFailed(e) from e
def sync(self, path: str) -> None:
raise NotImplementedError
pass

View File

@ -25,15 +25,12 @@ from ahriman.core.exceptions import InvalidOptionException
class SignSettings(Enum):
Disabled = auto()
SignPackages = auto()
SignRepository = auto()
@staticmethod
def from_option(value: str) -> SignSettings:
if value.lower() in ('no', 'disabled'):
return SignSettings.Disabled
elif value.lower() in ('package', 'packages', 'sign-package'):
if value.lower() in ('package', 'packages', 'sign-package'):
return SignSettings.SignPackages
elif value.lower() in ('repository', 'sign-repository'):
return SignSettings.SignRepository