Skip to content

Commit

Permalink
create myworkingfiles dir on login
Browse files Browse the repository at this point in the history
  • Loading branch information
rstijerina committed Aug 3, 2023
1 parent a4ff9f9 commit 4a89aae
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
1 change: 1 addition & 0 deletions conf/env_files/designsafe.sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ AGAVE_CLIENT_SECRET=
AGAVE_SUPER_TOKEN=

AGAVE_STORAGE_SYSTEM=
AGAVE_WORKING_SYSTEM=
AGAVE_JWT_PUBKEY=
AGAVE_JWT_ISSUER=
AGAVE_JWT_HEADER=
Expand Down
4 changes: 3 additions & 1 deletion designsafe/apps/accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,9 @@ def email_confirmation(request, code=None):
user = tas.get_user(username=username)
if tas.verify_user(user['id'], code, password=password):
logger.info('TAS Account activation succeeded.')
check_or_create_agave_home_dir.apply(args=(user["username"],))
from django.conf import settings
check_or_create_agave_home_dir.apply_async(args=(user.username, settings.AGAVE_STORAGE_SYSTEM))
check_or_create_agave_home_dir.apply_async(args=(user.username, settings.AGAVE_WORKING_SYSTEM))
return HttpResponseRedirect(reverse('designsafe_accounts:manage_profile'))
else:
messages.error(request,
Expand Down
12 changes: 6 additions & 6 deletions designsafe/apps/auth/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,28 @@


@shared_task(default_retry_delay=1*30, max_retries=3)
def check_or_create_agave_home_dir(username):
def check_or_create_agave_home_dir(username, systemId):
try:
# TODO should use OS calls to create directory.
logger.info(
"Checking home directory for user=%s on "
"default storage systemId=%s",
username,
settings.AGAVE_STORAGE_SYSTEM
systemId
)
ag = Agave(api_server=settings.AGAVE_TENANT_BASEURL,
token=settings.AGAVE_SUPER_TOKEN)
try:
listing_response = ag.files.list(
systemId=settings.AGAVE_STORAGE_SYSTEM,
systemId=systemId,
filePath=username)
logger.info('check home dir response: {}'.format(listing_response))

except HTTPError as e:
if e.response.status_code == 404:
logger.info("Creating the home directory for user=%s then going to run setfacl", username)
body = {'action': 'mkdir', 'path': username}
fm_response = ag.files.manage(systemId=settings.AGAVE_STORAGE_SYSTEM,
fm_response = ag.files.manage(systemId=systemId,
filePath='',
body=body)
logger.info('mkdir response: {}'.format(fm_response))
Expand Down Expand Up @@ -62,13 +62,13 @@ def check_or_create_agave_home_dir(username):

# add dir to index
logger.info("Indexing the home directory for user=%s", username)
agave_indexer.apply_async(kwargs={'username': username, 'systemId': settings.AGAVE_STORAGE_SYSTEM, 'filePath': username}, queue='indexing')
agave_indexer.apply_async(kwargs={'username': username, 'systemId': systemId, 'filePath': username}, queue='indexing')

except(AgaveException):
#except (HTTPError, AgaveException):
logger.exception('Failed to create home directory.',
extra={'user': username,
'systemId': settings.AGAVE_STORAGE_SYSTEM})
'systemId': systemId})


@shared_task(default_retry_delay=1*30, max_retries=3)
Expand Down
15 changes: 11 additions & 4 deletions designsafe/apps/auth/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def agave_oauth_callback(request):
http://agaveapi.co/documentation/authorization-guide/#authorization_code_flow
"""
state = request.GET.get('state')

if request.session['auth_state'] != state:
msg = (
'OAuth Authorization State mismatch!? auth_state=%s '
Expand Down Expand Up @@ -152,7 +152,7 @@ def agave_oauth_callback(request):
token_data['created'] = int(time.time())
# log user in
user = authenticate(backend='agave', token=token_data['access_token'])

if user:
try:
token = user.agave_oauth
Expand All @@ -172,8 +172,15 @@ def agave_oauth_callback(request):
filePath=user.username)
except HTTPError as e:
if e.response.status_code == 404:
check_or_create_agave_home_dir.apply_async(args=(user.username,),queue='files')

check_or_create_agave_home_dir.apply_async(args=(user.username, settings.AGAVE_STORAGE_SYSTEM),queue='files')

try:
ag.files.list(systemId=settings.AGAVE_WORKING_SYSTEM,
filePath=user.username)
except HTTPError as e:
if e.response.status_code == 404:
check_or_create_agave_home_dir.apply_async(args=(user.username, settings.AGAVE_WORKING_SYSTEM),queue='files')

else:
messages.error(
request,
Expand Down

0 comments on commit 4a89aae

Please sign in to comment.