Skip to content

Commit 1b74528

Browse files
author
Bernhard Grünewaldt
committed
userListFields working
1 parent ca72476 commit 1b74528

File tree

3 files changed

+50
-6
lines changed

3 files changed

+50
-6
lines changed

customfield_editor_plugin_client/cli_client.py

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,33 @@
88
from .model.user_input import UserInput
99
from .model.user_input_exception import UserInputException
1010
from .modules.admin_operations import AdminOperations
11+
from .modules.user_operations import UserOperations
1112

1213
def main():
14+
#
15+
# INIT
16+
#
1317
colorama.init(autoreset=True)
1418
printHelper = PrintHelper()
15-
1619
print(colorama.Fore.CYAN + '\n~~ REST API Client for Customfield Editor Plugin ~~ v1.2rc1')
1720

21+
#
22+
# CLI PARAMS
23+
#
1824
parser = argparse.ArgumentParser(description='Customfield Editor Plugin REST API CLI Client.')
1925
parser.add_argument("-cid", "--customFieldId", type=int, help='The ID of the custom field.')
2026
parser.add_argument("-ulist", "--userList", nargs='+', help='space separated user names to grant permission')
2127
parser.add_argument("-glist", "--groupList", nargs='+', help='space separated group names to grant permission')
22-
parser.add_argument("-a", "--action", help='Which action to execute.', choices=['adminListFields', 'adminGrantPermission'], required=True)
28+
parser.add_argument("-a", "--action", help='Which action to execute.', choices=['adminListFields', 'adminGrantPermission', 'userListFields'], required=True)
2329
parser.add_argument("-url", "--baseUrl", help='baseUrl to JIRA instance e.g. http://server:port/jira/', required=True)
2430
parser.add_argument("-user", "--authUsername", help='username for basic auth.', required=True)
2531
parser.add_argument("-pass", "--authPassword", help='password for basic auth.', required=True)
2632
args = parser.parse_args()
2733

2834

35+
#
36+
# INITIALIZE HELPERS
37+
#
2938
printHelper.step('initializing')
3039
try:
3140
userInput = UserInput(args.baseUrl, args.authUsername, args.authPassword)
@@ -34,9 +43,6 @@ def main():
3443
print (ex)
3544
sys.exit(1)
3645
printHelper.success('UserInput is valid.')
37-
38-
39-
4046
try:
4147
apiHelper = ApiHelper(userInput)
4248
except ApiHelperException as ex:
@@ -46,12 +52,25 @@ def main():
4652
printHelper.success('ApiHelper initialized.')
4753

4854

55+
#
56+
# INITIALIZE OPERATIONS
57+
#
4958
adminOperations = AdminOperations(apiHelper)
59+
userOperations = UserOperations(apiHelper)
60+
5061

62+
#
63+
# EXECUTE ACTIONS
64+
#
5165
try:
66+
printHelper.action(args.action)
5267

68+
#
69+
# ADMIN ACTIONS
70+
#
5371
# $> cep-client -a adminListFields -url http://localhost:2990/jira/ -user admin -pass admin
5472
if args.action == 'adminListFields':
73+
5574
adminOperations.list_fields()
5675

5776
#> cep-client -a adminGrantPermission --customFieldId 10100 --userList bob steve -url http://localhost:2990/jira -user admin -pass admin
@@ -60,6 +79,14 @@ def main():
6079
adminOperations.grant_permission(args.customFieldId, args.userList, args.groupList)
6180

6281

82+
#
83+
# USER ACTIONS
84+
#
85+
if args.action == 'userListFields':
86+
userOperations.list_fields()
87+
88+
89+
6390
except requests.ConnectionError as ex:
6491
print ('')
6592
printHelper.error('There seemed to a be problem with your request. Check errors above. EXIT')
@@ -70,6 +97,8 @@ def main():
7097
printHelper.error('There seemed to a be problem with your request. Check errors above. EXIT')
7198
sys.exit(1)
7299

73-
100+
#
101+
# EXIT SUCCESS
102+
#
74103
print ('\n')
75104
printHelper.success('EXIT gracefully')

customfield_editor_plugin_client/helper/print_helper.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,8 @@ def error(self, text):
2323
def step(self, text):
2424
print(colorama.Fore.CYAN + '\n> ' + text)
2525

26+
def action(self, text):
27+
print(colorama.Fore.MAGENTA + '\n# Action: ' + text)
28+
2629
def table(self, json):
2730
print(textwrap.indent(tabulate.tabulate(json, headers="keys"), ' '))
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from customfield_editor_plugin_client.helper.print_helper import PrintHelper
2+
from customfield_editor_plugin_client.helper.api_helper import ApiHelper
3+
4+
class UserOperations:
5+
6+
def __init__(self, api_helper):
7+
self._print = PrintHelper()
8+
self._api = api_helper
9+
10+
def list_fields(self):
11+
response_json = self._api.get('/user/customfields')
12+
self._print.table(response_json)

0 commit comments

Comments
 (0)