-
Notifications
You must be signed in to change notification settings - Fork 0
/
registry.go
87 lines (75 loc) · 1.88 KB
/
registry.go
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
* *******************************************************************************
* * Copyright (c) 2023 Datasance Teknoloji A.S.
* *
* * This program and the accompanying materials are made available under the
* * terms of the Eclipse Public License v. 2.0 which is available at
* * http://www.eclipse.org/legal/epl-2.0
* *
* * SPDX-License-Identifier: EPL-2.0
* *******************************************************************************
*
*/
package get
import (
"strconv"
clientutil "github.com/datasance/potctl/internal/util/client"
"github.com/datasance/iofog-go-sdk/v3/pkg/client"
)
type registryExecutor struct {
namespace string
}
func newRegistryExecutor(namespace string) *registryExecutor {
a := ®istryExecutor{}
a.namespace = namespace
return a
}
func (exe *registryExecutor) Execute() error {
printNamespace(exe.namespace)
if err := generateRegistryOutput(exe.namespace); err != nil {
return err
}
return nil
}
func (exe *registryExecutor) GetName() string {
return ""
}
func generateRegistryOutput(namespace string) error {
// Init remote resources
clt, err := clientutil.NewControllerClient(namespace)
if err != nil {
return err
}
registryList, err := clt.ListRegistries()
if err != nil {
return err
}
return tabulateRegistries(registryList.Registries)
}
func tabulateRegistries(catalogItems []client.RegistryInfo) error {
// Generate table and headers
table := make([][]string, len(catalogItems)+1)
headers := []string{
"ID",
"URL",
"USERNAME",
"PRIVATE",
"SECURE",
}
table[0] = append(table[0], headers...)
// Populate rows
idx := 0
for _, item := range catalogItems {
row := []string{
strconv.Itoa(item.ID),
item.URL,
item.Username,
strconv.FormatBool(!item.IsPublic),
strconv.FormatBool(item.IsSecure),
}
table[idx+1] = append(table[idx+1], row...)
idx++
}
// Print table
return print(table)
}