lib/travis/cli/api_command.rb in travis-1.5.7.travis.341.4 vs lib/travis/cli/api_command.rb in travis-1.5.7.travis.345.4

- old
+ new

@@ -52,13 +52,17 @@ self.access_token ||= fetch_token endpoint_config['access_token'] ||= access_token endpoint_config['insecure'] = insecure unless insecure.nil? self.insecure = endpoint_config['insecure'] session.ssl = { :verify => false } if insecure? - authenticate if pro? + authenticate if pro? or enterprise? end + def enterprise? + !!endpoint_config['enterprise'] + end + def pro? api_endpoint == Travis::Client::PRO_URI end def org? @@ -93,16 +97,19 @@ def setup_enterprise c = config['enterprise'] ||= {} c[enterprise_name] = api_endpoint if explicit_api_endpoint? c[enterprise_name] ||= write_to($stderr) do error "enterprise setup not configured" unless interactive? - user_input = ask(color("Enterprise domain: ", :bold)).to_s - domain = user_input[%r{^(?:https?://)?(.*?)(?:/api/?)?$}, 1] - "https://#{domain}/api/" + user_input = ask(color("Enterprise domain: ", :bold)).to_s + domain = user_input[%r{^(?:https?://)?(.*?)/?(?:/api/?)?$}, 1] + endpoint = "https://#{domain}/api" + config['default_endpoint'] = endpoint if agree("Use #{color domain, :bold} as default endpoint? ") { |q| q.default = 'yes' } + endpoint end - self.api_endpoint = c[enterprise_name] - self.insecure = true if insecure.nil? + self.api_endpoint = c[enterprise_name] + self.insecure = true if insecure.nil? + endpoint_config['enterprise'] = true end def enterprise? !!enterprise_name end @@ -142,9 +149,16 @@ def endpoint_option return "" if org? and detected_endpoint? return " --org" if org? return " --pro" if pro? + + if config['enterprise'] + key, _ = config['enterprise'].detect { |k,v| v.start_with? api_endpoint } + return " -X" if key == "default" + return " -X #{key}" if key + end + " -e %p" % api_endpoint end def fetch_token ENV['TRAVIS_TOKEN'] || endpoint_config['access_token']