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

Fix using default duration on auto approved requests #748

Merged
Merged
Changes from 5 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
45 changes: 25 additions & 20 deletions pkg/hook/accessrequesthook/accessrequesthook.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,24 @@ func (h Hook) NoEntitlementAccess(ctx context.Context, cfg *config.Context, inpu
req.Justification.Reason = &customReason
}
}

for i := range req.Entitlements {

if input.Duration != nil {
req.Entitlements[i].Duration = input.Duration
continue
}

if result.DurationConfiguration != nil {
if result.DurationConfiguration.DefaultDuration != nil {
req.Entitlements[i].Duration = result.DurationConfiguration.DefaultDuration
} else {
req.Entitlements[i].Duration = result.DurationConfiguration.MaxDuration
}
}

}
JoshuaWilkes marked this conversation as resolved.
Show resolved Hide resolved

// 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..."
Expand All @@ -188,15 +206,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 := "<invalid expiry>"

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:
Expand Down Expand Up @@ -240,6 +251,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
Expand Down Expand Up @@ -392,17 +405,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 := "<invalid expiry>"

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
Expand Down Expand Up @@ -436,6 +440,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:
Expand Down
Loading