Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Token bugfix #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 45 additions & 37 deletions theia_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,49 @@ def checkDate(date_string):
###########################################################################


# ============================================================
# get a token to be allowed to bypass the authentification.
# The token is only valid for two hours. If your connection is slow
# or if you are downloading lots of products, it might be an issue
# =============================================================

def getToken(curl_proxy, config):

print("Get theia single sign on token")
get_token = 'curl -k -s -X POST %s --data-urlencode "ident=%s" --data-urlencode "pass=%s" %s/services/authenticate/>token.json' % (
curl_proxy, config["login_theia"], config["password_theia"], config["serveur"])

# print get_token

os.system(get_token)
print("Done")
token = ""
token_type = config["token_type"]
with open('token.json') as data_file:
try:
if token_type == "json":
token_json = json.load(data_file)
token = token_json["access_token"]

elif token_type == "text":
token = data_file.readline()

else:
print(str("error with config file, unknown token_type : %s" % token_type))
sys.exit(-1)
except:
print("Authentification is probably wrong")
print("check password file")
print("password should only contain alpha-numerics")
sys.exit(-1)
os.remove('token.json')

return token


###########################################################################


# ==================
# parse command line
# ==================
Expand Down Expand Up @@ -76,7 +119,7 @@ def checkDate(date_string):
parser.add_option("-l", "--location", dest="location", action="store", type="string",
help="town name (pick one which is not too frequent to avoid confusions)", default=None)
parser.add_option("-s", "--site", dest="site", action="store", type="string",
help="Ven�s Site name", default=None)
help="Venµs Site name", default=None)
parser.add_option("-a", "--alternative_config", dest="alternative_config", action="store", type="string",
help="alternative configuration file", default=None)
parser.add_option("-w", "--write_dir", dest="write_dir", action="store", type="string",
Expand Down Expand Up @@ -216,41 +259,6 @@ def checkDate(date_string):
(config["proxy"], config["login_proxy"], config["password_proxy"]))


# ============================================================
# get a token to be allowed to bypass the authentification.
# The token is only valid for two hours. If your connection is slow
# or if you are downloading lots of products, it might be an issue
# =============================================================

print("Get theia single sign on token")
get_token = 'curl -k -s -X POST %s --data-urlencode "ident=%s" --data-urlencode "pass=%s" %s/services/authenticate/>token.json' % (
curl_proxy, config["login_theia"], config["password_theia"], config["serveur"])

# print get_token

os.system(get_token)
print("Done")
token = ""
token_type = config["token_type"]
with open('token.json') as data_file:
try:
if token_type == "json":
token_json = json.load(data_file)
token = token_json["access_token"]

elif token_type == "text":
token = data_file.readline()

else:
print(str("error with config file, unknown token_type : %s" % token_type))
sys.exit(-1)
except:
print("Authentification is probably wrong")
print("check password file")
print("password should only contain alpha-numerics")
sys.exit(-1)
os.remove('token.json')

# ====================
# search catalogue
# ====================
Expand Down Expand Up @@ -321,7 +329,7 @@ def checkDate(date_string):
unzip_exists = False
tmpfile = "%s/%s.tmp" % (options.write_dir, prod)
get_product = 'curl %s -o "%s" -k -H "Authorization: Bearer %s" %s/%s/collections/%s/%s/download/?issuerId=theia' % (
curl_proxy, tmpfile, token, config["serveur"], config["resto"], options.collection, feature_id)
curl_proxy, tmpfile, getToken(curl_proxy, config), config["serveur"], config["resto"], options.collection, feature_id)
print(get_product)
if not(options.no_download) and not(file_exists) and not(unzip_exists):
# download only if cloudCover below maxcloud
Expand Down