Module: Aptible::CLI::ResourceFormatter
- Defined in:
- lib/aptible/cli/resource_formatter.rb
Constant Summary collapse
- NO_NESTING =
Object.new.freeze
Class Method Summary collapse
- .inject_account(node, account) ⇒ Object
- .inject_app(node, app, account) ⇒ Object
- .inject_backup(node, backup, include_db: false) ⇒ Object
- .inject_credential(node, credential) ⇒ Object
- .inject_database(node, database, account) ⇒ Object
- .inject_deleted_database(node, database, account) ⇒ Object
- .inject_operation(node, operation) ⇒ Object
- .inject_service(node, service, app) ⇒ Object
- .inject_vhost(node, vhost, service) ⇒ Object
Class Method Details
.inject_account(node, account) ⇒ Object
42 43 44 45 |
# File 'lib/aptible/cli/resource_formatter.rb', line 42 def inject_account(node, account) node.value('id', account.id) node.value('handle', account.handle) end |
.inject_app(node, app, account) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/aptible/cli/resource_formatter.rb', line 55 def inject_app(node, app, account) node.value('id', app.id) node.value('handle', app.handle) node.value('status', app.status) node.value('git_remote', app.git_repo) if app.last_deploy_operation node.keyed_object('last_deploy_operation', 'id') do |n| inject_operation(n, app.last_deploy_operation) end end node.list('services') do |services_list| app.each_service do |service| services_list.object do |n| inject_service(n, service, NO_NESTING) end end end attach_account(node, account) end |
.inject_backup(node, backup, include_db: false) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/aptible/cli/resource_formatter.rb', line 7 def inject_backup(node, backup, include_db: false) description = "#{backup.id}: #{backup.created_at}, " \ "#{backup.aws_region}" if include_db db = backup.database_with_deleted node.keyed_object('database', 'id') do |n| inject_deleted_database(n, db, backup.account) end description = "#{description}, " \ "#{db.handle} deleted at #{db.deleted_at}" end node.value('id', backup.id) node.value('description', description) node.value('created_at', backup.created_at) node.value('region', backup.aws_region) node.value('size', backup.size) if backup.copied_from node.keyed_object('copied_from', 'description') do |n| inject_backup(n, backup.copied_from) end end end |
.inject_credential(node, credential) ⇒ Object
96 97 98 99 100 101 102 |
# File 'lib/aptible/cli/resource_formatter.rb', line 96 def inject_credential(node, credential) # TODO: Should this accept a DB for nesting? Maybe if we have any # callers that could benefit from it. node.value('type', credential.type) node.value('connection_url', credential.connection_url) node.value('default', credential.default) end |
.inject_database(node, database, account) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/aptible/cli/resource_formatter.rb', line 79 def inject_database(node, database, account) node.value('id', database.id) node.value('handle', database.handle) node.value('type', database.type) node.value('status', database.status) node.value('connection_url', database.connection_url) node.list('credentials') do |creds_list| database.database_credentials.each do |cred| creds_list.object { |n| inject_credential(n, cred) } end end attach_account(node, account) end |
.inject_deleted_database(node, database, account) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/aptible/cli/resource_formatter.rb', line 34 def inject_deleted_database(node, database, account) node.value('id', database.id) node.value('handle', database.handle) node.value('type', database.type) node.value('deleted_at', database.deleted_at) attach_account(node, account) end |
.inject_operation(node, operation) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/aptible/cli/resource_formatter.rb', line 47 def inject_operation(node, operation) node.value('id', operation.id) node.value('status', operation.status) node.value('git_ref', operation.git_ref) node.value('user_email', operation.user_email) node.value('created_at', operation.created_at) end |
.inject_service(node, service, app) ⇒ Object
104 105 106 107 108 109 110 111 112 113 |
# File 'lib/aptible/cli/resource_formatter.rb', line 104 def inject_service(node, service, app) node.value('id', service.id) node.value('service', service.process_type) node.value('command', service.command || 'CMD') node.value('container_count', service.container_count) node.value('container_size', service.container_memory_limit_mb) attach_app(node, app) end |
.inject_vhost(node, vhost, service) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/aptible/cli/resource_formatter.rb', line 115 def inject_vhost(node, vhost, service) node.value('id', vhost.id) node.value('hostname', vhost.external_host) node.value('status', vhost.status) case vhost.type when 'tcp', 'tls' ports = if vhost.container_ports.any? vhost.container_ports.map(&:to_s).join(' ') else 'all' end node.value('type', vhost.type) node.value('ports', ports) when 'http', 'http_proxy_protocol' port = vhost.container_port ? vhost.container_port : 'default' node.value('type', 'https') node.value('port', port) end node.value('internal', vhost.internal) ip_whitelist = if vhost.ip_whitelist.any? vhost.ip_whitelist.join(' ') else 'all traffic' end node.value('ip_whitelist', ip_whitelist) node.value('default_domain_enabled', vhost.default) node.value('default_domain', vhost.virtual_domain) if vhost.default node.value('managed_tls_enabled', vhost.acme) if vhost.acme node.value('managed_tls_domain', vhost.user_domain) node.value( 'managed_tls_dns_challenge_hostname', vhost.acme_dns_challenge_host ) node.value('managed_tls_status', vhost.acme_status) end attach_service(node, service) end |