registry

package
v1.0.63 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 1, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultScopeScore = 0

DefaultScopeScore is the score assigned to scopes not in the priorities table. Higher score = more recommended. Unscored scopes get 0 (least preferred).

Variables

This section is empty.

Functions

func BuildConsoleScopeURL added in v1.0.40

func BuildConsoleScopeURL(brand core.LarkBrand, appID, scope string) string

BuildConsoleScopeURL returns the developer-console "apply scope" URL for the given app and scope, branded for feishu / lark. Returns "" when appID or scope is empty so callers can omit the field cleanly.

func CollectAllScopesFromMeta

func CollectAllScopesFromMeta(identity string) []string

CollectAllScopesFromMeta collects all unique scopes from from_meta/*.json for the given identity ("user" or "tenant"). Results are deduplicated and sorted.

func CollectScopesForProjects

func CollectScopesForProjects(projects []string, identity string) []string

CollectScopesForProjects collects the recommended scope for each API method in the specified from_meta projects. For each method, only the scope with the highest priority score is selected.

func CollectScopesWithSources

func CollectScopesWithSources(projects []string, identity string) ([]string, map[string]*ScopeSource)

CollectScopesWithSources is like CollectScopesForProjects but also records which API method contributed each scope. Used by scope-audit.

func ComputeMinimumScopeSet

func ComputeMinimumScopeSet(identity string) []string

ComputeMinimumScopeSet computes the minimum set of scopes that covers all from_meta API methods. Equivalent to CollectScopesForProjects with all projects.

func DeclaredScopesForMethod added in v1.0.45

func DeclaredScopesForMethod(m meta.Method, identity string) []string

DeclaredScopesForMethod returns the scopes declared by a method for the given identity. Prefers the explicit `requiredScopes` field when present; otherwise returns the single recommended scope from `scopes` (or the first scope as a final fallback). Returns nil when the method has no scope information.

func EmbeddedCatalog added in v1.0.54

func EmbeddedCatalog() apicatalog.Catalog

EmbeddedCatalog returns a navigation catalog over the embedded (overlay-free) metadata — deterministic across machines, for `lark-cli schema`, golden tests and schema lint.

func EmbeddedServicesTyped added in v1.0.54

func EmbeddedServicesTyped() []meta.Service

EmbeddedServicesTyped returns the embedded services (no remote overlay) as the typed meta model, sorted by name. This is the overlay-free parse boundary the schema envelope builds from — deterministic across machines.

func ExtractRequiredScopes added in v1.0.40

func ExtractRequiredScopes(detail interface{}) []string

ExtractRequiredScopes pulls scope names out of the API error's permission_violations field. The detail argument is the raw `error` block that the platform returns alongside lark code 99991672 / 99991679 — typically shaped as:

{ "permission_violations": [ {"subject": "<scope>"}, ... ] }

Returns nil when the structure does not match or no non-empty subjects are present, so callers can branch on a simple len() == 0 check.

func FilterAutoApproveScopes

func FilterAutoApproveScopes(scopes []string) []string

FilterAutoApproveScopes filters a scope list to only include auto-approve scopes.

func FilterForStrictMode added in v1.0.54

func FilterForStrictMode(mode core.StrictMode) apicatalog.MethodFilter

FilterForStrictMode returns a method filter enforcing the strict-mode forced identity, or nil when strict mode is inactive (no filtering). The token/identity vocabulary (meta.TokenForIdentity) and the "no accessTokens = permissive" predicate (meta.Method.SupportsToken) both live in meta, so this only composes them — schema completion/render and service commands never re-derive identity semantics.

func FilterScopes

func FilterScopes(allScopes []string, domains []string, permissions []string) []string

FilterScopes filters scopes by domain and permission level.

func GetAuthChildren added in v1.0.8

func GetAuthChildren(parent string) []string

GetAuthChildren returns all service names whose auth_domain equals parent.

func GetAuthDomain added in v1.0.8

func GetAuthDomain(service string) string

GetAuthDomain returns the auth_domain for a service, or "" if not set. When auth_domain is set, the service's scopes are collected under the parent domain during auth login.

func GetReadOnlyScopes

func GetReadOnlyScopes(identity string) []string

GetReadOnlyScopes returns read-only scopes from the recommended (best-per-method) scope set.

func GetRegistryDir

func GetRegistryDir() string

GetRegistryDir returns the filesystem path to the registry directory. Used for finding skills files etc.

func GetScopeScore

func GetScopeScore(scope string) int

GetScopeScore returns the priority score for a scope, or DefaultScopeScore if not found.

func GetScopesForDomains

func GetScopesForDomains(projects []string, identity string) []string

GetScopesForDomains returns scopes for specific projects (by project name).

func GetServiceDescription

func GetServiceDescription(name, lang string) string

GetServiceDescription returns the localized description for a service domain, suitable for --help output. Returns the description field directly. Returns empty string if not found in the config.

func GetServiceDetailDescription

func GetServiceDetailDescription(name, lang string) string

GetServiceDetailDescription returns the localized detail description for a service domain. Returns empty string if not found.

func GetServiceTitle

func GetServiceTitle(name, lang string) string

GetServiceTitle returns the localized title for a service domain. Returns empty string if not found.

func HasAuthDomain added in v1.0.8

func HasAuthDomain(service string) bool

HasAuthDomain reports whether the service has an auth_domain configured.

func Init

func Init()

Init initializes the registry with default brand (feishu). It is safe to call multiple times (sync.Once).

func InitWithBrand

func InitWithBrand(brand core.LarkBrand)

InitWithBrand initializes the registry by loading embedded data and optionally overlaying cached remote data. The brand determines which remote API host to use. It is safe to call multiple times (sync.Once). Remote fetch errors are silently ignored when embedded data is available. If no embedded data exists and no cache is found, a synchronous fetch is attempted.

func IsAutoApproveScope

func IsAutoApproveScope(scope string) bool

IsAutoApproveScope returns true if the scope has AutoApprove rule.

func ListFromMetaProjects

func ListFromMetaProjects() []string

ListFromMetaProjects lists available service project names (sorted).

func LoadAutoApproveSet

func LoadAutoApproveSet() map[string]bool

LoadAutoApproveSet returns the set of auto-approve scope names. Sources (merged): recommend=="true" in scope_priorities.json + explicit allow/deny in scope_overrides.json.

func LoadOverrideAutoApproveAllow

func LoadOverrideAutoApproveAllow() map[string]bool

LoadOverrideAutoApproveAllow returns scopes explicitly listed in scope_overrides.json recommend.allow (our desired additions).

func LoadOverrideAutoApproveDeny

func LoadOverrideAutoApproveDeny() map[string]bool

LoadOverrideAutoApproveDeny returns scopes explicitly listed in scope_overrides.json recommend.deny

func LoadPlatformAutoApproveSet

func LoadPlatformAutoApproveSet() map[string]bool

LoadPlatformAutoApproveSet returns scopes with AutoApprove rule on the platform (from scope_priorities.json only, before overrides).

func LoadScopePriorities

func LoadScopePriorities() map[string]int

LoadScopePriorities loads the scope priorities map from scope_priorities.json. Scores are stored as float strings (e.g. "52.42") and rounded to int.

func ResolveScopesFromFilters

func ResolveScopesFromFilters(projects []string, permissions []string, identity string) []string

ResolveScopesFromFilters resolves scopes from project and permission filters.

func RuntimeCatalog added in v1.0.54

func RuntimeCatalog() apicatalog.Catalog

RuntimeCatalog returns a navigation catalog over the merged (embedded + remote overlay) metadata — for service command registration and scope discovery, where overlay methods must be reachable.

func SelectRecommendedScopeFromStrings added in v1.0.40

func SelectRecommendedScopeFromStrings(scopes []string, _ string) string

SelectRecommendedScopeFromStrings returns the highest-priority (least-privilege) scope to surface to users, or "" for no scopes. Unknown scopes score DefaultScopeScore, so an all-unknown list yields the first entry. Priority is identity-independent; the parameter is kept for call-site clarity.

func ServiceTyped added in v1.0.54

func ServiceTyped(name string) (meta.Service, bool)

ServiceTyped returns one merged service (embedded + overlay) by name, or false if unknown.

func ServicesTyped added in v1.0.54

func ServicesTyped() []meta.Service

ServicesTyped returns the merged registry (embedded + remote overlay) as typed meta.Services, sorted by name. The merged store is already typed, so this just projects it into a sorted slice — no map round-trip. This is the typed entry the command tree and scope computation build from.

Types

type CacheMeta

type CacheMeta struct {
	LastCheckAt int64  `json:"last_check_at"`
	Version     string `json:"version,omitempty"`
	Brand       string `json:"brand,omitempty"`
}

CacheMeta holds metadata about the cached remote_meta.json file.

type CommandEntry

type CommandEntry struct {
	Command    string   // CLI label, e.g. "calendars create" or "+agenda"
	Type       string   // "api" or "shortcut"
	Scopes     []string // effective scopes (requiredScopes if present, else [bestScope])
	HTTPMethod string   // e.g. "POST" (API only)
}

CommandEntry represents a CLI command (API method or shortcut) and its scopes.

func CollectCommandScopes

func CollectCommandScopes(projects []string, identity string) []CommandEntry

CollectCommandScopes walks from_meta methods for the given projects and returns one CommandEntry per API method, sorted by command label.

Scope selection per method:

  • If the method has a "requiredScopes" field, all of those scopes are needed (conjunction).
  • Otherwise, only the highest-priority scope from "scopes" is shown (minimum privilege).

type MergedRegistry

type MergedRegistry struct {
	Version  string         `json:"version"`
	Services []meta.Service `json:"services"`
}

MergedRegistry is the top-level structure of remote_meta.json. Services are decoded straight into the typed meta model so embedded, cached, and remote data share one representation (no map intermediary, no re-parse).

type ScopeSource

type ScopeSource struct {
	APIs      []string // e.g. "POST calendar.event.create"
	Shortcuts []string // e.g. "+send", "+reply"
}

ScopeSource tracks which APIs and shortcuts contributed a scope.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL