-
Notifications
You must be signed in to change notification settings - Fork 5
service: name services for domains, methods for what they do #1446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| package service | ||
|
|
||
| import ( | ||
| "path/filepath" | ||
| "strings" | ||
| "testing" | ||
| ) | ||
|
|
||
| // A tool's name is derived, not written: service + "_" + method. That only | ||
| // reads well if the two halves say different things, which holds when a | ||
| // service is named for a domain (news, mail, places) and a method for what it | ||
| // does with that domain. | ||
| // | ||
| // A service named for an action has nowhere left to go: its main method has to | ||
| // repeat it. That is how "search" ended up with search.Search, deriving the | ||
| // tool name search_search. The capability moved to web.Search, and this test | ||
| // stops the next one arriving. | ||
| func TestNoMethodRepeatsItsService(t *testing.T) { | ||
| forEachService(t, func(svc string, methods []string) { | ||
| for _, m := range methods { | ||
| if strings.EqualFold(m, svc) { | ||
| t.Errorf("%s.%s derives the tool name %s_%s — name the service for a "+ | ||
| "domain and the method for what it does", | ||
| svc, m, svc, strings.ToLower(m)) | ||
| } | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| // Two endpoints deriving the same tool name would make one of them | ||
| // unreachable, silently. | ||
| func TestDerivedToolNamesAreUnique(t *testing.T) { | ||
| seen := map[string]string{} | ||
| forEachService(t, func(svc string, methods []string) { | ||
| for _, m := range methods { | ||
| name := svc + "_" + strings.ToLower(m) | ||
| if prev, dup := seen[name]; dup { | ||
| t.Errorf("%s.%s and %s both derive %q", svc, m, prev, name) | ||
| continue | ||
| } | ||
| seen[name] = svc + "." + m | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| // forEachService walks the service packages, handing each one its name and the | ||
| // RPC methods it declares. The directory name is the service name — that is | ||
| // the convention, and SERVICE_REGISTRY.md documents it. | ||
| func forEachService(t *testing.T, fn func(service string, methods []string)) { | ||
| t.Helper() | ||
| root := repoRoot(t) | ||
| dirs, err := filepath.Glob(filepath.Join(root, "service", "*")) | ||
| if err != nil { | ||
| t.Fatalf("glob: %v", err) | ||
| } | ||
| checked := 0 | ||
| for _, dir := range dirs { | ||
| methods, _, ok := scanService(t, dir) | ||
| if !ok { | ||
| continue // a package with no handler, e.g. search | ||
| } | ||
| checked++ | ||
| fn(filepath.Base(dir), methods) | ||
| } | ||
| if checked < 15 { | ||
| t.Fatalf("only scanned %d services; the scan is not finding them", checked) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On upgrade, a user-defined agent persisted in
user_agents.jsonwith only the previously exposedsearchservice retainsTools: ["search"], because there is no migration toweb. SincefilterServicesreturns every service when a nonempty allow-list matches nothing, that agent changes from search-only to access to all private services, including mail, images, events, db, and wallet, potentially exposing personal data or enabling charged actions. Translate the legacy service ID before applying the allow-list.Useful? React with 👍 / 👎.