diff --git a/pkg/hook/accessrequesthook/accessrequesthook.go b/pkg/hook/accessrequesthook/accessrequesthook.go index 3aa8429f..e7bf339d 100644 --- a/pkg/hook/accessrequesthook/accessrequesthook.go +++ b/pkg/hook/accessrequesthook/accessrequesthook.go @@ -166,6 +166,7 @@ func (h Hook) NoEntitlementAccess(ctx context.Context, cfg *config.Context, inpu req.Justification.Reason = &customReason } } + // the spinner must be started after prompting for reason, otherwise the prompt gets hidden si := spinner.New(spinner.CharSets[14], 100*time.Millisecond) si.Suffix = " ensuring access..." @@ -188,15 +189,8 @@ func (h Hook) NoEntitlementAccess(ctx context.Context, cfg *config.Context, inpu for _, g := range res.Msg.Grants { names[eid.New("Access::Grant", g.Grant.Id)] = g.Grant.Name - exp := "" - - if res.Msg.DurationConfiguration != nil { - exp = ShortDur(res.Msg.DurationConfiguration.MaxDuration.AsDuration()) - if res.Msg.DurationConfiguration.DefaultDuration != nil { - exp = ShortDur(res.Msg.DurationConfiguration.DefaultDuration.AsDuration()) - - } - } + // default is to show the original duration, except for an active request, where it gets recalculated below to the time remaining + exp := ShortDur(g.Grant.Duration.AsDuration()) switch g.Change { case accessv1alpha1.GrantChange_GRANT_CHANGE_ACTIVATED: @@ -240,6 +234,8 @@ func (h Hook) NoEntitlementAccess(ctx context.Context, cfg *config.Context, inpu switch g.Grant.Status { case accessv1alpha1.GrantStatus_GRANT_STATUS_ACTIVE: + // work out how long is remaining on the active grant + exp = ShortDur(time.Until(g.Grant.ExpiresAt.AsTime())) color.New(color.FgGreen).Fprintf(os.Stderr, "[ACTIVE] %s is already active for the next %s: %s\n", g.Grant.Name, exp, requestURL(apiURL, g.Grant)) retry = true @@ -392,17 +388,8 @@ func DryRun(ctx context.Context, apiURL *url.URL, client accessv1alpha1connect.A for _, g := range res.Msg.Grants { names[eid.New("Access::Grant", g.Grant.Id)] = g.Grant.Name - exp := "" - - if res.Msg.DurationConfiguration != nil { - exp = ShortDur(res.Msg.DurationConfiguration.MaxDuration.AsDuration()) - if res.Msg.DurationConfiguration.DefaultDuration != nil { - exp = ShortDur(res.Msg.DurationConfiguration.DefaultDuration.AsDuration()) - } - } else if g.Grant.ExpiresAt != nil { - //attempt to work out duration from expiry to preserve backwards compatability with older common fate versions - exp = ShortDur(time.Until(g.Grant.ExpiresAt.AsTime())) - } + // default is to show the original duration, except for an active request, where it gets recalculated below to the time remaining + exp := ShortDur(g.Grant.Duration.AsDuration()) if g.Change > 0 { hasChanges = true @@ -436,6 +423,7 @@ func DryRun(ctx context.Context, apiURL *url.URL, client accessv1alpha1connect.A switch g.Grant.Status { case accessv1alpha1.GrantStatus_GRANT_STATUS_ACTIVE: + exp = ShortDur(time.Until(g.Grant.ExpiresAt.AsTime())) color.New(color.FgGreen).Fprintf(os.Stderr, "[ACTIVE] %s is already active for the next %s: %s\n", g.Grant.Name, exp, requestURL(apiURL, g.Grant)) continue case accessv1alpha1.GrantStatus_GRANT_STATUS_PENDING: