From b44e835275d10c16dfe1418802c6e958a779de56 Mon Sep 17 00:00:00 2001 From: David Lawrence Date: Mon, 20 Jul 2015 14:44:35 -0700 Subject: [PATCH] update default expiry times to those agreed on Signed-off-by: David Lawrence (github: endophage) --- Godeps/Godeps.json | 2 +- .../src/github.com/endophage/gotuf/README.md | 2 +- .../src/github.com/endophage/gotuf/data/types.go | 15 ++++++++------- client/client.go | 10 ++++++++++ server/server.go | 9 +++++++++ 5 files changed, 29 insertions(+), 9 deletions(-) diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 58736171cd..047aa5e3d8 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -63,7 +63,7 @@ }, { "ImportPath": "github.com/endophage/gotuf", - "Rev": "b1fb060403583500ba06b11e35130b7c16c74c92" + "Rev": "31d0377282dac4a9e5800933d9a920fb09a15331" }, { "ImportPath": "github.com/go-sql-driver/mysql", diff --git a/Godeps/_workspace/src/github.com/endophage/gotuf/README.md b/Godeps/_workspace/src/github.com/endophage/gotuf/README.md index 3c50f8b8b5..ac8d6d1132 100644 --- a/Godeps/_workspace/src/github.com/endophage/gotuf/README.md +++ b/Godeps/_workspace/src/github.com/endophage/gotuf/README.md @@ -14,7 +14,7 @@ from Docker should be considered the official CLI to be used with this implement - [X] Sign metadata files - [X] Refactor TufRepo to take care of signing ~~and verification~~ - [ ] 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 - [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 diff --git a/Godeps/_workspace/src/github.com/endophage/gotuf/data/types.go b/Godeps/_workspace/src/github.com/endophage/gotuf/data/types.go index 7a5b0a46cb..9d4667165c 100644 --- a/Godeps/_workspace/src/github.com/endophage/gotuf/data/types.go +++ b/Godeps/_workspace/src/github.com/endophage/gotuf/data/types.go @@ -136,15 +136,16 @@ func NewDelegations() *Delegations { } } -var defaultExpiryTimes = map[string]time.Time{ - "root": time.Now().AddDate(1, 0, 0), - "targets": time.Now().AddDate(0, 3, 0), - "snapshot": time.Now().AddDate(0, 0, 7), - "timestamp": time.Now().AddDate(0, 0, 1), +// defines number of days in which something should expire +var defaultExpiryTimes = map[string]int{ + "root": 365, + "targets": 90, + "snapshot": 7, + "timestamp": 1, } // 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 { if _, ok := defaultExpiryTimes[key]; !ok { 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 { var t time.Time if t, ok := defaultExpiryTimes[role]; ok { - return t + return time.Now().AddDate(0, 0, t) } return t.UTC().Round(time.Second) } diff --git a/client/client.go b/client/client.go index 3cf2805641..2623a3a70a 100644 --- a/client/client.go +++ b/client/client.go @@ -26,6 +26,16 @@ import ( 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 // notary repository type ErrRepoNotInitialized struct{} diff --git a/server/server.go b/server/server.go index a23f04c688..c4cb9bebfa 100644 --- a/server/server.go +++ b/server/server.go @@ -9,6 +9,7 @@ import ( "github.com/Sirupsen/logrus" "github.com/docker/distribution/registry/auth" + "github.com/endophage/gotuf/data" "github.com/endophage/gotuf/signed" "github.com/gorilla/mux" "golang.org/x/net/context" @@ -17,6 +18,14 @@ import ( "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 // given configuration. The context it is passed is the context it should // use directly for the TLS server, and generate children off for requests