Skip to content

Commit ae637b8

Browse files
authored
fix: revert service accounts integration (#1732)
1 parent c60f1fc commit ae637b8

File tree

16 files changed

+80
-74
lines changed

16 files changed

+80
-74
lines changed

go.mod

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ require (
2828
github.com/redhat-developer/app-services-sdk-go/kafkamgmt v0.13.0
2929
github.com/redhat-developer/app-services-sdk-go/registryinstance v0.5.1
3030
github.com/redhat-developer/app-services-sdk-go/registrymgmt v0.10.0
31-
github.com/redhat-developer/app-services-sdk-go/serviceaccountmgmt v0.8.0
3231
github.com/redhat-developer/service-binding-operator v0.9.0
3332
github.com/spf13/cobra v1.5.0
3433
github.com/spf13/pflag v1.0.5

internal/build/build.go

-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ var (
6060
DefaultLoginTimeout = 60 * time.Second
6161
OfflineTokenURL = ConsoleURL + "/openshift/token"
6262
ProductionAuthURL = "https://sso.redhat.com/auth/realms/redhat-external"
63-
StagingAuthURL = "https://sso.stage.redhat.com/auth/realms/redhat-external"
6463
)
6564

6665
func init() {

pkg/cmd/connector/create/create.go

+6-7
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,13 @@ import (
2020
"github.com/redhat-developer/app-services-cli/pkg/core/ioutil/dump"
2121
"github.com/redhat-developer/app-services-cli/pkg/core/localize"
2222
connectorerror "github.com/redhat-developer/app-services-sdk-go/connectormgmt/apiv1/error"
23-
svcacctmgmtclient "github.com/redhat-developer/app-services-sdk-go/serviceaccountmgmt/apiv1/client"
24-
2523
"gopkg.in/AlecAivazis/survey.v1"
2624

2725
"github.com/redhat-developer/app-services-cli/pkg/shared/connection"
2826
"github.com/redhat-developer/app-services-cli/pkg/shared/factory"
2927
connectormgmtclient "github.com/redhat-developer/app-services-sdk-go/connectormgmt/apiv1/client"
3028

29+
kafkamgmtclient "github.com/redhat-developer/app-services-sdk-go/kafkamgmt/apiv1/client"
3130
"github.com/spf13/cobra"
3231
)
3332

@@ -138,17 +137,17 @@ func runCreate(opts *options) error {
138137
return nil
139138
}
140139

141-
func createServiceAccount(opts *factory.Factory, shortDescription string) (*svcacctmgmtclient.ServiceAccountData, error) {
140+
func createServiceAccount(opts *factory.Factory, shortDescription string) (*kafkamgmtclient.ServiceAccount, error) {
142141
conn, err := opts.Connection()
143142
if err != nil {
144143
return nil, err
145144
}
146-
serviceAccountPayload := svcacctmgmtclient.ServiceAccountCreateRequestData{Name: shortDescription}
145+
serviceAccountPayload := kafkamgmtclient.ServiceAccountRequest{Name: shortDescription}
147146

148147
serviceacct, httpRes, err := conn.API().
149148
ServiceAccountMgmt().
150149
CreateServiceAccount(opts.Context).
151-
ServiceAccountCreateRequestData(serviceAccountPayload).
150+
ServiceAccountRequest(serviceAccountPayload).
152151
Execute()
153152

154153
if httpRes != nil {
@@ -159,7 +158,7 @@ func createServiceAccount(opts *factory.Factory, shortDescription string) (*svca
159158
return nil, err
160159
}
161160
opts.Logger.Info(opts.Localizer.MustLocalize("connector.sa.created",
162-
localize.NewEntry("ClientId", serviceacct.ClientId), localize.NewEntry("ClientSecret", serviceacct.Secret), localize.NewEntry("Name", shortDescription)))
161+
localize.NewEntry("ClientId", serviceacct.ClientId), localize.NewEntry("ClientSecret", serviceacct.ClientSecret), localize.NewEntry("Name", shortDescription)))
163162
return &serviceacct, nil
164163
}
165164

@@ -184,7 +183,7 @@ func setDefaultValuesFromFlags(connector *connectormgmtclient.ConnectorRequest,
184183
if err1 != nil {
185184
return err1
186185
}
187-
connector.ServiceAccount = *connectormgmtclient.NewServiceAccount(serviceAccount.GetClientId(), serviceAccount.GetSecret())
186+
connector.ServiceAccount = *connectormgmtclient.NewServiceAccount(serviceAccount.GetClientId(), serviceAccount.GetClientSecret())
188187
}
189188
return nil
190189
}

pkg/cmd/login/login.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ var apiGatewayAliases = map[string]string{
3838
var authURLAliases = map[string]string{
3939
"production": build.ProductionAuthURL,
4040
"prod": build.ProductionAuthURL,
41-
"staging": build.StagingAuthURL,
42-
"stage": build.StagingAuthURL,
41+
"staging": build.ProductionAuthURL,
42+
"stage": build.ProductionAuthURL,
4343
}
4444

4545
type options struct {

pkg/cmd/serviceaccount/create/create.go

+10-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"github.com/redhat-developer/app-services-cli/pkg/core/logging"
1919
"github.com/redhat-developer/app-services-cli/pkg/shared/factory"
2020

21-
svcacctmgmtclient "github.com/redhat-developer/app-services-sdk-go/serviceaccountmgmt/apiv1/client"
21+
kafkamgmtclient "github.com/redhat-developer/app-services-sdk-go/kafkamgmt/apiv1/client"
2222

2323
"github.com/AlecAivazis/survey/v2"
2424
"github.com/spf13/cobra"
@@ -127,12 +127,17 @@ func runCreate(opts *options) error {
127127
spinner.SetSuffix(opts.localizer.MustLocalize("serviceAccount.create.log.info.creating"))
128128
spinner.Start()
129129
// create the service account
130-
serviceAccountPayload := svcacctmgmtclient.ServiceAccountCreateRequestData{Name: opts.shortDescription}
130+
serviceAccountPayload := kafkamgmtclient.ServiceAccountRequest{Name: opts.shortDescription}
131+
132+
providerUrls, err := svcaccountcmdutil.GetProvidersDetails(conn, opts.Context)
133+
if err != nil {
134+
return err
135+
}
131136

132137
serviceacct, httpRes, err := conn.API().
133138
ServiceAccountMgmt().
134139
CreateServiceAccount(opts.Context).
135-
ServiceAccountCreateRequestData(serviceAccountPayload).
140+
ServiceAccountRequest(serviceAccountPayload).
136141
Execute()
137142
spinner.Stop()
138143

@@ -148,8 +153,8 @@ func runCreate(opts *options) error {
148153

149154
creds := &credentials.Credentials{
150155
ClientID: serviceacct.GetClientId(),
151-
ClientSecret: serviceacct.GetSecret(),
152-
TokenURL: conn.API().GetConfig().AuthURL.String() + "/protocol/openid-connect/token",
156+
ClientSecret: serviceacct.GetClientSecret(),
157+
TokenURL: providerUrls.GetTokenUrl(),
153158
}
154159

155160
// save the credentials to a file

pkg/cmd/serviceaccount/delete/delete.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func runDelete(opts *options) (err error) {
7878
return err
7979
}
8080

81-
_, httpRes, err := conn.API().ServiceAccountMgmt().GetServiceAccount(opts.Context, opts.id).Execute()
81+
_, httpRes, err := conn.API().ServiceAccountMgmt().GetServiceAccountById(opts.Context, opts.id).Execute()
8282
if httpRes != nil {
8383
defer httpRes.Body.Close()
8484
}
@@ -118,7 +118,7 @@ func deleteServiceAccount(opts *options) error {
118118
return err
119119
}
120120

121-
httpRes, err := conn.API().ServiceAccountMgmt().DeleteServiceAccount(opts.Context, opts.id).Execute()
121+
_, httpRes, err := conn.API().ServiceAccountMgmt().DeleteServiceAccountById(opts.Context, opts.id).Execute()
122122
if httpRes != nil {
123123
defer httpRes.Body.Close()
124124
}

pkg/cmd/serviceaccount/describe/describe.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func runDescribe(opts *options) error {
6868

6969
api := conn.API()
7070

71-
res, httpRes, err := api.ServiceAccountMgmt().GetServiceAccount(opts.Context, opts.id).Execute()
71+
res, httpRes, err := api.ServiceAccountMgmt().GetServiceAccountById(opts.Context, opts.id).Execute()
7272
if httpRes != nil {
7373
defer httpRes.Body.Close()
7474
}

pkg/cmd/serviceaccount/list/list.go

+6-15
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ package list
22

33
import (
44
"context"
5-
"fmt"
6-
"time"
75

86
"github.com/redhat-developer/app-services-cli/pkg/core/cmdutil/flagutil"
97
"github.com/redhat-developer/app-services-cli/pkg/core/config"
@@ -12,8 +10,7 @@ import (
1210
"github.com/redhat-developer/app-services-cli/pkg/core/localize"
1311
"github.com/redhat-developer/app-services-cli/pkg/core/logging"
1412
"github.com/redhat-developer/app-services-cli/pkg/shared/factory"
15-
svcacctmgmtclient "github.com/redhat-developer/app-services-sdk-go/serviceaccountmgmt/apiv1/client"
16-
13+
kafkamgmtclient "github.com/redhat-developer/app-services-sdk-go/kafkamgmt/apiv1/client"
1714
"github.com/spf13/cobra"
1815
)
1916

@@ -77,11 +74,12 @@ func runList(opts *options) (err error) {
7774
return err
7875
}
7976

80-
serviceaccounts, _, err := conn.API().ServiceAccountMgmt().GetServiceAccounts(opts.Context).Execute()
77+
res, _, err := conn.API().ServiceAccountMgmt().GetServiceAccounts(opts.Context).Execute()
8178
if err != nil {
8279
return err
8380
}
8481

82+
serviceaccounts := res.GetItems()
8583
if len(serviceaccounts) == 0 && opts.output == "" {
8684
opts.Logger.Info(opts.localizer.MustLocalize("serviceAccount.list.log.info.noneFound"))
8785
return nil
@@ -93,33 +91,26 @@ func runList(opts *options) (err error) {
9391
rows := mapResponseItemsToRows(serviceaccounts)
9492
dump.Table(outStream, rows)
9593
default:
96-
return dump.Formatted(opts.IO.Out, opts.output, serviceaccounts)
94+
return dump.Formatted(opts.IO.Out, opts.output, res)
9795
}
9896

9997
return nil
10098
}
10199

102-
func mapResponseItemsToRows(svcAccts []svcacctmgmtclient.ServiceAccountData) []svcAcctRow {
100+
func mapResponseItemsToRows(svcAccts []kafkamgmtclient.ServiceAccountListItem) []svcAcctRow {
103101
rows := make([]svcAcctRow, len(svcAccts))
104102

105103
for i, sa := range svcAccts {
106-
107104
row := svcAcctRow{
108105
ID: sa.GetId(),
109106
Name: sa.GetName(),
110107
ClientID: sa.GetClientId(),
111108
Owner: sa.GetCreatedBy(),
112-
CreatedAt: unixTimestampToUTC(sa.GetCreatedAt()),
109+
CreatedAt: sa.GetCreatedAt().String(),
113110
}
114111

115112
rows[i] = row
116113
}
117114

118115
return rows
119116
}
120-
121-
// unixTimestampToUTC converts a unix timestamp to the corresponding local Time
122-
func unixTimestampToUTC(timestamp int64) string {
123-
localTime := time.Unix(timestamp, 0)
124-
return fmt.Sprint(localTime)
125-
}

pkg/cmd/serviceaccount/resetcredentials/reset_credentials.go

+13-14
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
"github.com/redhat-developer/app-services-cli/pkg/core/localize"
1818
"github.com/redhat-developer/app-services-cli/pkg/core/logging"
1919
"github.com/redhat-developer/app-services-cli/pkg/shared/factory"
20-
svcacctmgmtclient "github.com/redhat-developer/app-services-sdk-go/serviceaccountmgmt/apiv1/client"
20+
kafkamgmtclient "github.com/redhat-developer/app-services-sdk-go/kafkamgmt/apiv1/client"
2121

2222
"github.com/AlecAivazis/survey/v2"
2323
"github.com/spf13/cobra"
@@ -107,19 +107,16 @@ func runResetCredentials(opts *options) (err error) {
107107

108108
api := conn.API()
109109

110-
if opts.id != "" {
111-
_, httpRes, newErr := api.ServiceAccountMgmt().GetServiceAccount(opts.Context, opts.id).Execute()
112-
if httpRes != nil {
113-
defer httpRes.Body.Close()
114-
}
115-
if newErr != nil {
116-
return newErr
117-
}
110+
_, httpRes, err := api.ServiceAccountMgmt().GetServiceAccountById(opts.Context, opts.id).Execute()
111+
if httpRes != nil {
112+
defer httpRes.Body.Close()
113+
}
118114

115+
if err != nil {
116+
return err
119117
}
120118

121119
if opts.interactive {
122-
123120
err = runInteractivePrompt(opts)
124121
if err != nil {
125122
return err
@@ -159,10 +156,12 @@ func runResetCredentials(opts *options) (err error) {
159156

160157
opts.Logger.Info(icon.SuccessPrefix(), opts.localizer.MustLocalize("serviceAccount.resetCredentials.log.info.resetSuccess", localize.NewEntry("ID", updatedServiceAccount.GetId())))
161158

159+
providerUrls, err := svcaccountcmdutil.GetProvidersDetails(conn, opts.Context)
160+
162161
creds := &credentials.Credentials{
163162
ClientID: updatedServiceAccount.GetClientId(),
164-
ClientSecret: updatedServiceAccount.GetSecret(),
165-
TokenURL: conn.API().GetConfig().AuthURL.String() + "/protocol/openid-connect/token",
163+
ClientSecret: updatedServiceAccount.GetClientSecret(),
164+
TokenURL: providerUrls.GetTokenUrl(),
166165
}
167166

168167
// save the credentials to a file
@@ -179,7 +178,7 @@ func runResetCredentials(opts *options) (err error) {
179178
return nil
180179
}
181180

182-
func resetCredentials(opts *options) (*svcacctmgmtclient.ServiceAccountData, error) {
181+
func resetCredentials(opts *options) (*kafkamgmtclient.ServiceAccount, error) {
183182
conn, err := opts.Connection()
184183
if err != nil {
185184
return nil, err
@@ -190,7 +189,7 @@ func resetCredentials(opts *options) (*svcacctmgmtclient.ServiceAccountData, err
190189

191190
opts.Logger.Debug(opts.localizer.MustLocalize("serviceAccount.resetCredentials.log.debug.resettingCredentials", localize.NewEntry("ID", opts.id)))
192191

193-
serviceacct, httpRes, err := api.ServiceAccountMgmt().ResetServiceAccountSecret(opts.Context, opts.id).Execute()
192+
serviceacct, httpRes, err := api.ServiceAccountMgmt().ResetServiceAccountCreds(opts.Context, opts.id).Execute()
194193
if httpRes != nil {
195194
defer httpRes.Body.Close()
196195
}
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,30 @@
11
package svcaccountcmdutil
22

33
import (
4+
"context"
5+
46
"github.com/redhat-developer/app-services-cli/pkg/cmd/serviceaccount/svcaccountcmdutil/credentials"
7+
"github.com/redhat-developer/app-services-cli/pkg/shared/connection"
8+
9+
kafkamgmtclient "github.com/redhat-developer/app-services-sdk-go/kafkamgmt/apiv1/client"
510
)
611

712
var (
813
CredentialsOutputFormats = []string{credentials.EnvFormat, credentials.JSONFormat, credentials.PropertiesFormat, credentials.SecretFormat}
914
)
15+
16+
// Method fetches authentication details for providers
17+
func GetProvidersDetails(conn connection.Connection, context context.Context) (*kafkamgmtclient.SsoProvider, error) {
18+
providers, httpRes, err := conn.API().
19+
ServiceAccountMgmt().GetSsoProviders(context).Execute()
20+
21+
if httpRes != nil {
22+
defer httpRes.Body.Close()
23+
}
24+
25+
if err != nil {
26+
return nil, err
27+
}
28+
29+
return &providers, err
30+
}

pkg/core/cmdutil/flagutil/completions.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,13 @@ func RegisterServiceAccountCompletionFunc(cmd *cobra.Command, f *factory.Factory
6969
return cachedServiceAccounts, directive
7070
}
7171

72-
serviceAccounts, _, err := conn.API().ServiceAccountMgmt().GetServiceAccounts(cmd.Context()).Execute()
73-
if err != nil || len(serviceAccounts) == 0 {
72+
serviceAccountResults, _, err := conn.API().ServiceAccountMgmt().GetServiceAccounts(cmd.Context()).Execute()
73+
if err != nil || len(serviceAccountResults.GetItems()) == 0 {
7474
return emptyList, directive
7575
}
7676

77+
serviceAccounts := serviceAccountResults.GetItems()
78+
7779
for _, serviceAcct := range serviceAccounts {
7880
cachedServiceAccounts = append(cachedServiceAccounts, serviceAcct.GetClientId())
7981
}

pkg/shared/cluster/connect.go

+6-7
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ import (
1717
"github.com/AlecAivazis/survey/v2"
1818
"github.com/golang-jwt/jwt/v4"
1919
"github.com/redhat-developer/app-services-cli/internal/build"
20-
svcacctmgmtclient "github.com/redhat-developer/app-services-sdk-go/serviceaccountmgmt/apiv1/client"
21-
20+
kafkamgmtclient "github.com/redhat-developer/app-services-sdk-go/kafkamgmt/apiv1/client"
2221
apiv1 "k8s.io/api/core/v1"
2322
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2423

@@ -68,7 +67,7 @@ func (api *KubernetesClusterAPIImpl) ExecuteConnect(connectOpts *v1alpha.Connect
6867
localize.NewEntry("Namespace", color.Info(currentNamespace)),
6968
localize.NewEntry("ServiceAccountSecretName", color.Info(constants.ServiceAccountSecretName))))
7069

71-
if !connectOpts.ForceCreationWithoutAsk {
70+
if connectOpts.ForceCreationWithoutAsk == false {
7271
var shouldContinue bool
7372
confirm := &survey.Confirm{
7473
Message: cliOpts.Localizer.MustLocalize("cluster.kubernetes.input.confirm.message"),
@@ -209,7 +208,7 @@ func (c *KubernetesClusterAPIImpl) createServiceAccountSecretIfNeeded(namespace
209208
},
210209
StringData: map[string]string{
211210
"client-id": serviceAcct.GetClientId(),
212-
"client-secret": serviceAcct.GetSecret(),
211+
"client-secret": serviceAcct.GetClientSecret(),
213212
},
214213
}
215214

@@ -227,13 +226,13 @@ func (c *KubernetesClusterAPIImpl) createServiceAccountSecretIfNeeded(namespace
227226
}
228227

229228
// createServiceAccount creates a service account
230-
func (c *KubernetesClusterAPIImpl) createServiceAccount(ctx context.Context, cliOpts *v1alpha.CommandEnvironment) (*svcacctmgmtclient.ServiceAccountData, error) {
229+
func (c *KubernetesClusterAPIImpl) createServiceAccount(ctx context.Context, cliOpts *v1alpha.CommandEnvironment) (*kafkamgmtclient.ServiceAccount, error) {
231230
t := time.Now()
232231

233232
api := cliOpts.Connection.API()
234-
serviceAcct := &svcacctmgmtclient.ServiceAccountCreateRequestData{Name: fmt.Sprintf("rhoascli-%v", t.Unix())}
233+
serviceAcct := &kafkamgmtclient.ServiceAccountRequest{Name: fmt.Sprintf("rhoascli-%v", t.Unix())}
235234
req := api.ServiceAccountMgmt().CreateServiceAccount(ctx)
236-
req = req.ServiceAccountCreateRequestData(*serviceAcct)
235+
req = req.ServiceAccountRequest(*serviceAcct)
237236
serviceAcctRes, httpRes, err := req.Execute()
238237
if httpRes != nil {
239238
defer httpRes.Body.Close()

0 commit comments

Comments
 (0)