c59deca51e
Raw OpenSSL sockets don't find the system CA bundle the same way Net::HTTP does. ssl_verify (default: true) is now a config setting that applies to both HTTP REST calls and WebSocket connections. Set via `portainer-cli configure`. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
71 lines
1.9 KiB
Ruby
71 lines
1.9 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require_relative 'base'
|
|
|
|
module PortainerCli
|
|
module Commands
|
|
class Configure
|
|
include Base
|
|
|
|
def initialize(config)
|
|
@config = config
|
|
end
|
|
|
|
def run(_args)
|
|
puts bold("Portainer CLI configuration")
|
|
puts "Config will be saved to: #{cyan(Config::CONFIG_FILE)}"
|
|
puts
|
|
|
|
@config.url = prompt("Portainer URL", @config.url || "https://portainer.example.com")
|
|
|
|
puts
|
|
puts "Authentication — choose one:"
|
|
puts " #{cyan('1')} API Key (recommended, no expiry)"
|
|
puts " #{cyan('2')} JWT token (from login)"
|
|
choice = prompt("Choice [1/2]", "1")
|
|
|
|
if choice == "2"
|
|
@config.api_key = nil
|
|
@config.token = prompt_secret("JWT token", @config.token)
|
|
else
|
|
@config.token = nil
|
|
@config.api_key = prompt_secret("API key", @config.api_key)
|
|
end
|
|
|
|
puts
|
|
current_verify = @config.ssl_verify.nil? ? true : @config.ssl_verify
|
|
verify_choice = prompt("Verify SSL certificates? [y/n]", current_verify ? "y" : "n")
|
|
@config.ssl_verify = (verify_choice.downcase != "n")
|
|
|
|
@config.save
|
|
puts
|
|
puts green("Configuration saved to #{Config::CONFIG_FILE}")
|
|
end
|
|
|
|
private
|
|
|
|
def prompt(label, default = nil)
|
|
default_hint = default ? " [#{dim(default)}]" : ""
|
|
print "#{label}#{default_hint}: "
|
|
input = $stdin.gets&.chomp
|
|
(input.nil? || input.empty?) ? default.to_s : input
|
|
end
|
|
|
|
def prompt_secret(label, current = nil)
|
|
hint = current ? " [#{dim('keep current')}]" : ""
|
|
print "#{label}#{hint}: "
|
|
# Hide input if on a TTY
|
|
value = if $stdin.tty?
|
|
require 'io/console'
|
|
v = $stdin.noecho(&:gets)&.chomp
|
|
puts
|
|
v
|
|
else
|
|
$stdin.gets&.chomp
|
|
end
|
|
(value.nil? || value.empty?) ? current.to_s : value
|
|
end
|
|
end
|
|
end
|
|
end
|