Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit 8ad337e

Browse files
authored
feat/enterpriseportal: define SubscriptionLicenseChecksService (#64396)
This PR defines an Enterprise Portal version of the "license check" API that is currently bundled in Souregraph as a separate gRPC service that will be implemented in Enterprise Portal (in a PR I will stack on top of this one). The API schema is pretty much the same, except: - removed the `error` field, since I'm pretty sure we can return a real error instead in a connectRPC implementation for the same effect. - made `license_key` a parameter, as we already propagate the license key all over the place (pings, telemetry) - this is a fairly low-frequency check so there shouldn't be any bandwidth concerns or the like. For now, this parameter will support the existing format so we can forward checks in dotcom to EP, but I've set a target removal release Existing API: https://sourcegraph.com/github.com/sourcegraph/sourcegraph/-/blob/cmd/frontend/internal/dotcom/productsubscription/license_check_handler.go?L133 Part of https://linear.app/sourcegraph/issue/CORE-227 ## Test plan CI
1 parent b3e86a6 commit 8ad337e

File tree

8 files changed

+601
-1
lines changed

8 files changed

+601
-1
lines changed

lib/enterpriseportal/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ To regenerate all relevant bindings:
99
```sh
1010
sg gen buf \
1111
lib/enterpriseportal/subscriptions/v1/buf.gen.yaml \
12-
lib/enterpriseportal/codyaccess/v1/buf.gen.yaml
12+
lib/enterpriseportal/codyaccess/v1/buf.gen.yaml \
13+
lib/enterpriseportal/subscriptionlicensechecks/v1/buf.gen.yaml
1314
```
1415

1516
> [!CAUTION]
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
load("@io_bazel_rules_go//go:def.bzl", "go_library")
2+
load("@rules_proto//proto:defs.bzl", "proto_library")
3+
load("@rules_proto_grpc//doc:defs.bzl", "doc_template_compile")
4+
load("@rules_buf//buf:defs.bzl", "buf_lint_test")
5+
6+
# Bazel-generated files are different from what is generated locally by buf and
7+
# causes compilation errors - the next line disables Gazelle-generated Bazel
8+
# configuration that overrides the generated code that gets committed.
9+
# https://github.com/sourcegraph/devx-support/issues/932#issuecomment-2103608521
10+
# gazelle:proto disable_global
11+
12+
proto_library(
13+
name = "v1_proto",
14+
srcs = ["subscriptionlicensechecks.proto"],
15+
strip_import_prefix = "/lib", # keep
16+
visibility = ["//visibility:public"],
17+
deps = [
18+
"@com_google_protobuf//:field_mask_proto",
19+
"@com_google_protobuf//:timestamp_proto",
20+
],
21+
)
22+
23+
go_library(
24+
name = "subscriptionlicensechecks",
25+
srcs = [
26+
"subscriptionlicensechecks.pb.go",
27+
"subscriptionlicensechecks_grpc.pb.go",
28+
],
29+
importpath = "github.com/sourcegraph/sourcegraph/lib/enterpriseportal/subscriptionlicensechecks/v1",
30+
visibility = ["//visibility:public"],
31+
deps = [
32+
"@org_golang_google_grpc//:grpc",
33+
"@org_golang_google_grpc//codes",
34+
"@org_golang_google_grpc//status",
35+
"@org_golang_google_protobuf//reflect/protoreflect",
36+
"@org_golang_google_protobuf//runtime/protoimpl",
37+
],
38+
)
39+
40+
buf_lint_test(
41+
name = "v1_proto_lint",
42+
timeout = "short",
43+
config = "//internal:buf.yaml",
44+
targets = [":v1_proto"],
45+
)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Configuration file for https://buf.build/, which we use for Protobuf code generation.
2+
version: v1
3+
plugins:
4+
- plugin: buf.build/grpc/go:v1.3.0
5+
out: .
6+
opt:
7+
- paths=source_relative
8+
- plugin: buf.build/protocolbuffers/go:v1.33.0
9+
out: .
10+
opt:
11+
- paths=source_relative
12+
13+
# Generate connectrpc bindings in Go
14+
- plugin: buf.build/connectrpc/go:v1.16.1
15+
out: .
16+
opt:
17+
- paths=source_relative

lib/enterpriseportal/subscriptionlicensechecks/v1/subscriptionlicensechecks.pb.go

Lines changed: 258 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
syntax = "proto3";
2+
3+
package enterpriseportal.subscriptionlicensechecks.v1;
4+
5+
option go_package = "github.com/sourcegraph/sourcegraph/lib/enterpriseportal/subscriptionlicensechecks/v1";
6+
7+
// SubscriptionLicenseCheckService is the *public-facing* API specification for
8+
// Enterprise Portal's online license checks.
9+
//
10+
// Product implementations can use these endpoints to verify the status of a
11+
// license.
12+
service SubscriptionLicenseChecksService {
13+
// CheckLicenseKey returns the status of a license key.
14+
rpc CheckLicenseKey(CheckLicenseKeyRequest) returns (CheckLicenseKeyResponse) {}
15+
}
16+
17+
message CheckLicenseKeyRequest {
18+
// The signed license key to validate. For backwards compatibility, this
19+
// currently also accepts a token of the format 'slk_$hex($sha256(licenseKey))',
20+
// but this is deprecated and will be removed in Sourcegraph 5.8 onwards.
21+
//
22+
// Required.
23+
string license_key = 1;
24+
// Self-reported Sourcegraph instance identifier (also known as 'site ID').
25+
//
26+
// Required.
27+
string instance_id = 2;
28+
}
29+
30+
message CheckLicenseKeyResponse {
31+
// Valid indicates whether the license key is valid.
32+
bool valid = 1;
33+
// Reason can contain a human-readable explanation of the response.
34+
string reason = 2;
35+
}

0 commit comments

Comments
 (0)