Skip to content

Commit

Permalink
Upgrade dependencies
Browse files Browse the repository at this point in the history
Golang: 1.22

Submodule:
github.com/googleapis/googleapis 716a2814e199eeef8fd9f3e11418ee0881ac833a

Direct:
github.com/goreleaser/goreleaser v1.26.2
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0
github.com/lestrrat-go/jwx/v2 v2.0.21
github.com/pion/dtls/v2 v2.2.8-0.20240601040544-edc7ad02205f
github.com/plgd-dev/device/v2 v2.5.2-0.20240603131607-6c9b1dc14b00
github.com/plgd-dev/go-coap/v3 v3.3.5-0.20240603125124-ff2c47df37c4
github.com/plgd-dev/hub/v2 v2.19.1
go.opentelemetry.io/otel/trace v1.27.0
google.golang.org/grpc v1.64.0
google.golang.org/protobuf v1.34.1
  • Loading branch information
Danielius1922 authored and Daniel Adam committed Jun 4, 2024
1 parent 758cee5 commit 40b153e
Show file tree
Hide file tree
Showing 24 changed files with 791 additions and 944 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/buildTestBinaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
submodules: true
- uses: actions/setup-go@v5
with:
go-version: "^1.20" # The Go version to download (if necessary) and use.
go-version: "^1.22" # The Go version to download (if necessary) and use.
check-latest: true

- name: Set version and ui_file
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/checkFormat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
fetch-depth: 0
- uses: actions/setup-go@v5
with:
go-version: "^1.20" # The Go version to download (if necessary) and use.
go-version: "^1.22" # The Go version to download (if necessary) and use.
check-latest: true

- name: Check formatting
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "^1.20" # The Go version to download (if necessary) and use.
go-version: "^1.22" # The Go version to download (if necessary) and use.
check-latest: true
- run: go version
- name: golangci-lint
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.20"
go-version: "1.22"

- name: Print Go version
run: go version
Expand Down Expand Up @@ -68,7 +68,7 @@ jobs:
with:
# either 'goreleaser' (default) or 'goreleaser-pro'
distribution: goreleaser
version: latest
version: "~> v1"
args: ${{ steps.args.outputs.args }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/staticAnalysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.21" # The Go version to download (if necessary) and use.
go-version: "1.22" # The Go version to download (if necessary) and use.
check-latest: true
- run: go version

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:

- uses: actions/setup-go@v5
with:
go-version: "^1.20" # The Go version to download (if necessary) and use.
go-version: "^1.22" # The Go version to download (if necessary) and use.
check-latest: true

- name: Run a test
Expand Down
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,4 @@ issues:
- revive

run:
go: "1.20"
go: "1.22"
2 changes: 1 addition & 1 deletion dependency/googleapis
Submodule googleapis updated 2306 files
352 changes: 195 additions & 157 deletions go.mod

Large diffs are not rendered by default.

1,256 changes: 522 additions & 734 deletions go.sum

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions service/grpc/getJSONWebKeys.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"context"
"encoding/json"

"github.com/lestrrat-go/jwx/jwk"
"github.com/lestrrat-go/jwx/v2/jwk"
"github.com/plgd-dev/client-application/pb"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
Expand All @@ -34,9 +34,9 @@ func (s *ClientApplicationServer) GetJSONWebKeys(_ context.Context, _ *pb.GetJSO
}
keys := make([]jwk.Key, 0, jwksCache.keys.Len())
for i := 0; i < jwksCache.keys.Len(); i++ {
k, ok := jwksCache.keys.Get(i)
key, ok := jwksCache.keys.Key(i)
if ok {
keys = append(keys, k)
keys = append(keys, key)
}
}
marshaledJwk, err := json.Marshal(map[string]interface{}{
Expand Down
4 changes: 2 additions & 2 deletions service/grpc/jsonWebKeyCache.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/golang-jwt/jwt/v5"
"github.com/google/uuid"
"github.com/lestrrat-go/jwx/jwk"
"github.com/lestrrat-go/jwx/v2/jwk"
"github.com/plgd-dev/client-application/pb"
"github.com/plgd-dev/hub/v2/identity-store/events"
plgdJwt "github.com/plgd-dev/hub/v2/pkg/security/jwt"
Expand Down Expand Up @@ -44,7 +44,7 @@ func (c *JSONWebKeyCache) LookupKey(token *jwt.Token) (jwk.Key, error) {
return nil, errors.New("empty JWK cache")
}
if key, ok := c.keys.LookupKeyID(id); ok {
if key.Algorithm() == token.Method.Alg() {
if key.Algorithm().String() == token.Method.Alg() {
return key, nil
}
}
Expand Down
2 changes: 1 addition & 1 deletion service/grpc/updateJSONWebKeys.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"context"

"github.com/google/uuid"
"github.com/lestrrat-go/jwx/jwk"
"github.com/lestrrat-go/jwx/v2/jwk"
"github.com/plgd-dev/hub/v2/identity-store/events"
"github.com/plgd-dev/hub/v2/pkg/net/grpc"
plgdJwt "github.com/plgd-dev/hub/v2/pkg/security/jwt"
Expand Down
3 changes: 2 additions & 1 deletion service/http/clearCache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
plgdDevice "github.com/plgd-dev/device/v2/schema/device"
grpcgwPb "github.com/plgd-dev/hub/v2/grpc-gateway/pb"
httpgwTest "github.com/plgd-dev/hub/v2/http-gateway/test"
httpTest "github.com/plgd-dev/hub/v2/test/http"
"github.com/plgd-dev/kit/v2/codec/cbor"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -69,7 +70,7 @@ func TestClientApplicationServerClearCache(t *testing.T) {
assert.Equal(t, http.StatusOK, resp.StatusCode)

var device grpcgwPb.Device
err := httpgwTest.Unmarshal(resp.StatusCode, resp.Body, &device)
err := httpTest.Unmarshal(resp.StatusCode, resp.Body, &device)
require.NoError(t, err)

var v plgdDevice.Device
Expand Down
9 changes: 5 additions & 4 deletions service/http/createResource.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import (
"github.com/gorilla/mux"
"github.com/plgd-dev/hub/v2/http-gateway/serverMux"
"github.com/plgd-dev/hub/v2/http-gateway/uri"
kitNetGrpc "github.com/plgd-dev/hub/v2/pkg/net/grpc"
pkgGrpc "github.com/plgd-dev/hub/v2/pkg/net/grpc"
pkgHttp "github.com/plgd-dev/hub/v2/pkg/net/http"
"google.golang.org/grpc/codes"
)

Expand All @@ -31,15 +32,15 @@ func (requestHandler *RequestHandler) createResource(w http.ResponseWriter, r *h
deviceID := vars[uri.DeviceIDKey]
href := vars[uri.ResourceHrefKey]

contentType := r.Header.Get(uri.ContentTypeHeaderKey)
if contentType == uri.ApplicationProtoJsonContentType {
contentType := r.Header.Get(pkgHttp.ContentTypeHeaderKey)
if contentType == pkgHttp.ApplicationProtoJsonContentType {
requestHandler.mux.ServeHTTP(w, r)
return
}

newBody, err := createContentBody(r.Body)
if err != nil {
serverMux.WriteError(w, kitNetGrpc.ForwardErrorf(codes.InvalidArgument, "cannot create resource('%v%v'): %v", deviceID, href, err))
serverMux.WriteError(w, pkgGrpc.ForwardErrorf(codes.InvalidArgument, "cannot create resource('%v%v'): %v", deviceID, href, err))
return
}

Expand Down
3 changes: 2 additions & 1 deletion service/http/getDeviceResourceLinks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/plgd-dev/hub/v2/resource-aggregate/commands"
"github.com/plgd-dev/hub/v2/resource-aggregate/events"
hubTest "github.com/plgd-dev/hub/v2/test"
httpTest "github.com/plgd-dev/hub/v2/test/http"
hubTestPb "github.com/plgd-dev/hub/v2/test/pb"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -87,7 +88,7 @@ func TestClientApplicationServerGetDeviceResourceLinks(t *testing.T) {
assert.Equal(t, tt.wantCode, resp.StatusCode)

var val events.ResourceLinksPublished
err := httpgwTest.Unmarshal(resp.StatusCode, resp.Body, &val)
err := httpTest.Unmarshal(resp.StatusCode, resp.Body, &val)
if tt.wantErr {
require.Error(t, err)
return
Expand Down
3 changes: 2 additions & 1 deletion service/http/getDevice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
plgdDevice "github.com/plgd-dev/device/v2/schema/device"
grpcgwPb "github.com/plgd-dev/hub/v2/grpc-gateway/pb"
httpgwTest "github.com/plgd-dev/hub/v2/http-gateway/test"
httpTest "github.com/plgd-dev/hub/v2/test/http"
"github.com/plgd-dev/kit/v2/codec/cbor"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -67,7 +68,7 @@ func TestClientApplicationServerGetDevice(t *testing.T) {
assert.Equal(t, http.StatusOK, resp.StatusCode)

var device grpcgwPb.Device
err := httpgwTest.Unmarshal(resp.StatusCode, resp.Body, &device)
err := httpTest.Unmarshal(resp.StatusCode, resp.Body, &device)
require.NoError(t, err)

var v plgdDevice.Device
Expand Down
5 changes: 3 additions & 2 deletions service/http/getDevices_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/plgd-dev/client-application/test"
grpcgwPb "github.com/plgd-dev/hub/v2/grpc-gateway/pb"
httpgwTest "github.com/plgd-dev/hub/v2/http-gateway/test"
httpTest "github.com/plgd-dev/hub/v2/test/http"
"github.com/stretchr/testify/require"
)

Expand All @@ -43,7 +44,7 @@ func getDevices(t *testing.T, token string) {
require.Equal(t, http.StatusOK, resp.StatusCode)
for {
var dev grpcgwPb.Device
err := httpgwTest.Unmarshal(resp.StatusCode, resp.Body, &dev)
err := httpTest.Unmarshal(resp.StatusCode, resp.Body, &dev)
if errors.Is(err, io.EOF) {
break
}
Expand Down Expand Up @@ -115,7 +116,7 @@ func TestClientApplicationServerGetDevices(t *testing.T) {
var got []*grpcgwPb.Device
for {
var dev grpcgwPb.Device
err := httpgwTest.Unmarshal(resp.StatusCode, resp.Body, &dev)
err := httpTest.Unmarshal(resp.StatusCode, resp.Body, &dev)
if errors.Is(err, io.EOF) {
break
}
Expand Down
3 changes: 2 additions & 1 deletion service/http/getResource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
grpcgwPb "github.com/plgd-dev/hub/v2/grpc-gateway/pb"
httpgwTest "github.com/plgd-dev/hub/v2/http-gateway/test"
hubTest "github.com/plgd-dev/hub/v2/test"
httpTest "github.com/plgd-dev/hub/v2/test/http"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -110,7 +111,7 @@ func TestClientApplicationServerGetResource(t *testing.T) {
assert.Equal(t, tt.wantCode, resp.StatusCode)

var got grpcgwPb.Resource
err := httpgwTest.Unmarshal(resp.StatusCode, resp.Body, &got)
err := httpTest.Unmarshal(resp.StatusCode, resp.Body, &got)
if tt.wantErr {
require.Error(t, err)
return
Expand Down
8 changes: 5 additions & 3 deletions service/http/onboardDevice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import (
kitNetGrpc "github.com/plgd-dev/hub/v2/pkg/net/grpc"
hubTest "github.com/plgd-dev/hub/v2/test"
"github.com/plgd-dev/hub/v2/test/config"
"github.com/plgd-dev/hub/v2/test/device/ocf"
httpTest "github.com/plgd-dev/hub/v2/test/http"
hubTestOAuthServerTest "github.com/plgd-dev/hub/v2/test/oauth-server/test"
hubTestService "github.com/plgd-dev/hub/v2/test/service"
"github.com/stretchr/testify/require"
Expand All @@ -41,7 +43,7 @@ import (

func TestClientApplicationServerOnboardDeviceRemoteProvisioning(t *testing.T) {
dev := test.MustFindDeviceByName(test.DevsimName, []pb.GetDevicesRequest_UseMulticast{pb.GetDevicesRequest_IPV4})
ctx, cancel := context.WithTimeout(context.Background(), time.Second*3600)
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
tearDown := setupRemoteProvisioning(t, hubTestService.SetUpServicesOAuth|
hubTestService.SetUpServicesCertificateAuthority|
Expand Down Expand Up @@ -128,7 +130,7 @@ func TestClientApplicationServerOnboardDeviceRemoteProvisioning(t *testing.T) {
require.Equal(t, http.StatusOK, resp.StatusCode)

var httpClientCfg pb.GetConfigurationResponse
err = httpgwTest.Unmarshal(resp.StatusCode, resp.Body, &httpClientCfg)
err = httpTest.Unmarshal(resp.StatusCode, resp.Body, &httpClientCfg)
require.NoError(t, err)

// oauth server url to host
Expand All @@ -149,7 +151,7 @@ func TestClientApplicationServerOnboardDeviceRemoteProvisioning(t *testing.T) {
_ = resp.Body.Close()
require.Equal(t, http.StatusOK, resp.StatusCode)

hubTest.WaitForDevice(t, subClient, dev.GetId(), expectedEvent.GetSubscriptionId(), expectedEvent.GetCorrelationId(), hubTest.GetAllBackendResourceLinks())
hubTest.WaitForDevice(t, subClient, ocf.NewDevice(dev.GetId(), test.DevsimName), expectedEvent.GetSubscriptionId(), expectedEvent.GetCorrelationId(), hubTest.GetAllBackendResourceLinks())

// offboard
request = httpgwTest.NewRequest(http.MethodPost, serviceHttp.OffboardDevice, nil).Host(test.CLIENT_APPLICATION_HTTP_HOST).AuthToken(token).DeviceId(dev.GetId()).Build()
Expand Down
42 changes: 24 additions & 18 deletions service/http/ownDevice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ import (
"time"

"github.com/google/uuid"
"github.com/lestrrat-go/jwx/jwa"
"github.com/lestrrat-go/jwx/jwk"
"github.com/lestrrat-go/jwx/jws"
"github.com/lestrrat-go/jwx/jwt"
"github.com/lestrrat-go/jwx/v2/jwa"
"github.com/lestrrat-go/jwx/v2/jwk"
"github.com/lestrrat-go/jwx/v2/jws"
"github.com/lestrrat-go/jwx/v2/jwt"
"github.com/plgd-dev/client-application/pb"
serviceHttp "github.com/plgd-dev/client-application/service/http"
"github.com/plgd-dev/client-application/test"
Expand Down Expand Up @@ -66,29 +66,35 @@ func TestClientApplicationServerOwnDevice(t *testing.T) {
}

func createJwkKey(privateKey interface{}) (jwk.Key, error) {
var alg string
var publicKey interface{}
switch v := privateKey.(type) {
case *rsa.PrivateKey:
alg = jwa.RS256.String()
publicKey = &v.PublicKey
case *ecdsa.PrivateKey:
alg = jwa.ES256.String()
publicKey = &v.PublicKey
}

jwkKey, err := jwk.New(publicKey)
jwkKey, err := jwk.FromRaw(privateKey)
if err != nil {
return nil, fmt.Errorf("failed to create jwk: %w", err)
}
publicJwkKey, err := jwkKey.PublicKey()
if err != nil {
return nil, fmt.Errorf("failed to get public key: %w", err)
}
var publicKey any
err = publicJwkKey.Raw(&publicKey)
if err != nil {
return nil, fmt.Errorf("failed to get public key: %w", err)
}
data, err := x509.MarshalPKIXPublicKey(publicKey)
if err != nil {
return nil, fmt.Errorf("cannot marshal public key: %w", err)
}

if err = jwkKey.Set(jwk.KeyIDKey, uuid.NewSHA1(uuid.NameSpaceX500, data).String()); err != nil {
return nil, fmt.Errorf("failed to set %v: %w", jwk.KeyIDKey, err)
}
var alg string
switch privateKey.(type) {
case *rsa.PrivateKey:
alg = jwa.RS256.String()
case *ecdsa.PrivateKey:
alg = jwa.ES256.String()
default:
alg = jwkKey.Algorithm().String()
}
if err = jwkKey.Set(jwk.AlgorithmKey, alg); err != nil {
return nil, fmt.Errorf("failed to set %v: %w", jwk.AlgorithmKey, err)
}
Expand Down Expand Up @@ -144,7 +150,7 @@ func MakeJWTPayload(key interface{}, jwkKey jwk.Key, data []byte) ([]byte, error
if err := hdr.Set(jws.KeyIDKey, jwkKey.KeyID()); err != nil {
return nil, fmt.Errorf("failed to set %v: %w", jws.KeyIDKey, err)
}
payload, err := jws.Sign(data, jwa.SignatureAlgorithm(jwkKey.Algorithm()), key, jws.WithHeaders(hdr))
payload, err := jws.Sign(data, jws.WithKey(jwkKey.Algorithm(), key), jws.WithHeaders(hdr))
if err != nil {
return nil, fmt.Errorf("failed to create UserToken: %w", err)
}
Expand Down
9 changes: 5 additions & 4 deletions service/http/updateResource.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ import (
"github.com/plgd-dev/go-coap/v3/message"
"github.com/plgd-dev/hub/v2/http-gateway/serverMux"
"github.com/plgd-dev/hub/v2/http-gateway/uri"
kitNetGrpc "github.com/plgd-dev/hub/v2/pkg/net/grpc"
pkgGrpc "github.com/plgd-dev/hub/v2/pkg/net/grpc"
pkgHttp "github.com/plgd-dev/hub/v2/pkg/net/http"
"github.com/plgd-dev/hub/v2/resource-aggregate/commands"
"google.golang.org/grpc/codes"
"google.golang.org/protobuf/encoding/protojson"
Expand Down Expand Up @@ -55,15 +56,15 @@ func (requestHandler *RequestHandler) updateResource(w http.ResponseWriter, r *h
deviceID := vars[uri.DeviceIDKey]
href := vars[uri.ResourceHrefKey]

contentType := r.Header.Get(uri.ContentTypeHeaderKey)
if contentType == uri.ApplicationProtoJsonContentType {
contentType := r.Header.Get(pkgHttp.ContentTypeHeaderKey)
if contentType == pkgHttp.ApplicationProtoJsonContentType {
requestHandler.mux.ServeHTTP(w, r)
return
}

newBody, err := createContentBody(r.Body)
if err != nil {
serverMux.WriteError(w, kitNetGrpc.ForwardErrorf(codes.InvalidArgument, "cannot update resource('%v%v'): %v", deviceID, href, err))
serverMux.WriteError(w, pkgGrpc.ForwardErrorf(codes.InvalidArgument, "cannot update resource('%v%v'): %v", deviceID, href, err))
return
}

Expand Down
3 changes: 2 additions & 1 deletion service/http/updateResource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/plgd-dev/hub/v2/resource-aggregate/commands"
"github.com/plgd-dev/hub/v2/resource-aggregate/events"
hubTest "github.com/plgd-dev/hub/v2/test"
httpTest "github.com/plgd-dev/hub/v2/test/http"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -139,7 +140,7 @@ func TestClientApplicationServerUpdateResource(t *testing.T) {
assert.Equal(t, tt.wantCode, resp.StatusCode)

var got grpcgwPb.UpdateResourceResponse
err := httpgwTest.Unmarshal(resp.StatusCode, resp.Body, &got)
err := httpTest.Unmarshal(resp.StatusCode, resp.Body, &got)
if tt.wantErr {
require.Error(t, err)
return
Expand Down
Loading

0 comments on commit 40b153e

Please sign in to comment.