Skip to content

Commit

Permalink
Fixed ansible-test issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
apollo13 committed Jan 12, 2024
1 parent 7402b03 commit 1260acc
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 19 deletions.
4 changes: 2 additions & 2 deletions plugins/module_utils/consul.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ class RequestError(Exception):
pass


def auth_argument_spec(token_option_name="token"):
def auth_argument_spec(token_option_name="token", token_option_required=False):
args = dict(
host=dict(default="localhost"),
port=dict(type="int", default=8500),
scheme=dict(choices=["http", "https"], default="http"),
validate_certs=dict(type="bool", default=True),
)
args[token_option_name] = dict(no_log=True)
args[token_option_name] = dict(no_log=True, required=token_option_required)
return args


Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/consul.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ def main():
argument_spec=dict(
host=dict(default='localhost'),
port=dict(default=8500, type='int'),
scheme=dict(default='http'),
scheme=dict(default='http', choices=['http', 'https']),
validate_certs=dict(default=True, type='bool'),
check_id=dict(),
check_name=dict(),
Expand Down
22 changes: 13 additions & 9 deletions plugins/modules/consul_acl.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,8 @@
from collections import defaultdict
from ansible.module_utils.basic import to_text, AnsibleModule
from ansible_collections.community.general.plugins.module_utils.consul import (
auth_argument_spec,
auth_options
)
auth_argument_spec
)

RULE_SCOPES = [
"agent",
Expand All @@ -193,7 +192,11 @@
]

MANAGEMENT_PARAMETER_NAME = "mgmt_token"
HOST_PARAMETER_NAME = "host"
SCHEME_PARAMETER_NAME = "scheme"
VALIDATE_CERTS_PARAMETER_NAME = "validate_certs"
NAME_PARAMETER_NAME = "name"
PORT_PARAMETER_NAME = "port"
RULES_PARAMETER_NAME = "rules"
STATE_PARAMETER_NAME = "state"
TOKEN_PARAMETER_NAME = "token"
Expand Down Expand Up @@ -223,9 +226,9 @@
STATE_PARAMETER_NAME: dict(default=PRESENT_STATE_VALUE, choices=[PRESENT_STATE_VALUE, ABSENT_STATE_VALUE]),
TOKEN_PARAMETER_NAME: dict(no_log=False),
TOKEN_TYPE_PARAMETER_NAME: dict(choices=[CLIENT_TOKEN_TYPE_VALUE, MANAGEMENT_TOKEN_TYPE_VALUE],
default=CLIENT_TOKEN_TYPE_VALUE),
**auth_argument_spec(MANAGEMENT_PARAMETER_NAME)
default=CLIENT_TOKEN_TYPE_VALUE)
}
_ARGUMENT_SPEC.update(auth_argument_spec(MANAGEMENT_PARAMETER_NAME, True))


def set_acl(consul_client, configuration):
Expand Down Expand Up @@ -609,9 +612,6 @@ def check_dependencies():
raise ImportError("pyhcl required for this module. "
"See: https://pypi.org/project/pyhcl/")

if not has_requests:
raise ImportError("requests required for this module. See https://pypi.org/project/requests/")


def main():
"""
Expand All @@ -625,12 +625,16 @@ def main():
module.fail_json(msg=str(e))

configuration = Configuration(
management_token=module.params.get(MANAGEMENT_PARAMETER_NAME),
host=module.params.get(HOST_PARAMETER_NAME),
scheme=module.params.get(SCHEME_PARAMETER_NAME),
validate_certs=module.params.get(VALIDATE_CERTS_PARAMETER_NAME),
port=module.params.get(PORT_PARAMETER_NAME),
name=module.params.get(NAME_PARAMETER_NAME),
rules=decode_rules_as_yml(module.params.get(RULES_PARAMETER_NAME)),
state=module.params.get(STATE_PARAMETER_NAME),
token=module.params.get(TOKEN_PARAMETER_NAME),
token_type=module.params.get(TOKEN_TYPE_PARAMETER_NAME),
**auth_options(MANAGEMENT_PARAMETER_NAME)
)
consul_client = get_consul_client(configuration)

Expand Down
4 changes: 2 additions & 2 deletions plugins/modules/consul_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@
DESCRIPTION_PARAMETER_NAME: dict(required=False, type='str', default=''),
RULES_PARAMETER_NAME: dict(type='str'),
VALID_DATACENTERS_PARAMETER_NAME: dict(type='list', elements='str', default=[]),
STATE_PARAMETER_NAME: dict(default=PRESENT_STATE_VALUE, choices=[PRESENT_STATE_VALUE, ABSENT_STATE_VALUE]),
**auth_argument_spec()
STATE_PARAMETER_NAME: dict(default=PRESENT_STATE_VALUE, choices=[PRESENT_STATE_VALUE, ABSENT_STATE_VALUE])
}
_ARGUMENT_SPEC.update(auth_argument_spec())


def update_policy(policy, configuration, consul_module):
Expand Down
9 changes: 4 additions & 5 deletions plugins/modules/consul_role.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@
sample: update
"""

from ansible.module_utils.basic import AnsibleModule, missing_required_lib
from ansible.module_utils.basic import AnsibleModule
from ansible_collections.community.general.plugins.module_utils.consul import (
ConsulModule, auth_argument_spec)

Expand Down Expand Up @@ -211,10 +211,9 @@
mutually_exclusive=[('name', 'id')], required_one_of=[('name', 'id')], default=None),
SERVICE_IDENTITIES_PARAMETER_NAME: dict(type='list', elements='dict', options=SERVICE_ID_RULE_SPEC, default=None),
NODE_IDENTITIES_PARAMETER_NAME: dict(type='list', elements='dict', options=NODE_ID_RULE_SPEC, default=None),
STATE_PARAMETER_NAME: dict(default=PRESENT_STATE_VALUE, choices=[PRESENT_STATE_VALUE, ABSENT_STATE_VALUE]),
**auth_argument_spec()
STATE_PARAMETER_NAME: dict(default=PRESENT_STATE_VALUE, choices=[PRESENT_STATE_VALUE, ABSENT_STATE_VALUE])
}

_ARGUMENT_SPEC.update(auth_argument_spec())

def compare_consul_api_role_policy_objects(first, second):
# compare two lists of dictionaries, ignoring the ID element
Expand Down Expand Up @@ -484,7 +483,7 @@ class Configuration:
Configuration for this module.
"""

def __init__(self, name=None, description=None, policies=None, service_identities=None,
def __init__(self, name=None, description=None, policies=None, service_identities=None,
node_identities=None, state=None, check_mode=None):
self.name = name # type: str
self.description = description # type: str
Expand Down
1 change: 1 addition & 0 deletions plugins/modules/consul_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
auth_argument_spec, ConsulModule
)


def execute(module, consul_module):

state = module.params.get('state')
Expand Down

0 comments on commit 1260acc

Please sign in to comment.