Skip to content

Commit

Permalink
chore(pkg/gw): support multiple kv pairs in set endpoint (#34)
Browse files Browse the repository at this point in the history
* chore(pkg/gw): support multiple kv pairs in set endpoint

Signed-off-by: Jeronimo Irazabal <jeronimo.irazabal@gmail.com>

* chore(pkg/gw): upgrade to immudb v1.5.0

Signed-off-by: Jeronimo Irazabal <jeronimo.irazabal@gmail.com>

---------

Signed-off-by: Jeronimo Irazabal <jeronimo.irazabal@gmail.com>
  • Loading branch information
jeroiraz authored Jul 27, 2023
1 parent df2e9eb commit 5907d26
Show file tree
Hide file tree
Showing 12 changed files with 1,035 additions and 193 deletions.
2 changes: 1 addition & 1 deletion cmd/immugw/command/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import (
"github.com/codenotary/immudb/cmd/docs/man"
c "github.com/codenotary/immudb/cmd/helper"
"github.com/codenotary/immudb/cmd/version"
"github.com/codenotary/immudb/embedded/logger"
"github.com/codenotary/immudb/pkg/client"
"github.com/codenotary/immudb/pkg/client/homedir"
"github.com/codenotary/immudb/pkg/client/tokenservice"
"github.com/codenotary/immudb/pkg/logger"
"github.com/codenotary/immugw/cmd/immugw/command/service"
"github.com/codenotary/immugw/pkg/gw"
"github.com/spf13/cobra"
Expand Down
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ module github.com/codenotary/immugw
go 1.13

require (
github.com/codenotary/immudb v1.4.1
github.com/golang/protobuf v1.5.2
github.com/codenotary/immudb v1.5.1-0.20230727141041-91c79c4bc953
github.com/golang/protobuf v1.5.3
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/prometheus/client_golang v1.12.2
github.com/rs/cors v1.7.0
github.com/spf13/cobra v1.2.1
github.com/spf13/viper v1.12.0
github.com/stretchr/testify v1.7.1
github.com/spf13/cobra v1.6.1
github.com/spf13/viper v1.15.0
github.com/stretchr/testify v1.8.3
github.com/takama/daemon v0.12.0
google.golang.org/grpc v1.46.2
google.golang.org/grpc v1.56.2
)

replace github.com/takama/daemon v0.12.0 => github.com/codenotary/daemon v0.0.0-20200507161650-3d4bcb5230f4
Expand Down
1,138 changes: 991 additions & 147 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pkg/gw/immugw_server_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ limitations under the License.
package gw

import (
"github.com/codenotary/immudb/embedded/logger"
"github.com/codenotary/immudb/pkg/api/schema"
"github.com/codenotary/immudb/pkg/client"
"github.com/codenotary/immudb/pkg/logger"
)

// TODO OGG: move this in a subpackage: gwtest
Expand Down
2 changes: 1 addition & 1 deletion pkg/gw/immugw_server_mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (
"errors"
"testing"

"github.com/codenotary/immudb/embedded/logger"
"github.com/codenotary/immudb/pkg/api/schema"
"github.com/codenotary/immudb/pkg/logger"
"github.com/stretchr/testify/require"
)

Expand Down
7 changes: 4 additions & 3 deletions pkg/gw/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@ package gw
import (
"expvar"
"fmt"
"github.com/codenotary/immudb/pkg/api/schema"
"github.com/prometheus/client_golang/prometheus/promhttp"
"net/http"
"sync"
"time"

"github.com/codenotary/immudb/pkg/api/schema"
"github.com/prometheus/client_golang/prometheus/promhttp"

"github.com/prometheus/client_golang/prometheus/promauto"

"github.com/codenotary/immudb/pkg/logger"
"github.com/codenotary/immudb/embedded/logger"
"github.com/codenotary/immugw/pkg/json"
"github.com/prometheus/client_golang/prometheus"
)
Expand Down
45 changes: 23 additions & 22 deletions pkg/gw/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ limitations under the License.
package gw

import (
"github.com/prometheus/client_golang/prometheus"
"net/http"
"net/http/httptest"
"os"
"testing"

"github.com/prometheus/client_golang/prometheus"

"github.com/codenotary/immudb/embedded/logger"
"github.com/codenotary/immudb/pkg/api/schema"
"github.com/codenotary/immudb/pkg/logger"
"github.com/codenotary/immugw/pkg/json"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -64,27 +65,27 @@ func TestLastAuditHandler(t *testing.T) {
}

/*
func TestLastAuditHandlerJSONError(t *testing.T) {
req, err := http.NewRequest("GET", "/lastaudit", nil)
require.NoError(t, err)
rr := httptest.NewRecorder()
ms := metricServer{
mc: &MetricsCollection{},
srv: nil,
func TestLastAuditHandlerJSONError(t *testing.T) {
req, err := http.NewRequest("GET", "/lastaudit", nil)
require.NoError(t, err)
rr := httptest.NewRecorder()
ms := metricServer{
mc: &MetricsCollection{},
srv: nil,
}
handlerWithJSONErr := http.HandlerFunc(ms.lastAuditHandler(newTestJSONWithMarshalErr()))
handlerWithJSONErr.ServeHTTP(rr, req)
require.Equal(
t,
http.StatusInternalServerError,
rr.Code,
"lastAuditHandler returned wrong status code: expected %v, actual %v",
http.StatusInternalServerError,
rr.Code)
require.Contains(t, rr.Body.String(), "JSON marshal error")
}
handlerWithJSONErr := http.HandlerFunc(ms.lastAuditHandler(newTestJSONWithMarshalErr()))
handlerWithJSONErr.ServeHTTP(rr, req)
require.Equal(
t,
http.StatusInternalServerError,
rr.Code,
"lastAuditHandler returned wrong status code: expected %v, actual %v",
http.StatusInternalServerError,
rr.Code)
require.Contains(t, rr.Body.String(), "JSON marshal error")
}
*/
func TestUpdateAuditResult(t *testing.T) {
reg := prometheus.NewRegistry()
Expand Down
2 changes: 1 addition & 1 deletion pkg/gw/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import (
"testing"
"time"

"github.com/codenotary/immudb/embedded/logger"
"github.com/codenotary/immudb/pkg/client"
"github.com/codenotary/immudb/pkg/client/homedir"
"github.com/codenotary/immudb/pkg/client/tokenservice"
"github.com/codenotary/immudb/pkg/logger"
"github.com/codenotary/immudb/pkg/server"
"github.com/codenotary/immudb/pkg/server/servertest"
"github.com/stretchr/testify/assert"
Expand Down
7 changes: 1 addition & 6 deletions pkg/gw/set_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,12 @@ func (h *setHandler) Set(w http.ResponseWriter, req *http.Request, pathParams ma
return
}

if len(protoReq.KVs) > 1 {
h.runtime.HTTPError(ctx, h.mux, outboundMarshaler, w, req, status.Error(codes.InvalidArgument, "set accept only one key value pair"))
return
}

if len(protoReq.KVs) == 0 {
h.runtime.HTTPError(ctx, h.mux, outboundMarshaler, w, req, status.Error(codes.InvalidArgument, "set accept at least one key value pair"))
return
}

msg, err := client.Set(rctx, protoReq.KVs[0].Key, protoReq.KVs[0].Value)
msg, err := client.SetAll(rctx, &protoReq)
ctx = h.runtime.NewServerMetadataContext(rctx, metadata)
if err != nil {
h.runtime.HTTPError(ctx, h.mux, outboundMarshaler, w, req, mapSdkError(err))
Expand Down
4 changes: 2 additions & 2 deletions pkg/gw/set_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func setHandlerTestCases(mux *runtime.ServeMux, client immugwclient.Client, opts
sh := NewSetHandler(mux, client, rt, json)
icd, _ := immuclient.NewImmuClient(immuclient.DefaultOptions())

setWErr := func(context.Context, []byte, []byte) (*schema.TxHeader, error) {
setAllWErr := func(context.Context, *schema.SetRequest) (*schema.TxHeader, error) {
return nil, errors.New("set error")
}

Expand Down Expand Up @@ -177,7 +177,7 @@ func setHandlerTestCases(mux *runtime.ServeMux, client immugwclient.Client, opts
},
{
"Set error",
NewSetHandler(mux, immugwclient.NewMockClient(&clienttest.ImmuClientMock{ImmuClient: icd, SetF: setWErr}, opts), rt, json),
NewSetHandler(mux, immugwclient.NewMockClient(&clienttest.ImmuClientMock{ImmuClient: icd, SetAllF: setAllWErr}, opts), rt, json),
validPayload,
func(t *testing.T, testCase string, status int, body map[string]interface{}) {
requireResponseStatus(t, testCase, http.StatusInternalServerError, status)
Expand Down
5 changes: 3 additions & 2 deletions pkg/gw/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ limitations under the License.
package gw

import (
"github.com/codenotary/immudb/pkg/client"
"os"
"time"

"github.com/codenotary/immudb/pkg/client"

"github.com/codenotary/immudb/embedded/logger"
"github.com/codenotary/immudb/pkg/api/schema"
"github.com/codenotary/immudb/pkg/logger"
"github.com/codenotary/immudb/pkg/server"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/gw/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (
"os"
"testing"

"github.com/codenotary/immudb/embedded/logger"
"github.com/codenotary/immudb/pkg/api/schema"
"github.com/codenotary/immudb/pkg/logger"
"github.com/stretchr/testify/require"
)

Expand Down

0 comments on commit 5907d26

Please sign in to comment.