From 946059da76773d95bf5676986dbf69f401ddb4cf Mon Sep 17 00:00:00 2001 From: Andrew Jefferson Date: Wed, 11 Dec 2019 23:33:56 +0000 Subject: [PATCH] apply default configurations for plugins when installing a plugin (if the user has not already set the configuration value in question) --- docker-image-src/3.3/docker-entrypoint.sh | 51 +++++++++++++++--- docker-image-src/3.4/docker-entrypoint.sh | 51 +++++++++++++++--- docker-image-src/3.5/docker-entrypoint.sh | 52 ++++++++++++++++--- docker-image-src/4.0/docker-entrypoint.sh | 52 ++++++++++++++++--- docker-image-src/4.1/docker-entrypoint.sh | 52 ++++++++++++++++--- neo4jlabs-plugins.json | 34 ++++++++++-- .../neo4j/docker/TestPluginInstallation.java | 32 ++++++++++++ 7 files changed, 289 insertions(+), 35 deletions(-) diff --git a/docker-image-src/3.3/docker-entrypoint.sh b/docker-image-src/3.3/docker-entrypoint.sh index 1e352eea..ba9c6244 100755 --- a/docker-image-src/3.3/docker-entrypoint.sh +++ b/docker-image-src/3.3/docker-entrypoint.sh @@ -143,7 +143,7 @@ function load_plugin_from_github if [ -d /plugins ]; then local _plugins_dir="/plugins" fi - local _versions_json_url="$(jq --raw-output "with_entries( select(.key==\"${_plugin_name}\") ) | to_entries[] | .value" /neo4jlabs-plugins.json )" + local _versions_json_url="$(jq --raw-output "with_entries( select(.key==\"${_plugin_name}\") ) | to_entries[] | .value.versions" /neo4jlabs-plugins.json )" # Using the same name for the plugin irrespective of version ensures we don't end up with different versions of the same plugin local _destination="${_plugins_dir}/${_plugin_name}.jar" local _neo4j_version="$(neo4j --version | cut -d' ' -f2)" @@ -153,8 +153,9 @@ function load_plugin_from_github local _versions_json="$(curl --silent --show-error --fail --retry 30 --retry-max-time 300 -L "${_versions_json_url}")" local _plugin_jar_url="$(echo "${_versions_json}" | jq --raw-output ".[] | select(.neo4j==\"${_neo4j_version}\") | .jar")" if [[ -z "${_plugin_jar_url}" ]]; then - echo >&2 "No jar URL found for version '${_neo4j_version}' in versions.json from '${_versions_json_url}'" + echo >&2 "Error: No jar URL found for version '${_neo4j_version}' in versions.json from '${_versions_json_url}'" echo >&2 "${_versions_json}" + exit 1 fi echo "Installing Plugin '${_plugin_name}' from ${_plugin_jar_url} to ${_destination} " curl --silent --show-error --fail --retry 30 --retry-max-time 300 -L -o "${_destination}" "${_plugin_jar_url}" @@ -165,6 +166,46 @@ function load_plugin_from_github fi } +function apply_plugin_default_configuration +{ + # Set the correct Load a plugin at runtime. The provided github repository must have a versions.json on the master branch with the + # correct format. + local _plugin_name="${1}" #e.g. apoc, graph-algorithms, graph-ql + local _reference_conf="${2}" # used to determine if we can override properties + local _neo4j_conf="${NEO4J_HOME}/conf/neo4j.conf" + + local _property _value + echo "Applying default values for plugin ${_plugin_name} to neo4j.conf" + for _entry in $(jq --compact-output --raw-output "with_entries( select(.key==\"${_plugin_name}\") ) | to_entries[] | .value.properties | to_entries[]" /neo4jlabs-plugins.json); do + _property="$(jq --raw-output '.key' <<< "${_entry}")" + _value="$(jq --raw-output '.value' <<< "${_entry}")" + + # the first grep strips out comments + if grep -o "^[^#]*" "${_reference_conf}" | grep -q --fixed-strings "${_property}=" ; then + # property is already set in the user provided config. In this case we don't override what has been set explicitly by the user. + echo "Skipping ${_property} for plugin ${_plugin_name} because it is already set" + else + if grep -o "^[^#]*" "${_neo4j_conf}" | grep -q --fixed-strings "${_property}=" ; then + sed --in-place "s/${_property}=/&${_value},/" "${_neo4j_conf}" + else + echo "${_property}=${_value}" >> "${_neo4j_conf}" + fi + fi + done +} + +function install_neo4j_labs_plugins +{ + # We store a copy of the config before we modify it for the plugins to allow us to see if there are user-set values in the input config that we shouldn't override + local _old_config="$(mktemp)" + cp "${NEO4J_HOME}"/conf/neo4j.conf "${_old_config}" + for plugin_name in $(echo "${NEO4JLABS_PLUGINS}" | jq --raw-output '.[]'); do + load_plugin_from_github "${plugin_name}" + apply_plugin_default_configuration "${plugin_name}" "${_old_config}" + done + rm "${_old_config}" +} + # If we're running as root, then run as the neo4j user. Otherwise # docker is running with --user and we simply use that user. Note # that su-exec, despite its name, does not replicate the functionality @@ -421,10 +462,8 @@ for i in $( set | grep ^NEO4J_ | awk -F'=' '{print $1}' | sort -rn ); do done if [[ ! -z "${NEO4JLABS_PLUGINS:-}" ]]; then - # NEO4JLABS_PLUGINS should be a json array of plugins like '["graph-algorithms", "apoc-procedures", "streams", "graphql"]' - for plugin_name in $(echo "${NEO4JLABS_PLUGINS}" | jq --raw-output '.[]'); do - load_plugin_from_github "${plugin_name}" - done + # NEO4JLABS_PLUGINS should be a json array of plugins like '["graph-algorithms", "apoc", "streams", "graphql"]' + install_neo4j_labs_plugins fi [ -f "${EXTENSION_SCRIPT:-}" ] && . ${EXTENSION_SCRIPT} diff --git a/docker-image-src/3.4/docker-entrypoint.sh b/docker-image-src/3.4/docker-entrypoint.sh index a1e8473f..0405b2ed 100755 --- a/docker-image-src/3.4/docker-entrypoint.sh +++ b/docker-image-src/3.4/docker-entrypoint.sh @@ -143,7 +143,7 @@ function load_plugin_from_github if [ -d /plugins ]; then local _plugins_dir="/plugins" fi - local _versions_json_url="$(jq --raw-output "with_entries( select(.key==\"${_plugin_name}\") ) | to_entries[] | .value" /neo4jlabs-plugins.json )" + local _versions_json_url="$(jq --raw-output "with_entries( select(.key==\"${_plugin_name}\") ) | to_entries[] | .value.versions" /neo4jlabs-plugins.json )" # Using the same name for the plugin irrespective of version ensures we don't end up with different versions of the same plugin local _destination="${_plugins_dir}/${_plugin_name}.jar" local _neo4j_version="$(neo4j --version | cut -d' ' -f2)" @@ -153,8 +153,9 @@ function load_plugin_from_github local _versions_json="$(wget -q --timeout 300 --tries 30 -O - "${_versions_json_url}")" local _plugin_jar_url="$(echo "${_versions_json}" | jq --raw-output ".[] | select(.neo4j==\"${_neo4j_version}\") | .jar")" if [[ -z "${_plugin_jar_url}" ]]; then - echo >&2 "No jar URL found for version '${_neo4j_version}' in versions.json from '${_versions_json_url}'" + echo >&2 "Error: No jar URL found for version '${_neo4j_version}' in versions.json from '${_versions_json_url}'" echo >&2 "${_versions_json}" + exit 1 fi echo "Installing Plugin '${_plugin_name}' from ${_plugin_jar_url} to ${_destination} " wget -q --timeout 300 --tries 30 --output-document="${_destination}" "${_plugin_jar_url}" @@ -165,6 +166,46 @@ function load_plugin_from_github fi } +function apply_plugin_default_configuration +{ + # Set the correct Load a plugin at runtime. The provided github repository must have a versions.json on the master branch with the + # correct format. + local _plugin_name="${1}" #e.g. apoc, graph-algorithms, graph-ql + local _reference_conf="${2}" # used to determine if we can override properties + local _neo4j_conf="${NEO4J_HOME}/conf/neo4j.conf" + + local _property _value + echo "Applying default values for plugin ${_plugin_name} to neo4j.conf" + for _entry in $(jq --compact-output --raw-output "with_entries( select(.key==\"${_plugin_name}\") ) | to_entries[] | .value.properties | to_entries[]" /neo4jlabs-plugins.json); do + _property="$(jq --raw-output '.key' <<< "${_entry}")" + _value="$(jq --raw-output '.value' <<< "${_entry}")" + + # the first grep strips out comments + if grep -o "^[^#]*" "${_reference_conf}" | grep -q --fixed-strings "${_property}=" ; then + # property is already set in the user provided config. In this case we don't override what has been set explicitly by the user. + echo "Skipping ${_property} for plugin ${_plugin_name} because it is already set" + else + if grep -o "^[^#]*" "${_neo4j_conf}" | grep -q --fixed-strings "${_property}=" ; then + sed --in-place "s/${_property}=/&${_value},/" "${_neo4j_conf}" + else + echo "${_property}=${_value}" >> "${_neo4j_conf}" + fi + fi + done +} + +function install_neo4j_labs_plugins +{ + # We store a copy of the config before we modify it for the plugins to allow us to see if there are user-set values in the input config that we shouldn't override + local _old_config="$(mktemp)" + cp "${NEO4J_HOME}"/conf/neo4j.conf "${_old_config}" + for plugin_name in $(echo "${NEO4JLABS_PLUGINS}" | jq --raw-output '.[]'); do + load_plugin_from_github "${plugin_name}" + apply_plugin_default_configuration "${plugin_name}" "${_old_config}" + done + rm "${_old_config}" +} + # If we're running as root, then run as the neo4j user. Otherwise # docker is running with --user and we simply use that user. Note # that su-exec, despite its name, does not replicate the functionality @@ -421,10 +462,8 @@ for i in $( set | grep ^NEO4J_ | awk -F'=' '{print $1}' | sort -rn ); do done if [[ ! -z "${NEO4JLABS_PLUGINS:-}" ]]; then - # NEO4JLABS_PLUGINS should be a json array of plugins like '["graph-algorithms", "apoc-procedures", "streams", "graphql"]' - for plugin_name in $(echo "${NEO4JLABS_PLUGINS}" | jq --raw-output '.[]'); do - load_plugin_from_github "${plugin_name}" - done + # NEO4JLABS_PLUGINS should be a json array of plugins like '["graph-algorithms", "apoc", "streams", "graphql"]' + install_neo4j_labs_plugins fi [ -f "${EXTENSION_SCRIPT:-}" ] && . ${EXTENSION_SCRIPT} diff --git a/docker-image-src/3.5/docker-entrypoint.sh b/docker-image-src/3.5/docker-entrypoint.sh index 1f84398c..4174a35f 100755 --- a/docker-image-src/3.5/docker-entrypoint.sh +++ b/docker-image-src/3.5/docker-entrypoint.sh @@ -143,7 +143,7 @@ function load_plugin_from_github if [ -d /plugins ]; then local _plugins_dir="/plugins" fi - local _versions_json_url="$(jq --raw-output "with_entries( select(.key==\"${_plugin_name}\") ) | to_entries[] | .value" /neo4jlabs-plugins.json )" + local _versions_json_url="$(jq --raw-output "with_entries( select(.key==\"${_plugin_name}\") ) | to_entries[] | .value.versions" /neo4jlabs-plugins.json )" # Using the same name for the plugin irrespective of version ensures we don't end up with different versions of the same plugin local _destination="${_plugins_dir}/${_plugin_name}.jar" local _neo4j_version="$(neo4j --version | cut -d' ' -f2)" @@ -153,8 +153,9 @@ function load_plugin_from_github local _versions_json="$(wget -q --timeout 300 --tries 30 -O - "${_versions_json_url}")" local _plugin_jar_url="$(echo "${_versions_json}" | jq --raw-output ".[] | select(.neo4j==\"${_neo4j_version}\") | .jar")" if [[ -z "${_plugin_jar_url}" ]]; then - echo >&2 "No jar URL found for version '${_neo4j_version}' in versions.json from '${_versions_json_url}'" + echo >&2 "Error: No jar URL found for version '${_neo4j_version}' in versions.json from '${_versions_json_url}'" echo >&2 "${_versions_json}" + exit 1 fi echo "Installing Plugin '${_plugin_name}' from ${_plugin_jar_url} to ${_destination} " wget -q --timeout 300 --tries 30 --output-document="${_destination}" "${_plugin_jar_url}" @@ -165,6 +166,46 @@ function load_plugin_from_github fi } +function apply_plugin_default_configuration +{ + # Set the correct Load a plugin at runtime. The provided github repository must have a versions.json on the master branch with the + # correct format. + local _plugin_name="${1}" #e.g. apoc, graph-algorithms, graph-ql + local _reference_conf="${2}" # used to determine if we can override properties + local _neo4j_conf="${NEO4J_HOME}/conf/neo4j.conf" + + local _property _value + echo "Applying default values for plugin ${_plugin_name} to neo4j.conf" + for _entry in $(jq --compact-output --raw-output "with_entries( select(.key==\"${_plugin_name}\") ) | to_entries[] | .value.properties | to_entries[]" /neo4jlabs-plugins.json); do + _property="$(jq --raw-output '.key' <<< "${_entry}")" + _value="$(jq --raw-output '.value' <<< "${_entry}")" + + # the first grep strips out comments + if grep -o "^[^#]*" "${_reference_conf}" | grep -q --fixed-strings "${_property}=" ; then + # property is already set in the user provided config. In this case we don't override what has been set explicitly by the user. + echo "Skipping ${_property} for plugin ${_plugin_name} because it is already set" + else + if grep -o "^[^#]*" "${_neo4j_conf}" | grep -q --fixed-strings "${_property}=" ; then + sed --in-place "s/${_property}=/&${_value},/" "${_neo4j_conf}" + else + echo "${_property}=${_value}" >> "${_neo4j_conf}" + fi + fi + done +} + +function install_neo4j_labs_plugins +{ + # We store a copy of the config before we modify it for the plugins to allow us to see if there are user-set values in the input config that we shouldn't override + local _old_config="$(mktemp)" + cp "${NEO4J_HOME}"/conf/neo4j.conf "${_old_config}" + for plugin_name in $(echo "${NEO4JLABS_PLUGINS}" | jq --raw-output '.[]'); do + load_plugin_from_github "${plugin_name}" + apply_plugin_default_configuration "${plugin_name}" "${_old_config}" + done + rm "${_old_config}" +} + # If we're running as root, then run as the neo4j user. Otherwise # docker is running with --user and we simply use that user. Note # that su-exec, despite its name, does not replicate the functionality @@ -416,11 +457,10 @@ for i in $( set | grep ^NEO4J_ | awk -F'=' '{print $1}' | sort -rn ); do fi done + if [[ ! -z "${NEO4JLABS_PLUGINS:-}" ]]; then - # NEO4JLABS_PLUGINS should be a json array of plugins like '["graph-algorithms", "apoc-procedures", "streams", "graphql"]' - for plugin_name in $(echo "${NEO4JLABS_PLUGINS}" | jq --raw-output '.[]'); do - load_plugin_from_github "${plugin_name}" - done + # NEO4JLABS_PLUGINS should be a json array of plugins like '["graph-algorithms", "apoc", "streams", "graphql"]' + install_neo4j_labs_plugins fi [ -f "${EXTENSION_SCRIPT:-}" ] && . ${EXTENSION_SCRIPT} diff --git a/docker-image-src/4.0/docker-entrypoint.sh b/docker-image-src/4.0/docker-entrypoint.sh index cbf973ba..938f66fb 100755 --- a/docker-image-src/4.0/docker-entrypoint.sh +++ b/docker-image-src/4.0/docker-entrypoint.sh @@ -143,7 +143,7 @@ function load_plugin_from_github if [ -d /plugins ]; then local _plugins_dir="/plugins" fi - local _versions_json_url="$(jq --raw-output "with_entries( select(.key==\"${_plugin_name}\") ) | to_entries[] | .value" /neo4jlabs-plugins.json )" + local _versions_json_url="$(jq --raw-output "with_entries( select(.key==\"${_plugin_name}\") ) | to_entries[] | .value.versions" /neo4jlabs-plugins.json )" # Using the same name for the plugin irrespective of version ensures we don't end up with different versions of the same plugin local _destination="${_plugins_dir}/${_plugin_name}.jar" local _neo4j_version="$(neo4j --version | cut -d' ' -f2)" @@ -153,8 +153,9 @@ function load_plugin_from_github local _versions_json="$(wget -q --timeout 300 --tries 30 -O - "${_versions_json_url}")" local _plugin_jar_url="$(echo "${_versions_json}" | jq --raw-output ".[] | select(.neo4j==\"${_neo4j_version}\") | .jar")" if [[ -z "${_plugin_jar_url}" ]]; then - echo >&2 "No jar URL found for version '${_neo4j_version}' in versions.json from '${_versions_json_url}'" + echo >&2 "Error: No jar URL found for version '${_neo4j_version}' in versions.json from '${_versions_json_url}'" echo >&2 "${_versions_json}" + exit 1 fi echo "Installing Plugin '${_plugin_name}' from ${_plugin_jar_url} to ${_destination} " wget -q --timeout 300 --tries 30 --output-document="${_destination}" "${_plugin_jar_url}" @@ -165,6 +166,46 @@ function load_plugin_from_github fi } +function apply_plugin_default_configuration +{ + # Set the correct Load a plugin at runtime. The provided github repository must have a versions.json on the master branch with the + # correct format. + local _plugin_name="${1}" #e.g. apoc, graph-algorithms, graph-ql + local _reference_conf="${2}" # used to determine if we can override properties + local _neo4j_conf="${NEO4J_HOME}/conf/neo4j.conf" + + local _property _value + echo "Applying default values for plugin ${_plugin_name} to neo4j.conf" + for _entry in $(jq --compact-output --raw-output "with_entries( select(.key==\"${_plugin_name}\") ) | to_entries[] | .value.properties | to_entries[]" /neo4jlabs-plugins.json); do + _property="$(jq --raw-output '.key' <<< "${_entry}")" + _value="$(jq --raw-output '.value' <<< "${_entry}")" + + # the first grep strips out comments + if grep -o "^[^#]*" "${_reference_conf}" | grep -q --fixed-strings "${_property}=" ; then + # property is already set in the user provided config. In this case we don't override what has been set explicitly by the user. + echo "Skipping ${_property} for plugin ${_plugin_name} because it is already set" + else + if grep -o "^[^#]*" "${_neo4j_conf}" | grep -q --fixed-strings "${_property}=" ; then + sed --in-place "s/${_property}=/&${_value},/" "${_neo4j_conf}" + else + echo "${_property}=${_value}" >> "${_neo4j_conf}" + fi + fi + done +} + +function install_neo4j_labs_plugins +{ + # We store a copy of the config before we modify it for the plugins to allow us to see if there are user-set values in the input config that we shouldn't override + local _old_config="$(mktemp)" + cp "${NEO4J_HOME}"/conf/neo4j.conf "${_old_config}" + for plugin_name in $(echo "${NEO4JLABS_PLUGINS}" | jq --raw-output '.[]'); do + load_plugin_from_github "${plugin_name}" + apply_plugin_default_configuration "${plugin_name}" "${_old_config}" + done + rm "${_old_config}" +} + # If we're running as root, then run as the neo4j user. Otherwise # docker is running with --user and we simply use that user. Note # that su-exec, despite its name, does not replicate the functionality @@ -435,11 +476,10 @@ done export NEO4J_HOME="${temp_neo4j_home}" unset temp_neo4j_home + if [[ ! -z "${NEO4JLABS_PLUGINS:-}" ]]; then - # NEO4JLABS_PLUGINS should be a json array of plugins like '["graph-algorithms", "apoc-procedures", "streams", "graphql"]' - for plugin_name in $(echo "${NEO4JLABS_PLUGINS}" | jq --raw-output '.[]'); do - load_plugin_from_github "${plugin_name}" - done + # NEO4JLABS_PLUGINS should be a json array of plugins like '["graph-algorithms", "apoc", "streams", "graphql"]' + install_neo4j_labs_plugins fi [ -f "${EXTENSION_SCRIPT:-}" ] && . ${EXTENSION_SCRIPT} diff --git a/docker-image-src/4.1/docker-entrypoint.sh b/docker-image-src/4.1/docker-entrypoint.sh index cbf973ba..938f66fb 100755 --- a/docker-image-src/4.1/docker-entrypoint.sh +++ b/docker-image-src/4.1/docker-entrypoint.sh @@ -143,7 +143,7 @@ function load_plugin_from_github if [ -d /plugins ]; then local _plugins_dir="/plugins" fi - local _versions_json_url="$(jq --raw-output "with_entries( select(.key==\"${_plugin_name}\") ) | to_entries[] | .value" /neo4jlabs-plugins.json )" + local _versions_json_url="$(jq --raw-output "with_entries( select(.key==\"${_plugin_name}\") ) | to_entries[] | .value.versions" /neo4jlabs-plugins.json )" # Using the same name for the plugin irrespective of version ensures we don't end up with different versions of the same plugin local _destination="${_plugins_dir}/${_plugin_name}.jar" local _neo4j_version="$(neo4j --version | cut -d' ' -f2)" @@ -153,8 +153,9 @@ function load_plugin_from_github local _versions_json="$(wget -q --timeout 300 --tries 30 -O - "${_versions_json_url}")" local _plugin_jar_url="$(echo "${_versions_json}" | jq --raw-output ".[] | select(.neo4j==\"${_neo4j_version}\") | .jar")" if [[ -z "${_plugin_jar_url}" ]]; then - echo >&2 "No jar URL found for version '${_neo4j_version}' in versions.json from '${_versions_json_url}'" + echo >&2 "Error: No jar URL found for version '${_neo4j_version}' in versions.json from '${_versions_json_url}'" echo >&2 "${_versions_json}" + exit 1 fi echo "Installing Plugin '${_plugin_name}' from ${_plugin_jar_url} to ${_destination} " wget -q --timeout 300 --tries 30 --output-document="${_destination}" "${_plugin_jar_url}" @@ -165,6 +166,46 @@ function load_plugin_from_github fi } +function apply_plugin_default_configuration +{ + # Set the correct Load a plugin at runtime. The provided github repository must have a versions.json on the master branch with the + # correct format. + local _plugin_name="${1}" #e.g. apoc, graph-algorithms, graph-ql + local _reference_conf="${2}" # used to determine if we can override properties + local _neo4j_conf="${NEO4J_HOME}/conf/neo4j.conf" + + local _property _value + echo "Applying default values for plugin ${_plugin_name} to neo4j.conf" + for _entry in $(jq --compact-output --raw-output "with_entries( select(.key==\"${_plugin_name}\") ) | to_entries[] | .value.properties | to_entries[]" /neo4jlabs-plugins.json); do + _property="$(jq --raw-output '.key' <<< "${_entry}")" + _value="$(jq --raw-output '.value' <<< "${_entry}")" + + # the first grep strips out comments + if grep -o "^[^#]*" "${_reference_conf}" | grep -q --fixed-strings "${_property}=" ; then + # property is already set in the user provided config. In this case we don't override what has been set explicitly by the user. + echo "Skipping ${_property} for plugin ${_plugin_name} because it is already set" + else + if grep -o "^[^#]*" "${_neo4j_conf}" | grep -q --fixed-strings "${_property}=" ; then + sed --in-place "s/${_property}=/&${_value},/" "${_neo4j_conf}" + else + echo "${_property}=${_value}" >> "${_neo4j_conf}" + fi + fi + done +} + +function install_neo4j_labs_plugins +{ + # We store a copy of the config before we modify it for the plugins to allow us to see if there are user-set values in the input config that we shouldn't override + local _old_config="$(mktemp)" + cp "${NEO4J_HOME}"/conf/neo4j.conf "${_old_config}" + for plugin_name in $(echo "${NEO4JLABS_PLUGINS}" | jq --raw-output '.[]'); do + load_plugin_from_github "${plugin_name}" + apply_plugin_default_configuration "${plugin_name}" "${_old_config}" + done + rm "${_old_config}" +} + # If we're running as root, then run as the neo4j user. Otherwise # docker is running with --user and we simply use that user. Note # that su-exec, despite its name, does not replicate the functionality @@ -435,11 +476,10 @@ done export NEO4J_HOME="${temp_neo4j_home}" unset temp_neo4j_home + if [[ ! -z "${NEO4JLABS_PLUGINS:-}" ]]; then - # NEO4JLABS_PLUGINS should be a json array of plugins like '["graph-algorithms", "apoc-procedures", "streams", "graphql"]' - for plugin_name in $(echo "${NEO4JLABS_PLUGINS}" | jq --raw-output '.[]'); do - load_plugin_from_github "${plugin_name}" - done + # NEO4JLABS_PLUGINS should be a json array of plugins like '["graph-algorithms", "apoc", "streams", "graphql"]' + install_neo4j_labs_plugins fi [ -f "${EXTENSION_SCRIPT:-}" ] && . ${EXTENSION_SCRIPT} diff --git a/neo4jlabs-plugins.json b/neo4jlabs-plugins.json index fa77de24..68764da3 100644 --- a/neo4jlabs-plugins.json +++ b/neo4jlabs-plugins.json @@ -1,7 +1,31 @@ { - "apoc": "https://neo4j-contrib.github.io/neo4j-apoc-procedures/versions.json", - "streams": "https://neo4j-contrib.github.io/neo4j-streams/versions.json", - "graphql": "https://neo4j-graphql.github.io/neo4j-graphql/versions.json", - "graph-algorithms": "https://neo4j-contrib.github.io/neo4j-graph-algorithms/versions.json", - "_testing": "http://host.testcontainers.internal:3000/versions.json" + "apoc": { + "versions": "https://neo4j-contrib.github.io/neo4j-apoc-procedures/versions.json", + "properties": { + "dbms.security.procedures.unrestricted": "apoc.*" + } + }, + "streams": { + "versions": "https://neo4j-contrib.github.io/neo4j-streams/versions.json", + "properties": {} + }, + "graphql": { + "versions": "https://neo4j-graphql.github.io/neo4j-graphql/versions.json", + "properties": { + "dbms.unmanaged_extension_classes": "org.neo4j.graphql=/graphql", + "dbms.security.procedures.unrestricted": "graphql.*" + } + }, + "graph-algorithms": { + "versions": "https://neo4j-contrib.github.io/neo4j-graph-algorithms/versions.json", + "properties": { + "dbms.security.procedures.unrestricted":"algo.*" + } + }, + "_testing": { + "versions": "http://host.testcontainers.internal:3000/versions.json", + "properties": { + "dbms.security.procedures.unrestricted": "com.neo4j.docker.plugins.*" + } + } } diff --git a/src/test/java/com/neo4j/docker/TestPluginInstallation.java b/src/test/java/com/neo4j/docker/TestPluginInstallation.java index 22c39b67..6ceff646 100644 --- a/src/test/java/com/neo4j/docker/TestPluginInstallation.java +++ b/src/test/java/com/neo4j/docker/TestPluginInstallation.java @@ -130,6 +130,38 @@ public void testPlugin() throws Exception assertEquals( record.get( "aFloat" ).asDouble(), 3.14d, 0.000001, message ); assertEquals( record.get( "aBoolean" ).asBoolean(), true, message ); assertFalse( res.hasNext(), "Our procedure should only return a single result" ); + + // Check that the config has been set + res = session.run ( "CALL dbms.listConfig() YIELD name, value WHERE name='dbms.security.procedures.unrestricted' RETURN value" ); + record = res.single(); + assertEquals( record.get( "value" ).asString(), "com.neo4j.docker.plugins.*", "neo4j config not updated for plugin" ); + assertFalse( res.hasNext(), "Config lookup should only return a single result" ); + } + finally + { + container.stop(); + } + } + + @Test + @DisabledIfEnvironmentVariable(named = "NEO4J_DOCKER_TESTS_TestPluginInstallation", matches = "ignore") + public void testPluginConfigurationDoesNotOverrideUserSetValues() throws Exception + { + // When we set a config value explicitly + container = container.withEnv ("NEO4J_dbms_security_procedures_unrestricted", "foo" ); + // When we start the neo4j docker container + container.start(); + + // When we connect to the database with the plugin + String boltAddress = "bolt://" + container.getContainerIpAddress() + ":" + container.getMappedPort( DEFAULT_BOLT_PORT ); + try ( Driver coreDriver = GraphDatabase.driver( boltAddress, AuthTokens.basic( "neo4j", "neo" ) ) ) + { + Session session = coreDriver.session(); + // Check that the config remains as set by our env var and is not overriden by the plugin defaults + StatementResult res = session.run ( "CALL dbms.listConfig() YIELD name, value WHERE name='dbms.security.procedures.unrestricted' RETURN value" ); + Record record = res.single(); + assertEquals( record.get( "value" ).asString(), "foo", "neo4j config should not be overriden by plugin" ); + assertFalse( res.hasNext(), "Config lookup should only return a single result" ); } finally {