This repository has been archived by the owner on Nov 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcli.py
73 lines (62 loc) · 3.17 KB
/
cli.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python
import datetime
import logging
import os
import sys
import uuid
from optparse import OptionParser
from ingest.api.dssapi import DssApi
from ingest.api.ingestapi import IngestApi
from ingest.api.stagingapi import StagingApi
from ingest.exporter.ingestexportservice import IngestExporter
from ingest.exporter.staging import StagingService, StagingInfoRepository
from ingest.utils.s2s_token_client import S2STokenClient
from ingest.utils.token_manager import TokenManager
if __name__ == '__main__':
format = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
logging.basicConfig(format=format, stream=sys.stdout, level=logging.INFO)
parser = OptionParser()
parser.add_option("-b", "--bundle-uuid",
help="Bundle UUID (optional)")
parser.add_option("-v", "--bundle-version",
help="Bundle Version (optional)")
parser.add_option("-e", "--submission-uuid",
help="Submission envelope UUID for which to generate the bundle (Required)")
parser.add_option("-p", "--process-uuid",
help="Process UUID (Required)")
parser.add_option("-D", "--dry", help="do a dry run without submitting to ingest", action="store_true",
default=False)
parser.add_option("-o", "--output", dest="output",
help="Output directory where to dump json files submitted to ingest (Optional)", metavar="FILE",
default=None)
parser.add_option("-i", "--ingest", help="the URL to the ingest API (Required)")
parser.add_option("-s", "--staging", help="the URL to the staging API")
parser.add_option("-d", "--dss", help="the URL to the datastore service")
parser.add_option("-l", "--log", help="the logging level", default='INFO')
(options, args) = parser.parse_args()
if not options.submission_uuid:
print("You must supply a Submission Envelope UUID")
exit(2)
if not options.process_uuid:
print("You must supply a process UUID.")
exit(2)
bundle_uuid = str(uuid.uuid4())
bundle_version = datetime.datetime.utcnow().strftime("%Y-%m-%dT%H%M%S.%fZ")
if options.bundle_uuid:
bundle_uuid = options.bundle_uuid
if options.bundle_version:
bundle_version = options.bundle_version
dss_api = DssApi(url=options.dss)
s2s_token_client = S2STokenClient()
gcp_credentials_file = os.environ.get('GOOGLE_APPLICATION_CREDENTIALS')
s2s_token_client.setup_from_file(gcp_credentials_file)
token_manager = TokenManager(token_client=s2s_token_client)
ingest_api = IngestApi(token_manager=token_manager)
staging_api = StagingApi(url=options.staging)
staging_info_repo = StagingInfoRepository(ingest_client=ingest_api)
staging_service = StagingService(staging_client=staging_api, staging_info_repository=staging_info_repo)
exporter = IngestExporter(staging_service=staging_service, ingest_api=ingest_api, dss_api=dss_api)
exporter.export_bundle(bundle_uuid=bundle_uuid,
bundle_version=bundle_version,
submission_uuid=options.submission_uuid,
process_uuid=options.process_uuid)