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

Commit dbe0fc3

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

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

bintray/bintray.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,3 +538,41 @@ def get_user_gpg_public_key(self, user):
538538
"""
539539
url = "{}/users/{}/keys/gpg/public.key".format(Bintray.BINTRAY_URL, user)
540540
return self._requester.get(url)
541+
542+
def gpg_sign_version(self, subject, repo, package, version, key_subject=None, passphrase=None,
543+
key_path=None):
544+
""" GPG sign all files associated with the specified version.
545+
546+
GPG signing information may be needed
547+
548+
Security: Authenticated user with 'publish' permission.
549+
550+
:param subject: username or organization
551+
:param repo: repository name
552+
:param package: package name
553+
:param version: package version
554+
:param key_subject: Alternative Bintray subject for the GPG public key
555+
:param passphrase: Optional private key passphrase, if required
556+
:param key_path: Optional private key, if not stored in Bintray
557+
:return: request response
558+
"""
559+
url = "{}/gpg/{}/{}/{}/versions/{}".format(Bintray.BINTRAY_URL, subject, repo, package,
560+
version)
561+
body = {}
562+
if subject:
563+
body['subject'] = key_subject
564+
if passphrase:
565+
body['passphrase'] = passphrase
566+
if key_path:
567+
with open(key_path, 'r') as fd:
568+
body['private_key'] = fd.read()
569+
body = None if body == {} else body
570+
headers = None
571+
if "passphrase" in body and len(body.keys()) == 1:
572+
headers = {"X-GPG-PASSPHRASE": passphrase}
573+
body = None
574+
575+
response = self._requester.post(url, json=body, headers=headers)
576+
577+
self._logger.info("Sign successfully: {}".format(url))
578+
return response

tests/test_content_signing.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# -*- coding: utf-8 -*-
22

3+
import os
34
from bintray.bintray import Bintray
45

56

@@ -18,3 +19,9 @@ def test_get_user_gpg_public_key():
1819
assert response.get("statusCode") == 200
1920
assert "BEGIN PGP PUBLIC KEY BLOCK" in response.get("message")
2021

22+
23+
def test_gpg_sign_version():
24+
bintray = Bintray()
25+
response = bintray.gpg_sign_version("uilianries", "generic", "statistics", "test")
26+
assert {'error': False, 'message': 'success', 'statusCode': 200} == response or \
27+
{'error': False, 'message': 'success', 'statusCode': 201} == response

0 commit comments

Comments
 (0)