func changefeed(logger ctxu.Logger, store storage.MetaStore, imageName, changeID string, records int64) ([]byte, error) { changes, err := store.GetChanges(changeID, int(records), imageName) if err != nil { logger.Errorf("500 GET could not retrieve records: %s", err.Error()) return nil, errors.ErrUnknown.WithDetail(err) } out, err := json.Marshal(&changefeedResponse{ NumberOfRecords: len(changes), Records: changes, }) if err != nil { logger.Error("500 GET could not json.Marshal changefeedResponse") return nil, errors.ErrUnknown.WithDetail(err) } return out, nil }
func serveError(log ctxu.Logger, w http.ResponseWriter, err error) { if httpErr, ok := err.(errcode.Error); ok { // info level logging for non-5XX http errors httpErrCode := httpErr.ErrorCode().Descriptor().HTTPStatusCode if httpErrCode >= http.StatusInternalServerError { // error level logging for 5XX http errors log.Errorf("%s: %s: %v", httpErr.ErrorCode().Error(), httpErr.Message, httpErr.Detail) } else { log.Infof("%s: %s: %v", httpErr.ErrorCode().Error(), httpErr.Message, httpErr.Detail) } } e := errcode.ServeJSON(w, err) if e != nil { log.Error(e) } return }
func checkChangefeedInputs(logger ctxu.Logger, s interface{}, r string) ( store storage.MetaStore, pageSize int64, err error) { store, ok := s.(storage.MetaStore) if !ok { logger.Error("500 GET unable to retrieve storage") err = errors.ErrNoStorage.WithDetail(nil) return } pageSize, err = strconv.ParseInt(r, 10, 32) if err != nil { logger.Errorf("400 GET invalid pageSize: %s", r) err = errors.ErrInvalidParams.WithDetail( fmt.Sprintf("invalid records parameter: %s", err.Error()), ) return } if pageSize == 0 { pageSize = notary.DefaultPageSize } return }
// getTimestampHandler returns a timestamp.json given a GUN func getSnapshot(ctx context.Context, w http.ResponseWriter, logger ctxu.Logger, store storage.MetaStore, gun string) error { cryptoServiceVal := ctx.Value("cryptoService") cryptoService, ok := cryptoServiceVal.(signed.CryptoService) if !ok { return errors.ErrNoCryptoService.WithDetail(nil) } out, err := snapshot.GetOrCreateSnapshot(gun, store, cryptoService) if err != nil { switch err.(type) { case *storage.ErrNoKey, storage.ErrNotFound: logger.Error("404 GET snapshot") return errors.ErrMetadataNotFound.WithDetail(nil) default: logger.Error("500 GET snapshot") return errors.ErrUnknown.WithDetail(err) } } logger.Debug("200 GET snapshot") w.Write(out) return nil }