Class: Nvoi::Cli::Onboard::Steps::Domain
- Inherits:
-
Object
- Object
- Nvoi::Cli::Onboard::Steps::Domain
- Includes:
- Ui
- Defined in:
- lib/nvoi/cli/onboard/steps/domain.rb
Overview
Collects domain provider (Cloudflare) configuration
Constant Summary
Constants included from Ui
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#zones ⇒ Object
readonly
Returns the value of attribute zones.
Instance Method Summary collapse
- #call(existing: nil) ⇒ Object
-
#initialize(prompt, test_mode: false) ⇒ Domain
constructor
A new instance of Domain.
Methods included from Ui
#box, #error, #output, #prompt_with_retry, #section, #success, #table, #with_spinner
Constructor Details
#initialize(prompt, test_mode: false) ⇒ Domain
Returns a new instance of Domain.
13 14 15 16 17 18 |
# File 'lib/nvoi/cli/onboard/steps/domain.rb', line 13 def initialize(prompt, test_mode: false) @prompt = prompt @test_mode = test_mode @client = nil @zones = [] end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
11 12 13 |
# File 'lib/nvoi/cli/onboard/steps/domain.rb', line 11 def client @client end |
#zones ⇒ Object (readonly)
Returns the value of attribute zones.
11 12 13 |
# File 'lib/nvoi/cli/onboard/steps/domain.rb', line 11 def zones @zones end |
Instance Method Details
#call(existing: nil) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/nvoi/cli/onboard/steps/domain.rb', line 20 def call(existing: nil) section "Domain Provider" return nil unless @prompt.yes?("Configure Cloudflare for domains/tunnels?") token = prompt_with_retry("Cloudflare API Token:", mask: true) account_id = @prompt.ask("Cloudflare Account ID:") { |q| q.required true } @client = External::Dns::Cloudflare.new(token, account_id) @zones = with_spinner("Fetching domains...") do @client.validate_credentials @client.list_zones.select { |z| z[:status] == "active" } end output.puts "No active domains found in Cloudflare account" if @zones.empty? { "cloudflare" => { "api_token" => token, "account_id" => account_id } } end |