From e85c1e2edb5a52d1f4e92d4eff7e95b6e50b1ea5 Mon Sep 17 00:00:00 2001 From: Alec Date: Wed, 30 Oct 2024 18:56:14 -0500 Subject: [PATCH] cleanup testing, checking for api creds --- condor_history_to_es.py | 22 ++++++++++------------ condor_queue_to_es.py | 19 +++++++++++-------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/condor_history_to_es.py b/condor_history_to_es.py index 1cee00b..0b7d1c4 100755 --- a/condor_history_to_es.py +++ b/condor_history_to_es.py @@ -22,9 +22,9 @@ help="query jobs, but do not ingest into ES",) parser.add_argument('--collectors', default=False, action='store_true', help='Args are collector addresses, not files') -parser.add_argument('--client_id',help='oauth2 client id') -parser.add_argument('--client_secret',help='oauth2 client secret') -parser.add_argument('--token_url',help='oauth2 realm token url') +parser.add_argument('--client_id',help='oauth2 client id',default=None) +parser.add_argument('--client_secret',help='oauth2 client secret',default=None) +parser.add_argument('--token_url',help='oauth2 realm token url',default=None) parser.add_argument("positionals", nargs='+') options = parser.parse_args() @@ -55,13 +55,14 @@ def es_generator(entries): if '://' in address: prefix,address = address.split('://') -api = ClientCredentialsAuth(address='https://elasticsearch.icecube.aq', - token_url=options.token_url, - client_secret=options.client_secret, - client_id=options.client_id) -token = api.make_access_token() +token = None -print(token) +if None not in (options.token_url, options.client_secret, options.client_id): + api = ClientCredentialsAuth(address='https://elasticsearch.icecube.aq', + token_url=options.token_url, + client_secret=options.client_secret, + client_id=options.client_id) + token = api.make_access_token() url = '{}://{}'.format(prefix, address) logging.info('connecting to ES at %s',url) @@ -69,8 +70,6 @@ def es_generator(entries): request_timeout=5000, bearer_auth=token) -print('made it here') - def es_import(document_generator): if options.dry_run: import json @@ -94,7 +93,6 @@ def es_import(document_generator): else: print(options.positionals) for path in options.positionals: - print(path) for filename in glob.glob(path): gen = es_generator(read_from_file(filename)) success = es_import(gen) diff --git a/condor_queue_to_es.py b/condor_queue_to_es.py index 62fd695..52e388e 100755 --- a/condor_queue_to_es.py +++ b/condor_queue_to_es.py @@ -19,9 +19,9 @@ help="query jobs, but do not ingest into ES",) parser.add_argument('--collectors', default=False, action='store_true', help='Args are collector addresses, not files') -parser.add_argument('--client_id',help='oauth2 client id') -parser.add_argument('--client_secret',help='oauth2 client secret') -parser.add_argument('--token_url',help='oauth2 realm token url') +parser.add_argument('--client_id',help='oauth2 client id',default=None) +parser.add_argument('--client_secret',help='oauth2 client secret',default=None) +parser.add_argument('--token_url',help='oauth2 realm token url',default=None) parser.add_argument("positionals", nargs='+') options = parser.parse_args() @@ -68,11 +68,14 @@ def es_generator(entries): url = '{}://{}'.format(prefix, address) -api = ClientCredentialsAuth(address='https://elasticsearch.icecube.aq', - token_url=options.token_url, - client_secret=options.client_secret, - client_id=options.client_id) -token = api.make_access_token() +token = None + +if None not in (options.token_url, options.client_secret, options.client_id): + api = ClientCredentialsAuth(address='https://elasticsearch.icecube.aq', + token_url=options.token_url, + client_secret=options.client_secret, + client_id=options.client_id) + token = api.make_access_token() logging.info('connecting to ES at %s',url) es = Elasticsearch(hosts=[url],