-
Notifications
You must be signed in to change notification settings - Fork 4
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
First pass at adding support for blob time-to-live. #1
Changes from 6 commits
7bf5f44
1efdb12
1166e0f
9f1535e
c812664
23a8228
c066f21
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 |
---|---|---|
|
@@ -8,6 +8,7 @@ import ( | |
log "github.com/sirupsen/logrus" | ||
"net/http" | ||
"regexp" | ||
"time" | ||
) | ||
|
||
const ( | ||
|
@@ -26,6 +27,7 @@ var ( | |
tagNameRegex, _ = regexp.Compile(`(^[a-zA-Z][a-zA-Z0-9_\-]{0,63}$)|$null`) | ||
commonTagValidator = CombineTagValidators(ValidateTagName, ValidateGenericTagValues) | ||
systemTagValidator = CombineTagValidators(commonTagValidator, ValidateOnlyOneTag) | ||
ttlTagValidator = CombineTagValidators(ValidateTimeToLive, systemTagValidator) | ||
subjectTagValidator = CombineTagValidators(ValidateSubjectTagValue, systemTagValidator) | ||
) | ||
|
||
|
@@ -80,7 +82,7 @@ func (handler *Handler) CreateBlob(w http.ResponseWriter, r *http.Request) { | |
if err := handler.store.SaveBlob(r.Context(), r.Body, key); err != nil { | ||
log.Errorf("Failed to save blob: %v", err) | ||
|
||
err = handler.db.RevertStagedBlobMetadata(r.Context(), key) | ||
err = handler.db.DeleteBlobMetadata(r.Context(), key) | ||
if err != nil { | ||
log.Errorf("Failed to revert staged blob metadata: %v", err) | ||
} | ||
|
@@ -138,6 +140,17 @@ func ValidateSubjectTagValue(tagName string, tagValues []string) error { | |
return nil | ||
} | ||
|
||
func ValidateTimeToLive(tagName string, tagValues []string) error { | ||
|
||
for _, t := range tagValues { | ||
if _, err := time.ParseDuration(t); err != nil { | ||
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. You should validate that the the ttl is not negative |
||
return err | ||
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. I suggest we add the parameter name to the error. Right now, we return this message: 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. No problem, good errors are worth their weight in gold. |
||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func CombineTagValidators(validators ...TagValidator) TagValidator { | ||
return func(tagName string, tagValues []string) error { | ||
for _, v := range validators { | ||
|
@@ -150,8 +163,8 @@ func CombineTagValidators(validators ...TagValidator) TagValidator { | |
} | ||
} | ||
|
||
func ValidateAndStoreOptionalSystemTag(tagName string, tagValues []string, field **string) error { | ||
if err := systemTagValidator(tagName, tagValues); err != nil { | ||
func ValidateAndStoreOptionalSystemTag(tagName string, tagValues []string, field **string, validator TagValidator) error { | ||
if err := validator(tagName, tagValues); err != nil { | ||
return err | ||
} | ||
|
||
|
@@ -162,11 +175,13 @@ func ValidateAndStoreOptionalSystemTag(tagName string, tagValues []string, field | |
func ValidateAndStoreTag(tags *core.BlobTags, tagName string, tagValues []string) error { | ||
switch tagName { | ||
case "device": | ||
return ValidateAndStoreOptionalSystemTag(tagName, tagValues, &tags.Device) | ||
return ValidateAndStoreOptionalSystemTag(tagName, tagValues, &tags.Device, systemTagValidator) | ||
case "name": | ||
return ValidateAndStoreOptionalSystemTag(tagName, tagValues, &tags.Name) | ||
return ValidateAndStoreOptionalSystemTag(tagName, tagValues, &tags.Name, systemTagValidator) | ||
case "session": | ||
return ValidateAndStoreOptionalSystemTag(tagName, tagValues, &tags.Session) | ||
return ValidateAndStoreOptionalSystemTag(tagName, tagValues, &tags.Session, systemTagValidator) | ||
case "ttl": | ||
return ValidateAndStoreOptionalSystemTag(tagName, tagValues, &tags.TimeToLive, ttlTagValidator) | ||
default: | ||
if err := commonTagValidator(tagName, tagValues); 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.
I suggest we add the expiration datetime to the response headers at the data endpoint
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.
Of course! I don't know why I forgot that.