Coverage for dak/manage_external_signature_requests.py: 84%

34 statements  

« prev     ^ index     » next       coverage.py v7.6.0, created at 2026-08-03 16:46 +0000

1"""Manage external signature requests 

2 

3@contact: Debian FTPMaster <ftpmaster@debian.org> 

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

5 

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 

22################################################################################ 

23 

24import sys 

25 

26import apt_pkg 

27 

28from daklib import daklog 

29from daklib.config import Config 

30from daklib.dbconn import DBConn 

31from daklib.externalsignature import ( 

32 export_external_signature_requests, 

33 sign_external_signature_requests, 

34) 

35 

36################################################################################ 

37 

38Options = None 

39Logger = None 

40 

41################################################################################ 

42 

43 

44def usage(exit_code=0): 

45 print( 

46 """Usage: dak manage-external-signature-requests [OPTIONS] 

47Manage external signature requests such as requests to sign EFI binaries or 

48kernel modules. 

49 

50 -h, --help show this help and exit""" 

51 ) 

52 

53 sys.exit(exit_code) 

54 

55 

56################################################################################ 

57 

58 

59def main(): 

60 global Options, Logger 

61 

62 cnf = Config() 

63 

64 for i in ["Help"]: 

65 key = "Manage-External-Signature-Requests::Options::{}".format(i) 

66 if key not in cnf: 66 ↛ 64line 66 didn't jump to line 64 because the condition on line 66 was always true

67 cnf[key] = "" 

68 

69 Arguments = [("h", "help", "Manage-External-Signature-Requests::Options::Help")] 

70 

71 apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv) # type: ignore[attr-defined] 

72 Options = cnf.subtree("Manage-External-Signature-Requests::Options") 

73 

74 if Options["Help"]: 

75 usage() 

76 

77 Logger = daklog.Logger("manage-external-signature-requests") 

78 

79 if "External-Signature-Requests" not in cnf: 79 ↛ 80line 79 didn't jump to line 80 because the condition on line 79 was never true

80 print("DAK not configured to handle external signature requests") 

81 return 

82 

83 config = cnf.subtree("External-Signature-Requests") 

84 

85 session = DBConn().session() 

86 

87 export_external_signature_requests(session, config["Export"]) 

88 

89 if "ExportSigningKeys" in config: 89 ↛ 90line 89 didn't jump to line 90

90 args = { 

91 "pubring": cnf.get("Dinstall::SigningPubKeyring") or None, 

92 "homedir": cnf.get("Dinstall::SigningHomedir") or None, 

93 "passphrase_file": cnf.get("Dinstall::SigningPassphraseFile") or None, 

94 } 

95 sign_external_signature_requests( 

96 session, config["Export"], config.value_list("ExportSigningKeys"), args 

97 ) 

98 

99 session.close() 

100 

101 Logger.close()