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

task/DES-2561: create Scratch dir on login #1081

Merged
merged 7 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
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
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
1 change: 1 addition & 0 deletions designsafe/settings/common_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@

AGAVE_TOKEN_SESSION_ID = os.environ.get('AGAVE_TOKEN_SESSION_ID', 'agave_token')
AGAVE_STORAGE_SYSTEM = os.environ.get('AGAVE_STORAGE_SYSTEM')
AGAVE_WORKING_SYSTEM = os.environ.get('AGAVE_WORKING_SYSTEM', 'designsafe.storage.frontera.scratch')

AGAVE_JWT_PUBKEY = os.environ.get('AGAVE_JWT_PUBKEY')
AGAVE_JWT_ISSUER = os.environ.get('AGAVE_JWT_ISSUER')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ class DataDepotNavCtrl {
state: 'myData',
description: 'Private directory for your data'
},
{
name: 'Working Files (scratch Frontera)',
collapsible: false,
state: 'myDataScratch',
description: 'Scratch directory on Frontera for use with JupyterHub'
},
{
name: 'My Projects',
collapsible: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class DataDepotToolbarCtrl {
placeholder() {
var stateNames = {
'myData': 'My Data',
'myDataScratch': 'Working Files (scratch Frontera)',
'projects.list': 'My Projects',
'sharedData': 'Shared Data',
'boxData': 'Box',
Expand Down
33 changes: 33 additions & 0 deletions designsafe/static/scripts/data-depot/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,39 @@ function config(
},
},
})
.state('myDataScratch', {
url: '/agave/{systemId}/{filePath:any}/?query_string&offset&limit',
component: 'dataDepotBrowser',
params: {
systemId: 'designsafe.storage.frontera.scratch',
filePath: Django.user,
},
resolve: {
apiParams: ()=> {
return {
fileMgr: 'agave',
};
},
path: ($stateParams, Django) => {
'ngInject';
if ($stateParams.filePath.replace(/^\/+/, '') === '') {
return Django.user;
}
return $stateParams.filePath;
},
auth: ($q, Django) => {
'ngInject';
if (Django.context.authenticated) {
return true;
}

return $q.reject({
type: 'authn',
context: Django.context,
});
},
},
})
.state('sharedData', {
url: '/shared/{systemId}/{filePath:any}?query_string',
component: 'dataDepotBrowser',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class FileOperationService {

getTests(files) {
const externalDataStates = ['boxData', 'dropboxData', 'googledriveData'];
const agaveDataStates = ['myData', 'projects.view', 'projects.curation'];
const agaveDataStates = ['myData', 'myDataScratch', 'projects.view', 'projects.curation'];
let isHazmapper = files.length > 0 ? files.some((e) => e.name.endsWith('hazmapper')) : false;
const tests = {
copy: this.Django.context.authenticated && !isHazmapper && files.length > 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class WorkspaceDataBrowserCtrl {

this.options = [
{ name: 'myData', label: 'My Data' },
{ name: 'myDataScratch', label: 'Working Files (scratch Frontera)' },
{ name: 'myProjects', label: 'My Projects' },
{ name: 'publications', label: 'Published' },
{ name: 'nees', label: 'Published (NEES)' },
Expand Down Expand Up @@ -58,6 +59,17 @@ class WorkspaceDataBrowserCtrl {
});
this.breadcrumbParams = this.FileListingService.fileMgrMappings.agave.breadcrumbParams;
break;
case 'myDataScratch':
this.listingType = 'files';
this.FileListingService.browse({
section: 'main',
api: 'agave',
scheme: 'private',
system: 'designsafe.storage.frontera.scratch',
path: this.Django.user,
});
this.breadcrumbParams = this.FileListingService.fileMgrMappings.agave.breadcrumbParams;
break;
case 'myProjects':
this.listingType = 'projects';
this.ProjectService.listProjects({ section: 'main' });
Expand Down
Loading