permissions¶
panel_flowdash.permissions
¶
The project file's permissions section: who may do what, layered under the code's rules.
permissions:
default_allow: true
admin_groups: [admins]
people:
ana: {groups: [analysts]}
priya: {groups: [field-ops], assistant: false}
assistant_groups: [analysts, admins]
sensitive_components: ["Lumen/deckgl"]
approval_rules:
- tool: run_command
when: {command: "action:refresh"}
default_allow and admin_groups are those of AuthConfig and only
apply when the project's __init__.py (or the app's auth_config)
does not set them. people adds groups to people, as
AuthConfig.user_groups does, and with assistant: false keeps the
assistant from someone. assistant_groups limits the assistant to their
members, unless the app has an agent_authorize. The
sensitive_components and approval_rules are added to the app's
agent_sensitive_components and agent_approval_rules; a rule's
when matches calls whose arguments have those values (text may use
* wildcards), and enabled: false keeps a rule without applying it.
AUTH_FIELDS = ('default_allow', 'admin_groups')
module-attribute
¶
KEYS = ('default_allow', 'admin_groups', 'people', 'assistant_groups', 'sensitive_components', 'approval_rules')
module-attribute
¶
_LAST_GOOD = {}
module-attribute
¶
_LAST_GOOD_LOCK = threading.Lock()
module-attribute
¶
_RULE_KEYS = ('tool', 'when', 'enabled')
module-attribute
¶
_parse = parse_project_data
module-attribute
¶
logger = logging.getLogger(__name__)
module-attribute
¶
AuthConfig
dataclass
¶
Project-level authorization configuration.
Loaded from the project's __init__.py by the serve command. All fields
are optional; the defaults reproduce the pre-auth behavior (allow by
default, groups read from the standard claim keys, no admin groups).
admin_groups = field(default_factory=frozenset)
class-attribute
instance-attribute
¶
default_allow = True
class-attribute
instance-attribute
¶
group_claims = DEFAULT_GROUP_CLAIMS
class-attribute
instance-attribute
¶
resolve_groups = None
class-attribute
instance-attribute
¶
user_groups = field(default_factory=dict)
class-attribute
instance-attribute
¶
from_module(module)
classmethod
¶
Build an :class:AuthConfig from names on a project __init__.
Reads group_claims, user_groups, resolve_groups,
admin_groups and default_allow if present, falling back to the
defaults otherwise. Missing module or names yield a default config.
Identity
dataclass
¶
The resolved principal for a session.
groups = field(default_factory=frozenset)
class-attribute
instance-attribute
¶
oauth_user = None
class-attribute
instance-attribute
¶
system_user = None
class-attribute
instance-attribute
¶
user
instance-attribute
¶
user_info = field(default_factory=dict)
class-attribute
instance-attribute
¶
user_names
property
¶
All names this identity may be referenced by in a rule.
in_groups(groups)
¶
Whether the identity belongs to any of groups.
is_user(users)
¶
Whether the identity matches any of users (OAuth or system name).
PermissionsUnavailable
¶
Bases: RuntimeError
The project file's permissions cannot be read and none were read from it before.
Project
dataclass
¶
A loaded project file.
It holds the raw data, where each key and value is written, by path
(e.g. ("metrics", "capacity", "table")), the value each registered
loader made of its section, the warnings found while loading and the
context the loaders were given.
context = field(default_factory=dict)
class-attribute
instance-attribute
¶
data = field(default_factory=dict)
class-attribute
instance-attribute
¶
directory
property
¶
Return the directory the file is in, against which paths it names resolve.
path = None
class-attribute
instance-attribute
¶
positions = field(default_factory=dict)
class-attribute
instance-attribute
¶
warnings = field(default_factory=list)
class-attribute
instance-attribute
¶
get(name, default=None)
¶
Return the value of section name, or default if the file has none.
The value is what the section's loader returned. A section whose loader
was registered after the file was loaded is loaded now (raising
ProjectError); a section no loader is registered for gives its
raw data.
load_all()
¶
Load every section a loader is registered for, warning about the others.
Raises ProjectError with every problem the loaders found.
position(path)
¶
Return the 1-based line and column of the value at path.
A path that is not in the file gives the position of its nearest enclosing value.
problem(path, message, key=False)
¶
Return a problem at the value at path (with key, at the key naming it).
raw(name, default=None)
¶
Return the raw YAML data of section name.
set(name, value)
¶
Set section name to value and write it to the project's file.
The value goes through the section's dump and the result through
its loader, so a value the loader rejects raises ProjectError,
positioned where it would be written, and the file is left alone.
Only the lines of this section change in the file; comments inside it
are not kept. Text a YAML 1.1 reader would take for something else,
such as no or 1:20, is quoted.
update(name, change)
¶
Change section name from its raw data as the file has it now, and write it.
change is called with a copy of the section's raw YAML data, read
again from the file (None when the file has no such section), and
returns the new value, which is written as set writes it. The read,
change and the write happen under FILE_LOCK, so no other write
from this process comes in between. An exception from change
leaves the file alone. Returns the value written.
ProjectError
¶
Bases: ValueError
The problems of a project file, each with the file, line and column it concerns.
problems = list(problems)
instance-attribute
¶
Section
dataclass
¶
One top-level section of a project file, as a loader receives it.
context
property
¶
Return what the app loaded the project with, e.g. its data sources.
name
instance-attribute
¶
project
instance-attribute
¶
value
instance-attribute
¶
position(path=())
¶
Return the line and column of the value at path in this section.
problem(path, message, key=False)
¶
Return a problem at the value at path in this section (with key, at its key).
warn(path, message, key=False)
¶
Report a problem at path that does not stop the section from loading.
SectionError
¶
Bases: ValueError
A section loader's problem at path inside its section.
path is e.g. ("capacity", "table"). With key=True the problem
is reported where the last key of path is written instead of its value.
_last_good(key, exc)
¶
_matcher(when)
¶
_names(value)
¶
approval_rules(permissions)
¶
Return the section's enabled approval rules as panel_agents.ApprovalRule objects.
assistant_allowed(permissions, identity)
¶
Whether the section gives identity the assistant.
auth_code_fields(auth_config, sources, explicit)
¶
Return the AuthConfig fields set in code, each with where.
flowdash serve names the fields the project's __init__.py sets
in settings_sources as auth_config.<field> (and the config
itself as auth_config); an auth_config given otherwise sets
every field that differs from the default.
describe_rule(rule)
¶
Return a rule given in code or the file as the tool it matches and when, for the admin view.
effective_auth_config(auth_config, permissions, in_code)
¶
Return auth_config with the section's settings for the fields not set in code.
load_permissions(section)
¶
Check the permissions section and return it as plain data.
project_permissions(path)
¶
Return the permissions section of the project file at path, read again when it changes.
A file that cannot be read or parsed, or whose section is invalid, does
not loosen anything: the permissions last read from it stay in force,
logged as an error, and with none read before PermissionsUnavailable
is raised, so callers deny access rather than fall back to defaults.
No file at all sets nothing.
rule_problems(rule)
¶
Return the problems of an approval rule, each with its path inside it.