-
Notifications
You must be signed in to change notification settings - Fork 34
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
adapt manage_bootstrap_user.py to change in lib/galaxy/web/security introduced in Galaxy release_19.05 #61
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
19aebbc
adapt to https://github.com/galaxyproject/galaxy/commit/528497f7c42f8…
drosofff d931fc2
pep8 linting of manage_bootstrap_user.py
drosofff d15a73f
comment code supporting switch from galaxy.web.security to galaxy.sec…
drosofff b2baf08
Use one argument per line
mvdbeek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -1,26 +1,30 @@ | ||||||||
#!/usr/bin/env python | ||||||||
|
||||||||
import ConfigParser | ||||||||
import argparse | ||||||||
import logging | ||||||||
import os | ||||||||
import re | ||||||||
import sys | ||||||||
|
||||||||
import galaxy.config | ||||||||
from galaxy import eggs | ||||||||
from galaxy.model import mapping | ||||||||
|
||||||||
import yaml | ||||||||
|
||||||||
import argparse | ||||||||
try: | ||||||||
from galaxy.security.idencoding import IdEncodingHelper as Security | ||||||||
except ImportError: | ||||||||
# maintains backwards compatibility with galaxy versions < 19.05 | ||||||||
# see https://github.com/galaxyproject/galaxy/pull/7560 | ||||||||
from galaxy.web.security import SecurityHelper as Security | ||||||||
|
||||||||
eggs.require("SQLAlchemy >= 0.4") | ||||||||
eggs.require("mercurial") | ||||||||
new_path = [os.path.join(os.getcwd(), "lib")] | ||||||||
new_path.extend(sys.path[1:]) | ||||||||
sys.path = new_path | ||||||||
|
||||||||
from galaxy import eggs | ||||||||
eggs.require("SQLAlchemy >= 0.4") | ||||||||
eggs.require("mercurial") | ||||||||
|
||||||||
import galaxy.config | ||||||||
from galaxy.web import security | ||||||||
from galaxy.model import mapping | ||||||||
|
||||||||
logging.captureWarnings(True) | ||||||||
|
||||||||
VALID_PUBLICNAME_RE = re.compile("^[a-z0-9\-]+$") | ||||||||
|
@@ -43,7 +47,7 @@ def __init__(self, config): | |||||||
self.config.database_connection, | ||||||||
engine_options={}, | ||||||||
create_tables=False) | ||||||||
self.security = security.SecurityHelper(id_secret=self.config.id_secret) | ||||||||
self.security = Security(id_secret=self.config.id_secret) | ||||||||
|
||||||||
@property | ||||||||
def sa_session(self): | ||||||||
|
@@ -189,7 +193,8 @@ def validate_publicname(username): | |||||||
if len(username) > 255: | ||||||||
return "Public name cannot be more than 255 characters in length" | ||||||||
if not(VALID_PUBLICNAME_RE.match(username)): | ||||||||
return "Public name must contain only lower-case letters, numbers and '-'" | ||||||||
return "Public name must contain only lower-case letters, \ | ||||||||
numbers and '-'" | ||||||||
return '' | ||||||||
|
||||||||
|
||||||||
|
@@ -209,7 +214,8 @@ def get_bootstrap_app(ini_file): | |||||||
return app | ||||||||
|
||||||||
|
||||||||
def create_bootstrap_user(ini_file, username, user_email, password, preset_api_key=None): | ||||||||
def create_bootstrap_user(ini_file, username, user_email, password, | ||||||||
preset_api_key=None): | ||||||||
app = get_bootstrap_app(ini_file) | ||||||||
user = get_or_create_user(app, user_email, password, username) | ||||||||
if user is not None: | ||||||||
|
@@ -231,16 +237,19 @@ def delete_bootstrap_user(ini_file, username): | |||||||
log.error("Problem deleting user: {0}".format(username)) | ||||||||
exit(1) | ||||||||
|
||||||||
|
||||||||
if __name__ == "__main__": | ||||||||
global log | ||||||||
log = _setup_global_logger() | ||||||||
parser = argparse.ArgumentParser(description="usage: python %prog [options]") | ||||||||
parser = argparse.ArgumentParser( | ||||||||
description="usage: python %prog [options]") | ||||||||
parser.add_argument("-c", "--config", | ||||||||
required=True, | ||||||||
help="Path to <galaxy .ini file>") | ||||||||
subparsers = parser.add_subparsers( | ||||||||
title="action", help='create or delete bootstrap users') | ||||||||
parser_create = subparsers.add_parser('create', help='create a new bootstrap user') | ||||||||
parser_create = subparsers.add_parser('create', | ||||||||
help='create a new bootstrap user') | ||||||||
parser_create.set_defaults(action='create') | ||||||||
parser_create.add_argument("-u", "--username", | ||||||||
default="cloud", | ||||||||
|
@@ -268,6 +277,7 @@ def delete_bootstrap_user(ini_file, username): | |||||||
args = parser.parse_args() | ||||||||
|
||||||||
if args.action == "create": | ||||||||
create_bootstrap_user(args.config, args.username, args.email, args.password, args.preset_api_key) | ||||||||
create_bootstrap_user(args.config, args.username, args.email, | ||||||||
args.password, args.preset_api_key) | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
elif args.action == "delete": | ||||||||
delete_bootstrap_user(args.config, args.username) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When breaking up long argument lines we usually make this one argument per line: