def main(): required_if = [ ("state", "present", ["address", "token", "version"]) ] module = AnsibleModule( supports_check_mode=True, required_if=required_if, argument_spec=dict( arguments.get_spec( "auth", "name", "state", ), address=dict(), token=dict(), version=dict( choices=["v1", "v2"], ), timeout=dict( type="int", ), max_retries=dict( type="int", ), rate_limit=dict( type="float", ), burst_limit=dict( type="int", ), tls=dict( type="dict", options=dict( ca_cert=dict(), cname=dict(), client_cert=dict(), client_key=dict(), ) ) ) ) client = arguments.get_sensu_client(module.params['auth']) path = utils.build_url_path( API_GROUP, API_VERSION, None, 'providers', module.params['name'] ) payload = dict( type="VaultProvider", api_version=API_VERSION, metadata=dict(name=module.params["name"]), spec=build_vault_provider_spec(module.params) ) try: changed, vault_provider = utils.sync_v1( module.params['state'], client, path, payload, module.check_mode, do_differ ) module.exit_json(changed=changed, object=vault_provider) except errors.Error as e: module.fail_json(msg=str(e))
def main(): module = AnsibleModule( supports_check_mode=True, argument_spec=dict( arguments.get_spec("auth"), name=dict(), # Name is not required in info modules. ), ) client = arguments.get_sensu_client(module.params["auth"]) path = utils.build_url_path( API_GROUP, API_VERSION, None, "provider", module.params["name"], ) try: stores = utils.prepare_result_list(utils.get(client, path)) except errors.Error as e: module.fail_json(msg=str(e)) # We simulate the behavior of v2 API here and only return the spec. module.exit_json( changed=False, objects=[utils.convert_v1_to_v2_response(s) for s in stores])
def main(): module = AnsibleModule(supports_check_mode=True, argument_spec=dict( arguments.get_spec( "auth", "state", ), )) client = arguments.get_sensu_client(module.params['auth']) path = utils.build_url_path(API_GROUP, API_VERSION, None, 'providers', 'env') payload = dict( type="Env", api_version=API_VERSION, metadata=dict(name='env'), spec={}, ) try: changed, env_provider = utils.sync_v1( module.params['state'], client, path, payload, module.check_mode, ) module.exit_json(changed=changed, object=env_provider) except errors.Error as e: module.fail_json(msg=str(e))
def main(): required_if = [("state", "present", ["dsn"])] module = AnsibleModule( required_if=required_if, supports_check_mode=True, argument_spec=dict(arguments.get_spec("auth", "name", "state"), dsn=dict(), pool_size=dict(type="int", )), ) client = arguments.get_sensu_client(module.params["auth"]) list_path = utils.build_url_path(API_GROUP, API_VERSION, None, "provider") resource_path = utils.build_url_path( API_GROUP, API_VERSION, None, "provider", module.params["name"], ) payload = dict( type="PostgresConfig", api_version=API_VERSION, spec=arguments.get_mutation_payload(module.params, "dsn", "pool_size"), ) try: changed, datastore = sync( module.params["state"], client, list_path, resource_path, payload, module.check_mode, ) # We simulate the behavior of v2 API here and only return the spec. module.exit_json( changed=changed, object=datastore and datastore["spec"], ) except errors.Error as e: module.fail_json(msg=str(e))
def test_build_url_path_with_namespace(self, parts, expectation): path = "/api/core/v2/namespaces/default" + expectation assert path == utils.build_url_path("core", "v2", "default", *parts)
def test_build_url_path_no_namespace(self, parts, expectation): path = "/api/enterprise/store/v1" + expectation assert path == utils.build_url_path("enterprise/store", "v1", None, *parts)