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 

23 

24import sqlalchemy.dialects.postgresql as pgsql 

25import sqlalchemy.sql as sql 

26 

27import daklib.gpg 

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 = ( 

41 sql.select( 

42 [ 

43 tbl_bin.c.package, 

44 tbl_src.c.source, 

45 tbl_suite.c.suite_name, 

46 tbl_suite.c.codename, 

47 tbl_arch.c.arch_string, 

48 sql.func.max(tbl_bin.c.version), 

49 ] 

50 ) 

51 .select_from( 

52 tbl_esr.join(tbl_suite) 

53 .join(tbl_ba, tbl_ba.c.id == tbl_esr.c.association_id) 

54 .join(tbl_bin) 

55 .join(tbl_arch) 

56 .join(tbl_src, tbl_bin.c.source == tbl_src.c.id) 

57 ) 

58 .group_by( 

59 tbl_bin.c.package, 

60 tbl_src.c.source, 

61 tbl_suite.c.suite_name, 

62 tbl_suite.c.codename, 

63 tbl_arch.c.arch_string, 

64 ) 

65 ) 

66 requests = session.execute(query) 

67 

68 data = { 

69 "packages": [ 

70 { 

71 "package": row[0], 

72 "source": row[1], 

73 "suite": row[2], 

74 "codename": row[3], 

75 "architecture": row[4], 

76 "version": row[5], 

77 } 

78 for row in requests 

79 ], 

80 } 

81 

82 with open(path, "w") as fh: 

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

84 

85 

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

87 outpath = "{}.gpg".format(path) 

88 with open(path, "r") as infile, open(outpath, "w") as outfile: 

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

90 

91 

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

93 tbl_ba = DBConn().tbl_bin_associations 

94 tbl_esr = DBConn().tbl_external_signature_requests 

95 

96 select = sql.select([tbl_ba.c.id, target_suite.suite_id]).where( 

97 (tbl_ba.c.suite == suite.suite_id) & (tbl_ba.c.bin == binary.binary_id) 

98 ) 

99 insert = ( 

100 pgsql.insert(tbl_esr) 

101 .from_select([tbl_esr.c.association_id, tbl_esr.c.suite_id], select) 

102 .on_conflict_do_nothing() 

103 ) 

104 session.execute(insert) 

105 

106 

107def check_upload_for_external_signature_request( 

108 session, target_suite, suite, binary 

109) -> None: 

110 if "External-Signature-Requests" not in Config(): 

111 return 

112 config = Config().subtree("External-Signature-Requests") 

113 config_sources = config.subtree("Sources") 

114 

115 source = binary.source 

116 

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

118 return 

119 src_config = config_sources.subtree(source.source) 

120 

121 if binary.package not in src_config.value_list("Packages"): 

122 return 

123 

124 suites = config.value_list("Default-Suites") 

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

126 suites = src_config.value_list("Suites") 

127 if target_suite.suite_name not in suites: 

128 return 

129 

130 archs = config.value_list("Default-Architectures") 

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

132 archs = src_config.value_list("Architectures") 

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

134 return 

135 

136 add_external_signature_request(session, target_suite, suite, binary)