Skip to content

Commit d4a6522

Browse files
author
Mathieu Grzybek
committed
[catalog] add a command to query /public/catalog
1 parent ea16ed7 commit d4a6522

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed

cmd/catalog.go

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
Copyright © 2021 NAME HERE <EMAIL ADDRESS>
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
package cmd
17+
18+
import (
19+
"encoding/json"
20+
"fmt"
21+
22+
"github.com/spf13/cobra"
23+
"onyxiactl/utils"
24+
)
25+
26+
var catalogCmd = &cobra.Command{
27+
Use: "catalog",
28+
Short: "List the available catalogs.",
29+
Long: `List the available catalogs.`,
30+
Run: func(cmd *cobra.Command, args []string) {
31+
catalog := &CatalogResponse{}
32+
token, _ := cmd.Flags().GetString("token")
33+
onyxiaURL, _ := cmd.Flags().GetString("onyxiaURL")
34+
35+
JsonCatalog, e := utils.CallAPIGet(onyxiaURL+"/public/catalog", token)
36+
if e != nil {
37+
panic(e)
38+
}
39+
40+
e = json.Unmarshal(JsonCatalog, &catalog)
41+
if e != nil {
42+
panic(e)
43+
}
44+
45+
for _, value := range catalog.Catalogs {
46+
j, _ := json.Marshal(value)
47+
fmt.Println(string(j))
48+
}
49+
},
50+
}
51+
52+
func init() {
53+
rootCmd.AddCommand(catalogCmd)
54+
}
55+
56+
type CatalogResponse struct {
57+
Catalogs []struct {
58+
/* Catalog struct {
59+
Packages []struct {
60+
APIVersion string `json:"apiVersion"`
61+
AppVersion string `json:"appVersion"`
62+
Config struct{} `json:"config"`
63+
Created string `json:"created"`
64+
Description string `json:"description"`
65+
Digest string `json:"digest"`
66+
Home string `json:"home"`
67+
Icon string `json:"icon"`
68+
Name string `json:"name"`
69+
Sources []string `json:"sources"`
70+
Urls []string `json:"urls"`
71+
Version string `json:"version"`
72+
} `json:"packages"`
73+
} `json:"catalog"`
74+
*/
75+
ID string `json:"id"`
76+
Description string `json:"description"`
77+
// LastUpdateTime uint `json:"lastUpdateTime"`
78+
Location string `json:"location"`
79+
Maintainer string `json:"maintainer"`
80+
Name string `json:"name"`
81+
Status string `json:"status"`
82+
Type string `json:"type"`
83+
} `json:"catalogs"`
84+
}

0 commit comments

Comments
 (0)