forked from canonical/snapd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
many: add CLI support for getting and setting aspects (canonical#13492)
* aspects: namespace Get value at API, not aspects/ Make aspects/ return the retrieved value without the namespace keyed by the request (per the spec). Since the API supports a GET with many request paths, it can then build the namespace only once with all the values it retrieved. Signed-off-by: Miguel Pires <[email protected]> * many: add a CLI for aspect get and set Signed-off-by: Miguel Pires <[email protected]> --------- Signed-off-by: Miguel Pires <[email protected]>
- Loading branch information
1 parent
e42aa42
commit d3055c9
Showing
13 changed files
with
533 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// -*- Mode: Go; indent-tabs-mode: t -*- | ||
|
||
/* | ||
* Copyright (C) 2024 Canonical Ltd | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License version 3 as | ||
* published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
package client | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"fmt" | ||
"net/url" | ||
"strings" | ||
) | ||
|
||
func (c *Client) AspectGet(aspectID string, requests []string) (result map[string]interface{}, err error) { | ||
query := url.Values{} | ||
query.Add("fields", strings.Join(requests, ",")) | ||
|
||
endpoint := fmt.Sprintf("/v2/aspects/%s", aspectID) | ||
_, err = c.doSync("GET", endpoint, query, nil, nil, &result) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return result, nil | ||
} | ||
|
||
func (c *Client) AspectSet(aspectID string, requestValues map[string]interface{}) (changeID string, err error) { | ||
body, err := json.Marshal(requestValues) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
headers := make(map[string]string) | ||
headers["Content-Type"] = "application/json" | ||
|
||
endpoint := fmt.Sprintf("/v2/aspects/%s", aspectID) | ||
return c.doAsync("PUT", endpoint, nil, headers, bytes.NewReader(body)) | ||
} |
Oops, something went wrong.