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

adapt manage_bootstrap_user.py to change in lib/galaxy/web/security introduced in Galaxy release_19.05 #61

Merged
merged 4 commits into from
Sep 29, 2019
Merged
Changes from 3 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
42 changes: 26 additions & 16 deletions files/manage_bootstrap_user.py
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\-]+$")
Expand All @@ -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):
Expand Down Expand Up @@ -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 ''


Expand All @@ -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:
Expand All @@ -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",
Expand Down Expand Up @@ -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,
Copy link
Member

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:

Suggested change
create_bootstrap_user(args.config, args.username, args.email,
create_bootstrap_user(args.config,
args.username,
args.email,

args.password, args.preset_api_key)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
args.password, args.preset_api_key)
args.password,
args.preset_api_key)

elif args.action == "delete":
delete_bootstrap_user(args.config, args.username)