-
Notifications
You must be signed in to change notification settings - Fork 512
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: David Lawrence <[email protected]> (github: endophage)
- Loading branch information
David Lawrence
committed
Oct 28, 2016
1 parent
3ca7b72
commit a437971
Showing
13 changed files
with
399 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
CREATE TABLE `changefeed` ( | ||
`id` int(11) NOT NULL AUTO_INCREMENT, | ||
`created_at` timestamp DEFAULT CURRENT_TIMESTAMP, | ||
`gun` varchar(255) NOT NULL, | ||
`version` int(11) NOT NULL, | ||
`sha256` CHAR(64) DEFAULT NULL, | ||
PRIMARY KEY (`id`) | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
CREATE TABLE "changefeed" ( | ||
"id" serial PRIMARY KEY, | ||
"created_at" timestamp DEFAULT CURRENT_TIMESTAMP, | ||
"gun" varchar(255) NOT NULL, | ||
"version" integer NOT NULL, | ||
"sha256" CHAR(64) DEFAULT NULL, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package handlers | ||
|
||
import ( | ||
"encoding/json" | ||
"net/http" | ||
"strconv" | ||
"strings" | ||
|
||
ctxu "github.com/docker/distribution/context" | ||
"golang.org/x/net/context" | ||
|
||
"github.com/docker/notary" | ||
"github.com/docker/notary/server/errors" | ||
"github.com/docker/notary/server/storage" | ||
) | ||
|
||
type changefeedResponse struct { | ||
NumberOfRecords int `json:"count"` | ||
Records []storage.Change `json:"records"` | ||
} | ||
|
||
// Changefeed returns a list of changes according to the provided filters | ||
func Changefeed(ctx context.Context, w http.ResponseWriter, r *http.Request) error { | ||
logger := ctxu.GetLogger(ctx) | ||
s := ctx.Value(notary.CtxKeyMetaStore) | ||
store, ok := s.(storage.MetaStore) | ||
if !ok { | ||
logger.Error("500 GET unable to retrieve storage") | ||
return errors.ErrNoStorage.WithDetail(nil) | ||
} | ||
|
||
qs := r.URL.Query() | ||
imageName := qs.Get("filter") | ||
if imageName == "" { | ||
// no image name means global feed | ||
imageName = "*" | ||
} | ||
pageSizeStr := qs.Get("pageSize") | ||
pageSize, err := strconv.ParseInt(pageSizeStr, 10, 32) | ||
if err != nil { | ||
logger.Errorf("400 GET invalid pageSize: %s", pageSizeStr) | ||
return errors.ErrInvalidParams.WithDetail("invalid pageSize parameter, must be an integer >= 0") | ||
} | ||
if pageSize == 0 { | ||
pageSize = notary.DefaultPageSize | ||
} | ||
|
||
changeID := qs.Get("changeID") | ||
reversedStr := qs.Get("reversed") | ||
reversed := reversedStr == "1" || strings.ToLower(reversedStr) == "true" | ||
|
||
changes, err := store.GetChanges(changeID, int(pageSize), reversed) | ||
if err != nil { | ||
logger.Errorf("500 GET could not retrieve records: %s", err.Error()) | ||
return errors.ErrUnknown.WithDetail(err) | ||
} | ||
|
||
// if reversed, we need to flip the list order so oldest is first | ||
if reversed { | ||
for i, j := 0, len(changes)-1; i < j; i, j = i+1, j-1 { | ||
changes[i], changes[j] = changes[j], changes[i] | ||
} | ||
} | ||
|
||
out, err := json.Marshal(&changefeedResponse{ | ||
NumberOfRecords: len(changes), | ||
Records: changes, | ||
}) | ||
if err != nil { | ||
logger.Error("500 GET could not json.Marshal changefeedResponse") | ||
return errors.ErrUnknown.WithDetail(err) | ||
} | ||
w.Write(out) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.