Files
@ dba6c44f0a30
Branch filter:
Location: kallithea/kallithea/bin/kallithea_api.py
dba6c44f0a30
4.3 KiB
text/x-python
auth: Fix bug where usernames are not consistently capitalized when using crowd login
If you try to log in to Kallithea via the Crowd auth module then the
capitalization of your username in Kallithea changes on every login based on
how you capitalized it in the login form.
E.g. Log in with "TestDude", username is entered as "TestDude" then log in
again, but this time as "tesTduDe", and your username gets changed to
"tesTduDe". etc.
Fix for this is to use the 'name' field returned from Crowd when saving the
username. This way the username is always capitalized identically to the record
in Crowd.
If you try to log in to Kallithea via the Crowd auth module then the
capitalization of your username in Kallithea changes on every login based on
how you capitalized it in the login form.
E.g. Log in with "TestDude", username is entered as "TestDude" then log in
again, but this time as "tesTduDe", and your username gets changed to
"tesTduDe". etc.
Fix for this is to use the 'name' field returned from Crowd when saving the
username. This way the username is always capitalized identically to the record
in Crowd.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | # -*- coding: utf-8 -*-
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
kallithea.bin.kallithea_api
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Api CLI client for Kallithea
This file was forked by the Kallithea project in July 2014.
Original author and date, and relevant copyright and licensing information is below:
:created_on: Jun 3, 2012
:author: marcink
:copyright: (c) 2013 RhodeCode GmbH, and others.
:license: GPLv3, see LICENSE.md for more details.
"""
import sys
import argparse
from kallithea.bin.base import json, api_call, RcConf, FORMAT_JSON, FORMAT_PRETTY
def argparser(argv):
usage = (
"kallithea-api [-h] [--format=FORMAT] [--apikey=APIKEY] [--apihost=APIHOST] "
"[--config=CONFIG] [--save-config] "
"METHOD <key:val> <key2:val> ...\n"
"Create config file: kallithea-api --apikey=<key> --apihost=http://kallithea.example.com --save-config"
)
parser = argparse.ArgumentParser(description='Kallithea API cli',
usage=usage)
## config
group = parser.add_argument_group('config')
group.add_argument('--apikey', help='api access key')
group.add_argument('--apihost', help='api host')
group.add_argument('--config', help='config file')
group.add_argument('--save-config', action='store_true', help='save the given config into a file')
group = parser.add_argument_group('API')
group.add_argument('method', metavar='METHOD', nargs='?', type=str, default=None,
help='API method name to call followed by key:value attributes',
)
group.add_argument('--format', dest='format', type=str,
help='output format default: `%s` can '
'be also `%s`' % (FORMAT_PRETTY, FORMAT_JSON),
default=FORMAT_PRETTY
)
args, other = parser.parse_known_args()
return parser, args, other
def main(argv=None):
"""
Main execution function for cli
:param argv:
"""
if argv is None:
argv = sys.argv
conf = None
parser, args, other = argparser(argv)
api_credentials_given = (args.apikey and args.apihost)
if args.save_config:
if not api_credentials_given:
raise parser.error('--save-config requires --apikey and --apihost')
conf = RcConf(config_location=args.config,
autocreate=True, config={'apikey': args.apikey,
'apihost': args.apihost})
sys.exit()
if not conf:
conf = RcConf(config_location=args.config, autoload=True)
if not conf:
if not api_credentials_given:
parser.error('Could not find config file and missing '
'--apikey or --apihost in params')
apikey = args.apikey or conf['apikey']
apihost = args.apihost or conf['apihost']
method = args.method
# if we don't have method here it's an error
if not method:
parser.error('Please specify method name')
try:
margs = dict(map(lambda s: s.split(':', 1), other))
except ValueError:
sys.stderr.write('Error parsing arguments \n')
sys.exit()
if args.format == FORMAT_PRETTY:
print 'Calling method %s => %s' % (method, apihost)
json_resp = api_call(apikey, apihost, method, **margs)
error_prefix = ''
if json_resp['error']:
error_prefix = 'ERROR:'
json_data = json_resp['error']
else:
json_data = json_resp['result']
if args.format == FORMAT_JSON:
print json.dumps(json_data)
elif args.format == FORMAT_PRETTY:
print 'Server response \n%s%s' % (
error_prefix, json.dumps(json_data, indent=4, sort_keys=True)
)
return 0
if __name__ == '__main__':
sys.exit(main(sys.argv))
|