-
Notifications
You must be signed in to change notification settings - Fork 432
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
feat(api, cli, ui): auth consumer token expiration and last authentication #5822
Changes from all commits
3914a83
7c85425
a215387
85112da
823b666
841f5c5
639834c
c4ffda0
494bec2
2d6a902
5a0b4b1
1d99ba9
27287c4
7dfe111
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,11 @@ package api | |
import ( | ||
"context" | ||
"net/http" | ||
"time" | ||
|
||
"github.com/gorilla/mux" | ||
"github.com/ovh/cds/sdk" | ||
"github.com/pkg/errors" | ||
"github.com/rockbears/log" | ||
|
||
"github.com/ovh/cds/engine/api/authentication" | ||
|
@@ -77,8 +79,12 @@ func (api *API) postConsumerByUserHandler() service.Handler { | |
return err | ||
} | ||
|
||
if reqData.ValidityPeriods.Latest() == nil { | ||
reqData.ValidityPeriods = sdk.NewAuthConsumerValidityPeriod(time.Now(), time.Duration(api.Config.Auth.TokenDefaultDuration)*(24*time.Hour)) | ||
} | ||
|
||
// Create the new built in consumer from request data | ||
newConsumer, token, err := builtin.NewConsumer(ctx, tx, reqData.Name, reqData.Description, | ||
newConsumer, token, err := builtin.NewConsumer(ctx, tx, reqData.Name, reqData.Description, reqData.ValidityPeriods.Latest().Duration, | ||
consumer, reqData.GroupIDs, reqData.ScopeDetails) | ||
if err != nil { | ||
return err | ||
|
@@ -153,7 +159,30 @@ func (api *API) postConsumerRegenByUserHandler() service.Handler { | |
return err | ||
} | ||
|
||
if err := authentication.ConsumerRegen(ctx, tx, consumer); err != nil { | ||
if req.OverlapDuration == "" { | ||
req.OverlapDuration = api.Config.Auth.TokenOverlapDefaultDuration | ||
} | ||
if req.NewDuration == 0 { | ||
req.NewDuration = api.Config.Auth.TokenDefaultDuration | ||
} | ||
var overlapDuration time.Duration | ||
if req.OverlapDuration != "" { | ||
overlapDuration, err = time.ParseDuration(req.OverlapDuration) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not both overlap and validity duration in same format (string duration vs count of hours) ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. because overlap should be in minutes or hours, and validity should be a matter of days |
||
if err != nil { | ||
return sdk.NewError(sdk.ErrWrongRequest, err) | ||
} | ||
} | ||
|
||
newDuration := time.Duration(req.NewDuration) * (24 * time.Hour) | ||
|
||
if overlapDuration > newDuration { | ||
return sdk.NewError(sdk.ErrWrongRequest, errors.New("invalid duration")) | ||
} | ||
|
||
if err := authentication.ConsumerRegen(ctx, tx, consumer, | ||
overlapDuration, | ||
newDuration, | ||
); err != nil { | ||
return err | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should check that overlap duration is less than duration ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done