44 "context"
55 "encoding/json"
66 "fmt"
7+ "strings"
78
89 "github.com/stackitcloud/stackit-cli/internal/pkg/args"
910 "github.com/stackitcloud/stackit-cli/internal/pkg/errors"
@@ -52,14 +53,21 @@ func NewCmd() *cobra.Command {
5253 return err
5354 }
5455
55- // Call API
56- req := buildRequest (ctx , model , apiClient )
57- resp , err := req .Execute ()
56+ // Call API to get instance details
57+ req := buildGetInstanceRequest (ctx , model , apiClient )
58+ instance , err := req .Execute ()
5859 if err != nil {
5960 return fmt .Errorf ("read Secrets Manager instance: %w" , err )
6061 }
6162
62- return outputResult (cmd , model .OutputFormat , resp )
63+ // Call API to get instance acls
64+ listACLsReq := buildListACLsRequest (ctx , model , apiClient )
65+ aclList , err := listACLsReq .Execute ()
66+ if err != nil {
67+ return fmt .Errorf ("read Secrets Manager instance ACLs: %w" , err )
68+ }
69+
70+ return outputResult (cmd , model .OutputFormat , instance , aclList )
6371 },
6472 }
6573 return cmd
@@ -79,12 +87,17 @@ func parseInput(cmd *cobra.Command, inputArgs []string) (*inputModel, error) {
7987 }, nil
8088}
8189
82- func buildRequest (ctx context.Context , model * inputModel , apiClient * secretsmanager.APIClient ) secretsmanager.ApiGetInstanceRequest {
90+ func buildGetInstanceRequest (ctx context.Context , model * inputModel , apiClient * secretsmanager.APIClient ) secretsmanager.ApiGetInstanceRequest {
8391 req := apiClient .GetInstance (ctx , model .ProjectId , model .InstanceId )
8492 return req
8593}
8694
87- func outputResult (cmd * cobra.Command , outputFormat string , instance * secretsmanager.Instance ) error {
95+ func buildListACLsRequest (ctx context.Context , model * inputModel , apiClient * secretsmanager.APIClient ) secretsmanager.ApiListACLsRequest {
96+ req := apiClient .ListACLs (ctx , model .ProjectId , model .InstanceId )
97+ return req
98+ }
99+
100+ func outputResult (cmd * cobra.Command , outputFormat string , instance * secretsmanager.Instance , aclList * secretsmanager.AclList ) error {
88101 switch outputFormat {
89102 case globalflags .PrettyOutputFormat :
90103
@@ -101,14 +114,29 @@ func outputResult(cmd *cobra.Command, outputFormat string, instance *secretsmana
101114 table .AddSeparator ()
102115 table .AddRow ("CREATION DATE" , * instance .CreationStartDate )
103116 table .AddSeparator ()
117+ // Only show ACL if it's present and not empty
118+ if aclList != nil && aclList .Acls != nil && len (* aclList .Acls ) > 0 {
119+ var cidrs []string
120+
121+ for _ , acl := range * aclList .Acls {
122+ cidrs = append (cidrs , * acl .Cidr )
123+ }
124+
125+ table .AddRow ("ACL" , strings .Join (cidrs , "," ))
126+ }
104127 err := table .Display (cmd )
105128 if err != nil {
106129 return fmt .Errorf ("render table: %w" , err )
107130 }
108131
109132 return nil
110133 default :
111- details , err := json .MarshalIndent (instance , "" , " " )
134+ output := struct {
135+ * secretsmanager.Instance
136+ * secretsmanager.AclList
137+ }{instance , aclList }
138+
139+ details , err := json .MarshalIndent (output , "" , " " )
112140 if err != nil {
113141 return fmt .Errorf ("marshal Secrets Manager instance: %w" , err )
114142 }
0 commit comments