Skip to content

Commit

Permalink
OCM-8121 | fix: Show correct describe message for expired breakglass
Browse files Browse the repository at this point in the history
Signed-off-by: Maggie Chen <magchen@redhat.com>
  • Loading branch information
chenz4027 committed May 17, 2024
1 parent 193245a commit de02cd2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cmd/describe/breakglasscredential/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ func runWithRuntime(r *rosa.Runtime, cmd *cobra.Command, argv []string) error {
return nil
}

if breakGlassCredentialConfig.Status() == cmv1.BreakGlassCredentialStatusExpired {
r.Reporter.Warnf("Break glass credential '%s' for cluster '%s' is now expired.",
breakGlassCredentialId, clusterKey)
return nil
}

if output.HasFlag() {
var formattedOutput map[string]interface{}
formattedOutput, err = breakglasscredential.FormatBreakGlassCredentialOutput(breakGlassCredentialConfig)
Expand Down
17 changes: 17 additions & 0 deletions cmd/describe/breakglasscredential/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,22 @@ var _ = Describe("Break glass credential", func() {
Expect(stderr).To(Equal("WARN: Break glass credential 'test-id' for cluster 'cluster1' has been revoked.\n"))
Expect(stdout).To(Equal(""))
})

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

0 comments on commit de02cd2

Please sign in to comment.