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

Remove org ID check #293

Open
wants to merge 2 commits 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
59 changes: 2 additions & 57 deletions jovian/utils/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,66 +173,11 @@ def ensure_org(check_pro=True):
if check_pro and not is_flavor_pro():
return

# Read the credentials
creds = read_creds()
try:
org_id = creds[ORG_ID_KEY]
api_url = creds[API_URL_KEY]
webapp_url = creds[WEBAPP_URL_KEY]
if org_id and api_url and webapp_url:
return
except KeyError:
pass

# Request organization
org_id = request_org_id()

# Construct the webapp URL
if org_id:
webapp_url = 'https://' + org_id + '.jovian.ai/'
else:
org_id = DEFAULT_ORG_ID
webapp_url = 'https://jovian.ai/'

# Try to retrieve the config.json file from webapp
try:
config_url = webapp_url + 'config.json'
config_res = requests.get(config_url)
except ConnectionError as e:
msg = 'Failed to connect to ' + webapp_url + \
' . Please verify your organization ID and ensure you are connected to the internet.'
log(msg, error=True)
raise ConfigError(msg, e)

# Check for a successful response
if config_res.status_code != 200:
msg = 'Request to retrieve configuration file ' + config_url + \
' failed with status_code ' + str(config_res.status_code) + ' . ' + CONTACT_MSG
log(msg, error=True)
raise ConfigError(msg + ' Response (truncated):\n' +
config_res.text[:100])

# Parse JSON configuration
try:
config_json = config_res.json()
except JSONDecodeError as e:
msg = 'Failed to parse JSON configuration file from ' + \
config_url + ' . ' + CONTACT_MSG
log(msg, error=True)
raise ConfigError(msg + ' Response (truncated):\n' +
config_res.text[:100], e)

# Extract API URL
try:
api_url = config_json[API_URL_KEY]
except KeyError as e:
msg = 'Failed to extract API_URL from JSON configuration file ' + \
config_url + ' . ' + CONTACT_MSG
log(msg, error=True)
raise ConfigError(msg, e)
api_url = DEFAULT_API_URL
webapp_url = DEFAULT_WEBAPP_URL

# Save details to credentials file
write_org_id(org_id)
write_api_url(api_url)
write_webapp_url(webapp_url)

Expand Down