Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OCM-7169 | fix: error message when describe credential that status is revoked #1905

Merged
merged 1 commit into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cmd/describe/breakglasscredential/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ func runWithRuntime(r *rosa.Runtime, cmd *cobra.Command, argv []string) error {
return err
}

if breakGlassCredentialConfig.Status() == cmv1.BreakGlassCredentialStatusRevoked {
return fmt.Errorf("Break glass credential '%s' for cluster '%s' has been revoked.",
breakGlassCredentialId, clusterKey)
}

if output.HasFlag() {
var formattedOutput map[string]interface{}
formattedOutput, err = breakglasscredential.FormatBreakGlassCredentialOutput(breakGlassCredentialConfig)
Expand Down
16 changes: 16 additions & 0 deletions cmd/describe/breakglasscredential/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,21 @@ var _ = Describe("Break glass credential", func() {
Expect(stderr).To(BeEmpty())
Expect(stdout).To(Equal(describeStringOutput))
})

It("Pass a break glass credential id through parameter and it is found, but it has been revoked", func() {
args.id = breakGlassCredentialId
const breakGlassCredentialId = "test-id-1"
revokedCredential, err := cmv1.NewBreakGlassCredential().
ID(breakGlassCredentialId).Username("username").Status(cmv1.BreakGlassCredentialStatusRevoked).
Build()
Expect(err).To(BeNil())
testRuntime.ApiServer.AppendHandlers(RespondWithJSON(http.StatusOK, hypershiftClusterReady))
testRuntime.ApiServer.AppendHandlers(RespondWithJSON(http.StatusOK,
test.FormatResource(revokedCredential)))
_, stderr, err := test.RunWithOutputCaptureAndArgv(runWithRuntime, testRuntime.RosaRuntime,
Cmd, &[]string{})
Expect(err.Error()).To(Equal("Break glass credential 'test-id' for cluster 'cluster1' has been revoked."))
Expect(stderr).To(Equal(""))
})
})
})