Skip to content

Commit

Permalink
fix(deps): bump yaml to v3 and remove sigs.k8s.io/yaml (#2729)
Browse files Browse the repository at this point in the history
  • Loading branch information
sousandrei committed Jun 1, 2022
1 parent 4cf9014 commit 406eec6
Show file tree
Hide file tree
Showing 14 changed files with 100 additions and 45 deletions.
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ require (
google.golang.org/genproto v0.0.0-20220519153652-3a47de7e79bd
google.golang.org/grpc v1.46.2
google.golang.org/protobuf v1.28.0
gopkg.in/yaml.v2 v2.4.0
sigs.k8s.io/yaml v1.3.0
gopkg.in/yaml.v3 v3.0.1
)

require (
Expand Down
8 changes: 2 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWH
github.com/cncf/xds/go v0.0.0-20211001041855-01bcc9b48dfe/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
Expand Down Expand Up @@ -410,9 +408,9 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
Expand All @@ -423,5 +421,3 @@ honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo=
sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8=
2 changes: 1 addition & 1 deletion internal/descriptor/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ go_library(
"//protoc-gen-openapiv2/options",
"@com_github_golang_glog//:glog",
"@go_googleapis//google/api:annotations_go_proto",
"@io_k8s_sigs_yaml//:yaml",
"@in_gopkg_yaml_v3//:yaml_v3",
"@org_golang_google_protobuf//compiler/protogen",
"@org_golang_google_protobuf//encoding/protojson",
"@org_golang_google_protobuf//proto",
Expand Down
13 changes: 10 additions & 3 deletions internal/descriptor/grpc_api_configuration.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
package descriptor

import (
"encoding/json"
"fmt"
"io/ioutil"
"strings"

"github.com/grpc-ecosystem/grpc-gateway/v2/internal/descriptor/apiconfig"
"google.golang.org/protobuf/encoding/protojson"
"sigs.k8s.io/yaml"
"gopkg.in/yaml.v3"
)

func loadGrpcAPIServiceFromYAML(yamlFileContents []byte, yamlSourceLogName string) (*apiconfig.GrpcAPIService, error) {
jsonContents, err := yaml.YAMLToJSON(yamlFileContents)
var yamlContents interface{}
err := yaml.Unmarshal(yamlFileContents, &yamlContents)
if err != nil {
return nil, fmt.Errorf("failed to convert gRPC API Configuration from YAML in '%v' to JSON: %v", yamlSourceLogName, err)
return nil, fmt.Errorf("failed to parse gRPC API Configuration from YAML in '%v': %v", yamlSourceLogName, err)
}

jsonContents, err := json.Marshal(yamlContents)
if err != nil {
return nil, err
}

// As our GrpcAPIService is incomplete, accept unknown fields.
Expand Down
43 changes: 41 additions & 2 deletions internal/descriptor/grpc_api_configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ http:
t.Fatal(err)
}

if !strings.Contains(err.Error(), "line 7") {
t.Errorf("Expected yaml error to be detected in line 7. Got other error: %v", err)
if !strings.Contains(err.Error(), "line 6") {
t.Errorf("Expected yaml error to be detected in line 6. Got other error: %v", err)
}

if service != nil {
Expand Down Expand Up @@ -147,3 +147,42 @@ http:
t.Errorf("some.other.service has %v additional bindings when it should not have any. Got: %v", len(second.GetAdditionalBindings()), second.GetAdditionalBindings())
}
}

func TestLoadGrpcAPIServiceFromYAMLUnknownKeys(t *testing.T) {
service, err := loadGrpcAPIServiceFromYAML([]byte(`
type: google.api.Service
config_version: 3
very: key
much: 1
http:
rules:
- selector: some.other.service
delete: foo
invalidkey: yes
`), "example")
if err != nil {
t.Fatalf("Failed to load service description from YAML: %v", err)
}

if service == nil {
t.Fatal("No service returned")
}

if service.Http == nil {
t.Fatal("HTTP is empty")
}

if len(service.Http.GetRules()) != 1 {
t.Fatalf("%v service(s) returned when two were expected. Got: %v", len(service.Http.GetRules()), service.Http)
}

first := service.Http.GetRules()[0]
if first.GetSelector() != "some.other.service" {
t.Errorf("first.selector has unexpected selector '%v'", first.GetSelector())
}
if first.GetDelete() != "foo" {
t.Errorf("first.selector has unexpected delete '%v'", first.GetPost())
}
}
13 changes: 10 additions & 3 deletions internal/descriptor/openapi_configuration.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
package descriptor

import (
"encoding/json"
"fmt"
"io/ioutil"

"github.com/grpc-ecosystem/grpc-gateway/v2/internal/descriptor/openapiconfig"
"google.golang.org/protobuf/encoding/protojson"
"sigs.k8s.io/yaml"
"gopkg.in/yaml.v3"
)

func loadOpenAPIConfigFromYAML(yamlFileContents []byte, yamlSourceLogName string) (*openapiconfig.OpenAPIConfig, error) {
jsonContents, err := yaml.YAMLToJSON(yamlFileContents)
var yamlContents interface{}
err := yaml.Unmarshal(yamlFileContents, &yamlContents)
if err != nil {
return nil, fmt.Errorf("failed to convert OpenAPI Configuration from YAML in '%v' to JSON: %v", yamlSourceLogName, err)
return nil, fmt.Errorf("failed to parse gRPC API Configuration from YAML in '%v': %v", yamlSourceLogName, err)
}

jsonContents, err := json.Marshal(yamlContents)
if err != nil {
return nil, err
}

// Reject unknown fields because OpenAPIConfig is only used here
Expand Down
21 changes: 19 additions & 2 deletions internal/descriptor/openapi_configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ file:
t.Fatal(err)
}

if !strings.Contains(err.Error(), "line 4") {
t.Errorf("Expected yaml error to be detected in line 4. Got other error: %v", err)
if !strings.Contains(err.Error(), "line 3") {
t.Errorf("Expected yaml error to be detected in line 3. Got other error: %v", err)
}

if config != nil {
Expand Down Expand Up @@ -112,3 +112,20 @@ openapiOptions:
t.Fatalf("expected name to be X-API-Key but got %s", secOpt.Name)
}
}

func TestLoadOpenAPIConfigFromYAMLUnknownKeys(t *testing.T) {
_, err := loadOpenAPIConfigFromYAML([]byte(`
closedapiOptions:
get: it?
openapiOptions:
file:
- file: test.proto
option:
schemes:
- HTTP
`), "openapi_options")
if err == nil {
t.Errorf("Expected invalid key error")
}

}
4 changes: 2 additions & 2 deletions protoc-gen-openapiv2/internal/genopenapi/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ go_library(
"@go_googleapis//google/api:annotations_go_proto",
"@go_googleapis//google/api:visibility_go_proto",
"@go_googleapis//google/rpc:status_go_proto",
"@in_gopkg_yaml_v2//:yaml_v2",
"@in_gopkg_yaml_v3//:yaml_v3",
"@io_bazel_rules_go//proto/wkt:any_go_proto",
"@org_golang_google_protobuf//encoding/protojson",
"@org_golang_google_protobuf//proto",
Expand Down Expand Up @@ -58,7 +58,7 @@ go_test(
"@com_github_google_go_cmp//cmp",
"@go_googleapis//google/api:annotations_go_proto",
"@go_googleapis//google/api:visibility_go_proto",
"@in_gopkg_yaml_v2//:yaml_v2",
"@in_gopkg_yaml_v3//:yaml_v3",
"@io_bazel_rules_go//proto/wkt:field_mask_go_proto",
"@org_golang_google_protobuf//proto",
"@org_golang_google_protobuf//reflect/protodesc",
Expand Down
2 changes: 1 addition & 1 deletion protoc-gen-openapiv2/internal/genopenapi/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"errors"
"io"

"gopkg.in/yaml.v2"
"gopkg.in/yaml.v3"
)

type Format string
Expand Down
2 changes: 1 addition & 1 deletion protoc-gen-openapiv2/internal/genopenapi/format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"testing"

"github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2/internal/genopenapi"
"gopkg.in/yaml.v2"
"gopkg.in/yaml.v3"
)

func TestFormatValidate(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion protoc-gen-openapiv2/internal/genopenapi/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/grpc-ecosystem/grpc-gateway/v2/internal/descriptor"
"github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2/internal/genopenapi"
"gopkg.in/yaml.v2"
"gopkg.in/yaml.v3"

"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/descriptorpb"
Expand Down
12 changes: 4 additions & 8 deletions protoc-gen-openapiv2/internal/genopenapi/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"

"github.com/grpc-ecosystem/grpc-gateway/v2/internal/descriptor"
"gopkg.in/yaml.v2"
)

type param struct {
Expand Down Expand Up @@ -257,16 +256,13 @@ type keyVal struct {
type openapiSchemaObjectProperties []keyVal

func (p openapiSchemaObjectProperties) MarshalYAML() (interface{}, error) {
ms := make(yaml.MapSlice, len(p))
m := make(map[string]interface{})

for i, v := range p {
ms[i] = yaml.MapItem{
Key: v.Key,
Value: v.Value,
}
for _, v := range p {
m[v.Key] = v.Value
}

return ms, nil
return m, nil
}

func (op openapiSchemaObjectProperties) MarshalJSON() ([]byte, error) {
Expand Down
2 changes: 1 addition & 1 deletion protoc-gen-openapiv2/internal/genopenapi/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"strings"
"testing"

"gopkg.in/yaml.v2"
"gopkg.in/yaml.v3"
)

func newSpaceReplacer() *strings.Replacer {
Expand Down
18 changes: 6 additions & 12 deletions repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ def go_repositories():
go_repository(
name = "com_github_davecgh_go_spew",
importpath = "github.com/davecgh/go-spew",
sum = "h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=",
version = "v1.1.1",
sum = "h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=",
version = "v1.1.0",
)
go_repository(
name = "com_github_dgrijalva_jwt_go",
Expand Down Expand Up @@ -1007,27 +1007,21 @@ def go_repositories():
go_repository(
name = "in_gopkg_yaml_v2",
importpath = "gopkg.in/yaml.v2",
sum = "h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=",
version = "v2.4.0",
sum = "h1:fvjTMHxHEw/mxHbtzPi3JCcKXQRAnQTBRo6YCJSVHKI=",
version = "v2.2.3",
)
go_repository(
name = "in_gopkg_yaml_v3",
importpath = "gopkg.in/yaml.v3",
sum = "h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=",
version = "v3.0.0-20200313102051-9f266ea9e77c",
sum = "h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=",
version = "v3.0.1",
)
go_repository(
name = "io_etcd_go_bbolt",
importpath = "go.etcd.io/bbolt",
sum = "h1:Z/90sZLPOeCy2PwprqkFa25PdkusRzaj9P8zm/KNyvk=",
version = "v1.3.2",
)
go_repository(
name = "io_k8s_sigs_yaml",
importpath = "sigs.k8s.io/yaml",
sum = "h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo=",
version = "v1.3.0",
)

go_repository(
name = "io_opencensus_go",
Expand Down

0 comments on commit 406eec6

Please sign in to comment.