github.com/kubiko/snapd@v0.0.0-20201013125620-d4f3094d9ddf/client/conf.go (about) 1 // -*- Mode: Go; indent-tabs-mode: t -*- 2 3 /* 4 * Copyright (C) 2016 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 client 21 22 import ( 23 "bytes" 24 "encoding/json" 25 "net/url" 26 "strings" 27 ) 28 29 // SetConf requests a snap to apply the provided patch to the configuration. 30 func (client *Client) SetConf(snapName string, patch map[string]interface{}) (changeID string, err error) { 31 b, err := json.Marshal(patch) 32 if err != nil { 33 return "", err 34 } 35 return client.doAsync("PUT", "/v2/snaps/"+snapName+"/conf", nil, nil, bytes.NewReader(b)) 36 } 37 38 // Conf asks for a snap's current configuration. 39 // 40 // Note that the configuration may include json.Numbers. 41 func (client *Client) Conf(snapName string, keys []string) (configuration map[string]interface{}, err error) { 42 // Prepare query 43 query := url.Values{} 44 query.Set("keys", strings.Join(keys, ",")) 45 46 _, err = client.doSync("GET", "/v2/snaps/"+snapName+"/conf", query, nil, nil, &configuration) 47 if err != nil { 48 return nil, err 49 } 50 51 return configuration, nil 52 }