@@ -576,3 +576,37 @@ def gpg_sign_version(self, subject, repo, package, version, key_subject=None, pa
576576
577577 self ._logger .info ("Sign successfully: {}" .format (url ))
578578 return response
579+
580+ def gpg_sign_file (self , subject , repo , file_path , key_subject = None , passphrase = None ,
581+ key_path = None ):
582+ """ GPG sign the specified repository file.
583+
584+ GPG signing information may be needed
585+
586+ :param subject: username or organization
587+ :param repo: repository name
588+ :param file_path: file path to be signed
589+ :param key_subject: Alternative Bintray subject for the GPG public key
590+ :param passphrase: Optional private key passphrase, if required
591+ :param key_path: Optional private key, if not stored in Bintray
592+ :return: request response
593+ """
594+ url = "{}/gpg/{}/{}/{}" .format (Bintray .BINTRAY_URL , subject , repo , file_path )
595+ body = {}
596+ if subject :
597+ body ['subject' ] = key_subject
598+ if passphrase :
599+ body ['passphrase' ] = passphrase
600+ if key_path :
601+ with open (key_path , 'r' ) as fd :
602+ body ['private_key' ] = fd .read ()
603+ body = None if body == {} else body
604+ headers = None
605+ if "passphrase" in body and len (body .keys ()) == 1 :
606+ headers = {"X-GPG-PASSPHRASE" : passphrase }
607+ body = None
608+
609+ response = self ._requester .post (url , json = body , headers = headers )
610+
611+ self ._logger .info ("Sign successfully: {}" .format (url ))
612+ return response
0 commit comments