From c3dfb64a7248a21e8e9a5a37deb302e42ab0aefc Mon Sep 17 00:00:00 2001 From: Andrzej Ressel Date: Mon, 2 Dec 2024 03:10:17 +0100 Subject: [PATCH] Fix quotes in escapes in generated strings --- Cargo.lock | 1 + .../src/resource/access_identity_provider.rs | 3 +- .../src/resource/device_settings_policy.rs | 55 ++++----- .../src/resource/dlp_profile.rs | 104 ++++++++++-------- .../src/resource/filter.rs | 24 ++-- .../src/resource/firewall_rule.rs | 41 ++++--- .../src/resource/load_balancer.rs | 2 +- .../src/resource/mtls_certificate.rs | 8 +- .../src/resource/teams_rule.rs | 40 ++++--- .../src/resource/waiting_room_rules.rs | 2 +- .../zero_trust_access_identity_provider.rs | 3 +- .../resource/zero_trust_device_profiles.rs | 53 +++++---- .../src/resource/zero_trust_dlp_profile.rs | 104 ++++++++++-------- .../src/resource/zero_trust_gateway_policy.rs | 40 ++++--- .../src/resource/service_config.rs | 19 ++-- pulumi_wasm_generator_lib/Cargo.toml | 1 + .../src/code_generation.rs | 26 ++++- pulumi_wasm_generator_lib/src/yaml/mod.rs | 98 ++++++++++++++++- .../src/yaml/yaml_model.rs | 8 ++ 19 files changed, 409 insertions(+), 223 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fe5277ca8..e159f7389 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2333,6 +2333,7 @@ dependencies = [ "convert_case", "handlebars", "prettyplease", + "proc-macro2", "regex", "serde", "serde_json", diff --git a/providers/pulumi_wasm_provider_cloudflare_rust/src/resource/access_identity_provider.rs b/providers/pulumi_wasm_provider_cloudflare_rust/src/resource/access_identity_provider.rs index a0f20894c..961b6be0e 100644 --- a/providers/pulumi_wasm_provider_cloudflare_rust/src/resource/access_identity_provider.rs +++ b/providers/pulumi_wasm_provider_cloudflare_rust/src/resource/access_identity_provider.rs @@ -38,8 +38,7 @@ //! vec![ //! AccessIdentityProviderConfig::builder().attributes(vec!["email", //! "username",]) -//! .idpPublicCert("MIIDpDCCAoygAwIBAgIGAV2ka+55MA0GCSqGSIb3DQEBCwUAMIGSMQswCQ...GF/Q2/MHadws97cZg -//! uTnQyuOqPuHbnN83d/2l1NSYKCbHt24o") +//! .idpPublicCert("MIIDpDCCAoygAwIBAgIGAV2ka+55MA0GCSqGSIb3DQEBCwUAMIGSMQswCQ...GF/Q2/MHadws97cZg\nuTnQyuOqPuHbnN83d/2l1NSYKCbHt24o") //! .issuerUrl("jumpcloud").signRequest(false) //! .ssoTargetUrl("https://sso.myexample.jumpcloud.com/saml2/cloudflareaccess") //! .build_struct(), diff --git a/providers/pulumi_wasm_provider_cloudflare_rust/src/resource/device_settings_policy.rs b/providers/pulumi_wasm_provider_cloudflare_rust/src/resource/device_settings_policy.rs index d5de7677a..9e85a031f 100644 --- a/providers/pulumi_wasm_provider_cloudflare_rust/src/resource/device_settings_policy.rs +++ b/providers/pulumi_wasm_provider_cloudflare_rust/src/resource/device_settings_policy.rs @@ -3,31 +3,36 @@ //! ## Example Usage //! //! -//! ```yaml -//! resources: -//! developerWarpPolicy: -//! type: cloudflare:DeviceSettingsPolicy -//! name: developer_warp_policy -//! properties: -//! accountId: f037e56e89293a057740de681ac9abbe -//! name: Developers WARP settings policy -//! description: Developers WARP settings policy description -//! precedence: 10 -//! match: any(identity.groups.name[*] in {"Developers"}) -//! default: false -//! enabled: true -//! allowModeSwitch: true -//! allowUpdates: true -//! allowedToLeave: true -//! autoConnect: 0 -//! captivePortal: 5 -//! disableAutoFallback: true -//! supportUrl: https://cloudflare.com -//! switchLocked: true -//! serviceModeV2Mode: warp -//! serviceModeV2Port: 3000 -//! excludeOfficeIps: false -//! tunnelProtocol: wireguard +//! ```ignore +//! use pulumi_wasm_rust::Output; +//! use pulumi_wasm_rust::{add_export, pulumi_main}; +//! #[pulumi_main] +//! fn test_main() -> Result<(), Error> { +//! let developerWarpPolicy = device_settings_policy::create( +//! "developerWarpPolicy", +//! DeviceSettingsPolicyArgs::builder() +//! .account_id("f037e56e89293a057740de681ac9abbe") +//! .allow_mode_switch(true) +//! .allow_updates(true) +//! .allowed_to_leave(true) +//! .auto_connect(0) +//! .captive_portal(5) +//! .default(false) +//! .description("Developers WARP settings policy description") +//! .disable_auto_fallback(true) +//! .enabled(true) +//! .exclude_office_ips(false) +//! .match_("any(identity.groups.name[*] in {\"Developers\"})") +//! .name("Developers WARP settings policy") +//! .precedence(10) +//! .service_mode_v_2_mode("warp") +//! .service_mode_v_2_port(3000) +//! .support_url("https://cloudflare.com") +//! .switch_locked(true) +//! .tunnel_protocol("wireguard") +//! .build_struct(), +//! ); +//! } //! ``` //! //! diff --git a/providers/pulumi_wasm_provider_cloudflare_rust/src/resource/dlp_profile.rs b/providers/pulumi_wasm_provider_cloudflare_rust/src/resource/dlp_profile.rs index 858331555..dbb805c78 100644 --- a/providers/pulumi_wasm_provider_cloudflare_rust/src/resource/dlp_profile.rs +++ b/providers/pulumi_wasm_provider_cloudflare_rust/src/resource/dlp_profile.rs @@ -5,53 +5,63 @@ //! ## Example Usage //! //! -//! ```yaml -//! resources: -//! # Predefined profile must be imported, cannot be created -//! creds: -//! type: cloudflare:DlpProfile -//! properties: -//! accountId: f037e56e89293a057740de681ac9abbe -//! name: Credentials and Secrets -//! type: predefined -//! allowedMatchCount: 3 -//! entries: -//! - enabled: true -//! name: Amazon AWS Access Key ID -//! id: d8fcfc9c-773c-405e-8426-21ecbb67ba93 -//! - enabled: false -//! id: 2c0e33e1-71da-40c8-aad3-32e674ad3d96 -//! name: Amazon AWS Secret Access Key -//! - enabled: true -//! id: 4e92c006-3802-4dff-bbe1-8e1513b1c92a -//! name: Microsoft Azure Client Secret -//! - enabled: false -//! id: 5c713294-2375-4904-abcf-e4a15be4d592 -//! name: SSH Private Key -//! - enabled: true -//! id: 6c6579e4-d832-42d5-905c-8e53340930f2 -//! name: Google GCP API Key -//! # Custom profile -//! exampleCustom: -//! type: cloudflare:DlpProfile -//! name: example_custom -//! properties: -//! accountId: f037e56e89293a057740de681ac9abbe -//! name: Example Custom Profile -//! description: A profile with example entries -//! type: custom -//! allowedMatchCount: 0 -//! entries: -//! - name: Matches visa credit cards -//! enabled: true -//! pattern: -//! regex: 4\d{3}([-\. ])?\d{4}([-\. ])?\d{4}([-\. ])?\d{4} -//! validation: luhn -//! - name: Matches diners club card -//! enabled: true -//! pattern: -//! regex: (?:0[0-5]|[68][0-9])[0-9]{11} -//! validation: luhn +//! ```ignore +//! use pulumi_wasm_rust::Output; +//! use pulumi_wasm_rust::{add_export, pulumi_main}; +//! #[pulumi_main] +//! fn test_main() -> Result<(), Error> { +//! let creds = dlp_profile::create( +//! "creds", +//! DlpProfileArgs::builder() +//! .account_id("f037e56e89293a057740de681ac9abbe") +//! .allowed_match_count(3) +//! .entries( +//! vec![ +//! DlpProfileEntry::builder().enabled(true) +//! .id("d8fcfc9c-773c-405e-8426-21ecbb67ba93") +//! .name("Amazon AWS Access Key ID").build_struct(), +//! DlpProfileEntry::builder().enabled(false) +//! .id("2c0e33e1-71da-40c8-aad3-32e674ad3d96") +//! .name("Amazon AWS Secret Access Key").build_struct(), +//! DlpProfileEntry::builder().enabled(true) +//! .id("4e92c006-3802-4dff-bbe1-8e1513b1c92a") +//! .name("Microsoft Azure Client Secret").build_struct(), +//! DlpProfileEntry::builder().enabled(false) +//! .id("5c713294-2375-4904-abcf-e4a15be4d592").name("SSH Private Key") +//! .build_struct(), DlpProfileEntry::builder().enabled(true) +//! .id("6c6579e4-d832-42d5-905c-8e53340930f2") +//! .name("Google GCP API Key").build_struct(), +//! ], +//! ) +//! .name("Credentials and Secrets") +//! .type_("predefined") +//! .build_struct(), +//! ); +//! let exampleCustom = dlp_profile::create( +//! "exampleCustom", +//! DlpProfileArgs::builder() +//! .account_id("f037e56e89293a057740de681ac9abbe") +//! .allowed_match_count(0) +//! .description("A profile with example entries") +//! .entries( +//! vec![ +//! DlpProfileEntry::builder().enabled(true) +//! .name("Matches visa credit cards") +//! .pattern(DlpProfileEntryPattern::builder() +//! .regex("4\\d{3}([-\\. ])?\\d{4}([-\\. ])?\\d{4}([-\\. ])?\\d{4}") +//! .validation("luhn").build_struct()).build_struct(), +//! DlpProfileEntry::builder().enabled(true) +//! .name("Matches diners club card") +//! .pattern(DlpProfileEntryPattern::builder() +//! .regex("(?:0[0-5]|[68][0-9])[0-9]{11}").validation("luhn") +//! .build_struct()).build_struct(), +//! ], +//! ) +//! .name("Example Custom Profile") +//! .type_("custom") +//! .build_struct(), +//! ); +//! } //! ``` //! //! diff --git a/providers/pulumi_wasm_provider_cloudflare_rust/src/resource/filter.rs b/providers/pulumi_wasm_provider_cloudflare_rust/src/resource/filter.rs index 9f71126c1..265f47f5d 100644 --- a/providers/pulumi_wasm_provider_cloudflare_rust/src/resource/filter.rs +++ b/providers/pulumi_wasm_provider_cloudflare_rust/src/resource/filter.rs @@ -12,14 +12,22 @@ //! ## Example Usage //! //! -//! ```yaml -//! resources: -//! wordpress: -//! type: cloudflare:Filter -//! properties: -//! zoneId: 0da42c8d2132a9ddaf714f9e7c920711 -//! description: Wordpress break-in attempts that are outside of the office -//! expression: (http.request.uri.path ~ ".*wp-login.php" or http.request.uri.path ~ ".*xmlrpc.php") and ip.src ne 192.0.2.1 +//! ```ignore +//! use pulumi_wasm_rust::Output; +//! use pulumi_wasm_rust::{add_export, pulumi_main}; +//! #[pulumi_main] +//! fn test_main() -> Result<(), Error> { +//! let wordpress = filter::create( +//! "wordpress", +//! FilterArgs::builder() +//! .description("Wordpress break-in attempts that are outside of the office") +//! .expression( +//! "(http.request.uri.path ~ \".*wp-login.php\" or http.request.uri.path ~ \".*xmlrpc.php\") and ip.src ne 192.0.2.1", +//! ) +//! .zone_id("0da42c8d2132a9ddaf714f9e7c920711") +//! .build_struct(), +//! ); +//! } //! ``` //! //! diff --git a/providers/pulumi_wasm_provider_cloudflare_rust/src/resource/firewall_rule.rs b/providers/pulumi_wasm_provider_cloudflare_rust/src/resource/firewall_rule.rs index cc7e31fc7..8de3f2453 100644 --- a/providers/pulumi_wasm_provider_cloudflare_rust/src/resource/firewall_rule.rs +++ b/providers/pulumi_wasm_provider_cloudflare_rust/src/resource/firewall_rule.rs @@ -15,22 +15,31 @@ //! ## Example Usage //! //! -//! ```yaml -//! resources: -//! wordpress: -//! type: cloudflare:Filter -//! properties: -//! zoneId: 0da42c8d2132a9ddaf714f9e7c920711 -//! description: Wordpress break-in attempts that are outside of the office -//! expression: (http.request.uri.path ~ ".*wp-login.php" or http.request.uri.path ~ ".*xmlrpc.php") and ip.src ne 192.0.2.1 -//! wordpressFirewallRule: -//! type: cloudflare:FirewallRule -//! name: wordpress -//! properties: -//! zoneId: 0da42c8d2132a9ddaf714f9e7c920711 -//! description: Block wordpress break-in attempts -//! filterId: ${wordpress.id} -//! action: block +//! ```ignore +//! use pulumi_wasm_rust::Output; +//! use pulumi_wasm_rust::{add_export, pulumi_main}; +//! #[pulumi_main] +//! fn test_main() -> Result<(), Error> { +//! let wordpress = filter::create( +//! "wordpress", +//! FilterArgs::builder() +//! .description("Wordpress break-in attempts that are outside of the office") +//! .expression( +//! "(http.request.uri.path ~ \".*wp-login.php\" or http.request.uri.path ~ \".*xmlrpc.php\") and ip.src ne 192.0.2.1", +//! ) +//! .zone_id("0da42c8d2132a9ddaf714f9e7c920711") +//! .build_struct(), +//! ); +//! let wordpressFirewallRule = firewall_rule::create( +//! "wordpressFirewallRule", +//! FirewallRuleArgs::builder() +//! .action("block") +//! .description("Block wordpress break-in attempts") +//! .filter_id("${wordpress.id}") +//! .zone_id("0da42c8d2132a9ddaf714f9e7c920711") +//! .build_struct(), +//! ); +//! } //! ``` //! //! diff --git a/providers/pulumi_wasm_provider_cloudflare_rust/src/resource/load_balancer.rs b/providers/pulumi_wasm_provider_cloudflare_rust/src/resource/load_balancer.rs index db7b5d870..e9811c50a 100644 --- a/providers/pulumi_wasm_provider_cloudflare_rust/src/resource/load_balancer.rs +++ b/providers/pulumi_wasm_provider_cloudflare_rust/src/resource/load_balancer.rs @@ -43,7 +43,7 @@ //! .rules( //! vec![ //! LoadBalancerRule::builder() -//! .condition("http.request.uri.path contains "testing "") +//! .condition("http.request.uri.path contains \"testing\"") //! .fixedResponse(LoadBalancerRuleFixedResponse::builder() //! .contentType("html").location("www.example.com").messageBody("hello") //! .statusCode(200).build_struct()).name("example rule").build_struct(), diff --git a/providers/pulumi_wasm_provider_cloudflare_rust/src/resource/mtls_certificate.rs b/providers/pulumi_wasm_provider_cloudflare_rust/src/resource/mtls_certificate.rs index 093f9a3b0..f7bc12739 100644 --- a/providers/pulumi_wasm_provider_cloudflare_rust/src/resource/mtls_certificate.rs +++ b/providers/pulumi_wasm_provider_cloudflare_rust/src/resource/mtls_certificate.rs @@ -14,15 +14,11 @@ //! .account_id("f037e56e89293a057740de681ac9abbe") //! .ca(true) //! .certificates( -//! "-----BEGIN CERTIFICATE----- -//! MIIDmDCCAoCgAwIBAgIUKTOAZNj...i4JhqeoTewsxndhDDE -//! -----END CERTIFICATE-----", +//! "-----BEGIN CERTIFICATE-----\nMIIDmDCCAoCgAwIBAgIUKTOAZNj...i4JhqeoTewsxndhDDE\n-----END CERTIFICATE-----", //! ) //! .name("example") //! .private_key( -//! "-----BEGIN PRIVATE KEY----- -//! MIIEvQIBADANBgkqhkiG9w0BAQE...1IS3EnQRrz6WMYA= -//! -----END PRIVATE KEY-----", +//! "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQE...1IS3EnQRrz6WMYA=\n-----END PRIVATE KEY-----", //! ) //! .build_struct(), //! ); diff --git a/providers/pulumi_wasm_provider_cloudflare_rust/src/resource/teams_rule.rs b/providers/pulumi_wasm_provider_cloudflare_rust/src/resource/teams_rule.rs index 8d3efaa26..6c0d184cd 100644 --- a/providers/pulumi_wasm_provider_cloudflare_rust/src/resource/teams_rule.rs +++ b/providers/pulumi_wasm_provider_cloudflare_rust/src/resource/teams_rule.rs @@ -3,22 +3,30 @@ //! ## Example Usage //! //! -//! ```yaml -//! resources: -//! example: -//! type: cloudflare:TeamsRule -//! properties: -//! accountId: f037e56e89293a057740de681ac9abbe -//! name: office -//! description: desc -//! precedence: 1 -//! action: block -//! filters: -//! - http -//! traffic: http.request.uri == "https://www.example.com/malicious" -//! ruleSettings: -//! blockPageEnabled: true -//! blockPageReason: access not permitted +//! ```ignore +//! use pulumi_wasm_rust::Output; +//! use pulumi_wasm_rust::{add_export, pulumi_main}; +//! #[pulumi_main] +//! fn test_main() -> Result<(), Error> { +//! let example = teams_rule::create( +//! "example", +//! TeamsRuleArgs::builder() +//! .account_id("f037e56e89293a057740de681ac9abbe") +//! .action("block") +//! .description("desc") +//! .filters(vec!["http",]) +//! .name("office") +//! .precedence(1) +//! .rule_settings( +//! TeamsRuleRuleSettings::builder() +//! .blockPageEnabled(true) +//! .blockPageReason("access not permitted") +//! .build_struct(), +//! ) +//! .traffic("http.request.uri == \"https://www.example.com/malicious\"") +//! .build_struct(), +//! ); +//! } //! ``` //! //! diff --git a/providers/pulumi_wasm_provider_cloudflare_rust/src/resource/waiting_room_rules.rs b/providers/pulumi_wasm_provider_cloudflare_rust/src/resource/waiting_room_rules.rs index c14d94ef0..99469eb37 100644 --- a/providers/pulumi_wasm_provider_cloudflare_rust/src/resource/waiting_room_rules.rs +++ b/providers/pulumi_wasm_provider_cloudflare_rust/src/resource/waiting_room_rules.rs @@ -18,7 +18,7 @@ //! .expression("src.ip in {192.0.2.0 192.0.2.1}").status("enabled") //! .build_struct(), WaitingRoomRulesRule::builder() //! .action("bypass_waiting_room").description("bypass query string") -//! .expression("http.request.uri.query contains "bypass = true "") +//! .expression("http.request.uri.query contains \"bypass=true\"") //! .status("enabled").build_struct(), //! ], //! ) diff --git a/providers/pulumi_wasm_provider_cloudflare_rust/src/resource/zero_trust_access_identity_provider.rs b/providers/pulumi_wasm_provider_cloudflare_rust/src/resource/zero_trust_access_identity_provider.rs index 91cfc46d7..031599402 100644 --- a/providers/pulumi_wasm_provider_cloudflare_rust/src/resource/zero_trust_access_identity_provider.rs +++ b/providers/pulumi_wasm_provider_cloudflare_rust/src/resource/zero_trust_access_identity_provider.rs @@ -38,8 +38,7 @@ //! vec![ //! ZeroTrustAccessIdentityProviderConfig::builder() //! .attributes(vec!["email", "username",]) -//! .idpPublicCert("MIIDpDCCAoygAwIBAgIGAV2ka+55MA0GCSqGSIb3DQEBCwUAMIGSMQswCQ...GF/Q2/MHadws97cZg -//! uTnQyuOqPuHbnN83d/2l1NSYKCbHt24o") +//! .idpPublicCert("MIIDpDCCAoygAwIBAgIGAV2ka+55MA0GCSqGSIb3DQEBCwUAMIGSMQswCQ...GF/Q2/MHadws97cZg\nuTnQyuOqPuHbnN83d/2l1NSYKCbHt24o") //! .issuerUrl("jumpcloud").signRequest(false) //! .ssoTargetUrl("https://sso.myexample.jumpcloud.com/saml2/cloudflareaccess") //! .build_struct(), diff --git a/providers/pulumi_wasm_provider_cloudflare_rust/src/resource/zero_trust_device_profiles.rs b/providers/pulumi_wasm_provider_cloudflare_rust/src/resource/zero_trust_device_profiles.rs index 0811c3963..9ee047ae2 100644 --- a/providers/pulumi_wasm_provider_cloudflare_rust/src/resource/zero_trust_device_profiles.rs +++ b/providers/pulumi_wasm_provider_cloudflare_rust/src/resource/zero_trust_device_profiles.rs @@ -3,30 +3,35 @@ //! ## Example Usage //! //! -//! ```yaml -//! resources: -//! developerWarpPolicy: -//! type: cloudflare:ZeroTrustDeviceProfiles -//! name: developer_warp_policy -//! properties: -//! accountId: f037e56e89293a057740de681ac9abbe -//! name: Developers WARP settings policy -//! description: Developers WARP settings policy description -//! precedence: 10 -//! match: any(identity.groups.name[*] in {"Developers"}) -//! default: false -//! enabled: true -//! allowModeSwitch: true -//! allowUpdates: true -//! allowedToLeave: true -//! autoConnect: 0 -//! captivePortal: 5 -//! disableAutoFallback: true -//! supportUrl: https://cloudflare.com -//! switchLocked: true -//! serviceModeV2Mode: warp -//! serviceModeV2Port: 3000 -//! excludeOfficeIps: false +//! ```ignore +//! use pulumi_wasm_rust::Output; +//! use pulumi_wasm_rust::{add_export, pulumi_main}; +//! #[pulumi_main] +//! fn test_main() -> Result<(), Error> { +//! let developerWarpPolicy = zero_trust_device_profiles::create( +//! "developerWarpPolicy", +//! ZeroTrustDeviceProfilesArgs::builder() +//! .account_id("f037e56e89293a057740de681ac9abbe") +//! .allow_mode_switch(true) +//! .allow_updates(true) +//! .allowed_to_leave(true) +//! .auto_connect(0) +//! .captive_portal(5) +//! .default(false) +//! .description("Developers WARP settings policy description") +//! .disable_auto_fallback(true) +//! .enabled(true) +//! .exclude_office_ips(false) +//! .match_("any(identity.groups.name[*] in {\"Developers\"})") +//! .name("Developers WARP settings policy") +//! .precedence(10) +//! .service_mode_v_2_mode("warp") +//! .service_mode_v_2_port(3000) +//! .support_url("https://cloudflare.com") +//! .switch_locked(true) +//! .build_struct(), +//! ); +//! } //! ``` //! //! diff --git a/providers/pulumi_wasm_provider_cloudflare_rust/src/resource/zero_trust_dlp_profile.rs b/providers/pulumi_wasm_provider_cloudflare_rust/src/resource/zero_trust_dlp_profile.rs index 0ce1ac288..510bbf23f 100644 --- a/providers/pulumi_wasm_provider_cloudflare_rust/src/resource/zero_trust_dlp_profile.rs +++ b/providers/pulumi_wasm_provider_cloudflare_rust/src/resource/zero_trust_dlp_profile.rs @@ -5,53 +5,63 @@ //! ## Example Usage //! //! -//! ```yaml -//! resources: -//! # Predefined profile must be imported, cannot be created -//! creds: -//! type: cloudflare:ZeroTrustDlpProfile -//! properties: -//! accountId: f037e56e89293a057740de681ac9abbe -//! name: Credentials and Secrets -//! type: predefined -//! allowedMatchCount: 3 -//! entries: -//! - enabled: true -//! name: Amazon AWS Access Key ID -//! id: d8fcfc9c-773c-405e-8426-21ecbb67ba93 -//! - enabled: false -//! id: 2c0e33e1-71da-40c8-aad3-32e674ad3d96 -//! name: Amazon AWS Secret Access Key -//! - enabled: true -//! id: 4e92c006-3802-4dff-bbe1-8e1513b1c92a -//! name: Microsoft Azure Client Secret -//! - enabled: false -//! id: 5c713294-2375-4904-abcf-e4a15be4d592 -//! name: SSH Private Key -//! - enabled: true -//! id: 6c6579e4-d832-42d5-905c-8e53340930f2 -//! name: Google GCP API Key -//! # Custom profile -//! exampleCustom: -//! type: cloudflare:ZeroTrustDlpProfile -//! name: example_custom -//! properties: -//! accountId: f037e56e89293a057740de681ac9abbe -//! name: Example Custom Profile -//! description: A profile with example entries -//! type: custom -//! allowedMatchCount: 0 -//! entries: -//! - name: Matches visa credit cards -//! enabled: true -//! pattern: -//! regex: 4\d{3}([-\. ])?\d{4}([-\. ])?\d{4}([-\. ])?\d{4} -//! validation: luhn -//! - name: Matches diners club card -//! enabled: true -//! pattern: -//! regex: (?:0[0-5]|[68][0-9])[0-9]{11} -//! validation: luhn +//! ```ignore +//! use pulumi_wasm_rust::Output; +//! use pulumi_wasm_rust::{add_export, pulumi_main}; +//! #[pulumi_main] +//! fn test_main() -> Result<(), Error> { +//! let creds = zero_trust_dlp_profile::create( +//! "creds", +//! ZeroTrustDlpProfileArgs::builder() +//! .account_id("f037e56e89293a057740de681ac9abbe") +//! .allowed_match_count(3) +//! .entries( +//! vec![ +//! ZeroTrustDlpProfileEntry::builder().enabled(true) +//! .id("d8fcfc9c-773c-405e-8426-21ecbb67ba93") +//! .name("Amazon AWS Access Key ID").build_struct(), +//! ZeroTrustDlpProfileEntry::builder().enabled(false) +//! .id("2c0e33e1-71da-40c8-aad3-32e674ad3d96") +//! .name("Amazon AWS Secret Access Key").build_struct(), +//! ZeroTrustDlpProfileEntry::builder().enabled(true) +//! .id("4e92c006-3802-4dff-bbe1-8e1513b1c92a") +//! .name("Microsoft Azure Client Secret").build_struct(), +//! ZeroTrustDlpProfileEntry::builder().enabled(false) +//! .id("5c713294-2375-4904-abcf-e4a15be4d592").name("SSH Private Key") +//! .build_struct(), ZeroTrustDlpProfileEntry::builder().enabled(true) +//! .id("6c6579e4-d832-42d5-905c-8e53340930f2") +//! .name("Google GCP API Key").build_struct(), +//! ], +//! ) +//! .name("Credentials and Secrets") +//! .type_("predefined") +//! .build_struct(), +//! ); +//! let exampleCustom = zero_trust_dlp_profile::create( +//! "exampleCustom", +//! ZeroTrustDlpProfileArgs::builder() +//! .account_id("f037e56e89293a057740de681ac9abbe") +//! .allowed_match_count(0) +//! .description("A profile with example entries") +//! .entries( +//! vec![ +//! ZeroTrustDlpProfileEntry::builder().enabled(true) +//! .name("Matches visa credit cards") +//! .pattern(ZeroTrustDlpProfileEntryPattern::builder() +//! .regex("4\\d{3}([-\\. ])?\\d{4}([-\\. ])?\\d{4}([-\\. ])?\\d{4}") +//! .validation("luhn").build_struct()).build_struct(), +//! ZeroTrustDlpProfileEntry::builder().enabled(true) +//! .name("Matches diners club card") +//! .pattern(ZeroTrustDlpProfileEntryPattern::builder() +//! .regex("(?:0[0-5]|[68][0-9])[0-9]{11}").validation("luhn") +//! .build_struct()).build_struct(), +//! ], +//! ) +//! .name("Example Custom Profile") +//! .type_("custom") +//! .build_struct(), +//! ); +//! } //! ``` //! //! diff --git a/providers/pulumi_wasm_provider_cloudflare_rust/src/resource/zero_trust_gateway_policy.rs b/providers/pulumi_wasm_provider_cloudflare_rust/src/resource/zero_trust_gateway_policy.rs index 5cb7d9efe..382558014 100644 --- a/providers/pulumi_wasm_provider_cloudflare_rust/src/resource/zero_trust_gateway_policy.rs +++ b/providers/pulumi_wasm_provider_cloudflare_rust/src/resource/zero_trust_gateway_policy.rs @@ -3,22 +3,30 @@ //! ## Example Usage //! //! -//! ```yaml -//! resources: -//! example: -//! type: cloudflare:ZeroTrustGatewayPolicy -//! properties: -//! accountId: f037e56e89293a057740de681ac9abbe -//! name: office -//! description: desc -//! precedence: 1 -//! action: block -//! filters: -//! - http -//! traffic: http.request.uri == "https://www.example.com/malicious" -//! ruleSettings: -//! blockPageEnabled: true -//! blockPageReason: access not permitted +//! ```ignore +//! use pulumi_wasm_rust::Output; +//! use pulumi_wasm_rust::{add_export, pulumi_main}; +//! #[pulumi_main] +//! fn test_main() -> Result<(), Error> { +//! let example = zero_trust_gateway_policy::create( +//! "example", +//! ZeroTrustGatewayPolicyArgs::builder() +//! .account_id("f037e56e89293a057740de681ac9abbe") +//! .action("block") +//! .description("desc") +//! .filters(vec!["http",]) +//! .name("office") +//! .precedence(1) +//! .rule_settings( +//! ZeroTrustGatewayPolicyRuleSettings::builder() +//! .blockPageEnabled(true) +//! .blockPageReason("access not permitted") +//! .build_struct(), +//! ) +//! .traffic("http.request.uri == \"https://www.example.com/malicious\"") +//! .build_struct(), +//! ); +//! } //! ``` //! //! diff --git a/providers/pulumi_wasm_provider_docker_rust/src/resource/service_config.rs b/providers/pulumi_wasm_provider_docker_rust/src/resource/service_config.rs index 956e0ece2..09f174b78 100644 --- a/providers/pulumi_wasm_provider_docker_rust/src/resource/service_config.rs +++ b/providers/pulumi_wasm_provider_docker_rust/src/resource/service_config.rs @@ -18,13 +18,18 @@ //! //! you provide the definition for the resource as follows //! -//! ```yaml -//! resources: -//! foo: -//! type: docker:ServiceConfig -//! name: foo -//! properties: -//! data: 'base64encode("{\"a\": \"b\"}")' +//! ```ignore +//! use pulumi_wasm_rust::Output; +//! use pulumi_wasm_rust::{add_export, pulumi_main}; +//! #[pulumi_main] +//! fn test_main() -> Result<(), Error> { +//! let foo = service_config::create( +//! "foo", +//! ServiceConfigArgs::builder() +//! .data("base64encode(\"{\\\"a\\\": \\\"b\\\"}\")") +//! .build_struct(), +//! ); +//! } //! ``` //! //! then the import command is as follows diff --git a/pulumi_wasm_generator_lib/Cargo.toml b/pulumi_wasm_generator_lib/Cargo.toml index 4d58d8817..2bf63f7e8 100644 --- a/pulumi_wasm_generator_lib/Cargo.toml +++ b/pulumi_wasm_generator_lib/Cargo.toml @@ -15,6 +15,7 @@ convert_case.workspace = true serde_yaml.workspace = true prettyplease = "0.2.25" syn = "2.0.90" +proc-macro2 = "1.0.92" [dev-dependencies] assert_cmd.workspace = true diff --git a/pulumi_wasm_generator_lib/src/code_generation.rs b/pulumi_wasm_generator_lib/src/code_generation.rs index e2ed4890c..933c4f4c0 100644 --- a/pulumi_wasm_generator_lib/src/code_generation.rs +++ b/pulumi_wasm_generator_lib/src/code_generation.rs @@ -7,6 +7,8 @@ use convert_case::Case; use convert_case::Casing; use std::collections::BTreeMap; use std::panic; +use syn::LitStr; +use syn::__private::ToTokens; pub fn generate_code_from_string(yaml: String, package: &crate::model::Package) -> Result { let yaml_file = @@ -105,7 +107,10 @@ fn generate_object(element_id: ElementId, expr: BTreeMap) -> fn generate_expression(expr: Expression) -> String { match expr { - Expression::String(s) => format!("\"{}\"", s), + Expression::String(s) => { + let lit_str = LitStr::new(&s, proc_macro2::Span::call_site()); + format!("{}", lit_str.to_token_stream()) + } Expression::Number(n) => format!("{}", n), Expression::Integer(i) => format!("{}", i), Expression::Boolean(b) => format!("{}", b), @@ -138,7 +143,10 @@ fn generate_expression(expr: Expression) -> String { #[cfg(test)] mod tests { use crate::code_generation::generate_code; - use crate::yaml::tests::{access_rule, example_array, example_empty_properties}; + use crate::yaml::tests::{ + access_rule, example_array, example_empty_properties, example_escape_string, + example_numbers, + }; #[test] fn test_example_array() { @@ -160,4 +168,18 @@ mod tests { let code = generate_code(model).unwrap(); assert_eq!(example_empty_properties::get_rust_code(), code) } + + #[test] + fn test_numbers() { + let model = example_numbers::get_model(); + let code = generate_code(model).unwrap(); + assert_eq!(example_numbers::get_rust_code(), code) + } + + #[test] + fn test_string_escape() { + let model = example_escape_string::get_model(); + let code = generate_code(model).unwrap(); + assert_eq!(example_escape_string::get_rust_code(), code) + } } diff --git a/pulumi_wasm_generator_lib/src/yaml/mod.rs b/pulumi_wasm_generator_lib/src/yaml/mod.rs index fc1a6a384..7027c874f 100644 --- a/pulumi_wasm_generator_lib/src/yaml/mod.rs +++ b/pulumi_wasm_generator_lib/src/yaml/mod.rs @@ -679,6 +679,97 @@ resources: } } + pub fn get_rust_code() -> String { + reformat_code( + r#" + use pulumi_wasm_rust::Output; + use pulumi_wasm_rust::{add_export, pulumi_main}; + #[pulumi_main] + fn test_main() -> Result<(), Error> { + let example = keyless_certificate::create( + "example", + KeylessCertificateArgs::builder() + .port(24008) + .build_struct(), + ); + } + "#, + ) + } + } + + pub(crate) mod example_escape_string { + use super::*; + use crate::model::ElementId; + use crate::yaml::model::{Example, Expression, Resource}; + use crate::yaml::yaml_model::YamlExpression; + + use super::*; + + pub(crate) const YAML: &str = r#" +resources: + example: + type: cloudflare:AccessOrganization + properties: + name: my "name" + "#; + + pub(crate) fn get_yaml_file() -> YamlFile { + use crate::yaml::yaml_model::{YamlExpression, YamlFile, YamlResource}; + + YamlFile { + resources: { + let mut resources = BTreeMap::new(); + resources.insert( + "example".to_string(), + YamlResource { + type_: "cloudflare:AccessOrganization".to_string(), + name: None, + properties: { + let mut properties = BTreeMap::new(); + properties.insert( + "name".to_string(), + YamlExpression::String("my \"name\"".to_string()), + ); + properties + }, + }, + ); + resources + }, + } + } + + pub fn get_model() -> Example { + use crate::yaml::yaml_model::{YamlExpression, YamlFile, YamlResource}; + + Example { + resources: { + let mut map = BTreeMap::new(); + map.insert( + "example".to_string(), + Resource { + type_: ElementId::new( + "cloudflare:index/accessOrganization:AccessOrganization", + ) + .unwrap(), + // type_: "cloudflare:AccessMutualTlsCertificate".to_string(), + name: None, + properties: { + let mut props = BTreeMap::new(); + props.insert( + "name".to_string(), + Expression::String("my \"name\"".to_string()), + ); + props + }, + }, + ); + map + }, + } + } + pub fn get_rust_code() -> String { reformat_code( r#" @@ -686,9 +777,10 @@ resources: use pulumi_wasm_rust::{add_export, pulumi_main}; #[pulumi_main] fn test_main() -> Result<(), Error> { - let myCert = access_mutual_tls_certificate::create( - "myCert", - AccessMutualTlsCertificateArgs::builder() + let example = access_organization::create( + "example", + AccessOrganizationArgs::builder() + .name("my \"name\"") .build_struct(), ); } diff --git a/pulumi_wasm_generator_lib/src/yaml/yaml_model.rs b/pulumi_wasm_generator_lib/src/yaml/yaml_model.rs index ba437fafc..8d2f0b5b5 100644 --- a/pulumi_wasm_generator_lib/src/yaml/yaml_model.rs +++ b/pulumi_wasm_generator_lib/src/yaml/yaml_model.rs @@ -90,4 +90,12 @@ mod tests { let expected_yaml_file = get_yaml_file(); assert_eq!(yaml_file, expected_yaml_file); } + + #[test] + fn test_string_escape() { + use super::super::tests::example_escape_string::*; + let yaml_file = YamlFile::from_yaml(YAML).unwrap(); + let expected_yaml_file = get_yaml_file(); + assert_eq!(yaml_file, expected_yaml_file); + } }