From d8ec19faa8f71980f5a82a80e05710ea85dbdb66 Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Tue, 4 Sep 2018 12:25:19 -0700 Subject: [PATCH] Fixup: Update vagrant cloud command PR with feedback --- lib/vagrant/util/uploader.rb | 30 +++++++-------- plugins/commands/cloud/auth/login.rb | 1 - plugins/commands/cloud/auth/logout.rb | 2 +- plugins/commands/cloud/box/create.rb | 6 +-- plugins/commands/cloud/box/delete.rb | 10 ++--- plugins/commands/cloud/box/show.rb | 8 ++-- plugins/commands/cloud/box/update.rb | 9 ++--- plugins/commands/cloud/client/client.rb | 5 ++- plugins/commands/cloud/errors.rb | 4 ++ plugins/commands/cloud/list.rb | 2 +- plugins/commands/cloud/locales/en.yml | 21 ++++++++++ plugins/commands/cloud/provider/create.rb | 4 +- plugins/commands/cloud/provider/delete.rb | 8 ++-- plugins/commands/cloud/provider/update.rb | 4 +- plugins/commands/cloud/provider/upload.rb | 4 +- plugins/commands/cloud/publish.rb | 38 ++++++++++--------- plugins/commands/cloud/search.rb | 4 +- plugins/commands/cloud/util.rb | 9 ++++- plugins/commands/cloud/version/create.rb | 4 +- plugins/commands/cloud/version/delete.rb | 8 ++-- plugins/commands/cloud/version/release.rb | 8 ++-- plugins/commands/cloud/version/revoke.rb | 8 ++-- plugins/commands/cloud/version/update.rb | 4 +- plugins/commands/login/plugin.rb | 2 +- .../plugins/commands/cloud/client_test.rb | 4 +- website/source/docs/cli/cloud.html.md | 2 - 26 files changed, 121 insertions(+), 88 deletions(-) diff --git a/lib/vagrant/util/uploader.rb b/lib/vagrant/util/uploader.rb index d4dfea287..17af39ef3 100644 --- a/lib/vagrant/util/uploader.rb +++ b/lib/vagrant/util/uploader.rb @@ -13,12 +13,15 @@ module Vagrant # a hand-rolled Ruby library, so we defer to its expertise. class Uploader + # @param [String] destination - valid URL to upload file to + # @param [String] file - location of file to upload on disk + # @param [Hash] options def initialize(destination, file, options=nil) options ||= {} - @logger = Log4r::Logger.new("vagrant::util::uploader") + @logger = Log4r::Logger.new("vagrant::util::uploader") @destination = destination.to_s - @file = file.to_s - @ui = options[:ui] + @file = file.to_s + @ui = options[:ui] @request_method = options[:method] if !@request_method @@ -68,7 +71,7 @@ module Vagrant Subprocess.execute("curl", *options, &data_proc) end - # If the download was interrupted, then raise a specific error + # If the upload was interrupted, then raise a specific error raise Errors::UploaderInterrupted if interrupted # If it didn't exit successfully, we need to parse the data and @@ -76,20 +79,15 @@ module Vagrant if result.exit_code != 0 @logger.warn("Uploader exit code: #{result.exit_code}") check = result.stderr.match(/\n*curl:\s+\((?\d+)\)\s*(?.*)$/) - if check && check[:code] == "416" - # All good actually. 416 means there is no more bytes to download - @logger.warn("Uploader got a 416, but is likely fine. Continuing on...") + if !check + err_msg = result.stderr else - if !check - err_msg = result.stderr - else - err_msg = check[:error] - end - - raise Errors::UploaderError, - exit_code: result.exit_code, - message: err_msg + err_msg = check[:error] end + + raise Errors::UploaderError, + exit_code: result.exit_code, + message: err_msg end if @ui diff --git a/plugins/commands/cloud/auth/login.rb b/plugins/commands/cloud/auth/login.rb index 4dc206bd2..d8451f644 100644 --- a/plugins/commands/cloud/auth/login.rb +++ b/plugins/commands/cloud/auth/login.rb @@ -33,7 +33,6 @@ module VagrantPlugins options[:login] = l end end - # TODO: Should be an alias for the existing login command # Parse the options argv = parse_options(opts) diff --git a/plugins/commands/cloud/auth/logout.rb b/plugins/commands/cloud/auth/logout.rb index 19d7741ff..6dd3103b1 100644 --- a/plugins/commands/cloud/auth/logout.rb +++ b/plugins/commands/cloud/auth/logout.rb @@ -23,7 +23,7 @@ module VagrantPlugins # Parse the options argv = parse_options(opts) return if !argv - if argv.length > 1 + if !argv.empty? raise Vagrant::Errors::CLIInvalidUsage, help: opts.help.chomp end diff --git a/plugins/commands/cloud/box/create.rb b/plugins/commands/cloud/box/create.rb index a3e34b589..38457e746 100644 --- a/plugins/commands/cloud/box/create.rb +++ b/plugins/commands/cloud/box/create.rb @@ -33,14 +33,14 @@ module VagrantPlugins # Parse the options argv = parse_options(opts) return if !argv - if argv.empty? || argv.length > 2 + if argv.empty? || argv.length > 1 raise Vagrant::Errors::CLIInvalidUsage, help: opts.help.chomp end @client = VagrantPlugins::CloudCommand::Util.client_login(@env, options[:username]) - box = argv.first.split('/') + box = argv.first.split('/', 2) org = box[0] box_name = box[1] create_box(org, box_name, options, @client.token) @@ -51,7 +51,7 @@ module VagrantPlugins # @param [Hash] - options def create_box(org, box_name, options, access_token) server_url = VagrantPlugins::CloudCommand::Util.api_server_url - account = VagrantPlugins::CloudCommand::Util.account?(org, access_token, server_url) + account = VagrantPlugins::CloudCommand::Util.account(org, access_token, server_url) box = VagrantCloud::Box.new(account, box_name, nil, options[:short], options[:description], access_token) begin diff --git a/plugins/commands/cloud/box/delete.rb b/plugins/commands/cloud/box/delete.rb index 95a17c509..c7ef2a3ed 100644 --- a/plugins/commands/cloud/box/delete.rb +++ b/plugins/commands/cloud/box/delete.rb @@ -24,18 +24,18 @@ module VagrantPlugins # Parse the options argv = parse_options(opts) return if !argv - if argv.empty? || argv.length > 2 + if argv.empty? || argv.length > 1 raise Vagrant::Errors::CLIInvalidUsage, help: opts.help.chomp end @env.ui.warn(I18n.t("cloud_command.box.delete_warn", box: argv.first)) - continue = @env.ui.ask(I18n.t("cloud_command.continue")) - return 1 if continue.downcase != "y" + cont = @env.ui.ask(I18n.t("cloud_command.continue")) + return 1 if cont.strip.downcase != "y" @client = VagrantPlugins::CloudCommand::Util.client_login(@env, options[:username]) - box = argv.first.split('/') + box = argv.first.split('/', 2) org = box[0] box_name = box[1] delete_box(org, box_name, options[:username], @client.token) @@ -43,7 +43,7 @@ module VagrantPlugins def delete_box(org, box_name, username, access_token) server_url = VagrantPlugins::CloudCommand::Util.api_server_url - account = VagrantPlugins::CloudCommand::Util.account?(username, access_token, server_url) + account = VagrantPlugins::CloudCommand::Util.account(username, access_token, server_url) box = VagrantCloud::Box.new(account, box_name, nil, nil, nil, access_token) begin diff --git a/plugins/commands/cloud/box/show.rb b/plugins/commands/cloud/box/show.rb index 0cf6bb2ee..99b09bb86 100644 --- a/plugins/commands/cloud/box/show.rb +++ b/plugins/commands/cloud/box/show.rb @@ -27,13 +27,13 @@ module VagrantPlugins # Parse the options argv = parse_options(opts) return if !argv - if argv.empty? || argv.length > 2 + if argv.empty? || argv.length > 1 raise Vagrant::Errors::CLIInvalidUsage, help: opts.help.chomp end @client = VagrantPlugins::CloudCommand::Util.client_login(@env, options[:username]) - box = argv.first.split('/') + box = argv.first.split('/', 2) show_box(box[0], box[1], options, @client.token) end @@ -42,7 +42,7 @@ module VagrantPlugins username = options[:username] server_url = VagrantPlugins::CloudCommand::Util.api_server_url - account = VagrantPlugins::CloudCommand::Util.account?(username, access_token, server_url) + account = VagrantPlugins::CloudCommand::Util.account(username, access_token, server_url) box = VagrantCloud::Box.new(account, box_name, nil, nil, nil, access_token) begin @@ -52,7 +52,7 @@ module VagrantPlugins # show *this* version only results = success["versions"].select{ |v| v if v["version"] == options[:version] }.first if !results - @env.ui.warn(I18n.t("cloud_command.box.show_filter_empty", version: options[:version], org: org,box_name:box_name)) + @env.ui.warn(I18n.t("cloud_command.box.show_filter_empty", version: options[:version], org: org, box_name: box_name)) return 0 end else diff --git a/plugins/commands/cloud/box/update.rb b/plugins/commands/cloud/box/update.rb index 0d766bd41..2e9ae4806 100644 --- a/plugins/commands/cloud/box/update.rb +++ b/plugins/commands/cloud/box/update.rb @@ -16,8 +16,7 @@ module VagrantPlugins o.separator "Options:" o.separator "" - - o.on("-d", "--description DESCRIPTION", "Longer desscription of the box") do |d| + o.on("-d", "--description DESCRIPTION", "Longer description of the box") do |d| options[:description] = d end o.on("-u", "--username", "The username of the organization that will own the box") do |u| @@ -34,20 +33,20 @@ module VagrantPlugins # Parse the options argv = parse_options(opts) return if !argv - if argv.empty? || argv.length > 2 || options.length == 0 + if argv.empty? || argv.length > 1 || options.length == 0 raise Vagrant::Errors::CLIInvalidUsage, help: opts.help.chomp end @client = VagrantPlugins::CloudCommand::Util.client_login(@env, options[:username]) - box = argv.first.split('/') + box = argv.first.split('/', 2) update_box(box[0], box[1], options, @client.token) end def update_box(org, box_name, options, access_token) server_url = VagrantPlugins::CloudCommand::Util.api_server_url - account = VagrantPlugins::CloudCommand::Util.account?(options[:username], access_token, server_url) + account = VagrantPlugins::CloudCommand::Util.account(options[:username], access_token, server_url) box = VagrantCloud::Box.new(account, box_name, nil, nil, nil, access_token) options[:organization] = org diff --git a/plugins/commands/cloud/client/client.rb b/plugins/commands/cloud/client/client.rb index 599189ab5..b0ef7e9db 100644 --- a/plugins/commands/cloud/client/client.rb +++ b/plugins/commands/cloud/client/client.rb @@ -75,6 +75,7 @@ module VagrantPlugins } ) + Vagrant::Util::CredentialScrubber.sensitive(response["token"]) response["token"] end @@ -217,7 +218,9 @@ EOH raise Errors::ServerError, errors: errors rescue JSON::ParserError; end - raise "An unexpected error occurred: #{e.inspect}" + @logger.debug("Got an unexpected error:") + @logger.debug(e.inspect) + raise Errors::Unexpected, error: e.inspect rescue SocketError @logger.info("Socket error") raise Errors::ServerUnreachable, url: Vagrant.server_url.to_s diff --git a/plugins/commands/cloud/errors.rb b/plugins/commands/cloud/errors.rb index 1ba5652b2..29210aa2b 100644 --- a/plugins/commands/cloud/errors.rb +++ b/plugins/commands/cloud/errors.rb @@ -17,6 +17,10 @@ module VagrantPlugins error_key(:unauthorized) end + class Unexpected < Error + error_key(:unexpected_error) + end + class TwoFactorRequired < Error end end diff --git a/plugins/commands/cloud/list.rb b/plugins/commands/cloud/list.rb index 2344216bd..de365537c 100644 --- a/plugins/commands/cloud/list.rb +++ b/plugins/commands/cloud/list.rb @@ -35,7 +35,7 @@ module VagrantPlugins # Parse the options argv = parse_options(opts) return if !argv - if argv.length > 2 + if argv.length > 1 raise Vagrant::Errors::CLIInvalidUsage, help: opts.help.chomp end diff --git a/plugins/commands/cloud/locales/en.yml b/plugins/commands/cloud/locales/en.yml index d9957e05d..706c0b532 100644 --- a/plugins/commands/cloud/locales/en.yml +++ b/plugins/commands/cloud/locales/en.yml @@ -1,6 +1,8 @@ en: cloud_command: publish: + update_continue: |- + %{obj} already exists, updating instead... box_create: Creating a box entry... version_create: @@ -13,6 +15,23 @@ en: Releasing box... complete: Complete! Published %{org}/%{box_name} + confirm: + warn: |- + You are about to publish a box on Vagrant Cloud with the following options: + box: |- + %{org}/%{box_name}: (v%{version}) for provider '%{provider_name}' + private: |- + Private: true + release: |- + Automatic Release: true + box_url: |- + Remote Box file: %{url} + box_description: |- + Box Description: %{description} + box_short_desc: |- + Box Short Description: %{short_description} + version_desc: |- + Version Description: %{version_description} continue: |- Do you wish to continue? [y/N] box: @@ -112,6 +131,8 @@ en: unauthorized: |- Invalid username or password. Please try again. + unexpected_error: |- + An unexpected error occured: %{error} check_logged_in: |- You are already logged in. diff --git a/plugins/commands/cloud/provider/create.rb b/plugins/commands/cloud/provider/create.rb index 646370f70..df93cf8ec 100644 --- a/plugins/commands/cloud/provider/create.rb +++ b/plugins/commands/cloud/provider/create.rb @@ -31,7 +31,7 @@ module VagrantPlugins @client = VagrantPlugins::CloudCommand::Util.client_login(@env, options[:username]) - box = argv.first.split('/') + box = argv.first.split('/', 2) org = box[0] box_name = box[1] provider_name = argv[1] @@ -49,7 +49,7 @@ module VagrantPlugins org = options[:username] if options[:username] server_url = VagrantPlugins::CloudCommand::Util.api_server_url - account = VagrantPlugins::CloudCommand::Util.account?(org, access_token, server_url) + account = VagrantPlugins::CloudCommand::Util.account(org, access_token, server_url) box = VagrantCloud::Box.new(account, box_name, nil, nil, nil, access_token) cloud_version = VagrantCloud::Version.new(box, version, nil, nil, access_token) provider = VagrantCloud::Provider.new(cloud_version, provider_name, nil, url, org, box_name, access_token) diff --git a/plugins/commands/cloud/provider/delete.rb b/plugins/commands/cloud/provider/delete.rb index 625d01fd1..7ed970c65 100644 --- a/plugins/commands/cloud/provider/delete.rb +++ b/plugins/commands/cloud/provider/delete.rb @@ -29,15 +29,15 @@ module VagrantPlugins help: opts.help.chomp end - box = argv.first.split('/') + box = argv.first.split('/', 2) org = box[0] box_name = box[1] provider_name = argv[1] version = argv[2] @env.ui.warn(I18n.t("cloud_command.provider.delete_warn", provider: provider_name, version:version, box: argv.first)) - continue = @env.ui.ask(I18n.t("cloud_command.continue")) - return 1 if continue.downcase != "y" + cont = @env.ui.ask(I18n.t("cloud_command.continue")) + return 1 if cont.strip.downcase != "y" @client = VagrantPlugins::CloudCommand::Util.client_login(@env, options[:username]) @@ -48,7 +48,7 @@ module VagrantPlugins org = options[:username] if options[:username] server_url = VagrantPlugins::CloudCommand::Util.api_server_url - account = VagrantPlugins::CloudCommand::Util.account?(org, access_token, server_url) + account = VagrantPlugins::CloudCommand::Util.account(org, access_token, server_url) box = VagrantCloud::Box.new(account, box_name, nil, nil, nil, access_token) cloud_version = VagrantCloud::Version.new(box, version, nil, nil, access_token) provider = VagrantCloud::Provider.new(cloud_version, provider_name, nil, nil, nil, nil, access_token) diff --git a/plugins/commands/cloud/provider/update.rb b/plugins/commands/cloud/provider/update.rb index dae22f9d2..f34140bcd 100644 --- a/plugins/commands/cloud/provider/update.rb +++ b/plugins/commands/cloud/provider/update.rb @@ -31,7 +31,7 @@ module VagrantPlugins @client = VagrantPlugins::CloudCommand::Util.client_login(@env, options[:username]) - box = argv.first.split('/') + box = argv.first.split('/', 2) org = box[0] box_name = box[1] provider_name = argv[1] @@ -49,7 +49,7 @@ module VagrantPlugins org = options[:username] if options[:username] server_url = VagrantPlugins::CloudCommand::Util.api_server_url - account = VagrantPlugins::CloudCommand::Util.account?(org, access_token, server_url) + account = VagrantPlugins::CloudCommand::Util.account(org, access_token, server_url) box = VagrantCloud::Box.new(account, box_name, nil, nil, nil, access_token) cloud_version = VagrantCloud::Version.new(box, version, nil, nil, access_token) provider = VagrantCloud::Provider.new(cloud_version, provider_name, nil, url, org, box_name, access_token) diff --git a/plugins/commands/cloud/provider/upload.rb b/plugins/commands/cloud/provider/upload.rb index 050df2905..610d70775 100644 --- a/plugins/commands/cloud/provider/upload.rb +++ b/plugins/commands/cloud/provider/upload.rb @@ -32,7 +32,7 @@ module VagrantPlugins @client = VagrantPlugins::CloudCommand::Util.client_login(@env, options[:username]) - box = argv.first.split('/') + box = argv.first.split('/', 2) org = box[0] box_name = box[1] provider_name = argv[1] @@ -46,7 +46,7 @@ module VagrantPlugins org = options[:username] if options[:username] server_url = VagrantPlugins::CloudCommand::Util.api_server_url - account = VagrantPlugins::CloudCommand::Util.account?(org, access_token, server_url) + account = VagrantPlugins::CloudCommand::Util.account(org, access_token, server_url) box = VagrantCloud::Box.new(account, box_name, nil, nil, nil, access_token) cloud_version = VagrantCloud::Version.new(box, version, nil, nil, access_token) provider = VagrantCloud::Provider.new(cloud_version, provider_name, nil, nil, org, box_name, access_token) diff --git a/plugins/commands/cloud/publish.rb b/plugins/commands/cloud/publish.rb index a1294ff41..28d8d18af 100644 --- a/plugins/commands/cloud/publish.rb +++ b/plugins/commands/cloud/publish.rb @@ -48,14 +48,14 @@ module VagrantPlugins # Parse the options argv = parse_options(opts) return if !argv - if argv.empty? || argv.length > 5 || argv.length < 3 + if argv.empty? || argv.length > 4 || argv.length < 3 raise Vagrant::Errors::CLIInvalidUsage, help: opts.help.chomp end @client = VagrantPlugins::CloudCommand::Util.client_login(@env, options[:username]) - box = argv.first.split('/') + box = argv.first.split('/', 2) org = box[0] box_name = box[1] version = argv[1] @@ -67,23 +67,27 @@ module VagrantPlugins def publish_box(org, box_name, version, provider_name, box_file, options, access_token) server_url = VagrantPlugins::CloudCommand::Util.api_server_url - @env.ui.warn("You are about to publish a box on Vagrant Cloud with the following options:\n") - box_opts = " #{org}/#{box_name}: (v#{version}) for provider '#{provider_name}'\n" - box_opts << " Private: true\n" if options[:private] - box_opts << " Automatic Release: true\n" if options[:release] - box_opts << " Remote Box file: true\n" if options[:url] - box_opts << " Box Description: #{options[:description]}\n" if options[:description] - box_opts << " Box Short Description: #{options[:short_description]}\n" if options[:short_description] - box_opts << " Version Description: #{options[:version_description]}\n" if options[:version_description] + @env.ui.warn(I18n.t("cloud_command.publish.confirm.warn")) - @env.ui.info(box_opts) + @env.ui.info(I18n.t("cloud_command.publish.confirm.box", org: org, + box_name: box_name, version: version, provider_name: provider_name)) + @env.ui.info(I18n.t("cloud_command.publish.confirm.private")) if options[:private] + @env.ui.info(I18n.t("cloud_command.publish.confirm.release")) if options[:release] + @env.ui.info(I18n.t("cloud_command.publish.confirm.box_url", + url: options[:url])) if options[:url] + @env.ui.info(I18n.t("cloud_command.publish.confirm.box_description", + description: options[:description])) if options[:description] + @env.ui.info(I18n.t("cloud_command.publish.confirm.box_short_desc", + short_description: options[:short_description])) if options[:short_description] + @env.ui.info(I18n.t("cloud_command.publish.confirm.version_desc", + version_description: options[:version_description])) if options[:version_description] if !options[:force] - continue = @env.ui.ask(I18n.t("cloud_command.continue")) - return 1 if continue.downcase != "y" + cont = @env.ui.ask(I18n.t("cloud_command.continue")) + return 1 if cont.strip.downcase != "y" end - account = VagrantPlugins::CloudCommand::Util.account?(org, access_token, server_url) + account = VagrantPlugins::CloudCommand::Util.account(org, access_token, server_url) box = VagrantCloud::Box.new(account, box_name, nil, options[:short_description], options[:description], access_token) cloud_version = VagrantCloud::Version.new(box, version, nil, options[:version_description], access_token) provider = VagrantCloud::Provider.new(cloud_version, provider_name, nil, options[:url], org, box_name, access_token) @@ -95,7 +99,7 @@ module VagrantPlugins box.create rescue VagrantCloud::ClientError => e if e.error_code == 422 - ui.warn("Box already exists, updating instead...") + ui.warn(I18n.t("cloud_command.publish.update_continue", obj: "Box")) box.update(options) else @env.ui.error(I18n.t("cloud_command.errors.publish.fail", org: org, box_name: box_name)) @@ -109,7 +113,7 @@ module VagrantPlugins cloud_version.create_version rescue VagrantCloud::ClientError => e if e.error_code == 422 - ui.warn("Version already exists, updating instead...") + ui.warn(I18n.t("cloud_command.publish.update_continue", obj: "Version")) cloud_version.update else @env.ui.error(I18n.t("cloud_command.errors.publish.fail", org: org, box_name: box_name)) @@ -123,7 +127,7 @@ module VagrantPlugins provider.create_provider rescue VagrantCloud::ClientError => e if e.error_code == 422 - ui.warn("Provider already exists, updating instead...") + ui.warn(I18n.t("cloud_command.publish.update_continue", obj: "Provider")) provider.update else @env.ui.error(I18n.t("cloud_command.errors.publish.fail", org: org, box_name: box_name)) diff --git a/plugins/commands/cloud/search.rb b/plugins/commands/cloud/search.rb index b822da2b3..d0abeedf4 100644 --- a/plugins/commands/cloud/search.rb +++ b/plugins/commands/cloud/search.rb @@ -44,7 +44,7 @@ module VagrantPlugins # Parse the options argv = parse_options(opts) return if !argv - if argv.length > 2 + if argv.length > 1 raise Vagrant::Errors::CLIInvalidUsage, help: opts.help.chomp end @@ -52,7 +52,7 @@ module VagrantPlugins @client = VagrantPlugins::CloudCommand::Util.client_login(@env, options[:username]) query = argv.first - options[:limit] = 25 if !options[:limit] + options[:limit] = 25 if !(options[:limit].to_i < 1) && !options[:limit] search(query, options, @client.token) end diff --git a/plugins/commands/cloud/util.rb b/plugins/commands/cloud/util.rb index 149b37d89..aab94fb16 100644 --- a/plugins/commands/cloud/util.rb +++ b/plugins/commands/cloud/util.rb @@ -2,7 +2,11 @@ module VagrantPlugins module CloudCommand class Util class << self - def account?(username, access_token, vagrant_cloud_server) + # @param [String] username - Vagrant Cloud username + # @param [String] access_token - Vagrant Cloud Token used to authenticate + # @param [String] vagrant_cloud_server - Vagrant Cloud server to make API request + # @return [VagrantCloud::Account] + def account(username, access_token, vagrant_cloud_server) if !defined?(@_account) @_account = VagrantCloud::Account.new(username, access_token, vagrant_cloud_server) end @@ -17,6 +21,9 @@ module VagrantPlugins end end + # @param [Vagrant::Environment] env + # @param [Hash] options + # @returns [VagrantPlugins::CloudCommand::Client] def client_login(env, options) if !defined?(@_client) @_client = Client.new(env) diff --git a/plugins/commands/cloud/version/create.rb b/plugins/commands/cloud/version/create.rb index 116fa365f..06e2a043b 100644 --- a/plugins/commands/cloud/version/create.rb +++ b/plugins/commands/cloud/version/create.rb @@ -33,7 +33,7 @@ module VagrantPlugins end @client = VagrantPlugins::CloudCommand::Util.client_login(@env, options[:username]) - box = argv.first.split('/') + box = argv.first.split('/', 2) org = box[0] box_name = box[1] version = argv[1] @@ -45,7 +45,7 @@ module VagrantPlugins org = options[:username] if options[:username] server_url = VagrantPlugins::CloudCommand::Util.api_server_url - account = VagrantPlugins::CloudCommand::Util.account?(org, access_token, server_url) + account = VagrantPlugins::CloudCommand::Util.account(org, access_token, server_url) box = VagrantCloud::Box.new(account, box_name, nil, nil, nil, access_token) version = VagrantCloud::Version.new(box, box_version, nil, options[:description], access_token) diff --git a/plugins/commands/cloud/version/delete.rb b/plugins/commands/cloud/version/delete.rb index 39f599787..2f9d21876 100644 --- a/plugins/commands/cloud/version/delete.rb +++ b/plugins/commands/cloud/version/delete.rb @@ -28,14 +28,14 @@ module VagrantPlugins help: opts.help.chomp end - box = argv.first.split('/') + box = argv.first.split('/', 2) org = box[0] box_name = box[1] version = argv[1] @env.ui.warn(I18n.t("cloud_command.version.delete_warn", version: version, box: argv.first)) - continue = @env.ui.ask(I18n.t("cloud_command.continue")) - return 1 if continue.downcase != "y" + cont = @env.ui.ask(I18n.t("cloud_command.continue")) + return 1 if cont.strip.downcase != "y" @client = VagrantPlugins::CloudCommand::Util.client_login(@env, options[:username]) @@ -46,7 +46,7 @@ module VagrantPlugins org = options[:username] if options[:username] server_url = VagrantPlugins::CloudCommand::Util.api_server_url - account = VagrantPlugins::CloudCommand::Util.account?(org, access_token, server_url) + account = VagrantPlugins::CloudCommand::Util.account(org, access_token, server_url) box = VagrantCloud::Box.new(account, box_name, nil, nil, nil, access_token) version = VagrantCloud::Version.new(box, box_version, nil, nil, access_token) diff --git a/plugins/commands/cloud/version/release.rb b/plugins/commands/cloud/version/release.rb index a6e01aeaf..6151e8540 100644 --- a/plugins/commands/cloud/version/release.rb +++ b/plugins/commands/cloud/version/release.rb @@ -29,11 +29,11 @@ module VagrantPlugins end @env.ui.warn(I18n.t("cloud_command.version.release_warn", version: argv[1], box: argv.first)) - continue = @env.ui.ask(I18n.t("cloud_command.continue")) - return 1 if continue.downcase != "y" + cont = @env.ui.ask(I18n.t("cloud_command.continue")) + return 1 if cont.strip.downcase != "y" @client = VagrantPlugins::CloudCommand::Util.client_login(@env, options[:username]) - box = argv.first.split('/') + box = argv.first.split('/', 2) org = box[0] box_name = box[1] version = argv[1] @@ -45,7 +45,7 @@ module VagrantPlugins org = options[:username] if options[:username] server_url = VagrantPlugins::CloudCommand::Util.api_server_url - account = VagrantPlugins::CloudCommand::Util.account?(org, access_token, server_url) + account = VagrantPlugins::CloudCommand::Util.account(org, access_token, server_url) box = VagrantCloud::Box.new(account, box_name, nil, nil, nil, access_token) version = VagrantCloud::Version.new(box, version, nil, nil, access_token) diff --git a/plugins/commands/cloud/version/revoke.rb b/plugins/commands/cloud/version/revoke.rb index f1550e788..e11af2aba 100644 --- a/plugins/commands/cloud/version/revoke.rb +++ b/plugins/commands/cloud/version/revoke.rb @@ -29,11 +29,11 @@ module VagrantPlugins end @env.ui.warn(I18n.t("cloud_command.version.revoke_warn", version: argv[1], box: argv.first)) - continue = @env.ui.ask(I18n.t("cloud_command.continue")) - return 1 if continue.downcase != "y" + cont = @env.ui.ask(I18n.t("cloud_command.continue")) + return 1 if cont.strip.downcase != "y" @client = VagrantPlugins::CloudCommand::Util.client_login(@env, options[:username]) - box = argv.first.split('/') + box = argv.first.split('/', 2) org = box[0] box_name = box[1] version = argv[1] @@ -45,7 +45,7 @@ module VagrantPlugins org = options[:username] if options[:username] server_url = VagrantPlugins::CloudCommand::Util.api_server_url - account = VagrantPlugins::CloudCommand::Util.account?(org, access_token, server_url) + account = VagrantPlugins::CloudCommand::Util.account(org, access_token, server_url) box = VagrantCloud::Box.new(account, box_name, nil, nil, nil, access_token) version = VagrantCloud::Version.new(box, box_version, nil, nil, access_token) diff --git a/plugins/commands/cloud/version/update.rb b/plugins/commands/cloud/version/update.rb index 032251a8c..4c6b19a62 100644 --- a/plugins/commands/cloud/version/update.rb +++ b/plugins/commands/cloud/version/update.rb @@ -33,7 +33,7 @@ module VagrantPlugins end @client = VagrantPlugins::CloudCommand::Util.client_login(@env, options[:username]) - box = argv.first.split('/') + box = argv.first.split('/', 2) org = box[0] box_name = box[1] version = argv[1] @@ -45,7 +45,7 @@ module VagrantPlugins org = options[:username] if options[:username] server_url = VagrantPlugins::CloudCommand::Util.api_server_url - account = VagrantPlugins::CloudCommand::Util.account?(org, access_token, server_url) + account = VagrantPlugins::CloudCommand::Util.account(org, access_token, server_url) box = VagrantCloud::Box.new(account, box_name, nil, nil, nil, access_token) version = VagrantCloud::Version.new(box, box_version, nil, options[:description], access_token) diff --git a/plugins/commands/login/plugin.rb b/plugins/commands/login/plugin.rb index 917cd7dcb..a82d84fe6 100644 --- a/plugins/commands/login/plugin.rb +++ b/plugins/commands/login/plugin.rb @@ -14,7 +14,7 @@ module VagrantPlugins command(:login) do require File.expand_path("../../cloud/auth/login", __FILE__) init! - # TODO: Print dep warning here? + $stderr.puts "WARNING: This command has been deprecated in favor of `vagrant cloud auth login`" VagrantPlugins::CloudCommand::AuthCommand::Command::Login end diff --git a/test/unit/plugins/commands/cloud/client_test.rb b/test/unit/plugins/commands/cloud/client_test.rb index bad54a811..9cdfe8ac0 100644 --- a/test/unit/plugins/commands/cloud/client_test.rb +++ b/test/unit/plugins/commands/cloud/client_test.rb @@ -87,7 +87,7 @@ describe VagrantPlugins::CloudCommand::Client do } let(:response) { { - token: "baz" + token: "mysecrettoken" } } @@ -99,7 +99,7 @@ describe VagrantPlugins::CloudCommand::Client do client.username_or_email = login client.password = password - expect(client.login(description: "Token description")).to eq("baz") + expect(client.login(description: "Token description")).to eq("mysecrettoken") end context "when 2fa is required" do diff --git a/website/source/docs/cli/cloud.html.md b/website/source/docs/cli/cloud.html.md index 4854110a9..566054f65 100644 --- a/website/source/docs/cli/cloud.html.md +++ b/website/source/docs/cli/cloud.html.md @@ -26,8 +26,6 @@ The main functionality of this command is exposed via even more subcommands: **Command: `vagrant cloud auth`** -Information about this subcommand goes here - * [`login`](#cloud-auth-login) * [`logout`](#cloud-auth-logout) * [`who`](#cloud-auth-who)