Skip to content

Commit 38dbc6e

Browse files
committed
feat(externalauth): remove ROSI limitation from add-secret command
The external-auth add-secret command no longer requires apps to be deployed to Slack managed infrastructure. Any app in a valid project directory can now use this command without the --force flag.
1 parent 37b8a53 commit 38dbc6e

2 files changed

Lines changed: 4 additions & 83 deletions

File tree

cmd/externalauth/add_secret.go

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ func NewAddClientSecretCommand(clients *shared.ClientFactory) *cobra.Command {
3838
"Add the client secret for an external provider of a workflow app.",
3939
"",
4040
"This secret will be used when initiating the OAuth2 flow.",
41-
"",
42-
"This command is supported for apps deployed to Slack managed infrastructure but",
43-
"other apps can attempt to run the command with the --force flag.",
4441
}, "\n"),
4542
Example: style.ExampleCommandsf([]style.ExampleCommand{
4643
{
@@ -67,18 +64,10 @@ func NewAddClientSecretCommand(clients *shared.ClientFactory) *cobra.Command {
6764
return cmd
6865
}
6966

70-
// preRunAddClientSecretCommand determines if the command is supported for a
71-
// project and configures flags
72-
func preRunAddClientSecretCommand(ctx context.Context, clients *shared.ClientFactory, cmd *cobra.Command) error {
67+
// preRunAddClientSecretCommand configures flags and validates the project directory
68+
func preRunAddClientSecretCommand(_ context.Context, clients *shared.ClientFactory, cmd *cobra.Command) error {
7369
clients.Config.SetFlags(cmd)
74-
err := cmdutil.IsValidProjectDirectory(clients)
75-
if err != nil {
76-
return err
77-
}
78-
if clients.Config.ForceFlag {
79-
return nil
80-
}
81-
return cmdutil.IsSlackHostedProject(ctx, clients)
70+
return cmdutil.IsValidProjectDirectory(clients)
8271
}
8372

8473
// runAddClientSecretCommand adds a client secret to an authentication provider

cmd/externalauth/add_secret_test.go

Lines changed: 1 addition & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ import (
1919
"errors"
2020
"testing"
2121

22-
"github.com/slackapi/slack-cli/internal/app"
23-
"github.com/slackapi/slack-cli/internal/config"
2422
"github.com/slackapi/slack-cli/internal/iostreams"
2523
"github.com/slackapi/slack-cli/internal/shared"
2624
"github.com/slackapi/slack-cli/internal/shared/types"
@@ -34,88 +32,22 @@ import (
3432

3533
func TestExternalAuthAddClientSecretCommandPreRun(t *testing.T) {
3634
tests := map[string]struct {
37-
mockFlagForce bool
38-
mockManifestResponse types.SlackYaml
39-
mockManifestError error
40-
mockManifestSource config.ManifestSource
4135
mockWorkingDirectory string
4236
expectedError error
4337
}{
44-
"continues if the application is hosted on slack": {
45-
mockManifestResponse: types.SlackYaml{
46-
AppManifest: types.AppManifest{
47-
Settings: &types.AppSettings{
48-
FunctionRuntime: types.SlackHosted,
49-
},
50-
},
51-
},
52-
mockManifestError: nil,
38+
"continues if the command is run in a valid project directory": {
5339
mockWorkingDirectory: "/slack/path/to/project",
5440
expectedError: nil,
5541
},
56-
"errors if the application is not hosted on slack": {
57-
mockManifestResponse: types.SlackYaml{
58-
AppManifest: types.AppManifest{
59-
Settings: &types.AppSettings{
60-
FunctionRuntime: types.Remote,
61-
},
62-
},
63-
},
64-
mockManifestError: nil,
65-
mockManifestSource: config.ManifestSourceLocal,
66-
mockWorkingDirectory: "/slack/path/to/project",
67-
expectedError: slackerror.New(slackerror.ErrAppNotHosted),
68-
},
69-
"continues if the force flag is used in a project": {
70-
mockFlagForce: true,
71-
mockWorkingDirectory: "/slack/path/to/project",
72-
expectedError: nil,
73-
},
74-
"errors if the project manifest cannot be retrieved": {
75-
mockManifestResponse: types.SlackYaml{},
76-
mockManifestError: slackerror.New(slackerror.ErrSDKHookInvocationFailed),
77-
mockManifestSource: config.ManifestSourceLocal,
78-
mockWorkingDirectory: "/slack/path/to/project",
79-
expectedError: slackerror.New(slackerror.ErrSDKHookInvocationFailed),
80-
},
8142
"errors if the command is not run in a project": {
82-
mockManifestResponse: types.SlackYaml{},
83-
mockManifestError: slackerror.New(slackerror.ErrSDKHookNotFound),
84-
mockManifestSource: config.ManifestSourceLocal,
8543
mockWorkingDirectory: "",
8644
expectedError: slackerror.New(slackerror.ErrInvalidAppDirectory),
8745
},
88-
"errors if the manifest source is set to remote": {
89-
mockManifestSource: config.ManifestSourceRemote,
90-
mockWorkingDirectory: "/slack/path/to/project",
91-
expectedError: slackerror.New(slackerror.ErrAppNotHosted),
92-
},
9346
}
9447
for name, tc := range tests {
9548
t.Run(name, func(t *testing.T) {
9649
clientsMock := shared.NewClientsMock()
97-
manifestMock := &app.ManifestMockObject{}
98-
manifestMock.On(
99-
"GetManifestLocal",
100-
mock.Anything,
101-
mock.Anything,
102-
mock.Anything,
103-
).Return(
104-
tc.mockManifestResponse,
105-
tc.mockManifestError,
106-
)
107-
clientsMock.AppClient.Manifest = manifestMock
108-
projectConfigMock := config.NewProjectConfigMock()
109-
projectConfigMock.On(
110-
"GetManifestSource",
111-
mock.Anything,
112-
).Return(
113-
tc.mockManifestSource,
114-
nil,
115-
)
116-
clientsMock.Config.ProjectConfig = projectConfigMock
11750
clients := shared.NewClientFactory(clientsMock.MockClientFactory(), func(cf *shared.ClientFactory) {
118-
cf.Config.ForceFlag = tc.mockFlagForce
11951
cf.SDKConfig.WorkingDirectory = tc.mockWorkingDirectory
12052
})
12153
cmd := NewAddClientSecretCommand(clients)

0 commit comments

Comments
 (0)