Skip to content

Commit

Permalink
OneOff: add success message (#30540)
Browse files Browse the repository at this point in the history
When the OneOff script completes, print a success message to let the
user know that everything worked as expected and what their next action
should be.
  • Loading branch information
marcoandredinis committed Aug 16, 2023
1 parent 300c437 commit 818a8e8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/web/integrations_awsoidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,8 @@ func (h *Handler) awsOIDCConfigureDeployServiceIAM(w http.ResponseWriter, r *htt
fmt.Sprintf("--task-role=%s", taskRole),
}
script, err := oneoff.BuildScript(oneoff.OneOffScriptParams{
TeleportArgs: strings.Join(argsList, " "),
TeleportArgs: strings.Join(argsList, " "),
SuccessMessage: "Success! You can now go back to the browser to complete the database enrollment.",
})
if err != nil {
return nil, trace.Wrap(err)
Expand Down
7 changes: 7 additions & 0 deletions lib/web/scripts/oneoff/oneoff.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ type OneOffScriptParams struct {
// Defaults to v<currentTeleportVersion>
// Eg, v13.1.0
TeleportVersion string

// SuccessMessage is a message shown to the user after the one off is completed.
SuccessMessage string
}

// CheckAndSetDefaults checks if the required params ara present.
Expand All @@ -89,6 +92,10 @@ func (p *OneOffScriptParams) CheckAndSetDefaults() error {
p.TeleportVersion = "v" + teleport.Version
}

if p.SuccessMessage == "" {
p.SuccessMessage = "Completed successfully."
}

return nil
}

Expand Down
5 changes: 3 additions & 2 deletions lib/web/scripts/oneoff/oneoff.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ set -euo pipefail

cdnBaseURL='{{.CDNBaseURL}}'
teleportVersion='{{.TeleportVersion}}'
successMessage='{{.SuccessMessage}}'

# shellcheck disable=all
tempDir=$({{.BinMktemp}} -d)
Expand Down Expand Up @@ -44,9 +45,9 @@ function main() {
mkdir -p ./bin
mv ./teleport/teleport ./bin/teleport
echo "> ./bin/teleport ${teleportArgs}"
./bin/teleport ${teleportArgs}
./bin/teleport ${teleportArgs} && echo $successMessage

popd > /dev/null
popd > /dev/null
}

main
2 changes: 2 additions & 0 deletions lib/web/scripts/oneoff/oneoff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func TestOneOffScript(t *testing.T) {
CDNBaseURL: testServer.URL,
TeleportVersion: "v13.1.0",
TeleportArgs: "version",
SuccessMessage: "Test was a success.",
})
require.NoError(t, err)

Expand All @@ -108,6 +109,7 @@ func TestOneOffScript(t *testing.T) {

require.Contains(t, string(out), "> ./bin/teleport version")
require.Contains(t, string(out), teleportVersionOutput)
require.Contains(t, string(out), "Test was a success.")
})

t.Run("invalid OS", func(t *testing.T) {
Expand Down

0 comments on commit 818a8e8

Please sign in to comment.