Baisc org deletion

This commit is contained in:
chris 2020-08-02 21:52:35 +02:00
parent e51e465709
commit 5a4dbf755d
1 changed files with 18 additions and 4 deletions

View File

@ -106,9 +106,12 @@ def run_module():
headers = {
"Content-Type": "application/json",
}
gitea_url = module.params['gitea_url']
gitea_token = module.params['auth_token']
username = module.params['username']
req_org = requests.get(
module.params['gitea_url']+'/api/v1/orgs/'+data['username']+'?access_token='+gitea_token,
gitea_url + '/api/v1/orgs/' + username +
'?access_token=' + gitea_token,
headers=headers
)
@ -127,11 +130,15 @@ def run_module():
"full_name": module.params['name'],
#TODO "location": "string",
#TODO "repo_admin_change_team_access": true,
"username": module.params['username'],
"username": username,
#TODO "visibility": "public",
#TODO "website": "string"
}
create_req = requests.post(gitea_url+'/api/v1/orgs'+'?access_token='+gitea_token, headers=headers, data=json.dumps(data))
create_req = requests.post(
gitea_url + '/api/v1/orgs' + '?access_token=' + gitea_token,
headers=headers,
data=json.dumps(data),
)
if create_req.status_code != 201:
result['gitea_response'] = create_req.json()
module.fail_json(msg="Creation failed", **result)
@ -146,7 +153,14 @@ def run_module():
result['gitea_response'] = req_org.json()
result['state'] = 'absent'
if req_org.status_code == 200:
##TODO delete
delete_req = requests.delete(
gitea_url + '/api/v1/orgs/' + username +
'?access_token=' + gitea_token,
headers=headers,
)
if delete_req.status_code != 204:
result['gitea_response'] = create_req.json()
module.fail_json(msg="Deletion failed", **result)
result['changed'] = True
result['state'] = 'absent'