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

Commit f42c059

Browse files
authored
lib/servicecatalog: init to distribute catalog (#46999)
Part of sourcegraph/security-issues#327 Part of sourcegraph/security-issues#328 Part of sourcegraph/security-issues#334 Used by sourcegraph/controller#306
1 parent acb5d06 commit f42c059

File tree

4 files changed

+106
-48
lines changed

4 files changed

+106
-48
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# This is the source of truth for services dependencies of Sourcegraph. All names
2+
# should correspond to published images.
3+
#
4+
# Cloud started this file to ensure we can correctly maintain Network Policies
5+
# to ensure only necessary services can talk to each other.
6+
#
7+
# This file is not owned by Cloud but the entire engineering department.
8+
9+
protected_services:
10+
# $ go run ./dev/depgraph/ summary internal/gitserver
11+
# union of all dependent commands
12+
gitserver:
13+
consumers:
14+
- frontend
15+
- repo-updater
16+
- searcher
17+
- symbols
18+
- worker
19+
- migrator
20+
- precise-code-intel-worker
21+
# other stuff we just know about
22+
- search-indexer
23+
- indexed-searcher
24+
25+
# $ go run ./dev/depgraph/ summary internal/redispool
26+
# $ go run ./dev/depgraph/ summary internal/rcache
27+
# union of all dependent commands
28+
redis:
29+
consumers:
30+
- blobstore
31+
- frontend
32+
- github-proxy
33+
- gitserver
34+
- migrator
35+
- repo-updater
36+
- searcher
37+
- symbols
38+
- worker
39+
# other stuff we just know about
40+
- redis-exporter
41+
42+
# $ go run ./dev/depgraph/ summary internal/database
43+
# the union of all dependent commands
44+
postgres:
45+
consumers:
46+
- frontend
47+
- gitserver
48+
- migrator
49+
- repo-updater
50+
- searcher
51+
- symbols
52+
- worker
53+
- precise-code-intel-worker

lib/servicecatalog/servicecatalog.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package servicecatalog
2+
3+
import (
4+
_ "embed"
5+
6+
"gopkg.in/yaml.v3"
7+
8+
"github.com/sourcegraph/sourcegraph/lib/errors"
9+
)
10+
11+
//go:embed service-catalog.yaml
12+
var rawCatalog string
13+
14+
type Service struct {
15+
Consumers []string `yaml:"consumers" json:"consumers"`
16+
}
17+
18+
type Catalog struct {
19+
ProtectedServices map[string]Service `yaml:"protected_services" json:"protected_services"`
20+
}
21+
22+
func Get() (Catalog, error) {
23+
var c Catalog
24+
if err := yaml.Unmarshal([]byte(rawCatalog), &c); err != nil {
25+
return c, errors.Wrap(err, "'service-catalog.yaml' is invalid")
26+
}
27+
return c, nil
28+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package servicecatalog
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
"github.com/stretchr/testify/require"
8+
)
9+
10+
func TestGet(t *testing.T) {
11+
c, err := Get()
12+
require.NoError(t, err)
13+
for _, k := range []string{
14+
"gitserver",
15+
"redis",
16+
"postgres",
17+
} {
18+
t.Run(k, func(t *testing.T) {
19+
require.NotEmpty(t, c.ProtectedServices)
20+
require.NotEmpty(t, c.ProtectedServices[k])
21+
assert.NotEmpty(t, c.ProtectedServices[k].Consumers)
22+
})
23+
}
24+
}

service-catalog.yaml

Lines changed: 0 additions & 48 deletions
This file was deleted.

service-catalog.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
./lib/servicecatalog/service-catalog.yaml

0 commit comments

Comments
 (0)