Skip to content

Commit

Permalink
[MM-42918] Add debug information for setup wizard (#379)
Browse files Browse the repository at this point in the history
  • Loading branch information
hanzei committed May 23, 2023
1 parent 0e8c416 commit 4a527b4
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
2 changes: 2 additions & 0 deletions server/flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ func (fm *FlowManager) StartSetupWizard(userID string, delegatedFrom string) err
return err
}

fm.client.Log.Debug("Started setup wizard", "userID", userID, "delegatedFrom", delegatedFrom)

fm.trackStartSetupWizard(userID, delegatedFrom != "")

return nil
Expand Down
8 changes: 7 additions & 1 deletion server/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,14 @@ func (p *Plugin) OnDeactivate() error {
}

func (p *Plugin) OnInstall(c *plugin.Context, event model.OnInstallEvent) error {
conf := p.getConfiguration()

// Don't start wizard if OAuth is configured
if p.getConfiguration().IsOAuthConfigured() {
if conf.IsOAuthConfigured() {
p.client.Log.Debug("OAuth is configured, skipping setup wizard",
"GitlabOAuthClientID", lastN(conf.GitlabOAuthClientID, 4),
"GitlabOAuthClientSecret", lastN(conf.GitlabOAuthClientSecret, 4),
"UsePreregisteredApplication", conf.UsePreregisteredApplication)
return nil
}

Expand Down
20 changes: 20 additions & 0 deletions server/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,23 @@ func isValidURL(rawURL string) error {

return nil
}

// lastN returns the last n characters of a string, with the rest replaced by *.
// At most 3 characters are replaced. The rest is cut off.
func lastN(s string, n int) string {
if n < 0 {
return ""
}

out := []byte(s)
if len(out) > n+3 {
out = out[len(out)-n-3:]
}
for i := range out {
if i < len(out)-n {
out[i] = '*'
}
}

return string(out)
}
22 changes: 22 additions & 0 deletions server/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,25 @@ func TestNormalizePath(t *testing.T) {
assert.Equal(t, tc.Expected, normalizePath(tc.Full, tc.BaseURL))
}
}

func TestLastN(t *testing.T) {
tcs := []struct {
Text string
N int
Expected string
}{
{Text: "", N: -99, Expected: ""},
{Text: "", N: -1, Expected: ""},
{Text: "", N: 0, Expected: ""},
{Text: "", N: 1, Expected: ""},
{Text: "", N: 99, Expected: ""},
{Text: "abcdef", N: 4, Expected: "**cdef"},
{Text: "abcdefghi", N: 2, Expected: "***hi"},
{Text: "abcdefghi", N: 0, Expected: "***"},
{Text: "abcdefghi", N: 99, Expected: "abcdefghi"},
}

for _, tc := range tcs {
assert.Equal(t, tc.Expected, lastN(tc.Text, tc.N))
}
}

0 comments on commit 4a527b4

Please sign in to comment.