fix: Horizon custom logo format error with SVG file (#1208)

Co-authored-by: Mohammed Naser <mnaser@vexxhost.com>
diff --git a/.charts.yml b/.charts.yml
index e7a20b3..33123ac 100644
--- a/.charts.yml
+++ b/.charts.yml
@@ -73,6 +73,10 @@
     version: 0.3.15
     repository: *openstack_helm_repository
     dependencies: *openstack_helm_dependencies
+    patches:
+      gerrit:
+        review.opendev.org:
+          - 919480
   - name: ingress-nginx
     version: 4.10.0
     repository:
diff --git a/charts/horizon/templates/bin/_horizon.sh.tpl b/charts/horizon/templates/bin/_horizon.sh.tpl
index 8d2b0be..4f4be33 100644
--- a/charts/horizon/templates/bin/_horizon.sh.tpl
+++ b/charts/horizon/templates/bin/_horizon.sh.tpl
@@ -87,9 +87,30 @@
 
   # Copy custom logo images
   {{- if .Values.manifests.configmap_logo }}
-  cp /tmp/favicon.ico ${SITE_PACKAGES_ROOT}/openstack_dashboard/static/dashboard/img/favicon.ico
-  cp /tmp/logo.svg ${SITE_PACKAGES_ROOT}/openstack_dashboard/static/dashboard/img/logo.svg
-  cp /tmp/logo-splash.svg ${SITE_PACKAGES_ROOT}/openstack_dashboard/static/dashboard/img/logo-splash.svg
+  if [ -f /tmp/favicon.ico ]; then
+    favicon=$(cat /tmp/favicon.ico)
+    if [[ "$favicon" =~ ^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)?$ ]]; then
+      echo $(echo $favicon | base64 --decode) > ${SITE_PACKAGES_ROOT}/openstack_dashboard/static/dashboard/img/favicon.ico
+    else
+      cp /tmp/favicon.ico ${SITE_PACKAGES_ROOT}/openstack_dashboard/static/dashboard/img/favicon.ico
+    fi
+  fi
+  if [ -f /tmp/logo-splash.svg ]; then
+    logo_splash=$(cat /tmp/logo-splash.svg)
+    if [[ "$logo_splash" =~ ^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)?$ ]]; then
+      echo $(echo $logo_splash | base64 --decode) > ${SITE_PACKAGES_ROOT}/openstack_dashboard/static/dashboard/img/logo-splash.svg
+    else
+      cp /tmp/logo-splash.svg ${SITE_PACKAGES_ROOT}/openstack_dashboard/static/dashboard/img/logo-splash.svg
+    fi
+  fi
+  if [ -f /tmp/logo.svg ]; then
+    logo=$(cat /tmp/logo.svg)
+    if [[ "$logo" =~ ^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)?$ ]]; then
+      echo $(echo $logo | base64 --decode) > ${SITE_PACKAGES_ROOT}/openstack_dashboard/static/dashboard/img/logo.svg
+    else
+      cp /tmp/logo.svg ${SITE_PACKAGES_ROOT}/openstack_dashboard/static/dashboard/img/logo.svg
+    fi
+  fi
   {{- end }}
 
   # Compress Horizon's assets.
diff --git a/charts/horizon/values.yaml b/charts/horizon/values.yaml
index 36de4ee..4a06045 100644
--- a/charts/horizon/values.yaml
+++ b/charts/horizon/values.yaml
@@ -77,6 +77,7 @@
         - status
   horizon:
     branding:
+      # logo, logo_splash and favicon accepts base64 encoded string.
       logo:
       logo_splash:
       favicon:
diff --git a/doc/source/config/horizon.rst b/doc/source/config/horizon.rst
new file mode 100644
index 0000000..c203447
--- /dev/null
+++ b/doc/source/config/horizon.rst
@@ -0,0 +1,42 @@
+#######
+Horizon
+#######
+
+The Horizon component serves as the web-based user interface for OpenStack,
+allowing users to interact with the cloud infrastructure.
+
+By default, Horizon is configured to work out of the box with minimal changes
+needed.  However, it can be extensively customized to fit the branding and
+requirements of your organization.
+
+.. admonition:: Deploying Horizon
+
+    If you make any changes to Horizon only and you want to deploy the Horizon
+    changes only, you can run the following command:
+
+    .. code-block:: bash
+
+        ansible-playbook vexxhost.atmosphere.openstack -t horizon
+
+********
+Branding
+********
+
+To customize the logos used in the Horizon dashboard, you need to update the
+Horizon Helm values with your custom logo files. Follow the steps below:
+
+.. code-block:: yaml
+
+    horizon_helm_values:
+      conf:
+        horizon:
+          branding:
+            logo: "{{ lookup('file', inventory_dir ~ '/files/logo.svg') | b64encode }}"
+            logo_splash: "{{ lookup('file', inventory_dir ~ '/files/logo-splash.svg') | b64encode }}"
+            favicon: "{{ lookup('file', inventory_dir ~ '/files/favicon.svg') | b64encode }}"
+      manifests:
+        configmap_logo: true
+
+It's recommended that you use ``base64`` encoded string for the values since the
+content of the files might contain special characters that could be wrongly
+handled by Helm, such as SVG files.
diff --git a/doc/source/config/index.rst b/doc/source/config/index.rst
index 6e6cb56..e37c3ba 100644
--- a/doc/source/config/index.rst
+++ b/doc/source/config/index.rst
@@ -6,3 +6,4 @@
    :maxdepth: 2
 
    ingress
+   horizon