# lib/designate_plugins/backend-ipa
# Configure the ipa backend

# Enable with:
# DESIGNATE_BACKEND_DRIVER=ipa

# Dependencies:
# ``functions`` file
# ``designate`` configuration

# install_designate_backend - install any external requirements
# configure_designate_backend - make configuration changes, including those to other services
# init_designate_backend - initialize databases, etc.
# start_designate_backend - start any external services
# stop_designate_backend - stop any external services
# cleanup_designate_backend - remove transient data and cache

# Save trace setting
DP_IPA_XTRACE=$(set +o | grep xtrace)
set +o xtrace

# Defaults
# --------
DESIGNATE_IPA_HOST=${DESIGNATE_IPA_HOST:-$(hostname)}
DESIGNATE_IPA_CA_CERT=${DESIGNATE_IPA_CA_CERT:-/etc/ipa/ca.crt}
DESIGNATE_IPA_CLIENT_KEYTAB=${DESIGNATE_IPA_CLIENT_KEYTAB:-$HOME/ipaadmin.keytab}

# Entry Points
# ------------

# install_designate_backend - install any external requirements
function install_designate_backend {
    :
}

# configure_designate_backend - make configuration changes, including those to other services
function configure_designate_backend {
    rc=0
    if [[ ! -f $DESIGNATE_IPA_CA_CERT ]]; then
        echo ERROR: IPA CA cert file $DESIGNATE_IPA_CA_CERT not found
        rc=1
    fi
    if [[ ! -f $DESIGNATE_IPA_CLIENT_KEYTAB ]]; then
        echo ERROR: IPA client keytab file $DESIGNATE_IPA_CLIENT_KEYTAB not found
        rc=1
    fi
    if [[ $rc = 1 ]]; then
        die $LINENO "Error with IPA configuration"
    fi
    iniset $DESIGNATE_CONF backend:ipa ipa_host $DESIGNATE_IPA_HOST
    iniset $DESIGNATE_CONF backend:ipa ipa_ca_cert $DESIGNATE_IPA_CA_CERT
    iniset $DESIGNATE_CONF backend:ipa ipa_client_keytab $DESIGNATE_IPA_CLIENT_KEYTAB
    # devstack tests use dummy NS records, so tell IPA to allow this
    iniset $DESIGNATE_CONF backend:ipa ipa_force_ns_use True
}

# init_designate_backend - initialize databases, etc.
function init_designate_backend {
    :
}

# start_designate_backend - start any external services
function start_designate_backend {
    :
}

# stop_designate_backend - stop any external services
function stop_designate_backend {
    :
}

# cleanup_designate_backend - remove transient data and cache
function cleanup_designate_backend {
    :
}

# Restore xtrace
$DP_IPA_XTRACE
