Class: RailsTemplate18f::Generators::PublicEgressGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- RailsTemplate18f::Generators::PublicEgressGenerator
- Includes:
- Base, CloudGovParsing
- Defined in:
- lib/generators/rails_template18f/public_egress/public_egress_generator.rb
Instance Method Summary collapse
- #check_terraform_exists ⇒ Object
- #setup_proxy_vars ⇒ Object
- #update_boundary_diagram ⇒ Object
- #update_oscal_doc ⇒ Object
- #update_readme ⇒ Object
- #use_terraform_module ⇒ Object
Instance Method Details
#check_terraform_exists ⇒ Object
18 19 20 21 22 |
# File 'lib/generators/rails_template18f/public_egress/public_egress_generator.rb', line 18 def check_terraform_exists unless terraform_dir_exists? fail "Run `rails g rails_template18f:terraform` before running this generator" end end |
#setup_proxy_vars ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/generators/rails_template18f/public_egress/public_egress_generator.rb', line 44 def setup_proxy_vars create_file ".profile", <<~EOP unless file_exists?(".profile") ## # Cloud Foundry app initialization script # https://docs.cloudfoundry.org/devguide/deploy-apps/deploy-app.html#profile ## EOP insert_into_file ".profile", <<~EOP proxy_creds=$(echo "$VCAP_SERVICES" | jq --arg service_name "egress-proxy-$RAILS_ENV-credentials" '.[][] | select(.name == $service_name) | .credentials') export http_proxy=$(echo "$proxy_creds" | jq --raw-output ".http_uri") export https_proxy=$(echo "$proxy_creds" | jq --raw-output ".https_uri") EOP end |
#update_boundary_diagram ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/generators/rails_template18f/public_egress/public_egress_generator.rb', line 63 def update_boundary_diagram boundary_filename = "doc/compliance/apps/application.boundary.md" insert_into_file boundary_filename, <<EOB, after: "System_Boundary(inventory, \"Application\") {\n" Boundary(restricted_space, "Restricted egress space") { } Boundary(egress_space, "Public egress space") { Container(proxy, "<&layers> Egress Proxy", "Caddy, cg-egress-proxy", "Proxy with allow-list of external connections") } EOB insert_into_file boundary_filename, <<~EOB, before: "@enduml" Rel(app, proxy, "Proxy outbound connections", "https (443)") EOB puts "\n ================ TODO ================ \n".yellow puts "Update your application boundary to:" puts "1. Place application and services within the Restricted egress space" puts "2. Connect outbound connections through the egress proxy" end |
#update_oscal_doc ⇒ Object
81 82 83 |
# File 'lib/generators/rails_template18f/public_egress/public_egress_generator.rb', line 81 def update_oscal_doc copy_remote_oscal_component "cg-egress-proxy", "https://raw.githubusercontent.com/GSA-TTS/cg-egress-proxy/refs/heads/main/docs/compliance/component-definitions/cg-egress-proxy/component-definition.json" end |
#update_readme ⇒ Object
59 60 61 |
# File 'lib/generators/rails_template18f/public_egress/public_egress_generator.rb', line 59 def update_readme insert_into_file "README.md", readme_content, before: "## Documentation" end |
#use_terraform_module ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/generators/rails_template18f/public_egress/public_egress_generator.rb', line 24 def use_terraform_module append_to_file file_path("terraform/main.tf"), terraform_module append_to_file file_path("terraform/variables.tf"), <<~EOT variable "egress_allowlist" { type = set(string) default = [] description = "The set of hostnames that the application is allowed to connect to" } EOT insert_into_file file_path("terraform/app.tf"), <<EOT, after: "environment = {\n" no_proxy = "apps.internal,s3-fips.us-gov-west-1.amazonaws.com" EOT insert_into_file file_path("terraform/app.tf"), <<EOT, after: "service_bindings = [\n" { service_instance = "egress-proxy-${var.env}-credentials" }, EOT insert_into_file file_path("terraform/app.tf"), <<EOT, after: "depends_on = [\n" cloudfoundry_service_instance.egress_proxy_credentials, EOT end |