Skip to content

Commit dcf2275

Browse files
feat(service-account): add support for service account SDK (#1743)
1 parent 64ebafb commit dcf2275

File tree

7 files changed

+79
-4
lines changed

7 files changed

+79
-4
lines changed

docs/commands/rhoas_service-account_describe.md

+3-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/commands/rhoas_service-account_list.md

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ require (
9292
github.com/prometheus/common v0.26.0 // indirect
9393
github.com/prometheus/procfs v0.6.0 // indirect
9494
github.com/redhat-developer/app-services-sdk-go v0.10.0 // indirect
95+
github.com/redhat-developer/app-services-sdk-go/serviceaccountmgmt v0.9.0 // indirect
9596
github.com/rivo/uniseg v0.2.0 // indirect
9697
github.com/russross/blackfriday/v2 v2.1.0 // indirect
9798
github.com/segmentio/backo-go v0.0.0-20200129164019-23eae7c10bd3 // indirect

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,8 @@ github.com/redhat-developer/app-services-sdk-go/registryinstance v0.5.1 h1:pgOtC
693693
github.com/redhat-developer/app-services-sdk-go/registryinstance v0.5.1/go.mod h1:HkNzOWHTW/SomobQ4343+yR4oTmiyvm85BIWlsh0qbA=
694694
github.com/redhat-developer/app-services-sdk-go/registrymgmt v0.10.0 h1:9kqTCGoz5jR6VE+cgz8fl5Zt9Ctctg9GN1XlkzheVQw=
695695
github.com/redhat-developer/app-services-sdk-go/registrymgmt v0.10.0/go.mod h1:UoxuqkUN+g5Ni8zgsCA7zidR5s774m9fqhZ5o4eOSIM=
696+
github.com/redhat-developer/app-services-sdk-go/serviceaccountmgmt v0.9.0 h1:kMvH66RXnxrF7FKraWu7n1BnaWrCUchw2unYa9rl/IM=
697+
github.com/redhat-developer/app-services-sdk-go/serviceaccountmgmt v0.9.0/go.mod h1:kpEKXWqyD6GUiQjBHCGzp/LIbCBfkTWpPo4VqkQ9zq4=
696698
github.com/redhat-developer/service-binding-operator v0.9.0 h1:CS+eEtzu/PtWuyvYQFQpZXd6ukSuFtN+U0EKKtTsvlA=
697699
github.com/redhat-developer/service-binding-operator v0.9.0/go.mod h1:D415gZQiz5Q8zyRbmrNrlieb6Xp73oFtCb+nCuTL6GA=
698700
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=

pkg/cmd/serviceaccount/describe/describe.go

+25
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,25 @@ import (
99
"github.com/redhat-developer/app-services-cli/pkg/core/ioutil/dump"
1010
"github.com/redhat-developer/app-services-cli/pkg/core/ioutil/iostreams"
1111
"github.com/redhat-developer/app-services-cli/pkg/core/localize"
12+
"github.com/redhat-developer/app-services-cli/pkg/core/logging"
1213
"github.com/redhat-developer/app-services-cli/pkg/shared/factory"
1314

15+
svcacctmgmtclient "github.com/redhat-developer/app-services-sdk-go/serviceaccountmgmt/apiv1/client"
16+
1417
"github.com/spf13/cobra"
1518
)
1619

1720
type options struct {
1821
id string
1922
outputFormat string
23+
enableAuthV2 bool
2024

2125
IO *iostreams.IOStreams
2226
Config config.IConfig
2327
Connection factory.ConnectionFunc
2428
localizer localize.Localizer
2529
Context context.Context
30+
Logger logging.Logger
2631
}
2732

2833
func NewDescribeCommand(f *factory.Factory) *cobra.Command {
@@ -32,6 +37,7 @@ func NewDescribeCommand(f *factory.Factory) *cobra.Command {
3237
IO: f.IOStreams,
3338
localizer: f.Localizer,
3439
Context: f.Context,
40+
Logger: f.Logger,
3541
}
3642

3743
cmd := &cobra.Command{
@@ -52,6 +58,7 @@ func NewDescribeCommand(f *factory.Factory) *cobra.Command {
5258

5359
cmd.Flags().StringVar(&opts.id, "id", "", opts.localizer.MustLocalize("serviceAccount.describe.flag.id.description"))
5460
cmd.Flags().StringVarP(&opts.outputFormat, "output", "o", "json", opts.localizer.MustLocalize("serviceAccount.common.flag.output.description"))
61+
cmd.Flags().BoolVar(&opts.enableAuthV2, "enable-auth-v2", false, opts.localizer.MustLocalize("serviceAccount.common.flag.enableAuthV2"))
5562

5663
_ = cmd.MarkFlagRequired("id")
5764

@@ -85,5 +92,23 @@ func runDescribe(opts *options) error {
8592
}
8693
}
8794

95+
// Temporary workaround to be removed
96+
if opts.enableAuthV2 {
97+
98+
timeInt := res.CreatedAt.Unix()
99+
100+
formattedRes := svcacctmgmtclient.ServiceAccountData{
101+
Id: &res.Id,
102+
ClientId: res.ClientId,
103+
Name: res.Name,
104+
Description: res.Description,
105+
CreatedBy: res.CreatedBy,
106+
CreatedAt: &timeInt,
107+
}
108+
109+
return dump.Formatted(opts.IO.Out, opts.outputFormat, formattedRes)
110+
}
111+
112+
opts.Logger.Info(opts.localizer.MustLocalize("serviceAccount.common.breakingChangeNotice.SDK"))
88113
return dump.Formatted(opts.IO.Out, opts.outputFormat, res)
89114
}

pkg/cmd/serviceaccount/list/list.go

+36-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import (
1212
"github.com/redhat-developer/app-services-cli/pkg/shared/factory"
1313
kafkamgmtclient "github.com/redhat-developer/app-services-sdk-go/kafkamgmt/apiv1/client"
1414
"github.com/spf13/cobra"
15+
16+
svcacctmgmtclient "github.com/redhat-developer/app-services-sdk-go/serviceaccountmgmt/apiv1/client"
1517
)
1618

1719
type options struct {
@@ -22,7 +24,8 @@ type options struct {
2224
localizer localize.Localizer
2325
Context context.Context
2426

25-
output string
27+
output string
28+
enableAuthV2 bool
2629
}
2730

2831
// svcAcctRow contains the properties used to
@@ -62,6 +65,7 @@ func NewListCommand(f *factory.Factory) *cobra.Command {
6265
}
6366

6467
cmd.Flags().StringVarP(&opts.output, "output", "o", "", opts.localizer.MustLocalize("serviceAccount.list.flag.output.description"))
68+
cmd.Flags().BoolVar(&opts.enableAuthV2, "enable-auth-v2", false, opts.localizer.MustLocalize("serviceAccount.common.flag.enableAuthV2"))
6569

6670
flagutil.EnableOutputFlagCompletion(cmd)
6771

@@ -91,6 +95,12 @@ func runList(opts *options) (err error) {
9195
rows := mapResponseItemsToRows(serviceaccounts)
9296
dump.Table(outStream, rows)
9397
default:
98+
// Temporary workaround to be removed
99+
if opts.enableAuthV2 {
100+
formattedRes := mapResponseToNewFormat(res)
101+
return dump.Formatted(opts.IO.Out, opts.output, formattedRes)
102+
}
103+
opts.Logger.Info(opts.localizer.MustLocalize("serviceAccount.common.breakingChangeNotice.SDK"))
94104
return dump.Formatted(opts.IO.Out, opts.output, res)
95105
}
96106

@@ -114,3 +124,28 @@ func mapResponseItemsToRows(svcAccts []kafkamgmtclient.ServiceAccountListItem) [
114124

115125
return rows
116126
}
127+
128+
// mapResponseToNewFormat accepts response of old sdk and transforms it to response of new sdk
129+
func mapResponseToNewFormat(res kafkamgmtclient.ServiceAccountList) []svcacctmgmtclient.ServiceAccountData {
130+
131+
var serviceaccounts []svcacctmgmtclient.ServiceAccountData
132+
133+
for _, svcAcct := range res.GetItems() {
134+
135+
timeInt := svcAcct.CreatedAt.Unix()
136+
137+
formattedServiceAccount := svcacctmgmtclient.ServiceAccountData{
138+
Id: &svcAcct.Id,
139+
ClientId: svcAcct.ClientId,
140+
Name: svcAcct.Name,
141+
Description: svcAcct.Description,
142+
CreatedBy: svcAcct.CreatedBy,
143+
CreatedAt: &timeInt,
144+
}
145+
146+
serviceaccounts = append(serviceaccounts, formattedServiceAccount)
147+
}
148+
149+
return serviceaccounts
150+
151+
}

pkg/core/localize/locales/en/cmd/serviceaccount.en.toml

+10
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ rhoas service-account list
2121
description = "Description for --output flag"
2222
one = 'Format in which to display the service account (choose from: "json", "yml", "yaml")'
2323

24+
[serviceAccount.common.flag.enableAuthV2]
25+
one = 'Format output according to new Service Account SDK'
26+
2427
[serviceAccount.list.flag.output.description]
2528
one = 'Format in which to display the service accounts (choose from: "json", "yml", "yaml")'
2629

@@ -105,3 +108,10 @@ one = 'invalid service account description: only lowercase letters (a-z), number
105108

106109
[serviceAccount.common.validation.id.error.invalidID]
107110
one = '"{{.ID}}" is not a valid UUID'
111+
112+
[serviceAccount.common.breakingChangeNotice.SDK]
113+
one = '''
114+
Breaking Change Notice: The CLI is soon going to have the output format for this command altered.
115+
116+
To try with the latest format, pass the "--enable-auth-v2" flag
117+
'''

0 commit comments

Comments
 (0)