Skip to content

Commit

Permalink
task: add token logic to default script and migration tool
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominick Leppich committed Sep 2, 2024
1 parent 7e00458 commit 21d3bec
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
3 changes: 2 additions & 1 deletion install/default_setup.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/usr/bin/env bash
HOST='localhost:8081/api/v1'
TOKEN='secret'

curl_call() {
curl --location "$HOST/$1" --header 'Content-Type: application/json' --data "$2"
curl --location "$HOST/$1" --header 'Content-Type: application/json' --header "Authorization: Bearer $TOKEN" --data "$2"
}

create_language() {
Expand Down
4 changes: 3 additions & 1 deletion migration/lib/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
SCHEMA_LOOKUP = 9

class API:
def __init__(self, host, port):
def __init__(self, host, port, token):
self.urls = {}
self.urls[SCHEMA_INSERTION] = SCHEMA_INSERTION_URL
self.urls[VOCABULARY_INSERTION] = VOCABULARY_INSERTION_URL
Expand All @@ -45,6 +45,8 @@ def __init__(self, host, port):
self.type_counter = 1
for u in self.urls:
self.urls[u] = self.urls[u].replace('{{HOST}}', host).replace('{{PORT}}', port)
if token != None:
HEADERS['Authorization'] = f'Bearer {token}'

def set_context(self, ctx):
self.ctx = ctx
Expand Down
4 changes: 3 additions & 1 deletion migration/metadata-migrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ def main():

api = API(
args.vocabulary_server_host,
args.vocabulary_server_port
args.vocabulary_server_port,
args.vocabulary_server_token
)
ctx = Context(api, args.dry, args.verbose, args.continue_on_error, args.metadata_directory, args.mapping_file, args.preferred_mets_main_value_language, args.manual_id_fix)

Expand All @@ -36,6 +37,7 @@ def parse_args():
parser.add_argument('--mapping-file', '-m', required=True, help='vocabulary and record mapping file')
parser.add_argument('--vocabulary-server-host', type=str, default='localhost', help='vocabulary server host')
parser.add_argument('--vocabulary-server-port', type=str, default='8081', help='vocabulary server port')
parser.add_argument('--vocabulary-server-token', type=str, default=None, help='vocabulary server security token')
parser.add_argument('--preferred-mets-main-value-language', type=str, default='eng', help='Default language to use for mets value writing, if present and prior value invalid')
parser.add_argument('--manual-id-fix', type=str, default=None, help='Manually fix the record ID of elements whose name attribute matches this parameter. Caution, this must not be executed twice!')
parser.add_argument('--log', required=False, default='INFO', help='logger level (possible values are: NOTSET, DEBUG, INFO, WARNING, ERROR, CRITICAL)')
Expand Down
4 changes: 3 additions & 1 deletion migration/vocabulary-migrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ def main():
)
api = API(
args.vocabulary_server_host,
args.vocabulary_server_port
args.vocabulary_server_port,
args.vocabulary_server_token
)
ctx = Context(db, api, args.dry, args.fallback_language, args.continue_on_error, args.lookup_file_directory)
api.set_context(ctx)
Expand All @@ -45,6 +46,7 @@ def parse_args():
parser.add_argument('--dry', type=str, required=False, help='Don\'t call the API but instead write the API calls to a file, provide the filename as a parameter')
parser.add_argument('--vocabulary-server-host', type=str, default='localhost', help='vocabulary server host')
parser.add_argument('--vocabulary-server-port', type=str, default='8081', help='vocabulary server port')
parser.add_argument('--vocabulary-server-token', type=str, default=None, help='vocabulary server security token')
parser.add_argument('--goobi-database-host', type=str, default='localhost', help='Goobi database host')
parser.add_argument('--goobi-database-port', type=str, default='3306', help='Goobi database port')
parser.add_argument('--goobi-database-name', type=str, default='goobi', help='Goobi database name')
Expand Down

0 comments on commit 21d3bec

Please sign in to comment.