Skip to content

Commit

Permalink
Add support for explicit cacert and client cert
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton Lundin committed Nov 27, 2019
1 parent 31112dd commit d7bc438
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,15 @@
class Requests:

def request(self, method, url, **kwargs):
return requests.request(method, url, **kwargs)
s = requests.Session()

if args.cert and args.key:
s.cert = (args.cert.name, args.key.name)

if args.cacert:
s.verify = args.cacert.name

return s.request(method, url, **kwargs)

def bearer_request(self, method, url, auth, **kwargs):
global DEBUG
Expand Down Expand Up @@ -513,6 +521,30 @@ def parse_args(args=None):
default=False,
const=True)

parser.add_argument(
'--cacert',
help='Use this CA certificate to validate the registrys certificate',
action='store',
type=argparse.FileType('r'),
default=False,
metavar="CERT")

parser.add_argument(
'--cert',
help='Use this client certificate to connect to registry',
action='store',
default=False,
type=argparse.FileType('r'),
metavar="CERT")

parser.add_argument(
'--key',
help='Use this client certificate key to connect to registry',
action='store',
default=False,
type=argparse.FileType('r'),
metavar="KEY")

parser.add_argument(
'--delete-all',
help="Will delete all tags. Be careful with this!",
Expand Down Expand Up @@ -740,6 +772,10 @@ def main_loop(args):

keep_last_versions = int(args.num)

if bool(args.cert) != bool(args.key):
print("Can't use only one of --cert and --key!")
sys.exit(1)

if args.no_validate_ssl:
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

Expand Down

0 comments on commit d7bc438

Please sign in to comment.