1"""external signature requests 

2 

3@contact: Debian FTP Master <ftpmaster@debian.org> 

4@copyright: 2018 Ansgar Burchardt <ansgar@debian.org> 

5@license: GNU General Public License version 2 or later 

6""" 

7 

8# This program is free software; you can redistribute it and/or modify 

9# it under the terms of the GNU General Public License as published by 

10# the Free Software Foundation; either version 2 of the License, or 

11# (at your option) any later version. 

12 

13# This program is distributed in the hope that it will be useful, 

14# but WITHOUT ANY WARRANTY; without even the implied warranty of 

15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

16# GNU General Public License for more details. 

17 

18# You should have received a copy of the GNU General Public License 

19# along with this program; if not, write to the Free Software 

20# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 

21 

22import json 

23import sqlalchemy.sql as sql 

24import sqlalchemy.dialects.postgresql as pgsql 

25 

26import daklib.gpg 

27 

28from daklib.config import Config 

29from daklib.dbconn import DBConn 

30 

31 

32def export_external_signature_requests(session, path: str) -> None: 

33 tbl_arch = DBConn().tbl_architecture 

34 tbl_ba = DBConn().tbl_bin_associations 

35 tbl_bin = DBConn().tbl_binaries 

36 tbl_src = DBConn().tbl_source 

37 tbl_esr = DBConn().tbl_external_signature_requests 

38 tbl_suite = DBConn().tbl_suite 

39 

40 query = sql.select([tbl_bin.c.package, tbl_src.c.source, tbl_suite.c.suite_name, tbl_suite.c.codename, tbl_arch.c.arch_string, sql.func.max(tbl_bin.c.version)]) \ 

41 .select_from(tbl_esr.join(tbl_suite).join(tbl_ba, tbl_ba.c.id == tbl_esr.c.association_id).join(tbl_bin).join(tbl_arch).join(tbl_src, tbl_bin.c.source == tbl_src.c.id)) \ 

42 .group_by(tbl_bin.c.package, tbl_src.c.source, tbl_suite.c.suite_name, tbl_suite.c.codename, tbl_arch.c.arch_string) 

43 requests = session.execute(query) 

44 

45 data = { 

46 'packages': [ 

47 { 

48 'package': row[0], 

49 'source': row[1], 

50 'suite': row[2], 

51 'codename': row[3], 

52 'architecture': row[4], 

53 'version': row[5], 

54 } 

55 for row in requests], 

56 } 

57 

58 with open(path, 'w') as fh: 

59 json.dump(data, fh, indent=2) 

60 

61 

62def sign_external_signature_requests(session, path: str, keyids, args={}) -> None: 

63 outpath = '{}.gpg'.format(path) 

64 with open(path, 'r') as infile, open(outpath, 'w') as outfile: 

65 daklib.gpg.sign(infile, outfile, keyids, inline=False, **args) 

66 

67 

68def add_external_signature_request(session, target_suite, suite, binary) -> None: 

69 tbl_ba = DBConn().tbl_bin_associations 

70 tbl_esr = DBConn().tbl_external_signature_requests 

71 

72 select = sql.select([tbl_ba.c.id, target_suite.suite_id]).where((tbl_ba.c.suite == suite.suite_id) & (tbl_ba.c.bin == binary.binary_id)) 

73 insert = pgsql.insert(tbl_esr).from_select([tbl_esr.c.association_id, tbl_esr.c.suite_id], select).on_conflict_do_nothing() 

74 session.execute(insert) 

75 

76 

77def check_upload_for_external_signature_request(session, target_suite, suite, binary) -> None: 

78 if 'External-Signature-Requests' not in Config(): 

79 return 

80 config = Config().subtree('External-Signature-Requests') 

81 config_sources = config.subtree('Sources') 

82 

83 source = binary.source 

84 

85 if source.source not in config_sources: 85 ↛ 86line 85 didn't jump to line 86, because the condition on line 85 was never true

86 return 

87 src_config = config_sources.subtree(source.source) 

88 

89 if binary.package not in src_config.value_list('Packages'): 

90 return 

91 

92 suites = config.value_list('Default-Suites') 

93 if 'Suites' in src_config: 93 ↛ 94line 93 didn't jump to line 94, because the condition on line 93 was never true

94 suites = src_config.value_list('Suites') 

95 if target_suite.suite_name not in suites: 

96 return 

97 

98 archs = config.value_list('Default-Architectures') 

99 if 'Architectures' in src_config: 99 ↛ 101line 99 didn't jump to line 101, because the condition on line 99 was never false

100 archs = src_config.value_list('Architectures') 

101 if binary.architecture.arch_string not in archs: 101 ↛ 102line 101 didn't jump to line 102, because the condition on line 101 was never true

102 return 

103 

104 add_external_signature_request(session, target_suite, suite, binary)