Merge pull request #103 from docker/default_expiry

update default expiry times to those agreed on
This commit is contained in:
Nathan McCauley 2015-07-20 15:21:23 -07:00
commit ac7c05516d
5 changed files with 29 additions and 9 deletions

2
Godeps/Godeps.json generated
View File

@ -63,7 +63,7 @@
}, },
{ {
"ImportPath": "github.com/endophage/gotuf", "ImportPath": "github.com/endophage/gotuf",
"Rev": "b1fb060403583500ba06b11e35130b7c16c74c92" "Rev": "31d0377282dac4a9e5800933d9a920fb09a15331"
}, },
{ {
"ImportPath": "github.com/go-sql-driver/mysql", "ImportPath": "github.com/go-sql-driver/mysql",

View File

@ -14,7 +14,7 @@ from Docker should be considered the official CLI to be used with this implement
- [X] Sign metadata files - [X] Sign metadata files
- [X] Refactor TufRepo to take care of signing ~~and verification~~ - [X] Refactor TufRepo to take care of signing ~~and verification~~
- [ ] Ensure consistent capitalization in naming (TUF\_\_\_ vs Tuf\_\_\_) - [ ] Ensure consistent capitalization in naming (TUF\_\_\_ vs Tuf\_\_\_)
- [ ] Make caching of metadata files smarter - PR #5 - [X] Make caching of metadata files smarter - PR #5
- [ ] ~~Add configuration for CLI commands. Order of configuration priority from most to least: flags, config file, defaults~~ Notary should be the official CLI - [ ] ~~Add configuration for CLI commands. Order of configuration priority from most to least: flags, config file, defaults~~ Notary should be the official CLI
- [X] Reasses organization of data types. Possibly consolidate a few things into the data package but break up package into a few more distinct files - [X] Reasses organization of data types. Possibly consolidate a few things into the data package but break up package into a few more distinct files
- [ ] Comprehensive test cases - [ ] Comprehensive test cases

View File

@ -136,15 +136,16 @@ func NewDelegations() *Delegations {
} }
} }
var defaultExpiryTimes = map[string]time.Time{ // defines number of days in which something should expire
"root": time.Now().AddDate(1, 0, 0), var defaultExpiryTimes = map[string]int{
"targets": time.Now().AddDate(0, 3, 0), "root": 365,
"snapshot": time.Now().AddDate(0, 0, 7), "targets": 90,
"timestamp": time.Now().AddDate(0, 0, 1), "snapshot": 7,
"timestamp": 1,
} }
// SetDefaultExpiryTimes allows one to change the default expiries. // SetDefaultExpiryTimes allows one to change the default expiries.
func SetDefaultExpiryTimes(times map[string]time.Time) { func SetDefaultExpiryTimes(times map[string]int) {
for key, value := range times { for key, value := range times {
if _, ok := defaultExpiryTimes[key]; !ok { if _, ok := defaultExpiryTimes[key]; !ok {
logrus.Errorf("Attempted to set default expiry for an unknown role: %s", key) logrus.Errorf("Attempted to set default expiry for an unknown role: %s", key)
@ -157,7 +158,7 @@ func SetDefaultExpiryTimes(times map[string]time.Time) {
func DefaultExpires(role string) time.Time { func DefaultExpires(role string) time.Time {
var t time.Time var t time.Time
if t, ok := defaultExpiryTimes[role]; ok { if t, ok := defaultExpiryTimes[role]; ok {
return t return time.Now().AddDate(0, 0, t)
} }
return t.UTC().Round(time.Second) return t.UTC().Round(time.Second)
} }

View File

@ -26,6 +26,16 @@ import (
const maxSize = 5 << 20 const maxSize = 5 << 20
func init() {
data.SetDefaultExpiryTimes(
map[string]int{
"root": 3650,
"targets": 1095,
"snapshot": 1095,
},
)
}
// ErrRepoNotInitialized is returned when trying to can publish on an uninitialized // ErrRepoNotInitialized is returned when trying to can publish on an uninitialized
// notary repository // notary repository
type ErrRepoNotInitialized struct{} type ErrRepoNotInitialized struct{}

View File

@ -9,6 +9,7 @@ import (
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
"github.com/docker/distribution/registry/auth" "github.com/docker/distribution/registry/auth"
"github.com/endophage/gotuf/data"
"github.com/endophage/gotuf/signed" "github.com/endophage/gotuf/signed"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"golang.org/x/net/context" "golang.org/x/net/context"
@ -17,6 +18,14 @@ import (
"github.com/docker/notary/utils" "github.com/docker/notary/utils"
) )
func init() {
data.SetDefaultExpiryTimes(
map[string]int{
"timestamp": 14,
},
)
}
// Run sets up and starts a TLS server that can be cancelled using the // Run sets up and starts a TLS server that can be cancelled using the
// given configuration. The context it is passed is the context it should // given configuration. The context it is passed is the context it should
// use directly for the TLS server, and generate children off for requests // use directly for the TLS server, and generate children off for requests