1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
// Copyright 2015 Canonical Ltd.
// Copyright 2015 Cloudbase Solutions SRL
// Licensed under the LGPLv3, see LICENCE file for details.
// +build windows
package featureflag
import (
"golang.org/x/sys/windows/registry"
)
// SetFlagsFromRegistry populates the global set from the registry keys on
// windows.
// White space between flags is ignored, and the flags are lower cased. Under
// normal circumstances this method is only ever called from the init
// function.
//
// NOTE: since SetFlagsFromRegistry should only ever called during the
// program startup (or tests), and it is serialized by the runtime, we don't
// use any mutux when setting the flag set. Should this change in the future,
// a mutex should be used.
func SetFlagsFromRegistry(regVarKey string, regVarName string) {
setFlags(getFlagsFromRegistry(regVarKey, regVarName))
}
// getFlagsFromRegistry returns the string value from a registry key
func getFlagsFromRegistry(regVarKey, regVarName string) string {
regKeyPath := regVarKey[len(`HKLM:\`):]
k, err := registry.OpenKey(registry.LOCAL_MACHINE, regKeyPath, registry.QUERY_VALUE)
if err != nil {
// Since this is called during init, we can't fail here. We just log
// the failure and move on.
logger.Warningf("Failed to open juju registry key %s; feature flags not enabled", regVarKey)
return ""
}
defer k.Close()
f, _, err := k.GetStringValue(regVarName)
if err != nil {
// Since this is called during init, we can't fail here. We just log
// the failure and move on.
logger.Warningf("Failed to read juju registry value %s; feature flags not enabled", regVarName)
return ""
}
return f
}
|