diff --git a/BUILD.bazel b/BUILD.bazel index d5626bd..0d53911 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -15,6 +15,8 @@ load("@gazelle//:def.bzl", "gazelle") # gazelle:resolve proto go pkg/proto/configuration/global/global.proto @com_github_buildbarn_bb_storage//pkg/proto/configuration/global # gazelle:resolve proto pkg/proto/configuration/http/http.proto @com_github_buildbarn_bb_storage//pkg/proto/configuration/http:http_proto # gazelle:resolve proto go pkg/proto/configuration/http/http.proto @com_github_buildbarn_bb_storage//pkg/proto/configuration/http +# gazelle:resolve proto pkg/proto/configuration/jmespath/jmespath.proto @com_github_buildbarn_bb_storage//pkg/proto/configuration/jmespath:jmespath_proto +# gazelle:resolve proto go pkg/proto/configuration/jmespath/jmespath.proto @com_github_buildbarn_bb_storage//pkg/proto/configuration/jmespath gazelle( name = "gazelle", ) diff --git a/cmd/bb_browser/BUILD.bazel b/cmd/bb_browser/BUILD.bazel index e524cd2..0456b31 100644 --- a/cmd/bb_browser/BUILD.bazel +++ b/cmd/bb_browser/BUILD.bazel @@ -40,10 +40,12 @@ go_library( "@com_github_buildbarn_bb_storage//pkg/auth/configuration", "@com_github_buildbarn_bb_storage//pkg/blobstore", "@com_github_buildbarn_bb_storage//pkg/blobstore/configuration", + "@com_github_buildbarn_bb_storage//pkg/clock", "@com_github_buildbarn_bb_storage//pkg/digest", "@com_github_buildbarn_bb_storage//pkg/filesystem/path", "@com_github_buildbarn_bb_storage//pkg/global", "@com_github_buildbarn_bb_storage//pkg/http", + "@com_github_buildbarn_bb_storage//pkg/jmespath", "@com_github_buildbarn_bb_storage//pkg/program", "@com_github_buildbarn_bb_storage//pkg/proto/auth", "@com_github_buildbarn_bb_storage//pkg/proto/fsac", @@ -52,7 +54,6 @@ go_library( "@com_github_buildkite_terminal_to_html//:terminal-to-html", "@com_github_dustin_go_humanize//:go-humanize", "@com_github_gorilla_mux//:mux", - "@com_github_jmespath_go_jmespath//:go-jmespath", "@com_github_kballard_go_shellquote//:go-shellquote", "@org_golang_google_grpc//codes", "@org_golang_google_grpc//metadata", diff --git a/cmd/bb_browser/main.go b/cmd/bb_browser/main.go index 4a480fb..9183cc9 100644 --- a/cmd/bb_browser/main.go +++ b/cmd/bb_browser/main.go @@ -17,16 +17,17 @@ import ( auth_configuration "github.com/buildbarn/bb-storage/pkg/auth/configuration" "github.com/buildbarn/bb-storage/pkg/blobstore" blobstore_configuration "github.com/buildbarn/bb-storage/pkg/blobstore/configuration" + "github.com/buildbarn/bb-storage/pkg/clock" "github.com/buildbarn/bb-storage/pkg/digest" "github.com/buildbarn/bb-storage/pkg/global" "github.com/buildbarn/bb-storage/pkg/http" + "github.com/buildbarn/bb-storage/pkg/jmespath" "github.com/buildbarn/bb-storage/pkg/program" auth_pb "github.com/buildbarn/bb-storage/pkg/proto/auth" "github.com/buildbarn/bb-storage/pkg/proto/iscc" "github.com/buildbarn/bb-storage/pkg/util" "github.com/dustin/go-humanize" "github.com/gorilla/mux" - "github.com/jmespath/go-jmespath" "github.com/kballard/go-shellquote" "google.golang.org/grpc/codes" @@ -131,7 +132,11 @@ func main() { routePrefix += "/" } - requestMetadataLinksJmespathExpression, err := jmespath.Compile(configuration.RequestMetadataLinksJmespathExpression) + requestMetadataLinksJmespathExpression, err := jmespath.NewExpressionFromConfiguration( + configuration.RequestMetadataLinksJmespathExpression, + dependenciesGroup, + clock.SystemClock, + ) if err != nil { return util.StatusWrap(err, "Failed to compile request metadata links JMESPath expression") } @@ -159,7 +164,7 @@ func main() { if err != nil { return nil, util.StatusWrap(err, "Failed to marshal request metadata") } - var rawRequestMetadata any + var rawRequestMetadata map[string]any if err := json.Unmarshal(marshaledRequestMetadata, &rawRequestMetadata); err != nil { return nil, util.StatusWrap(err, "Failed to unmarshal request metadata") } diff --git a/config/browser.jsonnet b/config/browser.jsonnet index c1f8d0a..b412095 100644 --- a/config/browser.jsonnet +++ b/config/browser.jsonnet @@ -22,5 +22,5 @@ authorizer: { allow: {}, }, - requestMetadataLinksJmespathExpression: '`{}`', + requestMetadataLinksJmespathExpression: { expression: '`{}`' }, } diff --git a/pkg/proto/configuration/bb_browser/BUILD.bazel b/pkg/proto/configuration/bb_browser/BUILD.bazel index a7c6456..73b48cb 100644 --- a/pkg/proto/configuration/bb_browser/BUILD.bazel +++ b/pkg/proto/configuration/bb_browser/BUILD.bazel @@ -11,6 +11,7 @@ proto_library( "@com_github_buildbarn_bb_storage//pkg/proto/configuration/blobstore:blobstore_proto", "@com_github_buildbarn_bb_storage//pkg/proto/configuration/global:global_proto", "@com_github_buildbarn_bb_storage//pkg/proto/configuration/http:http_proto", + "@com_github_buildbarn_bb_storage//pkg/proto/configuration/jmespath:jmespath_proto", ], ) @@ -24,6 +25,7 @@ go_proto_library( "@com_github_buildbarn_bb_storage//pkg/proto/configuration/blobstore", "@com_github_buildbarn_bb_storage//pkg/proto/configuration/global", "@com_github_buildbarn_bb_storage//pkg/proto/configuration/http", + "@com_github_buildbarn_bb_storage//pkg/proto/configuration/jmespath", ], ) diff --git a/pkg/proto/configuration/bb_browser/bb_browser.pb.go b/pkg/proto/configuration/bb_browser/bb_browser.pb.go index bd9463c..72c60a4 100644 --- a/pkg/proto/configuration/bb_browser/bb_browser.pb.go +++ b/pkg/proto/configuration/bb_browser/bb_browser.pb.go @@ -11,6 +11,7 @@ import ( blobstore "github.com/buildbarn/bb-storage/pkg/proto/configuration/blobstore" global "github.com/buildbarn/bb-storage/pkg/proto/configuration/global" http "github.com/buildbarn/bb-storage/pkg/proto/configuration/http" + jmespath "github.com/buildbarn/bb-storage/pkg/proto/configuration/jmespath" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" reflect "reflect" @@ -36,7 +37,7 @@ type ApplicationConfiguration struct { InitialSizeClassCache *blobstore.BlobAccessConfiguration `protobuf:"bytes,6,opt,name=initial_size_class_cache,json=initialSizeClassCache,proto3" json:"initial_size_class_cache,omitempty"` FileSystemAccessCache *blobstore.BlobAccessConfiguration `protobuf:"bytes,9,opt,name=file_system_access_cache,json=fileSystemAccessCache,proto3" json:"file_system_access_cache,omitempty"` Authorizer *auth.AuthorizerConfiguration `protobuf:"bytes,8,opt,name=authorizer,proto3" json:"authorizer,omitempty"` - RequestMetadataLinksJmespathExpression string `protobuf:"bytes,11,opt,name=request_metadata_links_jmespath_expression,json=requestMetadataLinksJmespathExpression,proto3" json:"request_metadata_links_jmespath_expression,omitempty"` + RequestMetadataLinksJmespathExpression *jmespath.Expression `protobuf:"bytes,11,opt,name=request_metadata_links_jmespath_expression,json=requestMetadataLinksJmespathExpression,proto3" json:"request_metadata_links_jmespath_expression,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } @@ -134,18 +135,18 @@ func (x *ApplicationConfiguration) GetAuthorizer() *auth.AuthorizerConfiguration return nil } -func (x *ApplicationConfiguration) GetRequestMetadataLinksJmespathExpression() string { +func (x *ApplicationConfiguration) GetRequestMetadataLinksJmespathExpression() *jmespath.Expression { if x != nil { return x.RequestMetadataLinksJmespathExpression } - return "" + return nil } var File_pkg_proto_configuration_bb_browser_bb_browser_proto protoreflect.FileDescriptor const file_pkg_proto_configuration_bb_browser_bb_browser_proto_rawDesc = "" + "\n" + - "3pkg/proto/configuration/bb_browser/bb_browser.proto\x12\"buildbarn.configuration.bb_browser\x1a'pkg/proto/configuration/auth/auth.proto\x1a1pkg/proto/configuration/blobstore/blobstore.proto\x1a+pkg/proto/configuration/global/global.proto\x1a'pkg/proto/configuration/http/http.proto\"\xd9\x06\n" + + "3pkg/proto/configuration/bb_browser/bb_browser.proto\x12\"buildbarn.configuration.bb_browser\x1a'pkg/proto/configuration/auth/auth.proto\x1a1pkg/proto/configuration/blobstore/blobstore.proto\x1a+pkg/proto/configuration/global/global.proto\x1a'pkg/proto/configuration/http/http.proto\x1a/pkg/proto/configuration/jmespath/jmespath.proto\"\x88\a\n" + "\x18ApplicationConfiguration\x12W\n" + "\tblobstore\x18\x01 \x01(\v29.buildbarn.configuration.blobstore.BlobstoreConfigurationR\tblobstore\x12;\n" + "\x1amaximum_message_size_bytes\x18\x02 \x01(\x03R\x17maximumMessageSizeBytes\x12T\n" + @@ -158,8 +159,8 @@ const file_pkg_proto_configuration_bb_browser_bb_browser_proto_rawDesc = "" + "\x18file_system_access_cache\x18\t \x01(\v2:.buildbarn.configuration.blobstore.BlobAccessConfigurationR\x15fileSystemAccessCache\x12U\n" + "\n" + "authorizer\x18\b \x01(\v25.buildbarn.configuration.auth.AuthorizerConfigurationR\n" + - "authorizer\x12Z\n" + - "*request_metadata_links_jmespath_expression\x18\v \x01(\tR&requestMetadataLinksJmespathExpressionJ\x04\b\x03\x10\x04BDZBgithub.com/buildbarn/bb-browser/pkg/proto/configuration/bb_browserb\x06proto3" + "authorizer\x12\x88\x01\n" + + "*request_metadata_links_jmespath_expression\x18\v \x01(\v2,.buildbarn.configuration.jmespath.ExpressionR&requestMetadataLinksJmespathExpressionJ\x04\b\x03\x10\x04BDZBgithub.com/buildbarn/bb-browser/pkg/proto/configuration/bb_browserb\x06proto3" var ( file_pkg_proto_configuration_bb_browser_bb_browser_proto_rawDescOnce sync.Once @@ -181,6 +182,7 @@ var file_pkg_proto_configuration_bb_browser_bb_browser_proto_goTypes = []any{ (*global.Configuration)(nil), // 3: buildbarn.configuration.global.Configuration (*blobstore.BlobAccessConfiguration)(nil), // 4: buildbarn.configuration.blobstore.BlobAccessConfiguration (*auth.AuthorizerConfiguration)(nil), // 5: buildbarn.configuration.auth.AuthorizerConfiguration + (*jmespath.Expression)(nil), // 6: buildbarn.configuration.jmespath.Expression } var file_pkg_proto_configuration_bb_browser_bb_browser_proto_depIdxs = []int32{ 1, // 0: buildbarn.configuration.bb_browser.ApplicationConfiguration.blobstore:type_name -> buildbarn.configuration.blobstore.BlobstoreConfiguration @@ -189,11 +191,12 @@ var file_pkg_proto_configuration_bb_browser_bb_browser_proto_depIdxs = []int32{ 4, // 3: buildbarn.configuration.bb_browser.ApplicationConfiguration.initial_size_class_cache:type_name -> buildbarn.configuration.blobstore.BlobAccessConfiguration 4, // 4: buildbarn.configuration.bb_browser.ApplicationConfiguration.file_system_access_cache:type_name -> buildbarn.configuration.blobstore.BlobAccessConfiguration 5, // 5: buildbarn.configuration.bb_browser.ApplicationConfiguration.authorizer:type_name -> buildbarn.configuration.auth.AuthorizerConfiguration - 6, // [6:6] is the sub-list for method output_type - 6, // [6:6] is the sub-list for method input_type - 6, // [6:6] is the sub-list for extension type_name - 6, // [6:6] is the sub-list for extension extendee - 0, // [0:6] is the sub-list for field type_name + 6, // 6: buildbarn.configuration.bb_browser.ApplicationConfiguration.request_metadata_links_jmespath_expression:type_name -> buildbarn.configuration.jmespath.Expression + 7, // [7:7] is the sub-list for method output_type + 7, // [7:7] is the sub-list for method input_type + 7, // [7:7] is the sub-list for extension type_name + 7, // [7:7] is the sub-list for extension extendee + 0, // [0:7] is the sub-list for field type_name } func init() { file_pkg_proto_configuration_bb_browser_bb_browser_proto_init() } diff --git a/pkg/proto/configuration/bb_browser/bb_browser.proto b/pkg/proto/configuration/bb_browser/bb_browser.proto index 8bdd462..c23795c 100644 --- a/pkg/proto/configuration/bb_browser/bb_browser.proto +++ b/pkg/proto/configuration/bb_browser/bb_browser.proto @@ -6,6 +6,7 @@ import "pkg/proto/configuration/auth/auth.proto"; import "pkg/proto/configuration/blobstore/blobstore.proto"; import "pkg/proto/configuration/global/global.proto"; import "pkg/proto/configuration/http/http.proto"; +import "pkg/proto/configuration/jmespath/jmespath.proto"; option go_package = "github.com/buildbarn/bb-browser/pkg/proto/configuration/bb_browser"; @@ -87,5 +88,6 @@ message ApplicationConfiguration { // // If no links to external services need to be provided, you may use // expression `{}` (including the backticks). - string request_metadata_links_jmespath_expression = 11; + buildbarn.configuration.jmespath.Expression + request_metadata_links_jmespath_expression = 11; }