def main():
    module = AnsibleModule(argument_spec=dict(
        api_token=dict(type='str', required=False, default=""),
        app_name=dict(type='str', required=True),
    ),
                           supports_check_mode=True)
    result = dict(changed=False, msg='The module was successfully deleted.')
    if module.check_mode:
        module.exit_json(**result)

    if not (module.params.get('app_name')):
        module.fail_json(msg="Required parameters must not be empty.")

    if module._socket_path:
        connection = Connection(module._socket_path)
        api_handler = CloudWafAPIHandler(connection,
                                         token=module.params.get("api_token"))

    else:
        module.fail_json(
            msg=
            "Socket Path Empty! A persistent connection manager error occurred. Try again in a few moments."
        )

    data = {"app_name": module.params['app_name'], "handler": api_handler}
    try:
        del_app(data=data)

    except Exception as e:
        module.fail_json(msg="During app deletion, an error occurred:" +
                         str(e))

    module.exit_json(
        changed=True,
        msg=f"Deletion of the app {data['app_name']} was successful.")
示例#2
0
def main():
    module = AnsibleModule(
        argument_spec=dict(
            api_token=dict(type='str', required=False, default=""),
            app_name=dict(type='str', required=True),
            http_status=dict(type='int', required=False, choices=[0, 1]),
            https_status=dict(type='int', required=False, choices=[0, 1]),
            ipv6_option=dict(type='int', required=False, choices=[0, 1]),
            custom_http_port=dict(type='int', required=False, default=80),
            custom_https_port=dict(type='int', required=False, default=443),
            http2_status=dict(type='int', required=False, choices=[0, 1], default=0),
            extra_domains=dict(type='list', require=False, default=[]),
            cert_type=dict(type='int', required=False, choices=[0, 1]),
            ssl_options=dict(required=False, type='dict',
                             options=dict(tls_1_0=dict(required=False, type='int', choices=[0, 1]),
                                          tls_1_1=dict(required=False, type='int', choices=[0, 1]),
                                          tls_1_2=dict(required=False, type='int', choices=[0, 1]),
                                          tls_1_3=dict(required=False, type='int', choices=[0, 1]),
                                          encryption_level=dict(required=False, type='int', choices=[1, 2]),
                                          http_2_https=dict(required=False, type='int', choices=[0, 1]))),
            custom_block_page=dict(type='str', required=False, choices=['enable', 'disable'], default='disable'),
            block_url=dict(type='str', required=False)
        ),
        supports_check_mode=True
    )
    result = dict(
        changed=False,
        msg='The module was successfully executed.'
    )

    if module.check_mode:
        module.exit_json(**result)

    api_handler = None
    if module._socket_path:
        connection = Connection(module._socket_path)
        api_handler = CloudWafAPIHandler(connection, token=module.params.get("api_token"))

    else:
        module.fail_json(msg="Socket Path Empty! The persistent connection manager is messed up. Try again in a few moments.")

    data = copy.deepcopy(module.params)
    try:
        is_error, changed, res = update_endpoint(data=data, handler=api_handler)
        if not is_error:
            result["meta"] = res
            result["changed"] = changed
            module.exit_json(**result)
        else:
            result["meta"] = res
            result["msg"] = "Error in repo."
            module.fail_json(**result)

    except Exception as e:
        module.fail_json(msg="While updating the app, an error occurred:" + str(e))
def main():
    module = AnsibleModule(argument_spec=dict(
        app_name=dict(type='str', required=True),
        validation_files=dict(type='list', require=False),
        force=dict(type='bool', required=False, default=True),
        enable=dict(type='bool', required=False, default=True),
        action=dict(type='str', required=True),
        api_token=dict(type='str', required=False, default=""),
    )  #,
                           # supports_check_mode=True
                           )
    result = dict(changed=False, msg='The module was successfully executed.')

    if module.check_mode:
        module.exit_json(**result)

    if module._socket_path:
        connection = Connection(module._socket_path)
        api_handler = CloudWafAPIHandler(connection,
                                         token=module.params.get("api_token"))

    else:
        module.fail_json(
            msg=
            "Socket Path Empty! A persistent connection manager error occurred. Try again in a few moments."
        )

    action_list = ["alert", "alert_deny", "deny_no_log"]
    if module.params['action'] not in action_list:
        raise Exception("in valid action %s, only allow %s" %
                        (module.params['action'], action_list))

    data = {
        "app_name": module.params['app_name'],
        "force": module.params['force'],
        "validation_files": module.params['validation_files'],
        "enable": module.params['enable'],
        "action": module.params['action'],
        "handler": api_handler,
        "api_token": module.params['api_token']
    }
    try:

        res, change = setup_openapi_validation(data=data)
        result["msg"] = res
        result["changed"] = change

    except Exception as e:
        module.fail_json(
            msg="During setup openapi validation, an error occurred:" + str(e))

    module.exit_json(**result)
示例#4
0
def main():
    fields = {
        "api_token": {
            "required": False,
            "type": "str",
            "default": ""
        },
        "app_name": {
            "required": False,
            "type": "str"
        },
        "temp_name": {
            "required": False,
            "type": "str"
        },
        "status": {
            "required": True,
            "type": "str",
            "choices": ["enable", "disable"]
        },
        "template_status": {
            "required": False,
            "type": "str",
            "choices": ["enable", "disable"]
        },
        "IPProtection": {
            "required": True,
            "type": "dict",
            "options": {
                "ip-reputation": {
                    "type": "str",
                    "choices": ["enable", "disable"]
                },
                "geo-ip-block": {
                    "type": "dict",
                    "default": None,
                    "options": {
                        "members": {
                            "type":
                            "list",
                            "choices": [
                                "Afghanistan", "Aland Islands", "Albania",
                                "Algeria", "American Samoa", "Andorra",
                                "Angola", "Anguilla", "Antarctica",
                                "Antigua And Barbuda", "Argentina", "Armenia",
                                "Aruba", "Australia", "Austria", "Azerbaijan",
                                "Bahamas", "Bahrain", "Bangladesh", "Barbados",
                                "Belarus", "Belgium", "Belize", "Benin",
                                "Bermuda", "Bhutan", "Bolivia",
                                "Bonaire Saint Eustatius And Saba",
                                "Bosnia And Herzegovina", "Botswana", "Brazil",
                                "British Indian Ocean Territory",
                                "British Virgin Islands", "Brunei Darussalam",
                                "Bulgaria", "Burkina Faso", "Burundi",
                                "Cambodia", "Cameroon", "Canada", "Cape Verde",
                                "Cayman Islands", "Central African Republic",
                                "Chad", "Chile", "China", "Colombia",
                                "Comoros", "Congo", "Cook Islands",
                                "Costa Rica", "Cote D'Ivoire", "Croatia",
                                "Cuba", "Curacao", "Cyprus", "Czech Republic",
                                "Democratic People'S Republic Of Korea",
                                "Democratic Republic Of The Congo", "Denmark",
                                "Djibouti", "Dominica", "Dominican Republic",
                                "Ecuador", "Egypt", "El Salvador",
                                "Equatorial Guinea", "Eritrea", "Estonia",
                                "Ethiopia", "Falkland Islands (Malvinas)",
                                "Faroe Islands",
                                "Federated States Of Micronesia", "Fiji",
                                "Finland", "France", "French Guiana",
                                "French Polynesia", "Gabon", "Gambia",
                                "Georgia", "Germany", "Ghana", "Gibraltar",
                                "Greece", "Greenland", "Grenada", "Guadeloupe",
                                "Guam", "Guatemala", "Guernsey", "Guinea",
                                "Guinea-Bissau", "Guyana", "Haiti", "Honduras",
                                "Hong Kong", "Hungary", "Iceland", "India",
                                "Indonesia", "Iran", "Iraq", "Ireland",
                                "Isle Of Man", "Israel", "Italy", "Jamaica",
                                "Japan", "Jersey", "Jordan", "Kazakhstan",
                                "Kenya", "Kiribati", "Kosovo", "Kuwait",
                                "Kyrgyzstan",
                                "Lao People'S Democratic Republic", "Latvia",
                                "Lebanon", "Lesotho", "Liberia", "Libya",
                                "Liechtenstein", "Lithuania", "Luxembourg",
                                "Macao", "Macedonia", "Madagascar", "Malawi",
                                "Malaysia", "Maldives", "Mali", "Malta",
                                "Marshall Islands", "Martinique", "Mauritania",
                                "Mauritius", "Mayotte", "Mexico", "Moldova",
                                "Monaco", "Mongolia", "Montenegro",
                                "Montserrat", "Morocco", "Mozambique",
                                "Myanmar", "Namibia", "Nauru", "Nepal",
                                "Netherlands", "New Caledonia", "New Zealand",
                                "Nicaragua", "Niger", "Nigeria", "Niue",
                                "Norfolk Island", "Northern Mariana Islands",
                                "Norway", "Oman", "Pakistan", "Palau",
                                "Palestine", "Panama", "Papua New Guinea",
                                "Paraguay", "Peru", "Philippines", "Poland",
                                "Portugal", "Puerto Rico", "Qatar",
                                "Republic Of Korea", "Reunion", "Romania",
                                "Russian Federation", "Rwanda",
                                "Saint Bartelemey", "Saint Kitts And Nevis",
                                "Saint Lucia", "Saint Martin",
                                "Saint Pierre And Miquelon",
                                "Saint Vincent And The Grenadines", "Samoa",
                                "San Marino", "Sao Tome And Principe",
                                "Saudi Arabia", "Senegal", "Serbia",
                                "Seychelles", "Sierra Leone", "Singapore",
                                "Sint Maarten", "Slovakia", "Slovenia",
                                "Solomon Islands", "Somalia", "South Africa",
                                "South Georgia And The South Sandwich Islands",
                                "South Sudan", "Spain", "Sri Lanka", "Sudan",
                                "Suriname", "Swaziland", "Sweden",
                                "Switzerland", "Syria", "Taiwan", "Tajikistan",
                                "Tanzania", "Thailand", "Timor-Leste", "Togo",
                                "Tokelau", "Tonga", "Trinidad And Tobago",
                                "Tunisia", "Turkey", "Turkmenistan",
                                "Turks And Caicos Islands", "Tuvalu",
                                "U.S. Virgin Islands", "Uganda", "Ukraine",
                                "United Arab Emirates", "United Kingdom",
                                "United States", "Uruguay", "Uzbekistan",
                                "Vanuatu", "Vatican", "Venezuela", "Vietnam",
                                "Wallis And Futuna", "Yemen", "Zambia",
                                "Zimbabwe"
                            ]
                        }
                    }
                },
                "ip-list": {
                    "type": "dict",
                    "options": {
                        "members": {
                            "type": "list",
                            "elements": "dict",
                            "options": {
                                "type": {
                                    "type":
                                    "str",
                                    "choices":
                                    ["trust-ip", "block-ip", "allow-only-ip"]
                                },
                                "ip": {
                                    "type": "str"
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    module = AnsibleModule(argument_spec=fields, supports_check_mode=True)
    result = dict(changed=False, msg='The module was successfully executed.')
    if module.check_mode:
        module.exit_json(**result)

    if module.params.get('app_name') and module.params.get('temp_name'):
        module.fail_json(
            msg="Please input the application name or template name.")

    if not ((module.params.get('app_name') or module.params.get('temp_name'))
            and module.params.get('IPProtection')
            and module.params.get('status')):
        module.fail_json(msg="Required parameters must not be empty.")

    if module._socket_path:
        connection = Connection(module._socket_path)
        api_handler = CloudWafAPIHandler(connection,
                                         token=module.params.get("api_token"))

        data = copy.deepcopy(module.params)
        data['_status'] = data.pop('status')

        try:
            is_error, changed, res = update_waf_config(data, api_handler,
                                                       'IPProtection')
            if not is_error:
                result["meta"] = res
                result["changed"] = changed
                module.exit_json(**result)
            else:
                result["meta"] = res
                result["msg"] = "Error in repo"
                module.fail_json(**result)

        except Exception as e:
            module.fail_json(
                msg="During app configuration, an error occurred:" + str(e))
    else:
        module.fail_json(
            msg=
            "Socket Path Empty! A persistent connection manager error occurred. Try again in a few moments."
        )
示例#5
0
def main():
    fields = {
        "api_token": {
            "required": False,
            "type": "str",
            "default": ""
        },
        "app_name": {
            "required": True,
            "type": "str"
        },
        "action": {
            "required": True,
            "type": "str",
            "choices": ["import", "delete", "get"]
        },
        "certificate": {
            "required": False,
            "type": "str"
        },
        "id": {
            "required": False,
            "type": "int"
        }
    }
    module = AnsibleModule(argument_spec=fields, supports_check_mode=True)
    result = dict(changed=False, msg='The module was successfully executed.')
    if module.check_mode:
        module.exit_json(**result)

    if ((module.params.get('action') == 'import'
         and not module.params.get('certificate'))
            or (module.params.get('action') == 'delete'
                and not module.params.get('id'))):
        module.fail_json(msg="Required parameters must not be empty.")

    if module.params.get('action') == 'import':
        module.params.pop('id')
    elif module.params.get('action') == 'delete':
        module.params.pop('certificate')
    else:
        module.params.pop('id')
        module.params.pop('certificate')

    if module._socket_path:
        connection = Connection(module._socket_path)
        api_handler = CloudWafAPIHandler(connection,
                                         token=module.params.get("api_token"))
        data = copy.deepcopy(module.params)
        if module.params.get('action') == 'get':
            con = dict({"size": 10, "cursor": "", "forward": True})
            is_error, changed, res = get_waf_config(data, api_handler,
                                                    'intercertificate', con)
            con['cursor'] = res['next_cursor']
            hits = res['hits']
            while res['next_cursor']:
                is_error, changed, res = get_waf_config(
                    data, api_handler, 'intercertificate', con)
                con['cursor'] = res['next_cursor']
                hits = hits + res['hits']

            result["meta"] = hits
            result["changed"] = changed
            module.exit_json(**result)
        else:
            try:
                is_error, changed, res = update_waf_config(
                    data, api_handler, 'intercertificate')
                if not is_error:
                    result["meta"] = res
                    result["changed"] = changed
                    module.exit_json(**result)
                else:
                    result["meta"] = res
                    result["msg"] = "Error in repo"
                    module.fail_json(**result)

            except Exception as e:
                module.fail_json(
                    msg="During app configuration, an error occurred:" +
                    str(e))
    else:
        module.fail_json(
            msg=
            "Socket Path Empty! A persistent connection manager error occurred. Try again in a few moments."
        )
def main():
    module = AnsibleModule(argument_spec=dict(
        app_name=dict(type='str', required=True),
        domain_name=dict(type='str', required=True),
        extra_domains=dict(type='list', require=False, default=[]),
        app_service=dict(type='dict', require=True),
        origin_server_ip=dict(type='str', required=True),
        origin_server_service=dict(type='str', required=False,
                                   default="HTTPS"),
        origin_server_port=dict(type='int', required=False, default=443),
        cdn=dict(type='bool', required=False, default=False),
        continent_cdn=dict(type='bool', required=False, default=False),
        block=dict(type='bool', required=False, default=False),
        template=dict(type='str', required=False, default=""),
        api_token=dict(type='str', required=False, default=""),
    ),
                           supports_check_mode=True)
    result = dict(changed=False, msg='The module was successfully executed.')

    if module.check_mode:
        module.exit_json(**result)

    app_service = module.params.get("app_service")
    if not app_service.get("http") and not app_service.get("https"):
        module.fail_json(msg="You must specify the http port or https port.")

    if not (module.params.get('app_name') and module.params.get('domain_name')
            and module.params.get('origin_server_ip')):
        module.fail_json(msg="Required parameters must not be empty.")

    if module._socket_path:
        connection = Connection(module._socket_path)
        api_handler = CloudWafAPIHandler(connection,
                                         token=module.params.get("api_token"))

    else:
        module.fail_json(
            msg=
            "Socket Path Empty! A persistent connection manager error occurred. Try again in a few moments."
        )

    data = {
        "app_name": module.params['app_name'],
        "domain": module.params['domain_name'],
        "extra_domains": module.params['extra_domains'],
        "app_service": module.params['app_service'],
        "server": module.params['origin_server_ip'],
        "backend_type": module.params['origin_server_service'],
        "port": module.params['origin_server_port'],
        "cdn": module.params['cdn'],
        "continent_cdn": module.params['continent_cdn'],
        "block": 1 if module.params['block'] else 0,
        "template": module.params['template'],
        "handler": api_handler
    }
    try:
        res, change = create_app(data=data)
        result["msg"] = json.dumps(res)
        result["changed"] = change

    except Exception as e:
        module.fail_json(msg="During app creation, an error occurred:" +
                         str(e))

    module.exit_json(**result)