Skip to content

Commit 3f9b102

Browse files
committed
feat(allow base64 decode for swarm configs)
1 parent 8af4830 commit 3f9b102

4 files changed

Lines changed: 41 additions & 1 deletion

File tree

internal/dao/docker.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,10 @@ func (d *DockerClient) UpdateConfig(id string, data []byte) error {
584584
return d.Config.Update(id, data)
585585
}
586586

587+
func (d *DockerClient) GetConfigData(id string) ([]byte, error) {
588+
return d.Config.GetData(id)
589+
}
590+
587591
func (d *DockerClient) ListStacks() ([]common.Resource, error) {
588592
return d.Stack.List()
589593
}

internal/dao/docker/dconfig/dconfig.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,14 @@ func (m *Manager) Create(name string, data []byte) error {
119119
return err
120120
}
121121

122+
func (m *Manager) GetData(id string) ([]byte, error) {
123+
cfg, _, err := m.cli.ConfigInspectWithRaw(m.ctx, id)
124+
if err != nil {
125+
return nil, err
126+
}
127+
return cfg.Spec.Data, nil
128+
}
129+
122130
func (m *Manager) Update(id string, data []byte) error {
123131
cfg, _, err := m.cli.ConfigInspectWithRaw(m.ctx, id)
124132
if err != nil {

internal/ui/components/inspect/utils.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"github.com/jr-k/d4s/internal/ui/styles"
88
)
99

10-
1110
// FormatInspectorTitle generates the standard title string for inspectors
1211
// Format: Action(subject) [Mode] <Search>
1312
func FormatInspectorTitle(action, subject, mode, filter string, matchIndex, matchCount int) string {

internal/ui/views/configs/configs.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ func GetShortcuts() []string {
2323
return []string{
2424
common.FormatSCHeader("s", "Services"),
2525
common.FormatSCHeader("d", "Describe"),
26+
common.FormatSCHeader("x", "Decode"),
2627
common.FormatSCHeader("a", "Add"),
2728
common.FormatSCHeader("ctrl-d", "Delete"),
2829
}
@@ -43,6 +44,9 @@ func InputHandler(v *view.ResourceView, event *tcell.EventKey) *tcell.EventKey {
4344
case 'd':
4445
app.InspectCurrentSelection()
4546
return nil
47+
case 'x':
48+
Decode(app, v)
49+
return nil
4650
case 'a':
4751
Create(app)
4852
return nil
@@ -143,6 +147,31 @@ func Create(app common.AppController) {
143147
})
144148
}
145149

150+
func Decode(app common.AppController, v *view.ResourceView) {
151+
id, err := v.GetSelectedID()
152+
if err != nil {
153+
return
154+
}
155+
156+
subject := resolveConfigSubject(v, id)
157+
inspector := inspect.NewTextInspector("Decode config", subject, fmt.Sprintf(" [%s]Decoding config...\n", styles.TagAccent), "data")
158+
app.OpenInspector(inspector)
159+
160+
app.RunInBackground(func() {
161+
data, err := app.GetDocker().GetConfigData(id)
162+
if err != nil {
163+
app.GetTviewApp().QueueUpdateDraw(func() {
164+
inspector.Viewer.Update(fmt.Sprintf("Error: %v", err), "text")
165+
})
166+
return
167+
}
168+
169+
app.GetTviewApp().QueueUpdateDraw(func() {
170+
inspector.Viewer.Update(string(data), "env")
171+
})
172+
})
173+
}
174+
146175
func Inspect(app common.AppController, id string) {
147176
subject := id
148177
if len(id) > 12 {

0 commit comments

Comments
 (0)