Class: Jatai::Commands::Domains
- Inherits:
-
Thor
- Object
- Thor
- Jatai::Commands::Domains
- Defined in:
- lib/jatai/commands/domains.rb
Instance Method Summary collapse
Instance Method Details
#add(hostname) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/jatai/commands/domains.rb', line 30 def add(hostname) slug = helper.app_slug result = helper.api.post("/api/v1/apps/#{slug}/domains", body: { domain: { hostname: hostname } }) app = helper.api.get("/api/v1/apps/#{slug}") helper.success("Domínio #{hostname} adicionado.") # Alvo do CNAME vem da URL canônica do servidor (marca atual); o # fallback local só cobre servidor antigo sem o campo "url". target = cname_target(app, slug) helper.info("Opção 1 (CNAME): aponte #{hostname} para #{target}") helper.info("Opção 2 (TXT): crie um registro TXT em #{hostname} com o valor #{result["verification_token"]}") helper.info("Domínio raiz (apex)? CNAME não é permitido no apex: use a Opção 2 (TXT) e crie um registro A — o IP está na aba Domínios do dashboard.") rescue Api::Client::ValidationError => e helper.error("Erro: #{e.}") rescue Api::Client::ApiError => e helper.error("Erro: #{e.}") end |
#list ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/jatai/commands/domains.rb', line 10 def list slug = helper.app_slug domains = helper.api.get("/api/v1/apps/#{slug}/domains") if domains.nil? || domains.empty? helper.info("Nenhum domínio configurado.") return end domains.each do |domain| status_icon = domain["status"] == "active" ? helper.pastel.green("●") : helper.pastel.yellow("○") puts "#{status_icon} #{helper.pastel.bold(domain["hostname"])} (#{domain["status"]})" puts " Token: #{domain["verification_token"]}" if domain["status"] == "pending" end rescue Api::Client::ApiError => e helper.error("Erro: #{e.}") end |
#remove(hostname) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/jatai/commands/domains.rb', line 49 def remove(hostname) slug = helper.app_slug domains = helper.api.get("/api/v1/apps/#{slug}/domains") domain = domains&.find { |d| d["hostname"] == hostname } unless domain helper.error("Domínio #{hostname} não encontrado.") return end helper.api.delete("/api/v1/apps/#{slug}/domains/#{domain["id"]}") helper.success("Domínio #{hostname} removido.") rescue Api::Client::ApiError => e helper.error("Erro: #{e.}") end |
#verify(hostname) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/jatai/commands/domains.rb', line 67 def verify(hostname) slug = helper.app_slug domains = helper.api.get("/api/v1/apps/#{slug}/domains") domain = domains&.find { |d| d["hostname"] == hostname } unless domain helper.error("Domínio #{hostname} não encontrado.") return end result = helper.api.post("/api/v1/apps/#{slug}/domains/#{domain["id"]}/verify") if result["status"] == "active" helper.success("Domínio #{hostname} verificado com sucesso!") else helper.error("Verificação falhou. Certifique-se de que o registro DNS está configurado.") end rescue Api::Client::ApiError => e helper.error("Erro: #{e.}") end |