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    Key,
7    Ai,
8    ArtifactRegistry,
9}
10
11/// One resource type's provider-neutral Remote Bindings contract.
12#[derive(Debug, Clone, Copy, PartialEq, Eq)]
13pub struct RemoteBindingDefinition {
14    pub resource_type: &'static str,
15    pub permission_set: &'static str,
16    pub kind: RemoteBindingKind,
17    pub description: &'static str,
18    /// Setup-owned parent resources that this binding kind may require. They do not turn a
19    /// bindings-only stack into an application stack.
20    pub setup_support_resource_types: &'static [&'static str],
21    /// Increment when the permission set's effective grants change. This makes direct setup
22    /// updates reconcile permissions even when the application resource config is unchanged.
23    pub revision: u32,
24}
25
26const DEFINITIONS: &[RemoteBindingDefinition] = &[
27    RemoteBindingDefinition {
28        resource_type: "storage",
29        permission_set: "storage/remote-data-write",
30        kind: RemoteBindingKind::Storage,
31        description: "Read and write objects in this storage resource",
32        setup_support_resource_types: &[
33            "azure_resource_group",
34            "azure_storage_account",
35            "service_activation",
36        ],
37        revision: 1,
38    },
39    RemoteBindingDefinition {
40        resource_type: "key",
41        permission_set: "key/remote-cryptography",
42        kind: RemoteBindingKind::Key,
43        description: "Encrypt and decrypt small values with this key",
44        setup_support_resource_types: &["azure_resource_group", "service_activation"],
45        revision: 1,
46    },
47    RemoteBindingDefinition {
48        resource_type: "ai",
49        permission_set: "ai/invoke",
50        kind: RemoteBindingKind::Ai,
51        description: "Invoke models through this AI resource",
52        setup_support_resource_types: &["azure_resource_group", "service_activation"],
53        revision: 1,
54    },
55    RemoteBindingDefinition {
56        resource_type: "artifact-registry",
57        permission_set: "artifact-registry/remote-read-write",
58        kind: RemoteBindingKind::ArtifactRegistry,
59        description: "Pull and push OCI artifacts in this registry",
60        setup_support_resource_types: &["azure_resource_group", "service_activation"],
61        revision: 1,
62    },
63];
64
65pub fn remote_binding_definition(
66    resource_type: &ResourceType,
67) -> Option<&'static RemoteBindingDefinition> {
68    DEFINITIONS
69        .iter()
70        .find(|definition| definition.resource_type == resource_type.as_ref())
71}
72
73pub fn remote_binding_for_entry(entry: &ResourceEntry) -> Option<&'static RemoteBindingDefinition> {
74    (entry.remote_access && entry.lifecycle == ResourceLifecycle::Frozen)
75        .then(|| remote_binding_definition(&entry.config.resource_type()))
76        .flatten()
77}
78
79pub fn remote_binding_definitions() -> &'static [RemoteBindingDefinition] {
80    DEFINITIONS
81}