Skip to content

Commit

Permalink
Expose cert and ca_bundle in CLI
Browse files Browse the repository at this point in the history
Allow users to specify the path to a CA bundle and client certificate
file via the command line interface to facilitate working with SSL secured
archives.
  • Loading branch information
hackermd committed Nov 1, 2018
1 parent 4f0a820 commit 204b810
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 19 deletions.
37 changes: 30 additions & 7 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -321,28 +321,51 @@ Retrieve bulk data given a URL:
Command Line Interface (CLI)
----------------------------

Search for instances:
Search for studies:

.. code-block:: none
dicomweb_client --url https://dicomcloud.azurewebsites.net/qidors search instances
dicomweb_client --url https://dicomcloud.azurewebsites.net/qidors search studies
Retrieve metadata for all instances of a given study:

.. code-block:: none
dicomweb_client --url https://dicomcloud.azurewebsites.net/wadors retrieve studies --study 1.2.826.0.1.3680043.8.1055.1.20111103111148288.98361414.79379639 metadata
dicomweb_client --url https://dicomcloud.azurewebsites.net/wadors \
retrieve studies \
--study 1.2.826.0.1.3680043.8.1055.1.20111103111148288.98361414.79379639 \
metadata
The output can be *dicomized* for human interpretation:

.. code-block:: none
dicomweb_client --url https://dicomcloud.azurewebsites.net/wadors retrieve studies --study 1.2.826.0.1.3680043.8.1055.1.20111103111148288.98361414.79379639 metadata --dicomize
dicomweb_client --url https://dicomcloud.azurewebsites.net/wadors \
retrieve studies \
--study 1.2.826.0.1.3680043.8.1055.1.20111103111148288.98361414.79379639 \
metadata \
--dicomize
Retrieve the full Part 3.10 files for all instances of a given study:

.. code-block:: none
dicomweb_client --url https://dicomcloud.azurewebsites.net/wadors \
retrieve studies \
--study 1.2.826.0.1.3680043.8.1055.1.20111103111148288.98361414.79379639 \
full
Retrieve a single frame of a given instances as JPEG compressed image and show it:
Retrieve a single frame of a given instances as JPEG compressed image:

.. code-block:: none
dicomweb_client --url https://dicomcloud.azurewebsites.net/wadors retrieve instances --study 1.2.826.0.1.3680043.8.1055.1.20111103111148288.98361414.79379639 --series 1.2.826.0.1.3680043.8.1055.1.20111103111208937.49685336.24517034 --instance 1.2.826.0.1.3680043.8.1055.1.20111103111208937.40440871.13152534 frames --numbers 1 --image-format jpeg --show
dicomweb_client --url https://dicomcloud.azurewebsites.net/wadors \
retrieve instances \
--study 1.2.826.0.1.3680043.8.1055.1.20111103111148288.98361414.79379639 \
--series 1.2.826.0.1.3680043.8.1055.1.20111103111208937.49685336.24517034 \
--instance 1.2.826.0.1.3680043.8.1055.1.20111103111208937.40440871.13152534 \
frames \
--numbers 1 \
--image-format jpeg
104 changes: 92 additions & 12 deletions src/dicomweb_client/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ def _get_parser():
'-p', '--password', dest='password', metavar='PASSWORD',
help='password for authentication with the DICOMweb service'
)
parser.add_argument(
'--ca', dest='ca_bundle', metavar='CERT-FILE',
help='path to a CA bundle file'
)
parser.add_argument(
'--cert', dest='cert', metavar='CERT-FILE',
help='path to a client certificate file in PEM format'
)
parser.add_argument(
'--url', dest='url', metavar='URL',
help='uniform resource locator of the DICOMweb service'
Expand Down Expand Up @@ -459,23 +467,41 @@ def _print_pixeldata(pixels):
def _search_for_studies(args):
'''Searches for *Studies* and writes metadata to standard output.'''
params = _parse_search_parameters(args)
client = DICOMwebClient(args.url, args.username, args.password)
client = DICOMwebClient(
args.url,
username=args.username,
password=args.password,
ca_bundle=args.ca_bundle,
cert=args.cert
)
studies = client.search_for_studies(**params)
_print_metadata(studies, args.prettify, args.dicomize)


def _search_for_series(args):
'''Searches for Series and writes metadata to standard output.'''
params = _parse_search_parameters(args)
client = DICOMwebClient(args.url, args.username, args.password)
client = DICOMwebClient(
args.url,
username=args.username,
password=args.password,
ca_bundle=args.ca_bundle,
cert=args.cert
)
series = client.search_for_series(args.study_instance_uid, **params)
_print_metadata(series, args.prettify, args.dicomize)


def _search_for_instances(args):
'''Searches for Instances and writes metadata to standard output.'''
params = _parse_search_parameters(args)
client = DICOMwebClient(args.url, args.username, args.password)
client = DICOMwebClient(
args.url,
username=args.username,
password=args.password,
ca_bundle=args.ca_bundle,
cert=args.cert
)
instances = client.search_for_instances(
args.study_instance_uid, args.series_instance_uid, **params
)
Expand All @@ -486,7 +512,13 @@ def _retrieve_study(args):
'''Retrieves all Instances of a given Study and either writes them to
standard output or to files on disk.
'''
client = DICOMwebClient(args.url, args.username, args.password)
client = DICOMwebClient(
args.url,
username=args.username,
password=args.password,
ca_bundle=args.ca_bundle,
cert=args.cert
)
instances = client.retrieve_study(args.study_instance_uid)
for inst in instances:
sop_instance_uid = inst.SOPInstanceUID
Expand All @@ -500,7 +532,13 @@ def _retrieve_series(args):
'''Retrieves all Instances of a given Series and either writes them to
standard output or to files on disk.
'''
client = DICOMwebClient(args.url, args.username, args.password)
client = DICOMwebClient(
args.url,
username=args.username,
password=args.password,
ca_bundle=args.ca_bundle,
cert=args.cert
)
instances = client.retrieve_series(
args.study_instance_uid, args.series_instance_uid
)
Expand All @@ -516,7 +554,13 @@ def _retrieve_instance(args):
'''Retrieves an Instances and either writes it to standard output or to a
file on disk.
'''
client = DICOMwebClient(args.url, args.username, args.password)
client = DICOMwebClient(
args.url,
username=args.username,
password=args.password,
ca_bundle=args.ca_bundle,
cert=args.cert
)
instance = client.retrieve_instance(
args.study_instance_uid, args.series_instance_uid,
args.sop_instance_uid
Expand All @@ -531,7 +575,13 @@ def _retrieve_study_metadata(args):
'''Retrieves metadata for all Instances of a given Study and either
writes it to standard output or to files on disk.
'''
client = DICOMwebClient(args.url, args.username, args.password)
client = DICOMwebClient(
args.url,
username=args.username,
password=args.password,
ca_bundle=args.ca_bundle,
cert=args.cert
)
metadata = client.retrieve_study_metadata(args.study_instance_uid)
if args.save:
for md in metadata:
Expand All @@ -549,7 +599,13 @@ def _retrieve_series_metadata(args):
'''Retrieves metadata for all Instances of a given Series and either
writes it to standard output or to files on disk.
'''
client = DICOMwebClient(args.url, args.username, args.password)
client = DICOMwebClient(
args.url,
username=args.username,
password=args.password,
ca_bundle=args.ca_bundle,
cert=args.cert
)
metadata = client.retrieve_series_metadata(
args.study_instance_uid, args.series_instance_uid
)
Expand All @@ -569,7 +625,13 @@ def _retrieve_instance_metadata(args):
'''Retrieves metadata for an individual Instances and either
writes it to standard output or to a file on disk.
'''
client = DICOMwebClient(args.url, args.username, args.password)
client = DICOMwebClient(
args.url,
username=args.username,
password=args.password,
ca_bundle=args.ca_bundle,
cert=args.cert
)
metadata = client.retrieve_instance_metadata(
args.study_instance_uid, args.series_instance_uid,
args.sop_instance_uid
Expand All @@ -588,7 +650,13 @@ def _retrieve_instance_frames(args):
writes it to standard output or to a file on disk or displays it
(depending on the requested content type).
'''
client = DICOMwebClient(args.url, args.username, args.password)
client = DICOMwebClient(
args.url,
username=args.username,
password=args.password,
ca_bundle=args.ca_bundle,
cert=args.cert
)
pixeldata = client.retrieve_instance_frames(
args.study_instance_uid, args.series_instance_uid,
args.sop_instance_uid, args.frame_numbers,
Expand Down Expand Up @@ -640,15 +708,27 @@ def _retrieve_bulkdata(args):
'''Retrieves bulk data and either writes them to standard output or to a
file on disk.
'''
client = DICOMwebClient(args.url, args.username, args.password)
client = DICOMwebClient(
args.url,
username=args.username,
password=args.password,
ca_bundle=args.ca_bundle,
cert=args.cert
)
data = client.retrieve_bulkdata(args.bulkdata_uri, args.image_format)
print(data)
print('\n')


def _store_instances(args):
'''Loads Instances from files on disk and stores them.'''
client = DICOMwebClient(args.url, args.username, args.password)
client = DICOMwebClient(
args.url,
username=args.username,
password=args.password,
ca_bundle=args.ca_bundle,
cert=args.cert
)
datasets = list()
for f in args.files:
ds = pydicom.dcmread(f)
Expand Down

0 comments on commit 204b810

Please sign in to comment.