def handle_noargs(self, **options): try: directory_listing = os.listdir(settings.CUSTOM_INSTALLER_ROOT) for entry_name in directory_listing: build_directory = os.path.join(settings.CUSTOM_INSTALLER_ROOT, entry_name) vesselinfo_filename = os.path.join(build_directory, 'vesselinfo') # We assume that if the base installers directory is in the mix, it # doesn't have a vesselinfo file. Therefore, it will automatically be spared. if os.path.isdir(build_directory) and os.path.isfile(vesselinfo_filename): # If the purge option is set, delete the whole directory. if options['purge']: shutil.rmtree(build_directory) continue # Otherwise, just remove the installers. for platform in constants.PLATFORM_BUNDLES: installer_filename = os.path.join(build_directory, constants.PLATFORM_BUNDLES[platform]) if os.path.isfile(installer_filename): os.remove(installer_filename) if options['purge']: print 'All custom installer data is now removed. Users will not be able to access their previous builds.' else: print 'All custom installers are now removed. New installers will be generated upon request.' except: log_exception() raise CommandError('Unable to remove custom installers!')
def build_installers(request): """ <Purpose> Uses the build data from the user's session to build the installers and cryptogrpahic key packages. Designed for AJAX use. <Arguments> request: A Django request. <Exceptions> None. <Side Effects> The created packages will be written to the appropriate location on disk. <Returns> A Django response with text indicating success or error. """ if 'build_string' not in request.session: return ErrorReponse('No build data provided.') build_data = json.loads(request.session['build_string']) user_data = {} for user in build_data['users']: user_data[user['name']] = {'public_key': user['public_key']} try: manager = BuildManager(vessel_list=build_data['vessels'], user_data=user_data) build_results = manager.prepare() except validations.ValidationError as e: return ErrorResponse(e) except: log_exception(request) return ErrorResponse( 'Unknown error occured while trying to build the installers.') else: # Save the build results so that the download pages can access the information. build_id = build_results['build_id'] if 'build_results' in request.session: request.session['build_results'][build_id] = build_results request.session.save() else: request.session['build_results'] = {build_id: build_results} return TextResponse( reverse('download-keys-page', kwargs={'build_id': manager.build_id}))
def build_installers(request): """ <Purpose> Uses the build data from the user's session to build the installers and cryptogrpahic key packages. Designed for AJAX use. <Arguments> request: A Django request. <Exceptions> None. <Side Effects> The created packages will be written to the appropriate location on disk. <Returns> A Django response with text indicating success or error. """ if 'build_string' not in request.session: return ErrorReponse('No build data provided.') build_data = json.loads(request.session['build_string']) user_data = {} for user in build_data['users']: user_data[user['name']] = {'public_key': user['public_key']} try: manager = BuildManager(vessel_list=build_data['vessels'], user_data=user_data) build_results = manager.prepare() except validations.ValidationError as e: return ErrorResponse(e) except: log_exception(request) return ErrorResponse('Unknown error occured while trying to build the installers.') else: # Save the build results so that the download pages can access the information. build_id = build_results['build_id'] if 'build_results' in request.session: request.session['build_results'][build_id] = build_results request.session.save() else: request.session['build_results'] = {build_id: build_results} return TextResponse(reverse('download-keys-page', kwargs={'build_id': manager.build_id}))
def add_user(request): """ <Purpose> Reponds to an HTML <form> submission to create a new user. Designed for use in a hidden <iframe>, due to browser limitations on file uploading. <Arguments> request: A Django request with user info in the POST data. <Exceptions> None. <Side Effects> None. <Returns> A Django response containing a JSON representation of the new user, or an error. """ def ErrorResponse(message=''): return TextResponse(json.dumps({'error': message})) if 'name' not in request.POST: return ErrorResponse('User name not specified.') name = request.POST['name'] public_key = None if 'public_key' in request.FILES: public_file = request.FILES['public_key'] public_key = public_file.read().strip() try: validations.validate_username(name) if public_key is not None: validations.validate_public_key(public_key) except validations.ValidationError as e: return ErrorResponse(e) except: log_exception(request) return ErrorResponse('Unknown error occured while trying to add user.') else: return TextResponse( json.dumps({'user': { 'name': name, 'public_key': public_key }}))
def add_user(request): """ <Purpose> Reponds to an HTML <form> submission to create a new user. Designed for use in a hidden <iframe>, due to browser limitations on file uploading. <Arguments> request: A Django request with user info in the POST data. <Exceptions> None. <Side Effects> None. <Returns> A Django response containing a JSON representation of the new user, or an error. """ def ErrorResponse(message=''): return TextResponse(json.dumps({'error': message})) if 'name' not in request.POST: return ErrorResponse('User name not specified.') name = request.POST['name'] public_key = None if 'public_key' in request.FILES: public_file = request.FILES['public_key'] public_key = public_file.read().strip() try: validations.validate_username(name) if public_key is not None: validations.validate_public_key(public_key) except validations.ValidationError as e: return ErrorResponse(e) except: log_exception(request) return ErrorResponse('Unknown error occured while trying to add user.') else: return TextResponse(json.dumps({'user': {'name': name, 'public_key': public_key}}))
def handle_noargs(self, **options): try: directory_listing = os.listdir(settings.CUSTOM_INSTALLER_ROOT) for entry_name in directory_listing: build_directory = os.path.join(settings.CUSTOM_INSTALLER_ROOT, entry_name) vesselinfo_filename = os.path.join(build_directory, 'vesselinfo') # We assume that if the base installers directory is in the mix, it # doesn't have a vesselinfo file. Therefore, it will automatically be spared. if os.path.isdir(build_directory) and os.path.isfile( vesselinfo_filename): # If the purge option is set, delete the whole directory. if options['purge']: shutil.rmtree(build_directory) continue # Otherwise, just remove the installers. for platform in constants.PLATFORM_BUNDLES: installer_filename = os.path.join( build_directory, constants.PLATFORM_BUNDLES[platform]) if os.path.isfile(installer_filename): os.remove(installer_filename) if options['purge']: print 'All custom installer data is now removed. Users will not be able to access their previous builds.' else: print 'All custom installers are now removed. New installers will be generated upon request.' except: log_exception() raise CommandError('Unable to remove custom installers!')
def fastlane_page(request): """ <Purpose> Renders a key and installer download page for a default user-built seattle build, i.e.: One 80 per-cent vessel, one owner/user Note: owner/user-name can be set in settings.FASTLANE_USER_NAME <Arguments> request: A Django request. <Exceptions> None. <Side Effects> If new session - Creates and stores vesselinfo to appropriate location on disk - Stores generated key pair to session (memory) <Returns> A Django response. """ try: existing_build_result = False # We have to check if the user already has a build result in his session # and make sure it's a fastlane build, i.e. # it does not collide with a build from the interactive CIB if 'build_results' in request.session.keys(): for val in request.session['build_results'].values(): if isinstance(val, dict) and val.get("fast_lane_build"): existing_build_result = val break else: # This dict will only be saved if the build succeeds request.session['build_results'] = {} if existing_build_result: # There is no need to build again, let's serve what's already there build_id = existing_build_result.get('build_id') keys_downloaded = existing_build_result.get('keys_downloaded', dict()) # The manager helps us to find the files stored to disk manager = BuildManager(build_id=build_id) installer_links = manager.get_urls() else: # The user is here for the first time # Create basic installation setup (1 owner, 1 vessel, no users) users = { settings.FASTLANE_USER_NAME: {u'public_key': None} } vessels = [ { u'owner': settings.FASTLANE_USER_NAME, u'percentage': 80, u'users': [] } ] # Use build manager to create and store vesselinfo # and create cryptographic key pair (only stored in memory) manager = BuildManager(vessel_list=vessels, user_data=users) new_fastlane_build_results = manager.prepare() # These are needed in the HTML template to render the proper links # to the keys and installer build_id = manager.build_id installer_links = manager.get_urls() # Used in template to display check marks next to buttons # The keys are new so they cannot have been downloaded keys_downloaded = False # This prevents collision when using interactive CIB and fastlane CIB # in the same session # also hides breadcrumbs when serving shared (w/o key links) fastlane # download page new_fastlane_build_results["fast_lane_build"] = True # download_installer and download_keys views get the build_results # from the session to serve the correct files request.session['build_results'][build_id] = new_fastlane_build_results request.session.save() except: log_exception(request) return ErrorResponse('Unknown error occured while' + \ ' trying to build the installers.') # Builds share_url by using view URLreversing and the request object share_url = request.build_absolute_uri(reverse('download-installers-page', args=[build_id])) return render(request, 'download_installers.html', { 'fast_lane': True, 'build_id': build_id, 'installers': installer_links, 'share_url': share_url, 'keys_downloaded': keys_downloaded, })
return ErrorReponse('No build data provided.') build_data = json.loads(request.session['build_string']) user_data = {} for user in build_data['users']: user_data[user['name']] = {'public_key': user['public_key']} try: manager = BuildManager(vessel_list=build_data['vessels'], user_data=user_data) build_results = manager.prepare() except validations.ValidationError, e: return ErrorResponse(e.message) except: log_exception(request) return ErrorResponse('Unknown error occured while trying to build the installers.') else: # Save the build results so that the download pages can access the information. build_id = build_results['build_id'] if 'build_results' in request.session: request.session['build_results'][build_id] = build_results request.session.save() else: request.session['build_results'] = {build_id: build_results} return TextResponse(reverse('download-keys-page', kwargs={'build_id': manager.build_id}))
def fastlane_page(request): """ <Purpose> Renders a key and installer download page for a default user-built seattle build, i.e.: One 80 per-cent vessel, one owner/user Note: owner/user-name can be set in settings.FASTLANE_USER_NAME <Arguments> request: A Django request. <Exceptions> None. <Side Effects> If new session - Creates and stores vesselinfo to appropriate location on disk - Stores generated key pair to session (memory) <Returns> A Django response. """ try: existing_build_result = False # We have to check if the user already has a build result in his session # and make sure it's a fastlane build, i.e. # it does not collide with a build from the interactive CIB if 'build_results' in request.session.keys(): for val in request.session['build_results'].values(): if isinstance(val, dict) and val.get("fast_lane_build"): existing_build_result = val break else: # This dict will only be saved if the build succeeds request.session['build_results'] = {} if existing_build_result: # There is no need to build again, let's serve what's already there build_id = existing_build_result.get('build_id') keys_downloaded = existing_build_result.get( 'keys_downloaded', dict()) # The manager helps us to find the files stored to disk manager = BuildManager(build_id=build_id) installer_links = manager.get_urls() else: # The user is here for the first time # Create basic installation setup (1 owner, 1 vessel, no users) users = {settings.FASTLANE_USER_NAME: {u'public_key': None}} vessels = [{ u'owner': settings.FASTLANE_USER_NAME, u'percentage': 80, u'users': [] }] # Use build manager to create and store vesselinfo # and create cryptographic key pair (only stored in memory) manager = BuildManager(vessel_list=vessels, user_data=users) new_fastlane_build_results = manager.prepare() # These are needed in the HTML template to render the proper links # to the keys and installer build_id = manager.build_id installer_links = manager.get_urls() # Used in template to display check marks next to buttons # The keys are new so they cannot have been downloaded keys_downloaded = False # This prevents collision when using interactive CIB and fastlane CIB # in the same session # also hides breadcrumbs when serving shared (w/o key links) fastlane # download page new_fastlane_build_results["fast_lane_build"] = True # download_installer and download_keys views get the build_results # from the session to serve the correct files request.session['build_results'][ build_id] = new_fastlane_build_results request.session.save() except: log_exception(request) return ErrorResponse('Unknown error occured while' + \ ' trying to build the installers.') # Builds share_url by using view URLreversing and the request object share_url = request.build_absolute_uri( reverse('download-installers-page', args=[build_id])) return render( request, 'download_installers.html', { 'fast_lane': True, 'build_id': build_id, 'installers': installer_links, 'share_url': share_url, 'keys_downloaded': keys_downloaded, })