-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathregistry.go
More file actions
110 lines (90 loc) · 2.46 KB
/
registry.go
File metadata and controls
110 lines (90 loc) · 2.46 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package commands
import (
"fmt"
"github.com/drycc/controller-sdk-go/api"
"github.com/drycc/controller-sdk-go/config"
"github.com/drycc/workflow-cli/internal/loader"
)
// RegistryList lists an app's registry information.
func (d *DryccCmd) RegistryList(appID, ptype string, version int) error {
appID, s, err := loader.LoadAppSettings(d.ConfigFile, appID)
if err != nil {
return err
}
config, err := config.List(s.Client, appID, version)
if d.checkAPICompatibility(s.Client, err) != nil {
return err
}
if len(config.Registry) == 0 {
d.Println(fmt.Sprintf("No registrys found in %s app.", appID))
return nil
}
ptypes := []string{}
if ptype != "" {
ptypes = append(ptypes, ptype)
} else {
for ptype := range config.Registry {
ptypes = append(ptypes, ptype)
}
}
table := d.getDefaultFormatTable([]string{"PTYPE", "USERNAME", "PASSWORD"})
for _, ptype := range sortPtypes(ptypes) {
if config.Registry[ptype]["username"] != nil {
table.Append([]string{
ptype,
fmt.Sprintf("%v", config.Registry[ptype]["username"]),
fmt.Sprintf("%v", config.Registry[ptype]["password"]),
})
}
}
table.Render()
return nil
}
// RegistrySet sets an app's registry information.
func (d *DryccCmd) RegistrySet(appID, ptype, username, password string) error {
appID, s, err := loader.LoadAppSettings(d.ConfigFile, appID)
if err != nil {
return err
}
d.Print("Applying registry information... ")
quit := progress(d.WOut)
configObj := api.Config{}
registry := make(map[string]map[string]any)
registry[ptype] = map[string]any{
"username": username,
"password": password,
}
configObj.Registry = registry
_, err = config.Set(s.Client, appID, configObj, true)
quit <- true
<-quit
if d.checkAPICompatibility(s.Client, err) != nil {
return err
}
d.Print("done\n\n")
return d.RegistryList(appID, ptype, -1)
}
// RegistryUnset removes an app's registry information.
func (d *DryccCmd) RegistryUnset(appID, ptype string) error {
appID, s, err := loader.LoadAppSettings(d.ConfigFile, appID)
if err != nil {
return err
}
d.Print("Applying registry information... ")
quit := progress(d.WOut)
configObj := api.Config{}
registry := make(map[string]map[string]any)
registry[ptype] = map[string]any{
"username": nil,
"password": nil,
}
configObj.Registry = registry
_, err = config.Set(s.Client, appID, configObj, true)
quit <- true
<-quit
if d.checkAPICompatibility(s.Client, err) != nil {
return err
}
d.Print("done\n\n")
return nil
}