vagrant-unbundled 2.2.10.0 → 2.2.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +60 -0
- data/Gemfile +1 -1
- data/README.md +4 -44
- data/RELEASE.md +1 -1
- data/contrib/zsh/_vagrant +3 -1
- data/contrib/zsh/generate_zsh_completion.rb +2 -3
- data/lib/vagrant.rb +0 -4
- data/lib/vagrant/action/builder.rb +6 -15
- data/lib/vagrant/action/builtin/box_add.rb +5 -1
- data/lib/vagrant/action/builtin/cloud_init_setup.rb +10 -15
- data/lib/vagrant/action/builtin/synced_folders.rb +8 -2
- data/lib/vagrant/action/runner.rb +1 -1
- data/lib/vagrant/box.rb +8 -2
- data/lib/vagrant/box_collection.rb +1 -1
- data/lib/vagrant/bundler.rb +43 -16
- data/lib/vagrant/machine.rb +8 -5
- data/lib/vagrant/machine_index.rb +1 -0
- data/lib/vagrant/plugin/v2/command.rb +2 -1
- data/lib/vagrant/shared_helpers.rb +8 -0
- data/lib/vagrant/util/downloader.rb +3 -2
- data/lib/vagrant/util/is_port_open.rb +1 -1
- data/lib/vagrant/util/mime.rb +92 -0
- data/lib/vagrant/util/platform.rb +2 -1
- data/lib/vagrant/util/template_renderer.rb +2 -2
- data/lib/vagrant/util/uploader.rb +7 -4
- data/plugins/commands/cap/command.rb +5 -1
- data/plugins/commands/cloud/auth/login.rb +20 -23
- data/plugins/commands/cloud/auth/logout.rb +2 -10
- data/plugins/commands/cloud/auth/middleware/add_downloader_authentication.rb +57 -0
- data/plugins/commands/cloud/auth/whoami.rb +18 -20
- data/plugins/commands/cloud/box/create.rb +33 -29
- data/plugins/commands/cloud/box/delete.rb +30 -24
- data/plugins/commands/cloud/box/show.rb +41 -31
- data/plugins/commands/cloud/box/update.rb +34 -26
- data/plugins/commands/cloud/client/client.rb +50 -81
- data/plugins/commands/cloud/list.rb +3 -4
- data/plugins/commands/cloud/locales/en.yml +9 -9
- data/plugins/commands/cloud/plugin.rb +10 -0
- data/plugins/commands/cloud/provider/create.rb +38 -28
- data/plugins/commands/cloud/provider/delete.rb +39 -29
- data/plugins/commands/cloud/provider/update.rb +37 -28
- data/plugins/commands/cloud/provider/upload.rb +44 -34
- data/plugins/commands/cloud/publish.rb +185 -108
- data/plugins/commands/cloud/search.rb +34 -21
- data/plugins/commands/cloud/util.rb +266 -162
- data/plugins/commands/cloud/version/create.rb +33 -28
- data/plugins/commands/cloud/version/delete.rb +35 -28
- data/plugins/commands/cloud/version/release.rb +35 -29
- data/plugins/commands/cloud/version/revoke.rb +36 -29
- data/plugins/commands/cloud/version/update.rb +29 -25
- data/plugins/commands/login/plugin.rb +0 -13
- data/plugins/guests/arch/cap/smb.rb +1 -1
- data/plugins/guests/darwin/cap/darwin_version.rb +40 -0
- data/plugins/guests/darwin/cap/mount_smb_shared_folder.rb +1 -1
- data/plugins/guests/darwin/cap/mount_vmware_shared_folder.rb +12 -2
- data/plugins/guests/darwin/plugin.rb +10 -0
- data/plugins/guests/debian/cap/change_host_name.rb +8 -7
- data/plugins/guests/linux/cap/mount_smb_shared_folder.rb +16 -41
- data/plugins/guests/linux/cap/mount_virtualbox_shared_folder.rb +6 -0
- data/plugins/guests/linux/cap/persist_mount_shared_folder.rb +18 -5
- data/plugins/guests/linux/cap/reboot.rb +10 -5
- data/plugins/guests/redhat/cap/change_host_name.rb +6 -2
- data/plugins/guests/suse/cap/change_host_name.rb +32 -11
- data/plugins/guests/windows/cap/reboot.rb +8 -4
- data/plugins/kernel_v2/config/cloud_init.rb +7 -0
- data/plugins/kernel_v2/config/disk.rb +1 -1
- data/plugins/kernel_v2/config/vm.rb +5 -4
- data/plugins/providers/hyperv/action.rb +1 -1
- data/plugins/providers/virtualbox/cap/mount_options.rb +1 -1
- data/plugins/providers/virtualbox/model/storage_controller_array.rb +4 -6
- data/plugins/providers/virtualbox/provider.rb +2 -1
- data/plugins/synced_folders/smb/cap/mount_options.rb +21 -1
- data/plugins/synced_folders/smb/plugin.rb +10 -0
- data/scripts/website_push_www.sh +1 -1
- data/vagrant.gemspec +5 -6
- data/version.txt +1 -1
- metadata +1202 -1595
- data/plugins/commands/login/client.rb +0 -253
- data/plugins/commands/login/command.rb +0 -137
- data/plugins/commands/login/errors.rb +0 -24
- data/plugins/commands/login/locales/en.yml +0 -49
- data/scripts/website_push_docs.sh +0 -40
| @@ -5,6 +5,8 @@ module VagrantPlugins | |
| 5 5 | 
             
                module BoxCommand
         | 
| 6 6 | 
             
                  module Command
         | 
| 7 7 | 
             
                    class Create < Vagrant.plugin("2", :command)
         | 
| 8 | 
            +
                      include Util
         | 
| 9 | 
            +
             | 
| 8 10 | 
             
                      def execute
         | 
| 9 11 | 
             
                        options = {}
         | 
| 10 12 |  | 
| @@ -19,13 +21,10 @@ module VagrantPlugins | |
| 19 21 | 
             
                          o.on("-d", "--description DESCRIPTION", String, "Full description of the box") do |d|
         | 
| 20 22 | 
             
                            options[:description] = d
         | 
| 21 23 | 
             
                          end
         | 
| 22 | 
            -
                          o.on("-u", "--username USERNAME_OR_EMAIL", String, "Vagrant Cloud username or email address") do |u|
         | 
| 23 | 
            -
                            options[:username] = u
         | 
| 24 | 
            -
                          end
         | 
| 25 24 | 
             
                          o.on("-s", "--short-description DESCRIPTION", String, "Short description of the box") do |s|
         | 
| 26 25 | 
             
                            options[:short] = s
         | 
| 27 26 | 
             
                          end
         | 
| 28 | 
            -
                          o.on("-p", "--private", "Makes box private") do |p|
         | 
| 27 | 
            +
                          o.on("-p", "--[no-]private", "Makes box private") do |p|
         | 
| 29 28 | 
             
                            options[:private] = p
         | 
| 30 29 | 
             
                          end
         | 
| 31 30 | 
             
                        end
         | 
| @@ -38,35 +37,40 @@ module VagrantPlugins | |
| 38 37 | 
             
                            help: opts.help.chomp
         | 
| 39 38 | 
             
                        end
         | 
| 40 39 |  | 
| 41 | 
            -
                        @client =  | 
| 40 | 
            +
                        @client = client_login(@env)
         | 
| 42 41 |  | 
| 43 | 
            -
                         | 
| 44 | 
            -
                        org  | 
| 45 | 
            -
                        box_name = box[1]
         | 
| 46 | 
            -
                        create_box(org, box_name, options, @client.token)
         | 
| 42 | 
            +
                        org, box_name = argv.first.split('/', 2)
         | 
| 43 | 
            +
                        create_box(org, box_name, @client.token, options.slice(:description, :short, :private))
         | 
| 47 44 | 
             
                      end
         | 
| 48 45 |  | 
| 49 | 
            -
                      #  | 
| 50 | 
            -
                      # | 
| 51 | 
            -
                      # @param [ | 
| 52 | 
            -
                       | 
| 53 | 
            -
             | 
| 54 | 
            -
             | 
| 55 | 
            -
             | 
| 56 | 
            -
             | 
| 57 | 
            -
             | 
| 58 | 
            -
             | 
| 59 | 
            -
             | 
| 60 | 
            -
             | 
| 61 | 
            -
                           | 
| 62 | 
            -
                           | 
| 63 | 
            -
                         | 
| 64 | 
            -
             | 
| 65 | 
            -
             | 
| 66 | 
            -
             | 
| 67 | 
            -
                         | 
| 46 | 
            +
                      # Create a new box
         | 
| 47 | 
            +
                      #
         | 
| 48 | 
            +
                      # @param [String] org Organization name of box
         | 
| 49 | 
            +
                      # @param [String] box_name Name of box
         | 
| 50 | 
            +
                      # @param [String] access_token User access token
         | 
| 51 | 
            +
                      # @param [Hash] options Options for box filtering
         | 
| 52 | 
            +
                      # @option options [String] :short Short description of box
         | 
| 53 | 
            +
                      # @option options [String] :description Full description of box
         | 
| 54 | 
            +
                      # @option options [Boolean] :private Set box visibility as private
         | 
| 55 | 
            +
                      # @return [Integer]
         | 
| 56 | 
            +
                      def create_box(org, box_name, access_token, options={})
         | 
| 57 | 
            +
                        account = VagrantCloud::Account.new(
         | 
| 58 | 
            +
                          custom_server: api_server_url,
         | 
| 59 | 
            +
                          access_token: access_token
         | 
| 60 | 
            +
                        )
         | 
| 61 | 
            +
                        box = account.organization(name: org).add_box(box_name)
         | 
| 62 | 
            +
                        box.short_description = options[:short] if options.key?(:short)
         | 
| 63 | 
            +
                        box.description = options[:description] if options.key?(:description)
         | 
| 64 | 
            +
                        box.private = options[:private] if options.key?(:private)
         | 
| 65 | 
            +
                        box.save
         | 
| 68 66 |  | 
| 69 | 
            -
                         | 
| 67 | 
            +
                        @env.ui.success(I18n.t("cloud_command.box.create_success", org: org, box_name: box_name))
         | 
| 68 | 
            +
                        format_box_results(box, @env)
         | 
| 69 | 
            +
                        0
         | 
| 70 | 
            +
                      rescue VagrantCloud::Error => e
         | 
| 71 | 
            +
                        @env.ui.error(I18n.t("cloud_command.errors.box.create_fail", org: org, box_name: box_name))
         | 
| 72 | 
            +
                        @env.ui.error(e.message)
         | 
| 73 | 
            +
                        1
         | 
| 70 74 | 
             
                      end
         | 
| 71 75 | 
             
                    end
         | 
| 72 76 | 
             
                  end
         | 
| @@ -5,6 +5,8 @@ module VagrantPlugins | |
| 5 5 | 
             
                module BoxCommand
         | 
| 6 6 | 
             
                  module Command
         | 
| 7 7 | 
             
                    class Delete < Vagrant.plugin("2", :command)
         | 
| 8 | 
            +
                      include Util
         | 
| 9 | 
            +
             | 
| 8 10 | 
             
                      def execute
         | 
| 9 11 | 
             
                        options = {}
         | 
| 10 12 |  | 
| @@ -16,8 +18,8 @@ module VagrantPlugins | |
| 16 18 | 
             
                          o.separator "Options:"
         | 
| 17 19 | 
             
                          o.separator ""
         | 
| 18 20 |  | 
| 19 | 
            -
                          o.on("- | 
| 20 | 
            -
                            options[: | 
| 21 | 
            +
                          o.on("-f", "--[no-]force", "Do not prompt for deletion confirmation") do |f|
         | 
| 22 | 
            +
                            options[:force] = f
         | 
| 21 23 | 
             
                          end
         | 
| 22 24 | 
             
                        end
         | 
| 23 25 |  | 
| @@ -29,34 +31,38 @@ module VagrantPlugins | |
| 29 31 | 
             
                            help: opts.help.chomp
         | 
| 30 32 | 
             
                        end
         | 
| 31 33 |  | 
| 32 | 
            -
                         | 
| 33 | 
            -
             | 
| 34 | 
            -
             | 
| 34 | 
            +
                        if !options[:force]
         | 
| 35 | 
            +
                          @env.ui.warn(I18n.t("cloud_command.box.delete_warn", box: argv.first))
         | 
| 36 | 
            +
                          cont = @env.ui.ask(I18n.t("cloud_command.continue"))
         | 
| 37 | 
            +
                          return 1 if cont.strip.downcase != "y"
         | 
| 38 | 
            +
                        end
         | 
| 35 39 |  | 
| 36 | 
            -
                        @client =  | 
| 40 | 
            +
                        @client = client_login(@env)
         | 
| 37 41 |  | 
| 38 | 
            -
                         | 
| 39 | 
            -
                        org  | 
| 40 | 
            -
                        box_name = box[1]
         | 
| 41 | 
            -
                        delete_box(org, box_name, options[:username], @client.token)
         | 
| 42 | 
            +
                        org, box_name = argv.first.split('/', 2)
         | 
| 43 | 
            +
                        delete_box(org, box_name, @client.token)
         | 
| 42 44 | 
             
                      end
         | 
| 43 45 |  | 
| 44 | 
            -
                       | 
| 45 | 
            -
             | 
| 46 | 
            -
             | 
| 47 | 
            -
             | 
| 48 | 
            -
             | 
| 49 | 
            -
             | 
| 50 | 
            -
             | 
| 46 | 
            +
                      # Delete the requested box
         | 
| 47 | 
            +
                      #
         | 
| 48 | 
            +
                      # @param [String] org Organization name of box
         | 
| 49 | 
            +
                      # @param [String] box_name Name of box
         | 
| 50 | 
            +
                      # @param [String] access_token User access token
         | 
| 51 | 
            +
                      # @return [Integer]
         | 
| 52 | 
            +
                      def delete_box(org, box_name, access_token)
         | 
| 53 | 
            +
                        account = VagrantCloud::Account.new(
         | 
| 54 | 
            +
                          custom_server: api_server_url,
         | 
| 55 | 
            +
                          access_token: access_token
         | 
| 56 | 
            +
                        )
         | 
| 57 | 
            +
                        with_box(account: account, org: org, box: box_name) do |box|
         | 
| 58 | 
            +
                          box.delete
         | 
| 51 59 | 
             
                          @env.ui.success(I18n.t("cloud_command.box.delete_success", org: org, box_name: box_name))
         | 
| 52 | 
            -
                           | 
| 53 | 
            -
                        rescue VagrantCloud::ClientError => e
         | 
| 54 | 
            -
                          @env.ui.error(I18n.t("cloud_command.errors.box.delete_fail", org: org, box_name: box_name))
         | 
| 55 | 
            -
                          @env.ui.error(e)
         | 
| 56 | 
            -
                          return 1
         | 
| 60 | 
            +
                          0
         | 
| 57 61 | 
             
                        end
         | 
| 58 | 
            -
             | 
| 59 | 
            -
                         | 
| 62 | 
            +
                      rescue VagrantCloud::Error => e
         | 
| 63 | 
            +
                        @env.ui.error(I18n.t("cloud_command.errors.box.delete_fail", org: org, box_name: box_name))
         | 
| 64 | 
            +
                        @env.ui.error(e.message)
         | 
| 65 | 
            +
                        1
         | 
| 60 66 | 
             
                      end
         | 
| 61 67 | 
             
                    end
         | 
| 62 68 | 
             
                  end
         | 
| @@ -5,8 +5,10 @@ module VagrantPlugins | |
| 5 5 | 
             
                module BoxCommand
         | 
| 6 6 | 
             
                  module Command
         | 
| 7 7 | 
             
                    class Show < Vagrant.plugin("2", :command)
         | 
| 8 | 
            +
                      include Util
         | 
| 9 | 
            +
             | 
| 8 10 | 
             
                      def execute
         | 
| 9 | 
            -
                        options = {}
         | 
| 11 | 
            +
                        options = {quiet: true, versions: []}
         | 
| 10 12 |  | 
| 11 13 | 
             
                        opts = OptionParser.new do |o|
         | 
| 12 14 | 
             
                          o.banner = "Usage: vagrant cloud box show [options] organization/box-name"
         | 
| @@ -16,11 +18,11 @@ module VagrantPlugins | |
| 16 18 | 
             
                          o.separator "Options:"
         | 
| 17 19 | 
             
                          o.separator ""
         | 
| 18 20 |  | 
| 19 | 
            -
                          o.on(" | 
| 20 | 
            -
                            options[: | 
| 21 | 
            +
                          o.on("--versions VERSION", String, "Display box information for a specific version (can be defined multiple times)") do |v|
         | 
| 22 | 
            +
                            options[:versions] << v
         | 
| 21 23 | 
             
                          end
         | 
| 22 | 
            -
                          o.on("-- | 
| 23 | 
            -
                            options[: | 
| 24 | 
            +
                          o.on("--[no-]auth", "Authenticate with Vagrant Cloud if required before searching") do |l|
         | 
| 25 | 
            +
                            options[:quiet] = !l
         | 
| 24 26 | 
             
                          end
         | 
| 25 27 | 
             
                        end
         | 
| 26 28 |  | 
| @@ -32,40 +34,48 @@ module VagrantPlugins | |
| 32 34 | 
             
                            help: opts.help.chomp
         | 
| 33 35 | 
             
                        end
         | 
| 34 36 |  | 
| 35 | 
            -
                        @client =  | 
| 36 | 
            -
                         | 
| 37 | 
            +
                        @client = client_login(@env, options.slice(:quiet))
         | 
| 38 | 
            +
                        org, box_name = argv.first.split('/', 2)
         | 
| 37 39 |  | 
| 38 | 
            -
                        show_box( | 
| 40 | 
            +
                        show_box(org, box_name, @client&.token, options.slice(:versions))
         | 
| 39 41 | 
             
                      end
         | 
| 40 42 |  | 
| 41 | 
            -
                       | 
| 42 | 
            -
             | 
| 43 | 
            -
             | 
| 44 | 
            -
             | 
| 45 | 
            -
             | 
| 46 | 
            -
             | 
| 47 | 
            -
             | 
| 48 | 
            -
             | 
| 49 | 
            -
             | 
| 43 | 
            +
                      # Display the requested box to the user
         | 
| 44 | 
            +
                      #
         | 
| 45 | 
            +
                      # @param [String] org Organization name of box
         | 
| 46 | 
            +
                      # @param [String] box_name Name of box
         | 
| 47 | 
            +
                      # @param [String] access_token User access token
         | 
| 48 | 
            +
                      # @param [Hash] options Options for box filtering
         | 
| 49 | 
            +
                      # @option options [String] :versions Specific verisons of box
         | 
| 50 | 
            +
                      # @return [Integer]
         | 
| 51 | 
            +
                      def show_box(org, box_name, access_token, options={})
         | 
| 52 | 
            +
                        account = VagrantCloud::Account.new(
         | 
| 53 | 
            +
                          custom_server: api_server_url,
         | 
| 54 | 
            +
                          access_token: access_token
         | 
| 55 | 
            +
                        )
         | 
| 56 | 
            +
                        with_box(account: account, org: org, box: box_name) do |box|
         | 
| 57 | 
            +
                          if box && !Array(options[:versions]).empty?
         | 
| 58 | 
            +
                            box = box.versions.find_all{ |v| options[:versions].include?(v.version) }
         | 
| 59 | 
            +
                          else
         | 
| 60 | 
            +
                            box = [box]
         | 
| 61 | 
            +
                          end
         | 
| 50 62 |  | 
| 51 | 
            -
                          if  | 
| 52 | 
            -
                             | 
| 53 | 
            -
             | 
| 54 | 
            -
             | 
| 55 | 
            -
                              @env.ui.warn(I18n.t("cloud_command.box.show_filter_empty", version: options[:version], org: org, box_name: box_name))
         | 
| 56 | 
            -
                              return 0
         | 
| 63 | 
            +
                          if !box.empty?
         | 
| 64 | 
            +
                            box.each do |b|
         | 
| 65 | 
            +
                              format_box_results(b, @env)
         | 
| 66 | 
            +
                              @env.ui.output("")
         | 
| 57 67 | 
             
                            end
         | 
| 68 | 
            +
                            0
         | 
| 58 69 | 
             
                          else
         | 
| 59 | 
            -
                             | 
| 70 | 
            +
                            @env.ui.warn(I18n.t("cloud_command.box.show_filter_empty",
         | 
| 71 | 
            +
                              version: options[:version], org: org, box_name: box_name))
         | 
| 72 | 
            +
                            1
         | 
| 60 73 | 
             
                          end
         | 
| 61 | 
            -
                          results = results.delete_if { |_, v| v.nil? }
         | 
| 62 | 
            -
                          VagrantPlugins::CloudCommand::Util.format_box_results(results, @env)
         | 
| 63 | 
            -
                          return 0
         | 
| 64 | 
            -
                        rescue VagrantCloud::ClientError => e
         | 
| 65 | 
            -
                          @env.ui.error(I18n.t("cloud_command.errors.box.show_fail", org: org,box_name:box_name))
         | 
| 66 | 
            -
                          @env.ui.error(e)
         | 
| 67 | 
            -
                          return 1
         | 
| 68 74 | 
             
                        end
         | 
| 75 | 
            +
                      rescue VagrantCloud::Error => e
         | 
| 76 | 
            +
                        @env.ui.error(I18n.t("cloud_command.errors.box.show_fail", org: org,box_name:box_name))
         | 
| 77 | 
            +
                        @env.ui.error(e.message)
         | 
| 78 | 
            +
                        1
         | 
| 69 79 | 
             
                      end
         | 
| 70 80 | 
             
                    end
         | 
| 71 81 | 
             
                  end
         | 
| @@ -5,6 +5,8 @@ module VagrantPlugins | |
| 5 5 | 
             
                module BoxCommand
         | 
| 6 6 | 
             
                  module Command
         | 
| 7 7 | 
             
                    class Update < Vagrant.plugin("2", :command)
         | 
| 8 | 
            +
                      include Util
         | 
| 9 | 
            +
             | 
| 8 10 | 
             
                      def execute
         | 
| 9 11 | 
             
                        options = {}
         | 
| 10 12 |  | 
| @@ -19,13 +21,10 @@ module VagrantPlugins | |
| 19 21 | 
             
                          o.on("-d", "--description DESCRIPTION", "Full description of the box") do |d|
         | 
| 20 22 | 
             
                            options[:description] = d
         | 
| 21 23 | 
             
                          end
         | 
| 22 | 
            -
                          o.on("-u", "--username", "The username of the organization that will own the box") do |u|
         | 
| 23 | 
            -
                            options[:username] = u
         | 
| 24 | 
            -
                          end
         | 
| 25 24 | 
             
                          o.on("-s", "--short-description DESCRIPTION", "Short description of the box") do |s|
         | 
| 26 | 
            -
                            options[: | 
| 25 | 
            +
                            options[:short] = s
         | 
| 27 26 | 
             
                          end
         | 
| 28 | 
            -
                          o.on("-p", "--private", "Makes box private") do |p|
         | 
| 27 | 
            +
                          o.on("-p", "--[no-]private", "Makes box private") do |p|
         | 
| 29 28 | 
             
                            options[:private] = p
         | 
| 30 29 | 
             
                          end
         | 
| 31 30 | 
             
                        end
         | 
| @@ -33,36 +32,45 @@ module VagrantPlugins | |
| 33 32 | 
             
                        # Parse the options
         | 
| 34 33 | 
             
                        argv = parse_options(opts)
         | 
| 35 34 | 
             
                        return if !argv
         | 
| 36 | 
            -
                        if argv.empty? || argv.length > 1 || options.length == 0
         | 
| 35 | 
            +
                        if argv.empty? || argv.length > 1 || options.slice(:description, :short, :private).length == 0
         | 
| 37 36 | 
             
                          raise Vagrant::Errors::CLIInvalidUsage,
         | 
| 38 37 | 
             
                            help: opts.help.chomp
         | 
| 39 38 | 
             
                        end
         | 
| 40 39 |  | 
| 41 | 
            -
                        @client =  | 
| 42 | 
            -
                         | 
| 40 | 
            +
                        @client = client_login(@env)
         | 
| 41 | 
            +
                        org, box_name = argv.first.split('/', 2)
         | 
| 43 42 |  | 
| 44 | 
            -
                        update_box( | 
| 43 | 
            +
                        update_box(org, box_name, @client.token, options.slice(:short, :description, :private))
         | 
| 45 44 | 
             
                      end
         | 
| 46 45 |  | 
| 47 | 
            -
                       | 
| 48 | 
            -
             | 
| 49 | 
            -
             | 
| 50 | 
            -
             | 
| 51 | 
            -
             | 
| 52 | 
            -
             | 
| 53 | 
            -
             | 
| 54 | 
            -
             | 
| 55 | 
            -
             | 
| 46 | 
            +
                      # Update an existing box
         | 
| 47 | 
            +
                      #
         | 
| 48 | 
            +
                      # @param [String] org Organization name of box
         | 
| 49 | 
            +
                      # @param [String] box_name Name of box
         | 
| 50 | 
            +
                      # @param [String] access_token User access token
         | 
| 51 | 
            +
                      # @param [Hash] options Options for box filtering
         | 
| 52 | 
            +
                      # @option options [String] :short Short description of box
         | 
| 53 | 
            +
                      # @option options [String] :description Full description of box
         | 
| 54 | 
            +
                      # @option options [Boolean] :private Set box visibility as private
         | 
| 55 | 
            +
                      # @return [Integer]
         | 
| 56 | 
            +
                      def update_box(org, box_name, access_token, options={})
         | 
| 57 | 
            +
                        account = VagrantCloud::Account.new(
         | 
| 58 | 
            +
                          custom_server: api_server_url,
         | 
| 59 | 
            +
                          access_token: access_token
         | 
| 60 | 
            +
                        )
         | 
| 61 | 
            +
                        with_box(account: account, org: org, box: box_name) do |box|
         | 
| 62 | 
            +
                          box.short_description = options[:short] if options.key?(:short)
         | 
| 63 | 
            +
                          box.description = options[:description] if options.key?(:description)
         | 
| 64 | 
            +
                          box.private = options[:private] if options.key?(:private)
         | 
| 65 | 
            +
                          box.save
         | 
| 56 66 | 
             
                          @env.ui.success(I18n.t("cloud_command.box.update_success", org: org, box_name: box_name))
         | 
| 57 | 
            -
                           | 
| 58 | 
            -
                           | 
| 59 | 
            -
                          return 0
         | 
| 60 | 
            -
                        rescue VagrantCloud::ClientError => e
         | 
| 61 | 
            -
                          @env.ui.error(I18n.t("cloud_command.errors.box.update_fail", org: org, box_name: box_name))
         | 
| 62 | 
            -
                          @env.ui.error(e)
         | 
| 63 | 
            -
                          return 1
         | 
| 67 | 
            +
                          format_box_results(box, @env)
         | 
| 68 | 
            +
                          0
         | 
| 64 69 | 
             
                        end
         | 
| 65 | 
            -
             | 
| 70 | 
            +
                      rescue VagrantCloud::Error => e
         | 
| 71 | 
            +
                        @env.ui.error(I18n.t("cloud_command.errors.box.update_fail", org: org, box_name: box_name))
         | 
| 72 | 
            +
                        @env.ui.error(e.message)
         | 
| 73 | 
            +
                        1
         | 
| 66 74 | 
             
                      end
         | 
| 67 75 | 
             
                    end
         | 
| 68 76 | 
             
                  end
         | 
| @@ -1,4 +1,3 @@ | |
| 1 | 
            -
            require "rest_client"
         | 
| 2 1 | 
             
            require "vagrant_cloud"
         | 
| 3 2 | 
             
            require "vagrant/util/downloader"
         | 
| 4 3 | 
             
            require "vagrant/util/presence"
         | 
| @@ -7,6 +6,13 @@ require Vagrant.source_root.join("plugins/commands/cloud/errors") | |
| 7 6 | 
             
            module VagrantPlugins
         | 
| 8 7 | 
             
              module CloudCommand
         | 
| 9 8 | 
             
                class Client
         | 
| 9 | 
            +
                  # @private
         | 
| 10 | 
            +
                  # Reset the cached values for scrubber. This is not considered a public
         | 
| 11 | 
            +
                  # API and should only be used for testing.
         | 
| 12 | 
            +
                  def self.reset!
         | 
| 13 | 
            +
                    class_variables.each(&method(:remove_class_variable))
         | 
| 14 | 
            +
                  end
         | 
| 15 | 
            +
             | 
| 10 16 | 
             
                  ######################################################################
         | 
| 11 17 | 
             
                  # Class that deals with managing users 'local' token for Vagrant Cloud
         | 
| 12 18 | 
             
                  ######################################################################
         | 
| @@ -14,6 +20,7 @@ module VagrantPlugins | |
| 14 20 |  | 
| 15 21 | 
             
                  include Vagrant::Util::Presence
         | 
| 16 22 |  | 
| 23 | 
            +
                  attr_accessor :client
         | 
| 17 24 | 
             
                  attr_accessor :username_or_email
         | 
| 18 25 | 
             
                  attr_accessor :password
         | 
| 19 26 | 
             
                  attr_reader :two_factor_default_delivery_method
         | 
| @@ -25,6 +32,7 @@ module VagrantPlugins | |
| 25 32 | 
             
                  def initialize(env)
         | 
| 26 33 | 
             
                    @logger = Log4r::Logger.new("vagrant::cloud::client")
         | 
| 27 34 | 
             
                    @env    = env
         | 
| 35 | 
            +
                    @client = VagrantCloud::Client.new(access_token: token)
         | 
| 28 36 | 
             
                  end
         | 
| 29 37 |  | 
| 30 38 | 
             
                  # Removes the token, effectively logging the user out.
         | 
| @@ -38,14 +46,11 @@ module VagrantPlugins | |
| 38 46 | 
             
                  #
         | 
| 39 47 | 
             
                  # @return [Boolean]
         | 
| 40 48 | 
             
                  def logged_in?
         | 
| 41 | 
            -
                     | 
| 42 | 
            -
                     | 
| 43 | 
            -
                    Vagrant::Util::CredentialScrubber.sensitive(token)
         | 
| 49 | 
            +
                    return false if !client.access_token
         | 
| 50 | 
            +
                    Vagrant::Util::CredentialScrubber.sensitive(client.access_token)
         | 
| 44 51 |  | 
| 45 52 | 
             
                    with_error_handling do
         | 
| 46 | 
            -
                       | 
| 47 | 
            -
                        "?access_token=#{token}"
         | 
| 48 | 
            -
                      RestClient.get(url, content_type: :json)
         | 
| 53 | 
            +
                      client.authentication_token_validate
         | 
| 49 54 | 
             
                      true
         | 
| 50 55 | 
             
                    end
         | 
| 51 56 | 
             
                  rescue Errors::Unauthorized
         | 
| @@ -62,23 +67,14 @@ module VagrantPlugins | |
| 62 67 | 
             
                    @logger.info("Logging in '#{username_or_email}'")
         | 
| 63 68 |  | 
| 64 69 | 
             
                    Vagrant::Util::CredentialScrubber.sensitive(password)
         | 
| 65 | 
            -
                     | 
| 66 | 
            -
                       | 
| 67 | 
            -
                         | 
| 68 | 
            -
             | 
| 69 | 
            -
             | 
| 70 | 
            -
             | 
| 71 | 
            -
             | 
| 72 | 
            -
             | 
| 73 | 
            -
                        },
         | 
| 74 | 
            -
                        two_factor: {
         | 
| 75 | 
            -
                          code: code
         | 
| 76 | 
            -
                        }
         | 
| 77 | 
            -
                      }
         | 
| 78 | 
            -
                    )
         | 
| 79 | 
            -
             | 
| 80 | 
            -
                    Vagrant::Util::CredentialScrubber.sensitive(response["token"])
         | 
| 81 | 
            -
                    response["token"]
         | 
| 70 | 
            +
                    with_error_handling do
         | 
| 71 | 
            +
                      r = client.authentication_token_create(username: username_or_email,
         | 
| 72 | 
            +
                        password: password, description: description, code: code)
         | 
| 73 | 
            +
             | 
| 74 | 
            +
                      Vagrant::Util::CredentialScrubber.sensitive(r[:token])
         | 
| 75 | 
            +
                      @client = VagrantCloud::Client.new(access_token: r[:token])
         | 
| 76 | 
            +
                      r[:token]
         | 
| 77 | 
            +
                    end
         | 
| 82 78 | 
             
                  end
         | 
| 83 79 |  | 
| 84 80 | 
             
                  # Requests a 2FA code
         | 
| @@ -87,50 +83,14 @@ module VagrantPlugins | |
| 87 83 | 
             
                    @env.ui.warn("Requesting 2FA code via #{delivery_method.upcase}...")
         | 
| 88 84 |  | 
| 89 85 | 
             
                    Vagrant::Util::CredentialScrubber.sensitive(password)
         | 
| 90 | 
            -
                    response = post(
         | 
| 91 | 
            -
                      "/api/v1/two-factor/request-code", {
         | 
| 92 | 
            -
                        user: {
         | 
| 93 | 
            -
                          login: username_or_email,
         | 
| 94 | 
            -
                          password: password
         | 
| 95 | 
            -
                        },
         | 
| 96 | 
            -
                        two_factor: {
         | 
| 97 | 
            -
                          delivery_method: delivery_method.downcase
         | 
| 98 | 
            -
                        }
         | 
| 99 | 
            -
                      }
         | 
| 100 | 
            -
                    )
         | 
| 101 | 
            -
             | 
| 102 | 
            -
                    two_factor = response['two_factor']
         | 
| 103 | 
            -
                    obfuscated_destination = two_factor['obfuscated_destination']
         | 
| 104 | 
            -
             | 
| 105 | 
            -
                    @env.ui.success("2FA code sent to #{obfuscated_destination}.")
         | 
| 106 | 
            -
                  end
         | 
| 107 | 
            -
             | 
| 108 | 
            -
                  # Issues a post to a Vagrant Cloud path with the given payload.
         | 
| 109 | 
            -
                  # @param [String] path
         | 
| 110 | 
            -
                  # @param [Hash] payload
         | 
| 111 | 
            -
                  # @return [Hash] response data
         | 
| 112 | 
            -
                  def post(path, payload)
         | 
| 113 86 | 
             
                    with_error_handling do
         | 
| 114 | 
            -
                       | 
| 115 | 
            -
             | 
| 116 | 
            -
             | 
| 117 | 
            -
                       | 
| 118 | 
            -
                       | 
| 119 | 
            -
             | 
| 120 | 
            -
             | 
| 121 | 
            -
                      response = RestClient::Request.execute(
         | 
| 122 | 
            -
                        method: :post,
         | 
| 123 | 
            -
                        url: url,
         | 
| 124 | 
            -
                        payload: JSON.dump(payload),
         | 
| 125 | 
            -
                        proxy: proxy,
         | 
| 126 | 
            -
                        headers: {
         | 
| 127 | 
            -
                          accept: :json,
         | 
| 128 | 
            -
                          content_type: :json,
         | 
| 129 | 
            -
                          user_agent: Vagrant::Util::Downloader::USER_AGENT,
         | 
| 130 | 
            -
                        },
         | 
| 131 | 
            -
                      )
         | 
| 132 | 
            -
             | 
| 133 | 
            -
                      JSON.load(response.to_s)
         | 
| 87 | 
            +
                      r = client.authentication_request_2fa_code(
         | 
| 88 | 
            +
                        username: username_or_email, password: password, delivery_method: delivery_method)
         | 
| 89 | 
            +
             | 
| 90 | 
            +
                      two_factor = r[:two_factor]
         | 
| 91 | 
            +
                      obfuscated_destination = two_factor[:obfuscated_destination]
         | 
| 92 | 
            +
             | 
| 93 | 
            +
                      @env.ui.success("2FA code sent to #{obfuscated_destination}.")
         | 
| 134 94 | 
             
                    end
         | 
| 135 95 | 
             
                  end
         | 
| 136 96 |  | 
| @@ -138,12 +98,16 @@ module VagrantPlugins | |
| 138 98 | 
             
                  #
         | 
| 139 99 | 
             
                  # @param [String] token
         | 
| 140 100 | 
             
                  def store_token(token)
         | 
| 101 | 
            +
                    Vagrant::Util::CredentialScrubber.sensitive(token)
         | 
| 141 102 | 
             
                    @logger.info("Storing token in #{token_path}")
         | 
| 142 103 |  | 
| 143 104 | 
             
                    token_path.open("w") do |f|
         | 
| 144 105 | 
             
                      f.write(token)
         | 
| 145 106 | 
             
                    end
         | 
| 146 107 |  | 
| 108 | 
            +
                    # Reset after we store the token since this is now _our_ token
         | 
| 109 | 
            +
                    @client = VagrantCloud::Client.new(access_token: token)
         | 
| 110 | 
            +
             | 
| 147 111 | 
             
                    nil
         | 
| 148 112 | 
             
                  end
         | 
| 149 113 |  | 
| @@ -154,7 +118,9 @@ module VagrantPlugins | |
| 154 118 | 
             
                  # @return [String]
         | 
| 155 119 | 
             
                  def token
         | 
| 156 120 | 
             
                    if present?(ENV["VAGRANT_CLOUD_TOKEN"]) && token_path.exist?
         | 
| 157 | 
            -
                       | 
| 121 | 
            +
                      # Only show warning if it has not been previously shown
         | 
| 122 | 
            +
                      if !defined?(@@double_token_warning)
         | 
| 123 | 
            +
                        @env.ui.warn <<-EOH.strip
         | 
| 158 124 | 
             
            Vagrant detected both the VAGRANT_CLOUD_TOKEN environment variable and a Vagrant login
         | 
| 159 125 | 
             
            token are present on this system. The VAGRANT_CLOUD_TOKEN environment variable takes
         | 
| 160 126 | 
             
            precedence over the locally stored token. To remove this error, either unset
         | 
| @@ -163,21 +129,24 @@ the VAGRANT_CLOUD_TOKEN environment variable or remove the login token stored on | |
| 163 129 | 
             
                ~/.vagrant.d/data/vagrant_login_token
         | 
| 164 130 |  | 
| 165 131 | 
             
            EOH
         | 
| 132 | 
            +
                        @@double_token_warning = true
         | 
| 133 | 
            +
                      end
         | 
| 166 134 | 
             
                    end
         | 
| 167 135 |  | 
| 168 136 | 
             
                    if present?(ENV["VAGRANT_CLOUD_TOKEN"])
         | 
| 169 137 | 
             
                      @logger.debug("Using authentication token from environment variable")
         | 
| 170 | 
            -
                       | 
| 171 | 
            -
                     | 
| 172 | 
            -
             | 
| 173 | 
            -
                    if token_path.exist?
         | 
| 138 | 
            +
                      t = ENV["VAGRANT_CLOUD_TOKEN"]
         | 
| 139 | 
            +
                    elsif token_path.exist?
         | 
| 174 140 | 
             
                      @logger.debug("Using authentication token from disk at #{token_path}")
         | 
| 175 | 
            -
                       | 
| 141 | 
            +
                      t = token_path.read.strip
         | 
| 142 | 
            +
                    elsif present?(ENV["ATLAS_TOKEN"])
         | 
| 143 | 
            +
                      @logger.warn("ATLAS_TOKEN detected within environment. Using ATLAS_TOKEN in place of VAGRANT_CLOUD_TOKEN.")
         | 
| 144 | 
            +
                      t = ENV["ATLAS_TOKEN"]
         | 
| 176 145 | 
             
                    end
         | 
| 177 146 |  | 
| 178 | 
            -
                    if  | 
| 179 | 
            -
                       | 
| 180 | 
            -
                      return  | 
| 147 | 
            +
                    if !t.nil?
         | 
| 148 | 
            +
                      Vagrant::Util::CredentialScrubber.sensitive(t)
         | 
| 149 | 
            +
                      return t
         | 
| 181 150 | 
             
                    end
         | 
| 182 151 |  | 
| 183 152 | 
             
                    @logger.debug("No authentication token in environment or #{token_path}")
         | 
| @@ -189,22 +158,22 @@ EOH | |
| 189 158 |  | 
| 190 159 | 
             
                  def with_error_handling(&block)
         | 
| 191 160 | 
             
                    yield
         | 
| 192 | 
            -
                  rescue  | 
| 161 | 
            +
                  rescue Excon::Error::Unauthorized
         | 
| 193 162 | 
             
                    @logger.debug("Unauthorized!")
         | 
| 194 163 | 
             
                    raise Errors::Unauthorized
         | 
| 195 | 
            -
                  rescue  | 
| 164 | 
            +
                  rescue Excon::Error::BadRequest => e
         | 
| 196 165 | 
             
                    @logger.debug("Bad request:")
         | 
| 197 166 | 
             
                    @logger.debug(e.message)
         | 
| 198 167 | 
             
                    @logger.debug(e.backtrace.join("\n"))
         | 
| 199 | 
            -
                    parsed_response = JSON.parse(e.response)
         | 
| 168 | 
            +
                    parsed_response = JSON.parse(e.response.body)
         | 
| 200 169 | 
             
                    errors = parsed_response["errors"].join("\n")
         | 
| 201 170 | 
             
                    raise Errors::ServerError, errors: errors
         | 
| 202 | 
            -
                  rescue  | 
| 171 | 
            +
                  rescue Excon::Error::NotAcceptable => e
         | 
| 203 172 | 
             
                    @logger.debug("Got unacceptable response:")
         | 
| 204 173 | 
             
                    @logger.debug(e.message)
         | 
| 205 174 | 
             
                    @logger.debug(e.backtrace.join("\n"))
         | 
| 206 175 |  | 
| 207 | 
            -
                    parsed_response = JSON.parse(e.response)
         | 
| 176 | 
            +
                    parsed_response = JSON.parse(e.response.body)
         | 
| 208 177 |  | 
| 209 178 | 
             
                    if two_factor = parsed_response['two_factor']
         | 
| 210 179 | 
             
                      store_two_factor_information two_factor
         |