Skip to content

Commit

Permalink
Remove zero time checking
Browse files Browse the repository at this point in the history
  • Loading branch information
kimlisa committed Feb 23, 2024
1 parent 4bdd3e4 commit 66c2592
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 21 deletions.
11 changes: 0 additions & 11 deletions api/types/access_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (

"github.com/gravitational/trace"

"github.com/gravitational/teleport/api/constants"
"github.com/gravitational/teleport/api/utils"
)

Expand Down Expand Up @@ -827,13 +826,3 @@ func NewAccessRequestAllowedPromotions(promotions []*AccessRequestAllowedPromoti
Promotions: promotions,
}
}

// ValidateAssumeStartTime returns error if start time too far in the future.
func ValidateAssumeStartTime(assumeStartTime time.Time) error {
if time.Until(assumeStartTime) > constants.MaxAssumeStartDuration {
return trace.BadParameter("assume start time is too far in the future: latest date %q",
assumeStartTime.Add(constants.MaxAssumeStartDuration).Format(time.RFC3339))
}

return nil
}
7 changes: 5 additions & 2 deletions lib/services/access_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (

"github.com/gravitational/teleport/api/accessrequest"
"github.com/gravitational/teleport/api/client"
"github.com/gravitational/teleport/api/constants"
apidefaults "github.com/gravitational/teleport/api/defaults"
"github.com/gravitational/teleport/api/types"
apiutils "github.com/gravitational/teleport/api/utils"
Expand Down Expand Up @@ -1097,8 +1098,10 @@ func (m *RequestValidator) Validate(ctx context.Context, req types.AccessRequest
}

if req.GetAssumeStartTime() != nil {
if err := types.ValidateAssumeStartTime(*req.GetAssumeStartTime()); err != nil {
return trace.Wrap(err)
assumeStartTime := *req.GetAssumeStartTime()
if time.Until(assumeStartTime) > constants.MaxAssumeStartDuration {
return trace.BadParameter("assume start time is too far in the future: latest date %q",
assumeStartTime.Add(constants.MaxAssumeStartDuration).Format(time.RFC3339))
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/teleterm/apiserver/handler/time_converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
func getProtoTimestamp(time *time.Time) *timestamppb.Timestamp {
var protoTime *timestamppb.Timestamp

if time != nil && !time.IsZero() {
if time != nil {
protoTime = timestamppb.New(*time)
}

Expand Down
6 changes: 1 addition & 5 deletions lib/teleterm/apiserver/handler/time_converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package handler

import (
"testing"
"time"

"github.com/jonboulle/clockwork"
"github.com/stretchr/testify/require"
Expand All @@ -28,10 +27,7 @@ import (
func TestGetProtoTimestamp(t *testing.T) {
clock := clockwork.NewFakeClock()

ts := getProtoTimestamp(&time.Time{})
require.Empty(t, ts)

ts = getProtoTimestamp(nil)
ts := getProtoTimestamp(nil)
require.Empty(t, ts)

time := clock.Now().UTC()
Expand Down
4 changes: 2 additions & 2 deletions lib/teleterm/clusters/cluster_access_requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func (c *Cluster) CreateAccessRequest(ctx context.Context, req *api.CreateAccess
request.SetRequestReason(req.Reason)
request.SetSuggestedReviewers(req.SuggestedReviewers)

if req.GetAssumeStartTime() != nil && !req.AssumeStartTime.AsTime().IsZero() {
if req.GetAssumeStartTime() != nil {
request.SetAssumeStartTime(req.AssumeStartTime.AsTime())
}

Expand Down Expand Up @@ -198,7 +198,7 @@ func (c *Cluster) ReviewAccessRequest(ctx context.Context, req *api.ReviewAccess
defer authClient.Close()

var assumeStartTimePtr *time.Time
if req.AssumeStartTime != nil && !req.AssumeStartTime.AsTime().IsZero() {
if req.AssumeStartTime != nil {
assumeStartTime := req.AssumeStartTime.AsTime()
assumeStartTimePtr = &assumeStartTime
}
Expand Down

0 comments on commit 66c2592

Please sign in to comment.