Browse Source

add first draft for user_info module

test
Markus Bergholz 4 months ago
parent
commit
742d7b08e8
Signed by: m GPG Key ID: B45724801354B174
  1. 2
      drone.yml
  2. 2
      galaxy.yml
  3. 14
      plugins/module_utils/nextcloud.py
  4. 2
      plugins/modules/file.py
  5. 2
      plugins/modules/talk.py
  6. 42
      plugins/modules/user_info.py
  7. 9
      tests/integration.yml

2
drone.yml

@ -19,7 +19,7 @@ steps:
- apk --update add ansible py3-requests curl
- ansible-galaxy collection build
- ansible-galaxy collection install markuman-nextcloud-*
- ansible-playbook tests/drone.yml
- ansible-playbook tests/integration.yml
services:
- name: nextcloud21

2
galaxy.yml

@ -1,7 +1,7 @@
namespace: "markuman"
description: bring up your nextcloud usage to the next level
name: "nextcloud"
version: "3.0.3"
version: "3.0.4"
readme: "README.md"
authors:
- "Markus Bergholz <markuman+spambelongstogoogle@gmail.com>"

14
plugins/module_utils/auth.py → plugins/module_utils/nextcloud.py

@ -29,10 +29,15 @@ class NextcloudHandler:
if self.TOKEN is None:
raise AnsibleError('Unable to continue. No Nextcloud Token is given.')
self.headers = {
'Accept': 'application/json',
'OCS-APIRequest': 'true'
}
def get(self, path):
r = requests.get(
'{HTTP}://{HOST}/{PATH}'.format(HTTP=self.HTTP, HOST=self.HOST, PATH=path),
auth=(self.USER, self.TOKEN), verify=self.ssl
auth=(self.USER, self.TOKEN), verify=self.ssl, headers=self.headers
)
if r.status_code == 200:
@ -69,11 +74,6 @@ class NextcloudHandler:
status_code_error(r.status_code)
def talk(self, message, channel):
headers = {
'Accept': 'application/json',
'OCS-APIRequest': 'true'
}
body = {
'message': message,
'replyTo': 0
@ -84,7 +84,7 @@ class NextcloudHandler:
r = requests.post(
'{HTTP}://{HOST}/{V1}/{CHANNEL}'.format(HTTP=self.HTTP, HOST=self.HOST, V1=spreed_v1_path, CHANNEL=channel),
data=body,
headers=headers,
headers=self.headers,
auth=(self.USER, self.TOKEN),
verify=self.ssl
)

2
plugins/modules/file.py

@ -86,7 +86,7 @@ EXAMPLES = '''
'''
from ansible.module_utils.basic import *
from ansible_collections.markuman.nextcloud.plugins.module_utils.auth import NextcloudHandler
from ansible_collections.markuman.nextcloud.plugins.module_utils.nextcloud import NextcloudHandler
import os.path
import hashlib

2
plugins/modules/talk.py

@ -59,7 +59,7 @@ EXAMPLES = '''
'''
from ansible.module_utils.basic import *
from ansible_collections.markuman.nextcloud.plugins.module_utils.auth import NextcloudHandler
from ansible_collections.markuman.nextcloud.plugins.module_utils.nextcloud import NextcloudHandler
import json

42
plugins/modules/user_info.py

@ -0,0 +1,42 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
DOCUMENTATION = '''
module: markuman.nextcloud.user_info
short_description: administrate nextcloud users
description:
- Add, remove, enable or disable users
version_added: "4.0.0"
author:
- "Markus Bergholz"
requirements:
- requests python module
'''
EXAMPLES = '''
- name: install and enable impersonate app
markuman.nextcloud.user_info:
'''
from ansible.module_utils.basic import *
from ansible_collections.markuman.nextcloud.plugins.module_utils.nextcloud import NextcloudHandler
def main():
module = AnsibleModule(
argument_spec = dict(
host = dict(required=False, type='str'),
api_token = dict(required=False, type='str', no_log=True, aliases=['access_token']),
ssl_mode = dict(required=False, type='str', default='https')
)
)
nc = NextcloudHandler(module.params)
retval = nc.get('/ocs/v1.php/cloud/users').json()
module.exit_json(users=retval.get('ocs', {}).get('data', {}).get('users', []))
if __name__ == '__main__':
main()

9
tests/drone.yml → tests/integration.yml

@ -85,3 +85,12 @@
assert:
that:
- out_state is not changed
- name: get nc users
markuman.nextcloud.user_info:
register: out
- name: verify change
assert:
that:
- out.users | count == 1
Loading…
Cancel
Save