Module: Aptible::CLI::Helpers::Vhost

Defined in:
lib/aptible/cli/helpers/vhost.rb,
lib/aptible/cli/helpers/vhost/option_set_builder.rb

Defined Under Namespace

Classes: OptionSetBuilder

Instance Method Summary collapse

Instance Method Details

#each_vhost(resource, &block) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/aptible/cli/helpers/vhost.rb', line 68

def each_vhost(resource, &block)
  return enum_for(:each_vhost, resource) unless block_given?

  klass = resource.class
  if klass == Aptible::Api::App
    resource.each_service(&block)
  elsif klass == Aptible::Api::Database
    [resource.service].each(&block)
  else
    raise "Unexpected resource: #{klass}"
  end
end

#explain_vhost(service, vhost) ⇒ Object



5
6
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
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/aptible/cli/helpers/vhost.rb', line 5

def explain_vhost(service, vhost)
  say "Service: #{service.process_type}"
  say "Hostname: #{vhost.external_host}"
  say "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
    say "Type: #{vhost.type}"
    say "Ports: #{ports}"
  when 'http', 'http_proxy_protocol'
    port = vhost.container_port ? vhost.container_port : 'default'
    say 'Type: https'
    say "Port: #{port}"
  end

  say "Internal: #{vhost.internal}"

  ip_whitelist = if vhost.ip_whitelist.any?
                   vhost.ip_whitelist.join(' ')
                 else
                   'all traffic'
                 end
  say "IP Whitelist: #{ip_whitelist}"

  say "Default Domain Enabled: #{vhost.default}"
  say "Default Domain: #{vhost.virtual_domain}" if vhost.default

  say "Managed TLS Enabled: #{vhost.acme}"
  if vhost.acme
    say "Managed TLS Domain: #{vhost.user_domain}"
    say 'Managed TLS DNS Challenge Hostname: ' \
        "#{vhost.acme_dns_challenge_host}"
    say "Managed TLS Status: #{vhost.acme_status}"
  end
end

#find_vhost(service_enumerator, hostname) ⇒ Object

Raises:

  • (Thor::Error)


53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/aptible/cli/helpers/vhost.rb', line 53

def find_vhost(service_enumerator, hostname)
  seen = []

  service_enumerator.each do |service|
    service.each_vhost do |vhost|
      seen << vhost.external_host
      return vhost if vhost.external_host == hostname
    end
  end

  e = "Endpoint with hostname #{hostname} does not exist"
  e = "#{e} (valid hostnames: #{seen.join(', ')})" if seen.any?
  raise Thor::Error, e
end

#provision_vhost_and_explain(service, vhost) ⇒ Object



46
47
48
49
50
51
# File 'lib/aptible/cli/helpers/vhost.rb', line 46

def provision_vhost_and_explain(service, vhost)
  op = vhost.create_operation!(type: 'provision')
  attach_to_operation_logs(op)
  explain_vhost(service, vhost.reload)
  # TODO: Instructions if ACME is enabled?
end