diff --git a/cmd/lekko/feature.go b/cmd/lekko/feature.go index afd1ace9..41c0cc26 100644 --- a/cmd/lekko/feature.go +++ b/cmd/lekko/feature.go @@ -281,7 +281,7 @@ func featureEval() *cobra.Command { } fmt.Fprintf(os.Stderr, "[%s] ", fType) - fmt.Printf("%s", res) + fmt.Printf("%v", res) fmt.Println() if verbose { fmt.Fprintf(os.Stderr, "[path] %v\n", path) diff --git a/go.mod b/go.mod index 75c28565..27c083ff 100644 --- a/go.mod +++ b/go.mod @@ -18,6 +18,7 @@ require ( github.com/migueleliasweb/go-github-mock v0.0.16 github.com/mitchellh/go-homedir v1.1.0 github.com/olekukonko/tablewriter v0.0.5 + github.com/shurcooL/githubv4 v0.0.0-20231126234147-1cffa1f02456 github.com/spf13/cobra v1.5.0 github.com/stoewer/go-strcase v1.2.0 github.com/stretchr/testify v1.8.0 @@ -72,6 +73,7 @@ require ( github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/pjbgf/sha1cd v0.3.0 // indirect github.com/sergi/go-diff v1.1.0 // indirect + github.com/shurcooL/graphql v0.0.0-20230722043721-ed46e5a46466 // indirect github.com/skeema/knownhosts v1.1.1 // indirect github.com/xanzy/ssh-agent v0.3.3 // indirect golang.org/x/crypto v0.9.0 // indirect diff --git a/go.sum b/go.sum index 623968ac..e9d9dab8 100644 --- a/go.sum +++ b/go.sum @@ -202,6 +202,10 @@ github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1: github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0= github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= +github.com/shurcooL/githubv4 v0.0.0-20231126234147-1cffa1f02456 h1:6dExqsYngGEiixqa1vmtlUd+zbyISilg0Cf3GWVdeYM= +github.com/shurcooL/githubv4 v0.0.0-20231126234147-1cffa1f02456/go.mod h1:zqMwyHmnN/eDOZOdiTohqIUKUrTFX62PNlu7IJdu0q8= +github.com/shurcooL/graphql v0.0.0-20230722043721-ed46e5a46466 h1:17JxqqJY66GmZVHkmAsGEkcIu0oCe3AM420QDgGwZx0= +github.com/shurcooL/graphql v0.0.0-20230722043721-ed46e5a46466/go.mod h1:9dIRpgIY7hVhoqfe0/FcYp0bpInZaT7dc3BYOprrIUE= github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= github.com/skeema/knownhosts v1.1.1 h1:MTk78x9FPgDFVFkDLTrsnnfCJl7g1C/nnKvePgrIngE= github.com/skeema/knownhosts v1.1.1/go.mod h1:g4fPeYpque7P0xefxtGzV81ihjC8sX2IqpAoNkjxbMo= diff --git a/pkg/encoding/encoding.go b/pkg/encoding/encoding.go index 17c0240a..bbb27523 100644 --- a/pkg/encoding/encoding.go +++ b/pkg/encoding/encoding.go @@ -40,6 +40,8 @@ func ParseFeature(ctx context.Context, rootPath string, featureFile feature.Feat case feature.NamespaceVersionV1Beta5.String(): fallthrough case feature.NamespaceVersionV1Beta6.String(): + fallthrough + case feature.NamespaceVersionV1Beta7.String(): var f featurev1beta1.Feature contents, err := provider.GetFileContents(ctx, filepath.Join(rootPath, nsMD.Name, featureFile.CompiledProtoBinFileName)) if err != nil { diff --git a/pkg/gh/github.go b/pkg/gh/github.go index f938b041..a77a0432 100644 --- a/pkg/gh/github.go +++ b/pkg/gh/github.go @@ -24,6 +24,7 @@ import ( "github.com/go-git/go-git/v5" "github.com/google/go-github/v52/github" "github.com/pkg/errors" + "github.com/shurcooL/githubv4" "golang.org/x/oauth2" ) @@ -37,20 +38,20 @@ const ( // relevant to lekko. type GithubClient struct { *github.Client + Graphql *githubv4.Client } func NewGithubClient(h *http.Client) *GithubClient { return &GithubClient{ - Client: github.NewClient(h), + Client: github.NewClient(h), + Graphql: githubv4.NewClient(h), } } func NewGithubClientFromToken(ctx context.Context, token string) *GithubClient { ts := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: token}) tc := oauth2.NewClient(ctx, ts) - return &GithubClient{ - Client: github.NewClient(tc), - } + return NewGithubClient(tc) } func (gc *GithubClient) GetUser(ctx context.Context) (*github.User, error) { diff --git a/pkg/repo/feature.go b/pkg/repo/feature.go index 3b71b37f..c873b0e1 100644 --- a/pkg/repo/feature.go +++ b/pkg/repo/feature.go @@ -428,7 +428,6 @@ func (r *repository) Compile(ctx context.Context, req *CompileRequest) ([]*Featu nsContextTypes := make(map[string]protoreflect.MessageType) for ns, nsMd := range nsMDs { if nsMd.ContextProto != "" { - r.Logf("%s: %s\n", ns, nsMd.ContextProto) ct, err := registry.FindMessageByName(protoreflect.FullName(nsMd.ContextProto)) if err != nil { return nil, err @@ -442,7 +441,7 @@ func (r *repository) Compile(ctx context.Context, req *CompileRequest) ([]*Featu "double", "string": default: - return nil, errors.New("Invalid context type thingy make this better") + return nil, errors.Errorf("proto message cannot be used as a context message because type: %v of key: %s is not allowed", f.Kind(), f.Name()) } } nsContextTypes[ns] = ct diff --git a/proto/lekko/bff/v1beta1/bff.proto b/proto/lekko/bff/v1beta1/bff.proto index a8ec1f89..df751801 100644 --- a/proto/lekko/bff/v1beta1/bff.proto +++ b/proto/lekko/bff/v1beta1/bff.proto @@ -468,6 +468,15 @@ message GetFeatureHistoryResponse { repeated FeatureHistoryItem history = 1; } +// The configs will have metadata fields populated based on the latest rolled +// out version of the repo. +// If a config was newly created since, created_at will not be set. +// If a config existed already but was updated, last_updated_at will not be set. +message ConfigMetadata { + google.protobuf.Timestamp created_at = 1; + google.protobuf.Timestamp last_updated_at = 2; +} + message Feature { string name = 1; string namespace_name = 2; @@ -479,6 +488,7 @@ message Feature { // the blob sha of the proto bin file according to git string sha = 6; lekko.feature.v1beta1.StaticFeature static_feature_new = 7; + ConfigMetadata metadata = 8; } message FeatureHistoryItem {