Skip to main content

alien_core/
remote_bindings.rs

1use crate::{ResourceEntry, ResourceLifecycle, ResourceType};
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq)]
4pub enum RemoteBindingKind {
5    Storage,
6}
7
8/// One resource type's provider-neutral Remote Bindings contract.
9#[derive(Debug, Clone, Copy, PartialEq, Eq)]
10pub struct RemoteBindingDefinition {
11    pub resource_type: &'static str,
12    pub permission_set: &'static str,
13    pub kind: RemoteBindingKind,
14    pub description: &'static str,
15    /// Setup-owned parent resources that this binding kind may require. They do not turn a
16    /// bindings-only stack into an application stack.
17    pub setup_support_resource_types: &'static [&'static str],
18    /// Increment when the permission set's effective grants change. This makes direct setup
19    /// updates reconcile permissions even when the application resource config is unchanged.
20    pub revision: u32,
21}
22
23const DEFINITIONS: &[RemoteBindingDefinition] = &[RemoteBindingDefinition {
24    resource_type: "storage",
25    permission_set: "storage/remote-data-write",
26    kind: RemoteBindingKind::Storage,
27    description: "Read and write objects in this storage resource",
28    setup_support_resource_types: &[
29        "azure_resource_group",
30        "azure_storage_account",
31        "service_activation",
32    ],
33    revision: 1,
34}];
35
36pub fn remote_binding_definition(
37    resource_type: &ResourceType,
38) -> Option<&'static RemoteBindingDefinition> {
39    DEFINITIONS
40        .iter()
41        .find(|definition| definition.resource_type == resource_type.as_ref())
42}
43
44pub fn remote_binding_for_entry(entry: &ResourceEntry) -> Option<&'static RemoteBindingDefinition> {
45    (entry.remote_access && entry.lifecycle == ResourceLifecycle::Frozen)
46        .then(|| remote_binding_definition(&entry.config.resource_type()))
47        .flatten()
48}
49
50pub fn remote_binding_definitions() -> &'static [RemoteBindingDefinition] {
51    DEFINITIONS
52}