From: Aric Gardner Date: Thu, 6 Jun 2019 17:25:14 +0000 (-0400) Subject: lfidapi create group checks if group exists X-Git-Tag: v0.25.0~8^2 X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=e485d2a9da67087e0d06b02c9632bff43b69c239;p=releng%2Flftools.git lfidapi create group checks if group exists There is a bug in lfidapi where if a group exists the reponse code does the right thing but some shadow group is created. Add a check so that we only create a group if it does not yet exist. Signed-off-by: Aric Gardner Change-Id: Ia80400cf74431a8ffdea1ae06459969649d94501 --- diff --git a/lftools/lfidapi.py b/lftools/lfidapi.py index cd464f01..3033c135 100755 --- a/lftools/lfidapi.py +++ b/lftools/lfidapi.py @@ -30,6 +30,16 @@ def check_response_code(response): response.text)) +def helper_check_group_exists(group): + """List members of a group.""" + access_token, url = oauth_helper() + url = PARSE(url, group) + headers = {'Authorization': 'Bearer ' + access_token} + response = requests.get(url, headers=headers) + status_code = response.status_code + return status_code + + def helper_search_members(group): """List members of a group.""" access_token, url = oauth_helper() @@ -77,15 +87,19 @@ def helper_invite(email, group): def helper_create_group(group): """Create group.""" - access_token, url = oauth_helper() - url = '{}/'.format(url) - headers = {'Authorization': 'Bearer ' + access_token} - data = {"title": group, "type": "group"} - print(data) - response = requests.post(url, json=data, headers=headers) - check_response_code(response) - result = (response.json()) - print(json.dumps(result, indent=4, sort_keys=True)) + check_response_code = helper_check_group_exists(group) + if check_response_code == 200: + print("Group {} already exists exiting...".format(group)) + else: + access_token, url = oauth_helper() + url = '{}/'.format(url) + headers = {'Authorization': 'Bearer ' + access_token} + data = {"title": group, "type": "group"} + print(data) + response = requests.post(url, json=data, headers=headers) + check_response_code(response) + result = (response.json()) + print(json.dumps(result, indent=4, sort_keys=True)) def helper_match_ldap_to_info(info_file, group, noop): diff --git a/releasenotes/notes/lfidapi-3265c24947b95d20.yaml b/releasenotes/notes/lfidapi-3265c24947b95d20.yaml new file mode 100644 index 00000000..767be7bc --- /dev/null +++ b/releasenotes/notes/lfidapi-3265c24947b95d20.yaml @@ -0,0 +1,4 @@ +--- +fixes: + - | + lfidapi create group checks if group exists before posting