If my understanding is correct the solutions snap should be used to read and write configuration files. I'm trying to do this in Go, and have added the "active-solution" plug to my snapcraft.yml plugs:
active-solution:
interface: content
content: solutions
target: $SNAP_COMMON/solutions My code is checking if the directory and file exists, and creates them if not. Creating seems to work, but reading the file results in the following error: Could not read configuration file: open /var/snap/rexroth-solutions/common/solutions/DefaultSolution/configurations/Default/my-snap/config.json: permission denied Trying to view the created directory from the sidebar in the Configurations menu of the virtual control shows this error: open /var/snap/rexroth-solutions/common/solutions/DefaultSolution/configurations/Default/my-snap: permission denied This is the Go source code, any ideas what permissions need to be changed when creating the configuration directory and file? type Config struct {
Greeting string `json:"greeting"`
}
snapCommon := os.Getenv("SNAP_COMMON")
activeConfiguration := path.Join(snapCommon, "/solutions/activeConfiguration")
resolvedPath, err := os.Readlink(activeConfiguration)
if err != nil {
log.Fatalln("Could not resolve active configuration path: ", err)
}
configurationPath := path.Join(resolvedPath, "/my-snap")
if _, err := os.Stat(configurationPath); os.IsNotExist(err) {
os.Mkdir(configurationPath, os.ModeDir)
}
configurationFile := path.Join(configurationPath, "/config.json")
if _, err := os.Stat(configurationFile); os.IsNotExist(err) {
file, err := json.MarshalIndent(Config{Greeting: "Hello World"}, "", " ")
if err != nil {
log.Fatalln("Could not write default configuration file: ", err)
}
ioutil.WriteFile(configurationFile, file, 0644)
}
config := Config{}
file, err := ioutil.ReadFile(configurationFile)
if err != nil {
log.Fatalln("Could not read configuration file: ", err)
}
err = json.Unmarshal([]byte(file), &config)
if err != nil {
log.Fatalln("Could not parse configuration file: ", err)
}
... View more