Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions plugins/action/auth_token.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright 2024, Itential Inc. All Rights Reserved

# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later

# Generates an auth token. No parameters required.
# Example:
# - name: Generate auth token
# itential.platform.auth_token:

from ansible.plugins.action import ActionBase
from ansible.module_utils.common import yaml
from ansible_collections.itential.platform.plugins.module_utils.login import login
from ansible_collections.itential.platform.plugins.module_utils import host as spec
from ansible_collections.itential.core.plugins.module_utils import hosts

class ActionModule(ActionBase):

_supports_check_mode = False
_supports_async = False
_requires_connection = False

def run(self, tmp=None, task_vars=None):
inventory_hostname = task_vars["inventory_hostname"]
hostvars = task_vars["hostvars"].get(inventory_hostname)

schema = yaml.yaml_load(spec.DOCUMENTATION)
host = hosts.new(schema, hostvars)

auth_token = login(host)

return {"auth_token": auth_token}
77 changes: 0 additions & 77 deletions plugins/action/command_template.py

This file was deleted.

34 changes: 34 additions & 0 deletions plugins/action/generic_request.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright 2024, Itential Inc. All Rights Reserved

# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later

from ansible.plugins.action import ActionBase
from ansible.errors import AnsibleError
from ansible_collections.itential.platform.plugins.module_utils.request import make_request

class ActionModule(ActionBase):

_supports_check_mode = False
_supports_async = False
_requires_connection = False

ALLOWED_METHODS = {"GET", "PUT", "POST", "DELETE"}

def run(self, tmp=None, task_vars=None):

module_args = self._task.args

method = module_args.get("method", "GET")
endpoint = module_args.get("endpoint")

if method not in self.ALLOWED_METHODS:
raise AnsibleError(f"Invalid HTTP method '{method}'. Allowed values: {', '.join(self.ALLOWED_METHODS)}")

if not endpoint:
raise AnsibleError("'endpoint' must be provided.")

params = module_args.get("params", None)
data = module_args.get("data", None)

return make_request(task_vars, method, endpoint, params=params, data=data)
84 changes: 0 additions & 84 deletions plugins/action/request.py

This file was deleted.

37 changes: 37 additions & 0 deletions plugins/modules/auth_token.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/python

# Copyright 2024, Itential Inc. All Rights Reserved
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later

from __future__ import absolute_import, division, print_function

__metaclass__ = type

DOCUMENTATION = """
---
module: itential.platform.auth_token
author: Itential

short_description: Generate an authentication token for IAP.

description:
- The M(itential.platform.auth_token) module generates an authentication token for an IAP system.
- This token can be used to authenticate API requests within the platform.
- The module does not require any input parameters.

options: {}

"""

EXAMPLES = """
- name: Generate auth token
itential.platform.auth_token:
"""

RETURN = """
auth_token:
description: The generated authentication token.
type: str
returned: always
"""
60 changes: 0 additions & 60 deletions plugins/modules/command_templates.py

This file was deleted.

Loading