Skip to content

Commit 023a8cb

Browse files
committed
Switch to github.com/buildbarn/bb-storage/pkg/jmespath
This adds support for file loading and providing test vectors to the JMESPath expressions accepted by bb_browser. This makes things consistent with the rest of Buildbarn.
1 parent cef29fb commit 023a8cb

File tree

7 files changed

+32
-17
lines changed

7 files changed

+32
-17
lines changed

BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ load("@gazelle//:def.bzl", "gazelle")
1515
# gazelle:resolve proto go pkg/proto/configuration/global/global.proto @com_github_buildbarn_bb_storage//pkg/proto/configuration/global
1616
# gazelle:resolve proto pkg/proto/configuration/http/http.proto @com_github_buildbarn_bb_storage//pkg/proto/configuration/http:http_proto
1717
# gazelle:resolve proto go pkg/proto/configuration/http/http.proto @com_github_buildbarn_bb_storage//pkg/proto/configuration/http
18+
# gazelle:resolve proto pkg/proto/configuration/jmespath/jmespath.proto @com_github_buildbarn_bb_storage//pkg/proto/configuration/jmespath:jmespath_proto
19+
# gazelle:resolve proto go pkg/proto/configuration/jmespath/jmespath.proto @com_github_buildbarn_bb_storage//pkg/proto/configuration/jmespath
1820
gazelle(
1921
name = "gazelle",
2022
)

cmd/bb_browser/BUILD.bazel

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,12 @@ go_library(
4040
"@com_github_buildbarn_bb_storage//pkg/auth/configuration",
4141
"@com_github_buildbarn_bb_storage//pkg/blobstore",
4242
"@com_github_buildbarn_bb_storage//pkg/blobstore/configuration",
43+
"@com_github_buildbarn_bb_storage//pkg/clock",
4344
"@com_github_buildbarn_bb_storage//pkg/digest",
4445
"@com_github_buildbarn_bb_storage//pkg/filesystem/path",
4546
"@com_github_buildbarn_bb_storage//pkg/global",
4647
"@com_github_buildbarn_bb_storage//pkg/http",
48+
"@com_github_buildbarn_bb_storage//pkg/jmespath",
4749
"@com_github_buildbarn_bb_storage//pkg/program",
4850
"@com_github_buildbarn_bb_storage//pkg/proto/auth",
4951
"@com_github_buildbarn_bb_storage//pkg/proto/fsac",
@@ -52,7 +54,6 @@ go_library(
5254
"@com_github_buildkite_terminal_to_html//:terminal-to-html",
5355
"@com_github_dustin_go_humanize//:go-humanize",
5456
"@com_github_gorilla_mux//:mux",
55-
"@com_github_jmespath_go_jmespath//:go-jmespath",
5657
"@com_github_kballard_go_shellquote//:go-shellquote",
5758
"@org_golang_google_grpc//codes",
5859
"@org_golang_google_grpc//metadata",

cmd/bb_browser/main.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,17 @@ import (
1717
auth_configuration "github.com/buildbarn/bb-storage/pkg/auth/configuration"
1818
"github.com/buildbarn/bb-storage/pkg/blobstore"
1919
blobstore_configuration "github.com/buildbarn/bb-storage/pkg/blobstore/configuration"
20+
"github.com/buildbarn/bb-storage/pkg/clock"
2021
"github.com/buildbarn/bb-storage/pkg/digest"
2122
"github.com/buildbarn/bb-storage/pkg/global"
2223
"github.com/buildbarn/bb-storage/pkg/http"
24+
"github.com/buildbarn/bb-storage/pkg/jmespath"
2325
"github.com/buildbarn/bb-storage/pkg/program"
2426
auth_pb "github.com/buildbarn/bb-storage/pkg/proto/auth"
2527
"github.com/buildbarn/bb-storage/pkg/proto/iscc"
2628
"github.com/buildbarn/bb-storage/pkg/util"
2729
"github.com/dustin/go-humanize"
2830
"github.com/gorilla/mux"
29-
"github.com/jmespath/go-jmespath"
3031
"github.com/kballard/go-shellquote"
3132

3233
"google.golang.org/grpc/codes"
@@ -131,7 +132,11 @@ func main() {
131132
routePrefix += "/"
132133
}
133134

134-
requestMetadataLinksJmespathExpression, err := jmespath.Compile(configuration.RequestMetadataLinksJmespathExpression)
135+
requestMetadataLinksJmespathExpression, err := jmespath.NewExpressionFromConfiguration(
136+
configuration.RequestMetadataLinksJmespathExpression,
137+
dependenciesGroup,
138+
clock.SystemClock,
139+
)
135140
if err != nil {
136141
return util.StatusWrap(err, "Failed to compile request metadata links JMESPath expression")
137142
}
@@ -159,7 +164,7 @@ func main() {
159164
if err != nil {
160165
return nil, util.StatusWrap(err, "Failed to marshal request metadata")
161166
}
162-
var rawRequestMetadata any
167+
var rawRequestMetadata map[string]any
163168
if err := json.Unmarshal(marshaledRequestMetadata, &rawRequestMetadata); err != nil {
164169
return nil, util.StatusWrap(err, "Failed to unmarshal request metadata")
165170
}

config/browser.jsonnet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@
2222
authorizer: {
2323
allow: {},
2424
},
25-
requestMetadataLinksJmespathExpression: '`{}`',
25+
requestMetadataLinksJmespathExpression: { expression: '`{}`' },
2626
}

pkg/proto/configuration/bb_browser/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ proto_library(
1111
"@com_github_buildbarn_bb_storage//pkg/proto/configuration/blobstore:blobstore_proto",
1212
"@com_github_buildbarn_bb_storage//pkg/proto/configuration/global:global_proto",
1313
"@com_github_buildbarn_bb_storage//pkg/proto/configuration/http:http_proto",
14+
"@com_github_buildbarn_bb_storage//pkg/proto/configuration/jmespath:jmespath_proto",
1415
],
1516
)
1617

@@ -24,6 +25,7 @@ go_proto_library(
2425
"@com_github_buildbarn_bb_storage//pkg/proto/configuration/blobstore",
2526
"@com_github_buildbarn_bb_storage//pkg/proto/configuration/global",
2627
"@com_github_buildbarn_bb_storage//pkg/proto/configuration/http",
28+
"@com_github_buildbarn_bb_storage//pkg/proto/configuration/jmespath",
2729
],
2830
)
2931

pkg/proto/configuration/bb_browser/bb_browser.pb.go

Lines changed: 14 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/proto/configuration/bb_browser/bb_browser.proto

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import "pkg/proto/configuration/auth/auth.proto";
66
import "pkg/proto/configuration/blobstore/blobstore.proto";
77
import "pkg/proto/configuration/global/global.proto";
88
import "pkg/proto/configuration/http/http.proto";
9+
import "pkg/proto/configuration/jmespath/jmespath.proto";
910

1011
option go_package = "github.com/buildbarn/bb-browser/pkg/proto/configuration/bb_browser";
1112

@@ -87,5 +88,6 @@ message ApplicationConfiguration {
8788
//
8889
// If no links to external services need to be provided, you may use
8990
// expression `{}` (including the backticks).
90-
string request_metadata_links_jmespath_expression = 11;
91+
buildbarn.configuration.jmespath.Expression
92+
request_metadata_links_jmespath_expression = 11;
9193
}

0 commit comments

Comments
 (0)