github.com/Lephar/snapd@v0.0.0-20210825215435-c7fba9cef4d2/overlord/configstate/configcore/users.go (about)

     1  // -*- Mode: Go; indent-tabs-mode: t -*-
     2  
     3  /*
     4   * Copyright (C) 2021 Canonical Ltd
     5   *
     6   * This program is free software: you can redistribute it and/or modify
     7   * it under the terms of the GNU General Public License version 3 as
     8   * published by the Free Software Foundation.
     9   *
    10   * This program is distributed in the hope that it will be useful,
    11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
    12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13   * GNU General Public License for more details.
    14   *
    15   * You should have received a copy of the GNU General Public License
    16   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    17   *
    18   */
    19  
    20  package configcore
    21  
    22  import (
    23  	"strings"
    24  
    25  	"github.com/snapcore/snapd/overlord/configstate/config"
    26  )
    27  
    28  func init() {
    29  	supportedConfigurations["core.users.create.automatic"] = true
    30  }
    31  
    32  func earlyUsersSettingsFilter(values, early map[string]interface{}) {
    33  	for key, v := range values {
    34  		if strings.HasPrefix(key, "users.") && supportedConfigurations["core."+key] {
    35  			early[key] = v
    36  		}
    37  	}
    38  }
    39  
    40  func validateUsersSettings(tr config.Conf) error {
    41  	return validateBoolFlag(tr, "users.create.automatic")
    42  }
    43  
    44  func handleUserSettings(tr config.Conf, opts *fsOnlyContext) error {
    45  	output, err := coreCfg(tr, "users.create.automatic")
    46  	if err != nil {
    47  		return nil
    48  	}
    49  
    50  	// normalize the value in case
    51  	switch output {
    52  	case "true":
    53  		tr.Set("core", "users.create.automatic", true)
    54  	case "false":
    55  		tr.Set("core", "users.create.automatic", false)
    56  	}
    57  
    58  	return nil
    59  }