support more paramaters
This commit is contained in:
parent
597f62fb77
commit
8d7d2f91ba
|
@ -26,13 +26,36 @@ options:
|
||||||
default: present
|
default: present
|
||||||
required: no
|
required: no
|
||||||
name:
|
name:
|
||||||
description:
|
|
||||||
- The full name for your organization account / group
|
|
||||||
required: false
|
|
||||||
username:
|
|
||||||
description:
|
description:
|
||||||
- The username for your organization account / group
|
- The username for your organization account / group
|
||||||
required: true
|
required: true
|
||||||
|
full_name:
|
||||||
|
description:
|
||||||
|
- The full name for your organization account / group
|
||||||
|
required: false
|
||||||
|
visibility:
|
||||||
|
description:
|
||||||
|
- Visibility of the organization, either private, public, or limited (visible to all logged in users)
|
||||||
|
choices: ['private', 'public', 'limited']
|
||||||
|
default: private
|
||||||
|
required: no
|
||||||
|
description:
|
||||||
|
description:
|
||||||
|
- The organizations description
|
||||||
|
required: no
|
||||||
|
location:
|
||||||
|
description:
|
||||||
|
- The organizations location
|
||||||
|
required: no
|
||||||
|
website:
|
||||||
|
description:
|
||||||
|
- The organizations website
|
||||||
|
required: no
|
||||||
|
repo_admin_change_team_access
|
||||||
|
description
|
||||||
|
- Wether repository admins can add and remove access for teams
|
||||||
|
choices: ['yes', 'no']
|
||||||
|
default: no
|
||||||
auth_token:
|
auth_token:
|
||||||
description:
|
description:
|
||||||
- Authentification token for your gitea account
|
- Authentification token for your gitea account
|
||||||
|
@ -50,29 +73,28 @@ EXAMPLES = '''
|
||||||
# Create an organization
|
# Create an organization
|
||||||
- name: Create organization
|
- name: Create organization
|
||||||
gitea_organization:
|
gitea_organization:
|
||||||
name: My Org
|
full_name: My Org
|
||||||
username: myorg
|
name: myorg
|
||||||
auth_token: 1234...6789
|
auth_token: 1234...6789
|
||||||
gitea_url: https://git.example.com
|
gitea_url: https://git.example.com
|
||||||
|
|
||||||
# Update organization
|
# Update organization
|
||||||
- name: Change organization
|
- name: Change organization
|
||||||
gitea_organization:
|
gitea_organization:
|
||||||
name: My better Org
|
full_name: My better Org
|
||||||
username: myorg
|
name: myorg
|
||||||
auth_token: 1234...6789
|
auth_token: 1234...6789
|
||||||
gitea_url: https://git.example.com
|
gitea_url: https://git.example.com
|
||||||
'''
|
'''
|
||||||
|
|
||||||
RETURN = '''
|
RETURN = '''
|
||||||
original_message:
|
return_code:
|
||||||
description: The original name param that was passed in
|
description: The HTTP return code from the Gitea API
|
||||||
type: str
|
type: int
|
||||||
returned: always
|
|
||||||
message:
|
|
||||||
description: The output message that the test module generates
|
|
||||||
type: str
|
|
||||||
returned: always
|
returned: always
|
||||||
|
gitea_respone:
|
||||||
|
description: The JSON output message that Gitea returns
|
||||||
|
type: dict
|
||||||
'''
|
'''
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
|
@ -83,14 +105,14 @@ def run_module():
|
||||||
auth_token=dict(type='str', required=True),
|
auth_token=dict(type='str', required=True),
|
||||||
gitea_url=dict(type='str', required=True),
|
gitea_url=dict(type='str', required=True),
|
||||||
|
|
||||||
username=dict(type='str', required=True),
|
name=dict(type='str', required=True),
|
||||||
name=dict(type='bool', required=False, default=False)
|
full_name=dict(type='str', default="", required=False),
|
||||||
|
visibility=dict(type='str', default="private", choices=['private', 'public', 'limited']),
|
||||||
|
|
||||||
# TODO support "description": "string",
|
repo_admin_change_team_access=dict(type="bool", required=False, default=False),
|
||||||
# TODO support "location": "string",
|
description=dict(type='str', default="", required=False),
|
||||||
# TODO support "repo_admin_change_team_access": true,
|
location=dict(type='str', default="", required=False),
|
||||||
# TODO support "visibility": "public",
|
website=dict(type='str', default="", required=False),
|
||||||
# TODO support "website": "string"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
result = dict(
|
result = dict(
|
||||||
|
@ -109,7 +131,7 @@ def run_module():
|
||||||
}
|
}
|
||||||
gitea_url = module.params['gitea_url']
|
gitea_url = module.params['gitea_url']
|
||||||
gitea_token = module.params['auth_token']
|
gitea_token = module.params['auth_token']
|
||||||
username = module.params['username']
|
username = module.params['name']
|
||||||
req_org = requests.get(
|
req_org = requests.get(
|
||||||
gitea_url + '/api/v1/orgs/' + username +
|
gitea_url + '/api/v1/orgs/' + username +
|
||||||
'?access_token=' + gitea_token,
|
'?access_token=' + gitea_token,
|
||||||
|
@ -119,26 +141,50 @@ def run_module():
|
||||||
if module.check_mode:
|
if module.check_mode:
|
||||||
module.exit_json(**result)
|
module.exit_json(**result)
|
||||||
|
|
||||||
|
# Prepare org data
|
||||||
|
new_data = {
|
||||||
|
"username": username,
|
||||||
|
"full_name": module.params['full_name'],
|
||||||
|
"visibility": module.params['visibility'],
|
||||||
|
"repo_admin_change_team_access": module.params['repo_admin_change_team_access'],
|
||||||
|
"description": module.params['description'],
|
||||||
|
"location": module.params['location'],
|
||||||
|
"website": module.params['website'],
|
||||||
|
}
|
||||||
|
|
||||||
if module.params['state'] == 'present':
|
if module.params['state'] == 'present':
|
||||||
|
# org is requested and already exists
|
||||||
if req_org.status_code == 200:
|
if req_org.status_code == 200:
|
||||||
##TODO support modify modifyable params
|
|
||||||
result['return_code'] = 200
|
result['return_code'] = 200
|
||||||
result['gitea_response'] = req_org.json()
|
result['gitea_response'] = req_org.json()
|
||||||
|
old_data = req_org.json()
|
||||||
|
# check if org needs to be patched
|
||||||
|
if (
|
||||||
|
new_data['full_name'] != old_data['full_name'] or
|
||||||
|
new_data['description'] != old_data['description'] or
|
||||||
|
new_data['location'] != old_data['location'] or
|
||||||
|
new_data['repo_admin_change_team_access'] !=
|
||||||
|
old_data['repo_admin_change_team_access'] or
|
||||||
|
new_data['visibility'] != old_data['visibility'] or
|
||||||
|
new_data['website'] != old_data['website']
|
||||||
|
):
|
||||||
|
new_data.pop('username')
|
||||||
|
req_patch = requests.patch(
|
||||||
|
gitea_url + '/api/v1/orgs/' + username + '?access_token=' + gitea_token,
|
||||||
|
headers=headers,
|
||||||
|
data=json.dumps(new_data),
|
||||||
|
)
|
||||||
|
result['return_code'] = req_patch.status_code
|
||||||
|
result['gitea_response'] = req_patch.json()
|
||||||
|
result['changed'] = True
|
||||||
|
# all is fine
|
||||||
result['state'] = 'present'
|
result['state'] = 'present'
|
||||||
if req_org.status_code == 404:
|
if req_org.status_code == 404:
|
||||||
data = {
|
# org is requesed and does not yet exist, create
|
||||||
#TODO "description": "string",
|
|
||||||
"full_name": module.params['name'],
|
|
||||||
#TODO "location": "string",
|
|
||||||
#TODO "repo_admin_change_team_access": true,
|
|
||||||
"username": username,
|
|
||||||
#TODO "visibility": "public",
|
|
||||||
#TODO "website": "string"
|
|
||||||
}
|
|
||||||
create_req = requests.post(
|
create_req = requests.post(
|
||||||
gitea_url + '/api/v1/orgs' + '?access_token=' + gitea_token,
|
gitea_url + '/api/v1/orgs' + '?access_token=' + gitea_token,
|
||||||
headers=headers,
|
headers=headers,
|
||||||
data=json.dumps(data),
|
data=json.dumps(new_data),
|
||||||
)
|
)
|
||||||
result['return_code'] = create_req.status_code
|
result['return_code'] = create_req.status_code
|
||||||
result['gitea_response'] = create_req.json()
|
result['gitea_response'] = create_req.json()
|
||||||
|
@ -149,10 +195,12 @@ def run_module():
|
||||||
|
|
||||||
if module.params['state'] == 'absent':
|
if module.params['state'] == 'absent':
|
||||||
if req_org.status_code == 404:
|
if req_org.status_code == 404:
|
||||||
|
# org should be absent and does not exist
|
||||||
result['return_code'] = 404
|
result['return_code'] = 404
|
||||||
result['gitea_response'] = req_org.json()
|
result['gitea_response'] = req_org.json()
|
||||||
result['state'] = 'absent'
|
result['state'] = 'absent'
|
||||||
if req_org.status_code == 200:
|
if req_org.status_code == 200:
|
||||||
|
# org should be abenst and needs to be deleted
|
||||||
delete_req = requests.delete(
|
delete_req = requests.delete(
|
||||||
gitea_url + '/api/v1/orgs/' + username +
|
gitea_url + '/api/v1/orgs/' + username +
|
||||||
'?access_token=' + gitea_token,
|
'?access_token=' + gitea_token,
|
||||||
|
@ -160,6 +208,7 @@ def run_module():
|
||||||
)
|
)
|
||||||
result['return_code'] = delete_req.status_code
|
result['return_code'] = delete_req.status_code
|
||||||
if delete_req.status_code != 204:
|
if delete_req.status_code != 204:
|
||||||
|
# deletion failed
|
||||||
result['gitea_response'] = create_req.json()
|
result['gitea_response'] = create_req.json()
|
||||||
module.fail_json(msg="Deletion failed", **result)
|
module.fail_json(msg="Deletion failed", **result)
|
||||||
result['changed'] = True
|
result['changed'] = True
|
||||||
|
|
Loading…
Reference in New Issue