Skip to content

Commit c845ada

Browse files
authored
feat(rdb): list ACLs when getting a rdb instance (#3473)
1 parent 88fa35b commit c845ada

File tree

4 files changed

+279
-174
lines changed

4 files changed

+279
-174
lines changed

internal/namespaces/rdb/v1/custom.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func GetCommands() *core.Commands {
3838
cmds.MustFind("rdb", "instance", "clone").Override(instanceCloneBuilder)
3939
cmds.MustFind("rdb", "instance", "upgrade").Override(instanceUpgradeBuilder)
4040
cmds.MustFind("rdb", "instance", "update").Override(instanceUpdateBuilder)
41+
cmds.MustFind("rdb", "instance", "get").Override(instanceGetBuilder)
4142

4243
cmds.MustFind("rdb", "engine", "list").Override(engineListBuilder)
4344

internal/namespaces/rdb/v1/custom_instance.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,62 @@ func instanceCreateBuilder(c *core.Command) *core.Command {
270270
return c
271271
}
272272

273+
func instanceGetBuilder(c *core.Command) *core.Command {
274+
c.Interceptor = func(ctx context.Context, argsI interface{}, runner core.CommandRunner) (interface{}, error) {
275+
res, err := runner(ctx, argsI)
276+
if err != nil {
277+
return nil, err
278+
}
279+
instance := res.(*rdb.Instance)
280+
281+
args := argsI.(*rdb.GetInstanceRequest)
282+
283+
acls, err := rdb.NewAPI(core.ExtractClient(ctx)).ListInstanceACLRules(&rdb.ListInstanceACLRulesRequest{
284+
Region: args.Region,
285+
InstanceID: args.InstanceID,
286+
}, scw.WithAllPages())
287+
if err != nil {
288+
return res, nil
289+
}
290+
291+
return struct {
292+
*rdb.Instance
293+
ACLs []*rdb.ACLRule `json:"acls"`
294+
}{
295+
instance,
296+
acls.Rules,
297+
}, nil
298+
}
299+
300+
c.View = &core.View{
301+
Sections: []*core.ViewSection{
302+
{
303+
FieldName: "Endpoint",
304+
Title: "Endpoint",
305+
},
306+
{
307+
FieldName: "Volume",
308+
Title: "Volume",
309+
},
310+
{
311+
FieldName: "BackupSchedule",
312+
Title: "Backup schedule",
313+
},
314+
{
315+
FieldName: "Settings",
316+
Title: "Settings",
317+
HideIfEmpty: true,
318+
},
319+
{
320+
FieldName: "ACLs",
321+
Title: "ACLs",
322+
HideIfEmpty: true,
323+
},
324+
},
325+
}
326+
return c
327+
}
328+
273329
func instanceUpgradeBuilder(c *core.Command) *core.Command {
274330
c.ArgSpecs.GetByName("node-type").AutoCompleteFunc = autoCompleteNodeType
275331

0 commit comments

Comments
 (0)