Skip to content
This repository was archived by the owner on Feb 27, 2023. It is now read-only.

Commit f86ab01

Browse files
committed
#3 GPG sign file
Signed-off-by: Uilian Ries <uilianries@gmail.com>
1 parent dbe0fc3 commit f86ab01

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

bintray/bintray.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

tests/test_content_signing.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,10 @@ def test_gpg_sign_version():
2525
response = bintray.gpg_sign_version("uilianries", "generic", "statistics", "test")
2626
assert {'error': False, 'message': 'success', 'statusCode': 200} == response or \
2727
{'error': False, 'message': 'success', 'statusCode': 201} == response
28+
29+
30+
def test_gpg_sign_file():
31+
bintray = Bintray()
32+
response = bintray.gpg_sign_file("uilianries", "generic", "packages.json")
33+
assert {'error': False, 'message': 'success', 'statusCode': 200} == response or \
34+
{'error': False, 'message': 'success', 'statusCode': 201} == response

0 commit comments

Comments
 (0)