Skip to content

Commit

Permalink
control: move segments and trust endpoints to separate packages
Browse files Browse the repository at this point in the history
Move `/segment*`, `/trc*` and `/certificate*` endpoints to separate package so they can easily be added to other services.
 - Moved segments  and trust endpoints from `control/spec.yml` to `segments/spec.yml` and `cppki/spec.yml` respectively.
 - Moved implementations and tests of segments and trust endpoints to separate package.
 - Updated instantiations of the api servers in the respective `main.go` files.
 -

GitOrigin-RevId: 1bc44aeb5d3b1314c849f703512d4eae089c7293
  • Loading branch information
uniquefine authored and lukedirtwalker committed Nov 30, 2021
1 parent 5b9a39c commit f57747a
Show file tree
Hide file tree
Showing 57 changed files with 4,498 additions and 1,315 deletions.
2 changes: 2 additions & 0 deletions go/cs/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ go_library(
"//go/lib/serrors:go_default_library",
"//go/lib/snet:go_default_library",
"//go/lib/topology:go_default_library",
"//go/pkg/api/cppki/api:go_default_library",
"//go/pkg/api/jwtauth:go_default_library",
"//go/pkg/api/segments/api:go_default_library",
"//go/pkg/app:go_default_library",
"//go/pkg/app/launcher:go_default_library",
"//go/pkg/ca/api:go_default_library",
Expand Down
10 changes: 8 additions & 2 deletions go/cs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ import (
"github.com/scionproto/scion/go/lib/serrors"
"github.com/scionproto/scion/go/lib/snet"
"github.com/scionproto/scion/go/lib/topology"
cppkiapi "github.com/scionproto/scion/go/pkg/api/cppki/api"
"github.com/scionproto/scion/go/pkg/api/jwtauth"
segapi "github.com/scionproto/scion/go/pkg/api/segments/api"
"github.com/scionproto/scion/go/pkg/app"
"github.com/scionproto/scion/go/pkg/app/launcher"
caapi "github.com/scionproto/scion/go/pkg/ca/api"
Expand Down Expand Up @@ -548,14 +550,18 @@ func realMain(ctx context.Context) error {
r.Get("/", api.ServeSpecInteractive)
r.Get("/openapi.json", api.ServeSpecJSON)
server := api.Server{
Segments: pathDB,
SegmentsServer: segapi.Server{
Segments: pathDB,
},
CPPKIServer: cppkiapi.Server{
TrustDB: trustDB,
},
CA: chainBuilder,
Config: service.NewConfigStatusPage(globalCfg).Handler,
Info: service.NewInfoStatusPage().Handler,
LogLevel: service.NewLogLevelStatusPage().Handler,
Signer: signer,
Topology: topo.HandleHTTP,
TrustDB: trustDB,
}
log.Info("Exposing API", "addr", globalCfg.API.Addr)
s := http.Server{
Expand Down
52 changes: 52 additions & 0 deletions go/pkg/api/cppki/api/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
load("//lint:go.bzl", "go_library", "go_test")
load("@com_github_scionproto_scion//rules_openapi:defs.bzl", "openapi_generate_go")

openapi_generate_go(
name = "api_generated",
src = "//spec:cppki",
server = True,
spec = False,
)

# exclude the *.gen.go filse in the workspace it's only for editor compatibility.
# gazelle:exclude *.gen.go
go_library(
name = "go_default_library",
srcs = [
"api.go",
":api_generated", # keep
],
importpath = "github.com/scionproto/scion/go/pkg/api/cppki/api",
visibility = ["//visibility:public"],
deps = [
"//go/lib/addr:go_default_library",
"//go/lib/scrypto:go_default_library",
"//go/lib/scrypto/cppki:go_default_library",
"//go/lib/serrors:go_default_library",
"//go/pkg/api:go_default_library",
"//go/pkg/storage:go_default_library",
"//go/pkg/storage/trust:go_default_library",
"//go/pkg/trust:go_default_library",
"@com_github_deepmap_oapi_codegen//pkg/runtime:go_default_library", # keep
"@com_github_go_chi_chi_v5//:go_default_library", # keep
],
)

go_test(
name = "go_default_test",
srcs = ["api_test.go"],
data = glob(["testdata/**"]),
embed = [":go_default_library"],
deps = [
"//go/lib/addr:go_default_library",
"//go/lib/scrypto:go_default_library",
"//go/lib/scrypto/cppki:go_default_library",
"//go/lib/serrors:go_default_library",
"//go/lib/xtest:go_default_library",
"//go/pkg/storage/mock_storage:go_default_library",
"//go/pkg/storage/trust:go_default_library",
"@com_github_golang_mock//gomock:go_default_library",
"@com_github_stretchr_testify//assert:go_default_library",
"@com_github_stretchr_testify//require:go_default_library",
],
)
Loading

0 comments on commit f57747a

Please sign in to comment.