Module: FastlyCTL::TLSUtils

Defined in:
lib/fastlyctl/commands/tls.rb

Class Method Summary collapse

Class Method Details

.get_tls_configsObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/fastlyctl/commands/tls.rb', line 17

def self.get_tls_configs
  data = FastlyCTL::Fetcher.api_request(:get,"/tls/configurations",{use_vnd:true})["data"]
  if data.length == 0
    thor = Thor::Shell::Basic.new
    thor.say "No TLS Configurations found. You may need to upgrade to a paid account if you are using a free account."
    thor.say "If you need assistance, please contact [email protected]."
    if (thor.yes?("Would you like to open the TLS configuration page in the Fastly app?"))
      FastlyCTL::Utils.open_app_path("/network/domains")
    end
    abort
  end

  return data
end


58
59
60
61
62
63
64
65
66
67
68
# File 'lib/fastlyctl/commands/tls.rb', line 58

def self.print_challenges(tls_authorization)
  thor = Thor::Shell::Basic.new
  thor.say "\nIn order to verify your ownership of the domain, the Certificate Authority provided the following challenges:"
  tls_authorization["attributes"]["challenges"].each do |challenge|
    thor.say("\n#{challenge["type"]}: Create #{challenge["record_type"]} record for #{challenge["record_name"]} with value(s) of:")
    challenge["values"].each do |val|
      thor.say("    #{val}")
    end
  end
  thor.say("\nNote: If you don't want to move all traffic to Fastly right now, use the managed-dns option. The other options result in traffic for that hostname being directed to Fastly.")
end

.select_tls_config(configs) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/fastlyctl/commands/tls.rb', line 32

def self.select_tls_config(configs)
  thor = Thor::Shell::Basic.new
  if configs.length == 1
    thor.say "Using TLS Configuration #{configs[0]["id"]} - #{configs[0]["name"]}"
    return configs[0]
  end

  loop do
    i = 1
    configs.each do |c|
      bulk = c["attributes"]["bulk"] ? " [Platform TLS]" : ""
      thor.say("[#{i}]#{bulk} #{c["id"]} - #{c["name"]}\n")
      i += 1
    end

    selected = thor.ask("Which TLS Configuration would you like to use? Please type the number next to the configuration(s) above.").to_i
    if selected > 0 && selected <= (configs.length+1)
      selected -= 1
      thor.say "Using TLS Configuration #{configs[selected]["id"]} - #{configs[selected]["name"]}"
      return configs[selected]
    end

    thor.say "#{selcted} is in invalid selection. Please try again."
  end
end