The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/8202

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===
Issue #7870 -- this allows configuration keys starting with `user.*` in server config (`lxc config`). In a cluster, `user.*` keys are replicated across the cluster.
From dae4f4083e8cdd97a8d3b264ed507058367d1467 Mon Sep 17 00:00:00 2001
From: JLRDRAGON92000 <jlrdra...@gmail.com>
Date: Mon, 30 Nov 2020 18:18:30 -0600
Subject: [PATCH] lxd/config: allowed user.* keys in server/cluster config

Signed-off-by: Jared Rankin <jared.ran...@utexas.edu>
---
 lxd/config/map.go | 51 +++++++++++++++++++++++++++++++++++++----------
 1 file changed, 40 insertions(+), 11 deletions(-)

diff --git a/lxd/config/map.go b/lxd/config/map.go
index a4e949269b..dce73165e0 100644
--- a/lxd/config/map.go
+++ b/lxd/config/map.go
@@ -5,6 +5,7 @@ import (
        "reflect"
        "sort"
        "strconv"
+       "strings"
 
        "github.com/lxc/lxd/shared"
 )
@@ -95,14 +96,21 @@ func (m *Map) Change(changes map[string]interface{}) 
(map[string]string, error)
 func (m *Map) Dump() map[string]interface{} {
        values := map[string]interface{}{}
 
-       for name, key := range m.schema {
-               value := m.GetRaw(name)
-               if value != key.Default {
-                       if key.Hidden {
-                               values[name] = true
-                       } else {
-                               values[name] = value
+       for name, value := range m.values {
+               key, ok := m.schema[name]
+               if ok {
+                       // Schema key
+                       value := m.GetRaw(name)
+                       if value != key.Default {
+                               if key.Hidden {
+                                       values[name] = true
+                               } else {
+                                       values[name] = value
+                               }
                        }
+               } else if strings.HasPrefix(name, "user.") {
+                       // User key, just include it as is
+                       values[name] = value
                }
        }
 
@@ -111,17 +119,21 @@ func (m *Map) Dump() map[string]interface{} {
 
 // GetRaw returns the value of the given key, which must be of type String.
 func (m *Map) GetRaw(name string) string {
-       key := m.schema.mustGetKey(name)
        value, ok := m.values[name]
-       if !ok {
-               value = key.Default
+       if !strings.HasPrefix(name, "user.") {
+               key := m.schema.mustGetKey(name)
+               if !ok {
+                       value = key.Default
+               }
        }
        return value
 }
 
 // GetString returns the value of the given key, which must be of type String.
 func (m *Map) GetString(name string) string {
-       m.schema.assertKeyType(name, String)
+       if !strings.HasPrefix(name, "user.") {
+               m.schema.assertKeyType(name, String)
+       }
        return m.GetRaw(name)
 }
 
@@ -182,6 +194,23 @@ func (m *Map) update(values map[string]string) ([]string, 
error) {
 // effectively revert it to the default. Return a boolean indicating whether
 // the value has changed, and error if something went wrong.
 func (m *Map) set(name string, value string, initial bool) (bool, error) {
+       // Bypass schema for user.* keys
+       if strings.HasPrefix(name, "user.") {
+               current, ok := m.values[name]
+               if ok && value == current {
+                       // Value is unchanged
+                       return false, nil
+               }
+
+               if value == "" {
+                       delete(m.values, name)
+               } else {
+                       m.values[name] = value
+               }
+
+               return true, nil
+       }
+
        key, ok := m.schema[name]
        if !ok {
                return false, fmt.Errorf("unknown key")
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to