Skip to content

Commit

Permalink
support both serialized protos and YAML
Browse files Browse the repository at this point in the history
  • Loading branch information
theganyo committed Jun 6, 2023
1 parent 8dab302 commit a818d2b
Show file tree
Hide file tree
Showing 22 changed files with 162 additions and 107 deletions.
4 changes: 2 additions & 2 deletions cmd/registry/cmd/check/rules/rule1000/rule1000.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ import (
"strings"

"github.com/apigee/registry/cmd/registry/cmd/check/lint"
"github.com/apigee/registry/cmd/registry/patch"
"github.com/apigee/registry/pkg/application/apihub"
"github.com/apigee/registry/pkg/application/check"
"github.com/apigee/registry/pkg/mime"
"github.com/apigee/registry/pkg/names"
"github.com/apigee/registry/pkg/visitor"
"github.com/apigee/registry/rpc"
"google.golang.org/protobuf/proto"
)

var ruleNum = 1000
Expand Down Expand Up @@ -92,7 +92,7 @@ var requiredArtifacts = &lint.ProjectRule{
func checkTaxonomies(a *rpc.Artifact) []*check.Problem {
message, err := mime.MessageForMimeType(a.GetMimeType())
if err == nil {
err = proto.Unmarshal(a.GetContents(), message)
err = patch.UnmarshalContents(a.GetContents(), a.GetMimeType(), message)
}
if err != nil {
return []*check.Problem{{
Expand Down
4 changes: 2 additions & 2 deletions cmd/registry/cmd/check/rules/rule1001/rule1001.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ import (
"strings"

"github.com/apigee/registry/cmd/registry/cmd/check/lint"
"github.com/apigee/registry/cmd/registry/patch"
"github.com/apigee/registry/pkg/application/apihub"
"github.com/apigee/registry/pkg/application/check"
"github.com/apigee/registry/pkg/names"
"github.com/apigee/registry/rpc"
"google.golang.org/protobuf/proto"
)

var ruleNum = 1001
Expand Down Expand Up @@ -84,7 +84,7 @@ func taxonomies(ctx context.Context, project names.Project) *TaxList {
})
if err == nil {
tl := new(apihub.TaxonomyList)
if err = proto.Unmarshal(ac.Data, tl); err == nil {
if err = patch.UnmarshalContents(ac.Data, ac.GetContentType(), tl); err == nil {
return &TaxList{tl}
}
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/registry/cmd/check/rules/rule1002/rule1002.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ import (
"strings"

"github.com/apigee/registry/cmd/registry/cmd/check/lint"
"github.com/apigee/registry/cmd/registry/patch"
"github.com/apigee/registry/pkg/application/check"
"github.com/apigee/registry/pkg/mime"
"github.com/apigee/registry/rpc"
"google.golang.org/protobuf/proto"
)

var ruleNum = 1002
Expand Down Expand Up @@ -72,7 +72,7 @@ var internalMimeTypeContents = &lint.FieldRule{
}

// does not validate contents, just proves type compatibility
err = proto.Unmarshal(contents, message)
err = patch.UnmarshalContents(contents, declared, message)
if err != nil {
return []*check.Problem{{
Severity: check.Problem_ERROR,
Expand Down
4 changes: 2 additions & 2 deletions cmd/registry/cmd/check/rules/rule1003/rule1003.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import (
"strings"

"github.com/apigee/registry/cmd/registry/cmd/check/lint"
"github.com/apigee/registry/cmd/registry/patch"
"github.com/apigee/registry/pkg/application/apihub"
"github.com/apigee/registry/pkg/application/check"
"github.com/apigee/registry/pkg/names"
"github.com/apigee/registry/rpc"
"google.golang.org/protobuf/proto"
)

var ruleNum = 1003
Expand Down Expand Up @@ -62,7 +62,7 @@ var stateIsValidLifecycleStage = &lint.ApiVersionRule{
})
if err == nil {
lc = new(apihub.Lifecycle)
err = proto.Unmarshal(ac.Data, lc)
err = patch.UnmarshalContents(ac.Data, ac.ContentType, lc)
}
if err != nil {
return []*check.Problem{{
Expand Down
10 changes: 5 additions & 5 deletions cmd/registry/cmd/compute/complexity/complexity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"testing"

"github.com/apigee/registry/cmd/registry/cmd/apply"
"github.com/apigee/registry/cmd/registry/patch"
"github.com/apigee/registry/pkg/connection"
"github.com/apigee/registry/pkg/connection/grpctest"
"github.com/apigee/registry/pkg/names"
Expand All @@ -33,7 +34,6 @@ import (
"github.com/google/go-cmp/cmp"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/testing/protocmp"
)

Expand Down Expand Up @@ -81,7 +81,7 @@ func TestComputeComplexity(t *testing.T) {
artifactName := project.Api("apigeeregistry").Version("v1").Spec("protos").Artifact("complexity")
err = visitor.GetArtifact(ctx, registryClient, artifactName, true, func(ctx context.Context, message *rpc.Artifact) error {
complexity := &metrics.Complexity{}
err = proto.Unmarshal(message.Contents, complexity)
err = patch.UnmarshalContents(message.Contents, message.MimeType, complexity)
if err != nil {
return err
}
Expand All @@ -106,7 +106,7 @@ func TestComputeComplexity(t *testing.T) {
artifactName := project.Api("apigeeregistry").Version("v1").Spec("openapi").Artifact("complexity")
err = visitor.GetArtifact(ctx, registryClient, artifactName, true, func(ctx context.Context, message *rpc.Artifact) error {
complexity := &metrics.Complexity{}
err = proto.Unmarshal(message.Contents, complexity)
err = patch.UnmarshalContents(message.Contents, message.MimeType, complexity)
if err != nil {
return err
}
Expand All @@ -131,7 +131,7 @@ func TestComputeComplexity(t *testing.T) {
artifactName := project.Api("apigeeregistry").Version("v1").Spec("discovery").Artifact("complexity")
err = visitor.GetArtifact(ctx, registryClient, artifactName, true, func(ctx context.Context, message *rpc.Artifact) error {
complexity := &metrics.Complexity{}
err = proto.Unmarshal(message.Contents, complexity)
err = patch.UnmarshalContents(message.Contents, message.MimeType, complexity)
if err != nil {
return err
}
Expand Down Expand Up @@ -251,7 +251,7 @@ func TestComputeComplexityValues(t *testing.T) {
t.Fatalf("Failed getting artifact contents %s: %s", test.getPattern, err)
}
gotProto := &metrics.Complexity{}
if err := proto.Unmarshal(contents.GetData(), gotProto); err != nil {
if err := patch.UnmarshalContents(contents.GetData(), contents.GetContentType(), gotProto); err != nil {
t.Fatalf("Failed to unmarshal artifact: %s", err)
}
opts := cmp.Options{protocmp.Transform()}
Expand Down
4 changes: 2 additions & 2 deletions cmd/registry/cmd/compute/conformance/conformance.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"fmt"

"github.com/apigee/registry/cmd/registry/conformance"
"github.com/apigee/registry/cmd/registry/patch"
"github.com/apigee/registry/cmd/registry/tasks"
"github.com/apigee/registry/pkg/application/style"
"github.com/apigee/registry/pkg/connection"
Expand All @@ -28,7 +29,6 @@ import (
"github.com/apigee/registry/pkg/visitor"
"github.com/apigee/registry/rpc"
"github.com/spf13/cobra"
"google.golang.org/protobuf/proto"
)

var styleguideFilter = fmt.Sprintf("mime_type.contains('%s')", mime.MimeTypeForKind("StyleGuide"))
Expand Down Expand Up @@ -78,7 +78,7 @@ func Command() *cobra.Command {
guides := make([]*style.StyleGuide, 0)
if err := visitor.ListArtifacts(ctx, client, name.Project().Artifact("-"), styleguideFilter, true, func(ctx context.Context, artifact *rpc.Artifact) error {
guide := new(style.StyleGuide)
if err := proto.Unmarshal(artifact.GetContents(), guide); err != nil {
if err := patch.UnmarshalContents(artifact.GetContents(), artifact.GetMimeType(), guide); err != nil {
log.FromContext(ctx).WithError(err).Debugf("Unmarshal() to StyleGuide failed on artifact: %s", artifact.GetName())
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/registry/cmd/compute/conformance/conformance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"testing"

"github.com/apigee/registry/cmd/registry/cmd/apply"
"github.com/apigee/registry/cmd/registry/patch"
"github.com/apigee/registry/pkg/application/style"
"github.com/apigee/registry/pkg/connection/grpctest"
"github.com/apigee/registry/rpc"
Expand All @@ -32,7 +33,6 @@ import (
"github.com/google/go-cmp/cmp/cmpopts"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/testing/protocmp"
)

Expand Down Expand Up @@ -477,7 +477,7 @@ func TestConformance(t *testing.T) {
}

gotProto := &style.ConformanceReport{}
if err := proto.Unmarshal(contents.GetData(), gotProto); err != nil {
if err := patch.UnmarshalContents(contents.GetData(), contents.GetContentType(), gotProto); err != nil {
t.Fatalf("Failed to unmarshal artifact: %s", err)
}

Expand Down
8 changes: 4 additions & 4 deletions cmd/registry/cmd/compute/lint/lint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ import (
"testing"

"github.com/apigee/registry/cmd/registry/cmd/apply"
"github.com/apigee/registry/cmd/registry/patch"
"github.com/apigee/registry/pkg/application/style"
"github.com/apigee/registry/pkg/connection"
"github.com/apigee/registry/pkg/connection/grpctest"
"github.com/apigee/registry/pkg/names"
"github.com/apigee/registry/pkg/visitor"
"github.com/apigee/registry/rpc"
"github.com/apigee/registry/server/registry"
"google.golang.org/protobuf/proto"
)

// TestMain will set up a local RegistryServer and grpc.Server for all
Expand Down Expand Up @@ -104,7 +104,7 @@ func TestComputeLint(t *testing.T) {
artifactName := specName.Artifact("lint-test")
if err = visitor.GetArtifact(ctx, registryClient, artifactName, true, func(ctx context.Context, message *rpc.Artifact) error {
var lint style.Lint
if err = proto.Unmarshal(message.Contents, &lint); err != nil {
if err = patch.UnmarshalContents(message.Contents, message.MimeType, &lint); err != nil {
return err
}
return nil
Expand All @@ -123,7 +123,7 @@ func TestComputeLint(t *testing.T) {
artifactName := specName.Artifact("lint-test")
if err = visitor.GetArtifact(ctx, registryClient, artifactName, true, func(ctx context.Context, message *rpc.Artifact) error {
var lint style.Lint
if err = proto.Unmarshal(message.Contents, &lint); err != nil {
if err = patch.UnmarshalContents(message.Contents, message.MimeType, &lint); err != nil {
return err
}
return nil
Expand All @@ -142,7 +142,7 @@ func TestComputeLint(t *testing.T) {
artifactName := specName.Artifact("lint-test")
if err = visitor.GetArtifact(ctx, registryClient, artifactName, true, func(ctx context.Context, message *rpc.Artifact) error {
var lint style.Lint
if err = proto.Unmarshal(message.Contents, &lint); err != nil {
if err = patch.UnmarshalContents(message.Contents, message.MimeType, &lint); err != nil {
return err
}
return nil
Expand Down
7 changes: 4 additions & 3 deletions cmd/registry/cmd/compute/lintstats/lintstats.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"fmt"
"sort"

"github.com/apigee/registry/cmd/registry/patch"
"github.com/apigee/registry/gapic"
"github.com/apigee/registry/pkg/application/style"
"github.com/apigee/registry/pkg/connection"
Expand Down Expand Up @@ -135,7 +136,7 @@ func computeLintStatsSpecs(ctx context.Context,
}

lint := &style.Lint{}
err = proto.Unmarshal(contents.GetData(), lint)
err = patch.UnmarshalContents(contents.GetData(), contents.GetContentType(), lint)
if err != nil {
return nil
}
Expand All @@ -153,7 +154,7 @@ func computeLintStatsSpecs(ctx context.Context,
return nil // ignore missing results
}
complexity := &metrics.Complexity{}
err := proto.Unmarshal(contents.GetData(), complexity)
err := patch.UnmarshalContents(contents.GetData(), contents.GetContentType(), complexity)
if err != nil {
return nil
}
Expand Down Expand Up @@ -283,7 +284,7 @@ func aggregateLintStats(ctx context.Context,
return // ignore missing results
}
stats := &style.LintStats{}
err := proto.Unmarshal(contents.GetData(), stats)
err := patch.UnmarshalContents(contents.GetData(), contents.GetContentType(), stats)
if err != nil {
return
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/registry/cmd/compute/score/score.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ package score
import (
"context"

"github.com/apigee/registry/cmd/registry/patch"
"github.com/apigee/registry/cmd/registry/patterns"
"github.com/apigee/registry/cmd/registry/scoring"
"github.com/apigee/registry/cmd/registry/tasks"
scoring_message "github.com/apigee/registry/pkg/application/scoring"
"github.com/apigee/registry/pkg/connection"
"github.com/apigee/registry/rpc"
"github.com/spf13/cobra"
"google.golang.org/protobuf/proto"
)

func Command() *cobra.Command {
Expand Down Expand Up @@ -67,7 +67,7 @@ func Command() *cobra.Command {
for _, d := range scoreDefinitions {
// Extract definition
definition := &scoring_message.ScoreDefinition{}
if err := proto.Unmarshal(d.GetContents(), definition); err != nil {
if err := patch.UnmarshalContents(d.GetContents(), d.GetMimeType(), definition); err != nil {
return err
}
mergedPattern, mergedFilter, err := scoring.GenerateCombinedPattern(definition.GetTargetResource(), inputPattern, filter)
Expand Down
4 changes: 2 additions & 2 deletions cmd/registry/cmd/compute/scorecard/scorecard.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ import (

scoring_message "github.com/apigee/registry/pkg/application/scoring"

"github.com/apigee/registry/cmd/registry/patch"
"github.com/apigee/registry/cmd/registry/patterns"
"github.com/apigee/registry/cmd/registry/scoring"
"github.com/apigee/registry/cmd/registry/tasks"
"github.com/apigee/registry/pkg/connection"
"github.com/apigee/registry/rpc"
"github.com/spf13/cobra"
"google.golang.org/protobuf/proto"
)

func Command() *cobra.Command {
Expand Down Expand Up @@ -68,7 +68,7 @@ func Command() *cobra.Command {
for _, d := range scoreCardDefinitions {
// Extract definition
definition := &scoring_message.ScoreCardDefinition{}
if err := proto.Unmarshal(d.GetContents(), definition); err != nil {
if err := patch.UnmarshalContents(d.GetContents(), d.GetMimeType(), definition); err != nil {
return err
}
mergedPattern, mergedFilter, err := scoring.GenerateCombinedPattern(definition.GetTargetResource(), inputPattern, filter)
Expand Down
8 changes: 4 additions & 4 deletions cmd/registry/cmd/compute/vocabulary/vocabulary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ import (
"testing"

"github.com/apigee/registry/cmd/registry/cmd/apply"
"github.com/apigee/registry/cmd/registry/patch"
"github.com/apigee/registry/pkg/connection"
"github.com/apigee/registry/pkg/connection/grpctest"
"github.com/apigee/registry/pkg/names"
"github.com/apigee/registry/pkg/visitor"
"github.com/apigee/registry/rpc"
"github.com/apigee/registry/server/registry"
metrics "github.com/google/gnostic/metrics"
"google.golang.org/protobuf/proto"
)

// TestMain will set up a local RegistryServer and grpc.Server for all
Expand Down Expand Up @@ -73,7 +73,7 @@ func TestComputeVocabulary(t *testing.T) {
artifactName := project.Api("apigeeregistry").Version("v1").Spec("protos").Artifact("vocabulary")
err = visitor.GetArtifact(ctx, registryClient, artifactName, true, func(ctx context.Context, message *rpc.Artifact) error {
vocabulary := &metrics.Vocabulary{}
err = proto.Unmarshal(message.Contents, vocabulary)
err = patch.UnmarshalContents(message.Contents, message.MimeType, vocabulary)
if err != nil {
return err
}
Expand All @@ -98,7 +98,7 @@ func TestComputeVocabulary(t *testing.T) {
artifactName := project.Api("apigeeregistry").Version("v1").Spec("openapi").Artifact("vocabulary")
err = visitor.GetArtifact(ctx, registryClient, artifactName, true, func(ctx context.Context, message *rpc.Artifact) error {
vocabulary := &metrics.Vocabulary{}
err = proto.Unmarshal(message.Contents, vocabulary)
err = patch.UnmarshalContents(message.Contents, message.MimeType, vocabulary)
if err != nil {
return err
}
Expand All @@ -123,7 +123,7 @@ func TestComputeVocabulary(t *testing.T) {
artifactName := project.Api("apigeeregistry").Version("v1").Spec("discovery").Artifact("vocabulary")
err = visitor.GetArtifact(ctx, registryClient, artifactName, true, func(ctx context.Context, message *rpc.Artifact) error {
vocabulary := &metrics.Vocabulary{}
err = proto.Unmarshal(message.Contents, vocabulary)
err = patch.UnmarshalContents(message.Contents, message.MimeType, vocabulary)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/registry/cmd/resolve/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"fmt"

"github.com/apigee/registry/cmd/registry/controller"
"github.com/apigee/registry/cmd/registry/patch"
"github.com/apigee/registry/cmd/registry/tasks"
controller_message "github.com/apigee/registry/pkg/application/controller"
"github.com/apigee/registry/pkg/connection"
Expand All @@ -27,7 +28,6 @@ import (
"github.com/apigee/registry/rpc"
"github.com/google/uuid"
"github.com/spf13/cobra"
"google.golang.org/protobuf/proto"
)

func fetchManifest(
Expand All @@ -45,7 +45,7 @@ func fetchManifest(
}

contents := body.GetData()
err = proto.Unmarshal(contents, manifest)
err = patch.UnmarshalContents(contents, body.GetContentType(), manifest)
if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit a818d2b

Please sign in to comment.