Example #1
0
def main():
    ecs_argument_spec = ecs_client_argument_spec()
    ecs_argument_spec.update(ecs_certificate_argument_spec())
    module = AnsibleModule(
        argument_spec=ecs_argument_spec,
        required_if=(
            ['request_type', 'new', ['cert_type']],
            ['request_type', 'validate_only', ['cert_type']],
            ['cert_type', 'CODE_SIGNING', ['end_user_key_storage_agreement']],
            ['cert_type', 'EV_CODE_SIGNING', ['end_user_key_storage_agreement']],
        ),
        mutually_exclusive=(
            ['cert_expiry', 'cert_lifetime'],
        ),
        supports_check_mode=True,
    )

    if not CRYPTOGRAPHY_FOUND or CRYPTOGRAPHY_VERSION < LooseVersion(MINIMAL_CRYPTOGRAPHY_VERSION):
        module.fail_json(msg=missing_required_lib('cryptography >= {0}'.format(MINIMAL_CRYPTOGRAPHY_VERSION)),
                         exception=CRYPTOGRAPHY_IMP_ERR)

    # If validate_only is used, pointing to an existing tracking_id is an invalid operation
    if module.params['tracking_id']:
        if module.params['request_type'] == 'new' or module.params['request_type'] == 'validate_only':
            module.fail_json(msg='The tracking_id field is invalid when request_type="{0}".'.format(module.params['request_type']))

    # A reissued request can not specify an expiration date or lifetime
    if module.params['request_type'] == 'reissue':
        if module.params['cert_expiry']:
            module.fail_json(msg='The cert_expiry field is invalid when request_type="reissue".')
        elif module.params['cert_lifetime']:
            module.fail_json(msg='The cert_lifetime field is invalid when request_type="reissue".')
    # Only a reissued request can omit the CSR
    else:
        module_params_csr = module.params['csr']
        if module_params_csr is None:
            module.fail_json(msg='The csr field is required when request_type={0}'.format(module.params['request_type']))
        elif not os.path.exists(module_params_csr):
            module.fail_json(msg='The csr field of {0} was not a valid path. csr is required when request_type={1}'.format(
                module_params_csr, module.params['request_type']))

    if module.params['ou'] and len(module.params['ou']) > 1:
        module.fail_json(msg='Multiple "ou" values are not currently supported.')

    if module.params['end_user_key_storage_agreement']:
        if module.params['cert_type'] != 'CODE_SIGNING' and module.params['cert_type'] != 'EV_CODE_SIGNING':
            module.fail_json(msg='Parameter "end_user_key_storage_agreement" is valid only for cert_types "CODE_SIGNING" and "EV_CODE_SIGNING"')

    if module.params['org'] and module.params['client_id'] != 1 and module.params['cert_type'] != 'PD_SSL':
        module.fail_json(msg='The "org" parameter is not supported when client_id parameter is set to a value other than 1, unless cert_type is "PD_SSL".')

    if module.params['cert_expiry']:
        if not validate_cert_expiry(module.params['cert_expiry']):
            module.fail_json(msg='The "cert_expiry" parameter of "{0}" is not a valid date or date-time'.format(module.params['cert_expiry']))

    certificate = EcsCertificate(module)
    certificate.request_cert(module)
    result = certificate.dump()
    module.exit_json(**result)
Example #2
0
def main():
    ecs_argument_spec = ecs_client_argument_spec()
    ecs_argument_spec.update(ecs_domain_argument_spec())
    module = AnsibleModule(
        argument_spec=ecs_argument_spec,
        supports_check_mode=False,
    )

    if module.params['verification_email'] and module.params['verification_method'] != 'email':
        module.fail_json(msg='The verification_email field is invalid when verification_method="{0}".'.format(module.params['verification_method']))

    domain = EcsDomain(module)
    domain.request_domain(module)
    result = domain.dump()
    module.exit_json(**result)