Skip to content

Commit

Permalink
tmp: prep for new auth method
Browse files Browse the repository at this point in the history
  • Loading branch information
keara-soloway authored May 30, 2024
1 parent 9e2728d commit 6515c7e
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions chessdata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# URL = 'https://chessdata.classe.cornell.edu:8243'
URL = 'https://chessdata.classe.cornell.edu:8244'

def get_contents(file):
def get_ticket(file):
"""Return the contents of a file as a byte string.
:param file: name of a file
Expand All @@ -20,6 +20,11 @@ def get_contents(file):
contents = f.read()
return contents

def get_token(ticket):
"""Get the kerberos token from a ticket"""
# foxden token create read/write
return 'bla'

def query(query, krb_file='~/krb5_ccache', url=URL):
"""Search the chess metadata database and return matching records
as JSON
Expand All @@ -35,16 +40,18 @@ def query(query, krb_file='~/krb5_ccache', url=URL):
:return: list of matching records
:rtype: list[dict]
"""
ticket = get_ticket(krb_file)
resp = requests.post(
f'{url}/search',
data={
'query': query,
'name': os.path.basename(krb_file),
'ticket': get_contents(krb_file),
'ticket': ticket,
'client': 'cli'
},
headers={
'Content-Type': 'application/x-www-form-urlencoded'
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': f'bearer {get_token(ticket)}'
}
)
return resp.json()
Expand All @@ -67,16 +74,18 @@ def insert(record, schema, krb_file='~/krb5_ccache', url=URL):
:return: response from the CHESS metadata server
:rtype: requests.Response
"""
ticket = get_ticket(krb_file)
resp = requests.post(
f'{url}/api',
data={
'record': get_contents(record),
'SchemaName': schema,
'name': os.path.basename(krb_file),
'ticket': get_contents(krb_file)
'ticket': ticket
},
headers={
'Content-Type': 'application/x-www-form-urlencoded'
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': f'bearer {get_token(ticket)}'
}
)
return resp

0 comments on commit 6515c7e

Please sign in to comment.