Skip to main content

rusty_cdk_lookups/
lib.rs

1use proc_macro::TokenStream;
2use syn::parse_macro_input;
3use crate::parsing::GenericInput;
4use crate::roles::{find_kms_ref, find_role_ref};
5
6mod roles;
7mod cloudcontrol;
8mod parsing;
9
10/// Tries to retrieve IAM role information from your AWS environment (the role ARN).
11/// This ensures that the role actually exists in your account and that your deployment will not fail.
12/// 
13/// You should pass on a unique id for the role, as well as the role name, separated by a comma: `lookup_role_ref!("SomeId","SomeRoleName")`
14#[proc_macro]
15pub fn lookup_role_ref(input: TokenStream) -> TokenStream {
16    let input: GenericInput = parse_macro_input!(input);
17
18    let rt = tokio::runtime::Runtime::new().unwrap();
19
20    rt.block_on(find_role_ref(&input.resource_id, &input.identifier)).unwrap_or_else(|e| e.into_compile_error().into())
21}
22
23/// Tries to retrieve KMS key information from your AWS environment (the role ARN).
24/// This ensures that the key actually exists in your account and that your deployment will not fail.
25/// 
26/// You should pass on a unique id, as well as the kms key id, separated by a comma: `lookup_kms_key_ref!("SomeId","SomeKeyId")`
27#[proc_macro]
28pub fn lookup_kms_key_ref(input: TokenStream) -> TokenStream {
29    let input: GenericInput = parse_macro_input!(input);
30
31    let rt = tokio::runtime::Runtime::new().unwrap();
32
33    rt.block_on(find_kms_ref(&input.resource_id, &input.identifier)).unwrap_or_else(|e| e.into_compile_error().into())
34}