Documentation
¶
Index ¶
- Constants
- func BuildConsoleScopeURL(brand core.LarkBrand, appID, scope string) string
- func CollectAllScopesFromMeta(identity string) []string
- func CollectScopesForProjects(projects []string, identity string) []string
- func CollectScopesWithSources(projects []string, identity string) ([]string, map[string]*ScopeSource)
- func ComputeMinimumScopeSet(identity string) []string
- func DeclaredScopesForMethod(m meta.Method, identity string) []string
- func EmbeddedCatalog() apicatalog.Catalog
- func EmbeddedServicesTyped() []meta.Service
- func ExtractRequiredScopes(detail interface{}) []string
- func FilterAutoApproveScopes(scopes []string) []string
- func FilterForStrictMode(mode core.StrictMode) apicatalog.MethodFilter
- func FilterScopes(allScopes []string, domains []string, permissions []string) []string
- func GetAuthChildren(parent string) []string
- func GetAuthDomain(service string) string
- func GetReadOnlyScopes(identity string) []string
- func GetRegistryDir() string
- func GetScopeScore(scope string) int
- func GetScopesForDomains(projects []string, identity string) []string
- func GetServiceDescription(name, lang string) string
- func GetServiceDetailDescription(name, lang string) string
- func GetServiceTitle(name, lang string) string
- func HasAuthDomain(service string) bool
- func Init()
- func InitWithBrand(brand core.LarkBrand)
- func IsAutoApproveScope(scope string) bool
- func ListFromMetaProjects() []string
- func LoadAutoApproveSet() map[string]bool
- func LoadOverrideAutoApproveAllow() map[string]bool
- func LoadOverrideAutoApproveDeny() map[string]bool
- func LoadPlatformAutoApproveSet() map[string]bool
- func LoadScopePriorities() map[string]int
- func ResolveScopesFromFilters(projects []string, permissions []string, identity string) []string
- func RuntimeCatalog() apicatalog.Catalog
- func SelectRecommendedScopeFromStrings(scopes []string, _ string) string
- func ServiceTyped(name string) (meta.Service, bool)
- func ServicesTyped() []meta.Service
- type CacheMeta
- type CommandEntry
- type MergedRegistry
- type ScopeSource
Constants ¶
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
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 ¶
CollectAllScopesFromMeta collects all unique scopes from from_meta/*.json for the given identity ("user" or "tenant"). Results are deduplicated and sorted.
func CollectScopesForProjects ¶
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 ¶
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
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
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 ¶
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 ¶
FilterScopes filters scopes by domain and permission level.
func GetAuthChildren ¶ added in v1.0.8
GetAuthChildren returns all service names whose auth_domain equals parent.
func GetAuthDomain ¶ added in v1.0.8
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 ¶
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 ¶
GetScopeScore returns the priority score for a scope, or DefaultScopeScore if not found.
func GetScopesForDomains ¶
GetScopesForDomains returns scopes for specific projects (by project name).
func GetServiceDescription ¶
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 ¶
GetServiceDetailDescription returns the localized detail description for a service domain. Returns empty string if not found.
func GetServiceTitle ¶
GetServiceTitle returns the localized title for a service domain. Returns empty string if not found.
func HasAuthDomain ¶ added in v1.0.8
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 ¶
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 ¶
IsAutoApproveScope returns true if the scope has AutoApprove rule.
func ListFromMetaProjects ¶
func ListFromMetaProjects() []string
ListFromMetaProjects lists available service project names (sorted).
func LoadAutoApproveSet ¶
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 ¶
LoadOverrideAutoApproveAllow returns scopes explicitly listed in scope_overrides.json recommend.allow (our desired additions).
func LoadOverrideAutoApproveDeny ¶
LoadOverrideAutoApproveDeny returns scopes explicitly listed in scope_overrides.json recommend.deny
func LoadPlatformAutoApproveSet ¶
LoadPlatformAutoApproveSet returns scopes with AutoApprove rule on the platform (from scope_priorities.json only, before overrides).
func LoadScopePriorities ¶
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 ¶
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
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
ServiceTyped returns one merged service (embedded + overlay) by name, or false if unknown.
func ServicesTyped ¶ added in v1.0.54
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.