-
Notifications
You must be signed in to change notification settings - Fork 77
LDAP Module #869
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lgetwan
wants to merge
61
commits into
devel
Choose a base branch
from
feature/ldap_module
base: devel
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
LDAP Module #869
Changes from all commits
Commits
Show all changes
61 commits
Select commit
Hold shift + click to select a range
5e76d20
LDAP module: First working version.
lgetwan 1782b2b
LDAP module: Added integration tests.
lgetwan 8f42a93
LDAP module: Sanity...
lgetwan 0850583
LDAP Module: documentation sanity, part 03
lgetwan dcf01b4
LDAP Module: documentation sanity, part 04
lgetwan 0aae87b
LDAP Module: documentation sanity, part 05
lgetwan 27d44a2
LDAP Module: documentation sanity, part 05
lgetwan 2c1dc67
LDAP Module: documentation sanity, part 06
lgetwan b3ba4f3
LDAP Module: documentation sanity, part 07
lgetwan 2b5128e
LDAP Module: documentation sanity, part 08
lgetwan 056c596
LDAP Module: documentation sanity, part 09
lgetwan 17eca8e
LDAP Module: documentation sanity, part 10
lgetwan f34f503
LDAP Module: documentation sanity, part 11
lgetwan 9f77e91
LDAP Module: integration test, part 01
lgetwan 50be593
LDAP Module: integration test, part 02
lgetwan aa1f4d5
LDAP Module: integration test, part 03
lgetwan d4338b7
LDAP Module: integration test, part 04
lgetwan 6a24bba
LDAP Module: integration test, part 05
lgetwan b3a102f
LDAP Module: integration test, part 06
lgetwan f7ab307
LDAP Module: integration test, part 07
lgetwan ef4484a
LDAP Module: integration test, part 08
lgetwan bb2ddca
LDAP Module: integration test, part 09
lgetwan 4f32189
LDAP Module: integration test, part 09
lgetwan f9cdded
LDAP Module: integration test, part 10
lgetwan 442b6a5
LDAP Module: integration test, part 11
lgetwan 273fca1
LDAP Module: lookup modules, part 01
lgetwan 7adf3ab
LDAP Module: lookup modules, part 02
lgetwan f0bb54f
LDAP Module: lookup modules, part 03
lgetwan daef8e0
LDAP Module: lookup modules, part 04
lgetwan 8e857fb
LDAP Module: lookup modules, part 05
lgetwan b8269d8
LDAP Module: lookup modules, part 05
lgetwan 17a1c5d
LDAP Module: lookup modules, part 05
lgetwan 5d02b08
LDAP Module: lookup modules, part 08
lgetwan debc5ad
LDAP Module: lookup modules, part 09
lgetwan 217200e
LDAP Module: lookup modules, part 10
lgetwan 2c1e9b4
LDAP Module: lookup modules, part 11
lgetwan 2352b4c
LDAP Module: lookup modules, part 12
lgetwan e4cbe96
LDAP Module: lookup modules, part 13
lgetwan 0306feb
LDAP Module: lookup modules, part 14
lgetwan a4659f2
LDAP Module: lookup modules, part 15
lgetwan 0b87b60
LDAP Module: lookup modules, part 16
lgetwan 1d09357
LDAP Module: lookup modules, part 17
lgetwan ef34b8a
LDAP Module: lookup modules, part 18
lgetwan cd21c5f
LDAP Module: lookup modules, part 19
lgetwan 93bd6f2
LDAP Module: lookup modules, part 20
lgetwan a2898fc
LDAP Module: lookup modules, part 21
lgetwan e060cfa
LDAP Module: lookup modules, part 22
lgetwan 66667d9
LDAP Module: Finalizing 000001
lgetwan 8e1f737
LDAP Module: Finalizing 000002
lgetwan f1ef6fd
LDAP Module: Finalizing 000003
lgetwan 0199c28
LDAP Module: Finalizing 000004
lgetwan 63959f6
LDAP Module: Pimped the examples.
lgetwan 893f50a
LDAP Module: Added changelog.
lgetwan f1c2c21
Fix linting findings.
robin-checkmk 00b1e76
Prepare fix for new auth options.
robin-checkmk 1fb4b61
Minor tweak to examples.
robin-checkmk cbbb712
Update GitHub Workflow.
robin-checkmk 95e20db
Align LDAP module tests with #921 and #930.
robin-checkmk e3b6b2d
default to 'create user on sync'. Repair group to role sync.
lgetwan e5215da
documentation sanity.
lgetwan f6fc62a
LDAP module: The integration test variables now meet the conditions.
lgetwan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| # README: | ||
| # - When changing the module name, it needs to be changed in 'env:MODULE_NAME' and in 'on:pull_requests:path'! | ||
| # | ||
| # Resources: | ||
| # - Template for this file: https://github.com/ansible-collections/collection_template/blob/main/.github/workflows/ansible-test.yml | ||
| # - About Ansible integration tests: https://docs.ansible.com/ansible/latest/dev_guide/testing_integration.html | ||
|
|
||
| env: | ||
| NAMESPACE: checkmk | ||
| COLLECTION_NAME: general | ||
| MODULE_NAME: ldap | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| name: Ansible Integration Tests for LDAP Module | ||
| on: | ||
| workflow_dispatch: | ||
| schedule: | ||
| - cron: '0 0 * * 0' | ||
| pull_request: | ||
| branches: | ||
| - main | ||
| - devel | ||
| paths: | ||
| - 'plugins/modules/ldap.py' | ||
| push: | ||
| paths: | ||
| - '.github/workflows/ans-int-test-ldap.yaml' | ||
| - 'plugins/lookup/ldap_connection.py' | ||
| - 'plugins/lookup/ldap_connections.py' | ||
| - 'plugins/module_utils/ldap.py' | ||
| - 'plugins/modules/ldap.py' | ||
| - 'plugins/module_utils/**' | ||
| - 'tests/integration/files/includes/**' | ||
| - 'tests/integration/targets/ldap/**' | ||
|
|
||
| jobs: | ||
|
|
||
| integration: | ||
| runs-on: ubuntu-24.04 | ||
| name: Ⓐ${{ matrix.ansible }}+py${{ matrix.python }} | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| ansible: | ||
| - stable-2.18 | ||
| - stable-2.19 | ||
| - stable-2.20 | ||
| - devel | ||
| python: | ||
| - '3.11' | ||
| - '3.12' | ||
| - '3.13' | ||
| exclude: | ||
| # Exclude unsupported sets. | ||
| - ansible: devel | ||
| python: '3.11' | ||
| - ansible: stable-2.20 | ||
| python: '3.11' | ||
|
|
||
| services: | ||
| stable_cre: | ||
| image: checkmk/check-mk-raw:2.4.0p15 | ||
| ports: | ||
| - 5024:5000 | ||
| env: | ||
| CMK_SITE_ID: "stable_cre" | ||
| CMK_PASSWORD: "Sup3rSec4et!" | ||
| stable_cme: | ||
| image: checkmk/check-mk-managed:2.4.0p15 | ||
| ports: | ||
| - 5324:5000 | ||
| env: | ||
| CMK_SITE_ID: "stable_cme" | ||
| CMK_PASSWORD: "Sup3rSec4et!" | ||
|
|
||
| steps: | ||
| - name: Check out code | ||
| uses: actions/checkout@v5 | ||
| with: | ||
| path: ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}} | ||
|
|
||
| - name: "Install uv and set the python version." | ||
| uses: astral-sh/setup-uv@v7 | ||
| with: | ||
| python-version: ${{ matrix.python }} | ||
| enable-cache: true | ||
| working-directory: ./ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}}/ | ||
|
|
||
| - name: "Setup uv venv." | ||
| run: uv venv | ||
| working-directory: ./ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}} | ||
|
|
||
| - name: Install ansible-base (${{ matrix.ansible }}) | ||
| run: uv pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible }}.tar.gz | ||
| working-directory: ./ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}} | ||
|
|
||
| - name: Run integration test | ||
| run: uv run ansible-test integration ${{env.MODULE_NAME}} -v --color --continue-on-error --diff --python ${{ matrix.python }} | ||
| working-directory: ./ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| major_changes: | ||
| - LDAP module - Add module for LDAP connections. | ||
| Refer to the module documentation for further details. | ||
| - LDAP Connection lookup module - Add module to lookup details of a single LDAP connection. | ||
| - LDAP Connections lookup module - Add module to lookup all LDAP connections and their details. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,188 @@ | ||
| # Copyright: (c) 2023, Lars Getwan <lars.getwan@checkmk.com> | ||
| # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) | ||
|
|
||
| from __future__ import absolute_import, division, print_function | ||
|
|
||
| __metaclass__ = type | ||
|
|
||
| DOCUMENTATION = """ | ||
| name: ldap_connection | ||
| author: Lars Getwan (@lgetwan) | ||
| version_added: "5.3.0" | ||
|
|
||
| short_description: Show the configuration of an ldap connection | ||
|
|
||
| description: | ||
| - Returns the configuration of an ldap connection | ||
|
|
||
| options: | ||
|
|
||
| _terms: | ||
| description: ldap connection ID | ||
| required: True | ||
|
|
||
| server_url: | ||
| description: URL of the Checkmk server. | ||
| required: True | ||
| vars: | ||
| - name: checkmk_var_server_url | ||
| - name: ansible_lookup_checkmk_server_url | ||
| env: | ||
| - name: CHECKMK_VAR_SERVER_URL | ||
| - name: ANSIBLE_LOOKUP_CHECKMK_SERVER_URL | ||
| ini: | ||
| - section: checkmk_lookup | ||
| key: server_url | ||
|
|
||
| site: | ||
| description: Site name. | ||
| required: True | ||
| vars: | ||
| - name: checkmk_var_site | ||
| - name: ansible_lookup_checkmk_site | ||
| env: | ||
| - name: CHECKMK_VAR_SITE | ||
| - name: ANSIBLE_LOOKUP_CHECKMK_SITE | ||
| ini: | ||
| - section: checkmk_lookup | ||
| key: site | ||
|
|
||
| automation_user: | ||
| description: Automation user for the REST API access. | ||
| required: True | ||
| vars: | ||
| - name: checkmk_var_automation_user | ||
| - name: ansible_lookup_checkmk_automation_user | ||
| env: | ||
| - name: CHECKMK_VAR_AUTOMATION_USER | ||
| - name: ANSIBLE_LOOKUP_CHECKMK_AUTOMATION_USER | ||
| ini: | ||
| - section: checkmk_lookup | ||
| key: automation_user | ||
|
|
||
| automation_secret: | ||
| description: Automation secret for the REST API access. | ||
| required: True | ||
| vars: | ||
| - name: checkmk_var_automation_secret | ||
| - name: ansible_lookup_checkmk_automation_secret | ||
| env: | ||
| - name: CHECKMK_VAR_AUTOMATION_SECRET | ||
| - name: ANSIBLE_LOOKUP_CHECKMK_AUTOMATION_SECRET | ||
| ini: | ||
| - section: checkmk_lookup | ||
| key: automation_secret | ||
|
|
||
| validate_certs: | ||
| description: Whether or not to validate TLS certificates. | ||
| type: boolean | ||
| required: False | ||
| default: True | ||
| vars: | ||
| - name: checkmk_var_validate_certs | ||
| - name: ansible_lookup_checkmk_validate_certs | ||
| env: | ||
| - name: CHECKMK_VAR_VALIDATE_CERTS | ||
| - name: ANSIBLE_LOOKUP_CHECKMK_VALIDATE_CERTS | ||
| ini: | ||
| - section: checkmk_lookup | ||
| key: validate_certs | ||
|
|
||
| notes: | ||
| - Like all lookups, this runs on the Ansible controller and is unaffected by other keywords such as 'become'. | ||
| If you need to use different permissions, you must change the command or run Ansible as another user. | ||
| - Alternatively, you can use a shell/command task that runs against localhost and registers the result. | ||
| - The directory of the play is used as the current working directory. | ||
| - It is B(NOT) possible to assign other variables to the variables mentioned in the C(vars) section! | ||
| This is a limitation of Ansible itself. | ||
| """ | ||
|
|
||
| EXAMPLES = """ | ||
| - name: Get a site with a particular ldap connection id | ||
| ansible.builtin.debug: | ||
| msg: "ldap connection: {{ extensions }}" | ||
| vars: | ||
| extensions: "{{ | ||
| lookup('checkmk.general.ldap_connection', | ||
| 'my_ldap_connection', | ||
| server_url=server_url, | ||
| site=site, | ||
| automation_user=automation_user, | ||
| automation_secret=automation_secret, | ||
| validate_certs=False | ||
| ) | ||
| }}" | ||
|
|
||
| - name: "Use variables from inventory." | ||
| ansible.builtin.debug: | ||
| msg: "ldap connection: {{ extensions }}" | ||
| vars: | ||
| checkmk_var_server_url: "http://myserver/" | ||
| checkmk_var_site: "mysite" | ||
| checkmk_var_automation_user: "myuser" | ||
| checkmk_var_automation_secret: "mysecret" | ||
| checkmk_var_validate_certs: false | ||
| attributes: "{{ lookup('checkmk.general.ldap_connection', 'my_ldap_connection') }}" | ||
| """ | ||
|
|
||
| RETURN = """ | ||
| _list: | ||
| description: | ||
| - The details of a particular ldap connection | ||
| type: list | ||
| elements: str | ||
| """ | ||
|
|
||
| import json | ||
|
|
||
| from ansible.errors import AnsibleError | ||
| from ansible.plugins.lookup import LookupBase | ||
| from ansible_collections.checkmk.general.plugins.module_utils.ldap import ( | ||
| compress_recursive, | ||
| ) | ||
| from ansible_collections.checkmk.general.plugins.module_utils.lookup_api import ( | ||
| CheckMKLookupAPI, | ||
| ) | ||
|
|
||
|
|
||
| class LookupModule(LookupBase): | ||
| def run(self, terms, variables, **kwargs): | ||
| self.set_options(var_options=variables, direct=kwargs) | ||
| server_url = self.get_option("server_url") | ||
| site = self.get_option("site") | ||
| # api_auth_type = self.get_option("api_auth_type") or "bearer" | ||
| # api_auth_cookie = self.get_option("api_auth_cookie") | ||
| automation_user = self.get_option("automation_user") | ||
| automation_secret = self.get_option("automation_secret") | ||
| validate_certs = self.get_option("validate_certs") | ||
|
|
||
| site_url = server_url + "/" + site | ||
|
|
||
| api = CheckMKLookupAPI( | ||
| site_url=site_url, | ||
| # api_auth_type=api_auth_type, | ||
| # api_auth_cookie=api_auth_cookie, | ||
| automation_user=automation_user, | ||
| automation_secret=automation_secret, | ||
|
Comment on lines
+163
to
+166
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I 'fixed' the authentication options, so the tests do not fail anymore, but with the |
||
| validate_certs=validate_certs, | ||
| ) | ||
|
|
||
| ret = [] | ||
|
|
||
| for term in terms: | ||
| response = json.loads(api.get("/objects/ldap_connection/" + term)) | ||
|
|
||
| if "code" in response: | ||
| raise AnsibleError( | ||
| "Received error for %s - %s: %s" | ||
| % ( | ||
| response.get("url", ""), | ||
| response.get("code", ""), | ||
| response.get("msg", ""), | ||
| ) | ||
| ) | ||
|
|
||
| ret.append(compress_recursive(response.get("extensions", {}))) | ||
|
|
||
| # return log | ||
| return ret | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I 'fixed' the authentication options, so the tests do not fail anymore, but with the
api_variables I got other errors, so I am certainly missing something here.