Skip to content

Commit f491ca7

Browse files
authored
refactor: rename clients.AuthInterface() to clients.Auth() (#81)
refactor: update the struct clients.AuthInterface to clients.Auth
1 parent 0526485 commit f491ca7

30 files changed

Lines changed: 294 additions & 294 deletions

cmd/app/add_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,9 +478,9 @@ func TestAppAddCommand(t *testing.T) {
478478
func prepareAddMocks(t *testing.T, clients *shared.ClientFactory, clientsMock *shared.ClientsMock) {
479479
clientsMock.AddDefaultMocks()
480480

481-
clientsMock.AuthInterface.On("ResolveAPIHost", mock.Anything, mock.Anything, mock.Anything).
481+
clientsMock.Auth.On("ResolveAPIHost", mock.Anything, mock.Anything, mock.Anything).
482482
Return("api host")
483-
clientsMock.AuthInterface.On("ResolveLogstashHost", mock.Anything, mock.Anything, mock.Anything).
483+
clientsMock.Auth.On("ResolveLogstashHost", mock.Anything, mock.Anything, mock.Anything).
484484
Return("logstash host")
485485

486486
manifestMock := &app.ManifestMockObject{}

cmd/app/delete_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,9 @@ func TestAppsDeleteCommand(t *testing.T) {
162162
func prepareCommonDeleteMocks(t *testing.T, cf *shared.ClientFactory, cm *shared.ClientsMock) {
163163
cm.AddDefaultMocks()
164164

165-
cm.AuthInterface.On("ResolveAPIHost", mock.Anything, mock.Anything, mock.Anything).
165+
cm.Auth.On("ResolveAPIHost", mock.Anything, mock.Anything, mock.Anything).
166166
Return("api host")
167-
cm.AuthInterface.On("ResolveLogstashHost", mock.Anything, mock.Anything, mock.Anything).
167+
cm.Auth.On("ResolveLogstashHost", mock.Anything, mock.Anything, mock.Anything).
168168
Return("logstash host")
169169

170170
// Mock list command

cmd/app/link.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ func promptExistingApp(ctx context.Context, clients *shared.ClientFactory) (type
292292

293293
// promptTeamSlackAuth retrieves an authenticated team from input
294294
func promptTeamSlackAuth(ctx context.Context, clients *shared.ClientFactory) (*types.SlackAuth, error) {
295-
allAuths, err := clients.AuthInterface().Auths(ctx)
295+
allAuths, err := clients.Auth().Auths(ctx)
296296
if err != nil {
297297
return &types.SlackAuth{}, err
298298
}
@@ -322,7 +322,7 @@ func promptTeamSlackAuth(ctx context.Context, clients *shared.ClientFactory) (*t
322322
return &types.SlackAuth{}, err
323323
}
324324
if selection.Prompt {
325-
clients.AuthInterface().SetSelectedAuth(ctx, allAuths[selection.Index], clients.Config, clients.Os)
325+
clients.Auth().SetSelectedAuth(ctx, allAuths[selection.Index], clients.Config, clients.Os)
326326
return &allAuths[selection.Index], nil
327327
}
328328
teamMatch := false
@@ -341,7 +341,7 @@ func promptTeamSlackAuth(ctx context.Context, clients *shared.ClientFactory) (*t
341341
if !teamMatch {
342342
return &types.SlackAuth{}, slackerror.New(slackerror.ErrCredentialsNotFound)
343343
}
344-
clients.AuthInterface().SetSelectedAuth(ctx, allAuths[teamIndex], clients.Config, clients.Os)
344+
clients.Auth().SetSelectedAuth(ctx, allAuths[teamIndex], clients.Config, clients.Os)
345345
return &allAuths[teamIndex], nil
346346
}
347347

cmd/app/link_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func Test_Apps_Link(t *testing.T) {
5757
testutil.TableTestCommand(t, testutil.CommandTests{
5858
"saves information about the provided deployed app": {
5959
Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) {
60-
cm.AuthInterface.On("Auths", mock.Anything).Return([]types.SlackAuth{
60+
cm.Auth.On("Auths", mock.Anything).Return([]types.SlackAuth{
6161
mockLinkSlackAuth2,
6262
mockLinkSlackAuth1,
6363
}, nil)
@@ -114,7 +114,7 @@ func Test_Apps_Link(t *testing.T) {
114114
},
115115
"saves information about the provided local app": {
116116
Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) {
117-
cm.AuthInterface.On("Auths", mock.Anything).Return([]types.SlackAuth{
117+
cm.Auth.On("Auths", mock.Anything).Return([]types.SlackAuth{
118118
mockLinkSlackAuth2,
119119
mockLinkSlackAuth1,
120120
}, nil)
@@ -173,7 +173,7 @@ func Test_Apps_Link(t *testing.T) {
173173
},
174174
"avoids overwriting an app saved in json without confirmation": {
175175
Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) {
176-
cm.AuthInterface.On("Auths", mock.Anything).Return([]types.SlackAuth{
176+
cm.Auth.On("Auths", mock.Anything).Return([]types.SlackAuth{
177177
mockLinkSlackAuth1,
178178
mockLinkSlackAuth2,
179179
}, nil)
@@ -242,7 +242,7 @@ func Test_Apps_Link(t *testing.T) {
242242
},
243243
"avoids overwriting a matching app id for the team without confirmation": {
244244
Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) {
245-
cm.AuthInterface.On("Auths", mock.Anything).Return([]types.SlackAuth{
245+
cm.Auth.On("Auths", mock.Anything).Return([]types.SlackAuth{
246246
mockLinkSlackAuth1,
247247
mockLinkSlackAuth2,
248248
}, nil)
@@ -317,7 +317,7 @@ func Test_Apps_Link(t *testing.T) {
317317
},
318318
"completes overwriting an app saved in json with confirmation": {
319319
Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) {
320-
cm.AuthInterface.On("Auths", mock.Anything).Return([]types.SlackAuth{
320+
cm.Auth.On("Auths", mock.Anything).Return([]types.SlackAuth{
321321
mockLinkSlackAuth1,
322322
mockLinkSlackAuth2,
323323
}, nil)
@@ -385,7 +385,7 @@ func Test_Apps_Link(t *testing.T) {
385385
},
386386
"refuses to write an app with app id not existing upstream": {
387387
Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) {
388-
cm.AuthInterface.On("Auths", mock.Anything).Return([]types.SlackAuth{
388+
cm.Auth.On("Auths", mock.Anything).Return([]types.SlackAuth{
389389
mockLinkSlackAuth1,
390390
mockLinkSlackAuth2,
391391
}, nil)
@@ -433,7 +433,7 @@ func Test_Apps_Link(t *testing.T) {
433433
},
434434
"accepting manifest source prompt should save information about the provided deployed app": {
435435
Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) {
436-
cm.AuthInterface.On("Auths", mock.Anything).Return([]types.SlackAuth{
436+
cm.Auth.On("Auths", mock.Anything).Return([]types.SlackAuth{
437437
mockLinkSlackAuth2,
438438
mockLinkSlackAuth1,
439439
}, nil)
@@ -540,7 +540,7 @@ func Test_Apps_Link(t *testing.T) {
540540
},
541541
"manifest source prompt should not display for Run-on-Slack apps with local manifest source": {
542542
Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) {
543-
cm.AuthInterface.On("Auths", mock.Anything).Return([]types.SlackAuth{
543+
cm.Auth.On("Auths", mock.Anything).Return([]types.SlackAuth{
544544
mockLinkSlackAuth1,
545545
mockLinkSlackAuth2,
546546
}, nil)
@@ -617,7 +617,7 @@ func Test_Apps_Link(t *testing.T) {
617617
},
618618
"manifest source prompt should display for GBP apps with local manifest source": {
619619
Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) {
620-
cm.AuthInterface.On("Auths", mock.Anything).Return([]types.SlackAuth{
620+
cm.Auth.On("Auths", mock.Anything).Return([]types.SlackAuth{
621621
mockLinkSlackAuth1,
622622
mockLinkSlackAuth2,
623623
}, nil)

cmd/app/uninstall_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ func prepareCommonUninstallMocks(ctx context.Context, clients *shared.ClientFact
102102
appSelectMock.On("AppSelectPrompt").Return(selectedProdApp, nil)
103103

104104
// Mock API calls
105-
clientsMock.AuthInterface.On("ResolveAPIHost", mock.Anything, mock.Anything, mock.Anything).
105+
clientsMock.Auth.On("ResolveAPIHost", mock.Anything, mock.Anything, mock.Anything).
106106
Return("api host")
107-
clientsMock.AuthInterface.On("ResolveLogstashHost", mock.Anything, mock.Anything, mock.Anything).
107+
clientsMock.Auth.On("ResolveLogstashHost", mock.Anything, mock.Anything, mock.Anything).
108108
Return("logstash host")
109109

110110
clientsMock.API.On("ValidateSession", mock.Anything, mock.Anything).Return(api.AuthSession{

cmd/auth/login_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ func TestLoginCommand(t *testing.T) {
6060
TeamName: &mockOrgAuth.TeamDomain,
6161
URL: &mockOrgAuthURL,
6262
}, nil)
63-
cm.AuthInterface.On("IsAPIHostSlackProd", mock.Anything).Return(true)
64-
cm.AuthInterface.On(
63+
cm.Auth.On("IsAPIHostSlackProd", mock.Anything).Return(true)
64+
cm.Auth.On(
6565
"AuthWithTeamDomain",
6666
mock.Anything,
6767
mock.Anything,
@@ -94,8 +94,8 @@ func TestLoginCommand(t *testing.T) {
9494
},
9595
nil,
9696
)
97-
cm.AuthInterface.On("IsAPIHostSlackProd", mock.Anything).Return(true)
98-
cm.AuthInterface.On(
97+
cm.Auth.On("IsAPIHostSlackProd", mock.Anything).Return(true)
98+
cm.Auth.On(
9999
"SetAuth",
100100
mock.Anything,
101101
mock.Anything,
@@ -124,8 +124,8 @@ func TestLoginCommand(t *testing.T) {
124124
},
125125
nil,
126126
)
127-
cm.AuthInterface.On("IsAPIHostSlackProd", mock.Anything).Return(true)
128-
cm.AuthInterface.On(
127+
cm.Auth.On("IsAPIHostSlackProd", mock.Anything).Return(true)
128+
cm.Auth.On(
129129
"SetAuth",
130130
mock.Anything,
131131
mock.Anything,
@@ -146,8 +146,8 @@ func TestLoginCommand(t *testing.T) {
146146
Required: true,
147147
}).Return(mockChallengeCode, nil)
148148
cm.API.On("ExchangeAuthTicket", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(api.ExchangeAuthTicketResult{}, nil)
149-
cm.AuthInterface.On("IsAPIHostSlackProd", mock.Anything).Return(true)
150-
cm.AuthInterface.On(
149+
cm.Auth.On("IsAPIHostSlackProd", mock.Anything).Return(true)
150+
cm.Auth.On(
151151
"SetAuth",
152152
mock.Anything,
153153
mock.Anything,

cmd/auth/logout.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,31 +94,31 @@ func handleAuthRemoval(ctx context.Context, clients *shared.ClientFactory, auth
9494
defer span.Finish()
9595

9696
// Update the API Host and Logstash Host to be the selected/default auth
97-
clients.Config.APIHostResolved = clients.AuthInterface().ResolveAPIHost(ctx, clients.Config.APIHostFlag, &auth)
98-
clients.Config.LogstashHostResolved = clients.AuthInterface().ResolveLogstashHost(ctx, clients.Config.APIHostResolved, clients.Config.Version)
97+
clients.Config.APIHostResolved = clients.Auth().ResolveAPIHost(ctx, clients.Config.APIHostFlag, &auth)
98+
clients.Config.LogstashHostResolved = clients.Auth().ResolveLogstashHost(ctx, clients.Config.APIHostResolved, clients.Config.Version)
9999

100100
// First, try to revoke the xoxe-xoxp (auth) token credential
101101
var xoxpToken = auth.Token
102-
if err := clients.AuthInterface().RevokeToken(ctx, xoxpToken); err != nil {
102+
if err := clients.Auth().RevokeToken(ctx, xoxpToken); err != nil {
103103
return err
104104
}
105105

106106
// Next, try to revoke the refresh token xoxe-1 credential
107107
var refreshToken = auth.RefreshToken
108108
if refreshToken != "" {
109-
if err := clients.AuthInterface().RevokeToken(ctx, refreshToken); err != nil {
109+
if err := clients.Auth().RevokeToken(ctx, refreshToken); err != nil {
110110
return err
111111
}
112112
}
113113

114114
// Once successfully revoked, remove from credentials.json
115-
if _, err := clients.AuthInterface().DeleteAuth(ctx, auth); err != nil {
115+
if _, err := clients.Auth().DeleteAuth(ctx, auth); err != nil {
116116
return err
117117
}
118118

119119
// Update the API Host and Logstash Host to be the selected/default auth
120-
clients.Config.APIHostResolved = clients.AuthInterface().ResolveAPIHost(ctx, clients.Config.APIHostFlag, nil)
121-
clients.Config.LogstashHostResolved = clients.AuthInterface().ResolveLogstashHost(ctx, clients.Config.APIHostResolved, clients.Config.Version)
120+
clients.Config.APIHostResolved = clients.Auth().ResolveAPIHost(ctx, clients.Config.APIHostFlag, nil)
121+
clients.Config.LogstashHostResolved = clients.Auth().ResolveLogstashHost(ctx, clients.Config.APIHostResolved, clients.Config.Version)
122122

123123
return nil
124124
}
@@ -136,7 +136,7 @@ func promptUserLogout(ctx context.Context, clients *shared.ClientFactory, cmd *c
136136
}
137137

138138
// Gather all available auths
139-
auths, err := clients.AuthInterface().Auths(ctx)
139+
auths, err := clients.Auth().Auths(ctx)
140140
if err != nil {
141141
return []types.SlackAuth{}, err
142142
}

0 commit comments

Comments
 (0)