From: Chris Roberts <code@chrisroberts.org>
Date: Sun, 25 Feb 2018 21:53:24 -0300
Subject: Convert atlas references to vagrant cloud

Backported-by: Antonio Terceiro <terceiro@debian.org>
---
 lib/vagrant/shared_helpers.rb                       |  4 ++--
 plugins/commands/box/command/add.rb                 |  2 +-
 plugins/commands/login/client.rb                    | 21 ++++++++++++---------
 plugins/commands/login/command.rb                   |  8 ++++----
 plugins/commands/login/locales/en.yml               | 10 +++++-----
 .../commands/login/middleware/add_authentication.rb |  3 ++-
 plugins/commands/login/plugin.rb                    |  2 +-
 templates/commands/init/Vagrantfile.erb             |  9 +--------
 templates/locales/en.yml                            |  8 ++++----
 test/unit/plugins/commands/login/client_test.rb     |  4 ++--
 10 files changed, 34 insertions(+), 37 deletions(-)

diff --git a/lib/vagrant/shared_helpers.rb b/lib/vagrant/shared_helpers.rb
index ffe61e5..93f4c11 100644
--- a/lib/vagrant/shared_helpers.rb
+++ b/lib/vagrant/shared_helpers.rb
@@ -5,12 +5,12 @@ require "thread"
 module Vagrant
   @@global_lock = Mutex.new
 
-  # This is the default endpoint of the Atlas in
+  # This is the default endpoint of the Vagrant Cloud in
   # use. API calls will be made to this for various functions
   # of Vagrant that may require remote access.
   #
   # @return [String]
-  DEFAULT_SERVER_URL = "https://atlas.hashicorp.com"
+  DEFAULT_SERVER_URL = "https://vagrantcloud.com"
 
   # This holds a global lock for the duration of the block. This should
   # be invoked around anything that is modifying process state (such as
diff --git a/plugins/commands/box/command/add.rb b/plugins/commands/box/command/add.rb
index 5545ea2..d8ae063 100644
--- a/plugins/commands/box/command/add.rb
+++ b/plugins/commands/box/command/add.rb
@@ -40,7 +40,7 @@ module VagrantPlugins
             end
 
             o.separator ""
-            o.separator "The box descriptor can be the name of a box on HashiCorp's Atlas,"
+            o.separator "The box descriptor can be the name of a box on HashiCorp's Vagrant Cloud,"
             o.separator "or a URL, or a local .box file, or a local .json file containing"
             o.separator "the catalog metadata."
             o.separator ""
diff --git a/plugins/commands/login/client.rb b/plugins/commands/login/client.rb
index 04b6ee0..fb2dd05 100644
--- a/plugins/commands/login/client.rb
+++ b/plugins/commands/login/client.rb
@@ -86,28 +86,26 @@ module VagrantPlugins
       end
 
       # Reads the access token if there is one. This will first read the
-      # `ATLAS_TOKEN` environment variable and then fallback to the stored
+      # `VAGRANT_CLOUD_TOKEN` environment variable and then fallback to the stored
       # access token on disk.
       #
       # @return [String]
       def token
-        if present?(ENV["ATLAS_TOKEN"]) && token_path.exist?
+        if present?(ENV["VAGRANT_CLOUD_TOKEN"]) && token_path.exist?
           @env.ui.warn <<-EOH.strip
-Vagrant detected both the ATLAS_TOKEN environment variable and a Vagrant login
-token are present on this system. The ATLAS_TOKEN environment variable takes
+Vagrant detected both the VAGRANT_CLOUD_TOKEN environment variable and a Vagrant login
+token are present on this system. The VAGRANT_CLOUD_TOKEN environment variable takes
 precedence over the locally stored token. To remove this error, either unset
-the ATLAS_TOKEN environment variable or remove the login token stored on disk:
+the VAGRANT_CLOUD_TOKEN environment variable or remove the login token stored on disk:
 
     ~/.vagrant.d/data/vagrant_login_token
 
-In general, the ATLAS_TOKEN is more preferred because it is respected by all
-HashiCorp products.
 EOH
         end
 
-        if present?(ENV["ATLAS_TOKEN"])
+        if present?(ENV["VAGRANT_CLOUD_TOKEN"])
           @logger.debug("Using authentication token from environment variable")
-          return ENV["ATLAS_TOKEN"]
+          return ENV["VAGRANT_CLOUD_TOKEN"]
         end
 
         if token_path.exist?
@@ -115,6 +113,11 @@ EOH
           return token_path.read.strip
         end
 
+        if present?(ENV["ATLAS_TOKEN"])
+          @logger.warn("ATLAS_TOKEN detected within environment. Using ATLAS_TOKEN in place of VAGRANT_CLOUD_TOKEN.")
+          return ENV["ATLAS_TOKEN"]
+        end
+
         @logger.debug("No authentication token in environment or #{token_path}")
 
         nil
diff --git a/plugins/commands/login/command.rb b/plugins/commands/login/command.rb
index 203b090..040bbb0 100644
--- a/plugins/commands/login/command.rb
+++ b/plugins/commands/login/command.rb
@@ -2,7 +2,7 @@ module VagrantPlugins
   module LoginCommand
     class Command < Vagrant.plugin("2", "command")
       def self.synopsis
-        "log in to HashiCorp's Atlas"
+        "log in to HashiCorp's Vagrant Cloud"
       end
 
       def execute
@@ -19,7 +19,7 @@ module VagrantPlugins
             options[:logout] = k
           end
 
-          o.on("-t", "--token TOKEN", String, "Set the Atlas token") do |t|
+          o.on("-t", "--token TOKEN", String, "Set the Vagrant Cloud token") do |t|
             options[:token] = t
           end
         end
@@ -44,14 +44,14 @@ module VagrantPlugins
 
         # If it is a private cloud installation, show that
         if Vagrant.server_url != Vagrant::DEFAULT_SERVER_URL
-          @env.ui.output("Atlas URL: #{Vagrant.server_url}")
+          @env.ui.output("Vagrant Cloud URL: #{Vagrant.server_url}")
         end
 
         # Ask for the username
         login    = nil
         password = nil
         while !login
-          login = @env.ui.ask("Atlas Username: ")
+          login = @env.ui.ask("Vagrant Cloud Username: ")
         end
 
         while !password
diff --git a/plugins/commands/login/locales/en.yml b/plugins/commands/login/locales/en.yml
index dba4d52..d7decaf 100644
--- a/plugins/commands/login/locales/en.yml
+++ b/plugins/commands/login/locales/en.yml
@@ -2,11 +2,11 @@ en:
   login_command:
     errors:
       server_error: |-
-        The Atlas server responded with an not-OK response:
+        The Vagrant Cloud server responded with an not-OK response:
 
         %{errors}
       server_unreachable: |-
-        The Atlas server is not currently accepting connections. Please check
+        The Vagrant Cloud server is not currently accepting connections. Please check
         your network connection and try again later.
 
     check_logged_in: |-
@@ -16,12 +16,12 @@ en:
       your login information to authenticate.
     command_header: |-
       In a moment we will ask for your username and password to HashiCorp's
-      Atlas. After authenticating, we will store an access token locally on
+      Vagrant Cloud. After authenticating, we will store an access token locally on
       disk. Your login details will be transmitted over a secure connection, and
       are never stored on disk locally.
 
-      If you do not have an Atlas account, sign up at
-      https://atlas.hashicorp.com.
+      If you do not have an Vagrant Cloud account, sign up at
+      https://www.vagrantcloud.com
     invalid_login: |-
       Invalid username or password. Please try again.
     invalid_token: |-
diff --git a/plugins/commands/login/middleware/add_authentication.rb b/plugins/commands/login/middleware/add_authentication.rb
index f176e34..c82bbf6 100644
--- a/plugins/commands/login/middleware/add_authentication.rb
+++ b/plugins/commands/login/middleware/add_authentication.rb
@@ -29,7 +29,8 @@ module VagrantPlugins
               # Vagrant Cloud to Atlas. This preserves access tokens
               # appending to both without leaking access tokens to
               # unsavory URLs.
-              if u.host == VCLOUD && server_uri.host == ATLAS
+              if (u.host == VCLOUD && server_uri.host == ATLAS) ||
+                  (u.host == ATLAS && server_uri.host == VCLOUD)
                 replace = true
               end
             end
diff --git a/plugins/commands/login/plugin.rb b/plugins/commands/login/plugin.rb
index efb84a5..a231bcb 100644
--- a/plugins/commands/login/plugin.rb
+++ b/plugins/commands/login/plugin.rb
@@ -8,7 +8,7 @@ module VagrantPlugins
     class Plugin < Vagrant.plugin("2")
       name "vagrant-login"
       description <<-DESC
-      Provides the login command and internal API access to Atlas.
+      Provides the login command and internal API access to Vagrant Cloud.
       DESC
 
       command(:login) do
diff --git a/templates/commands/init/Vagrantfile.erb b/templates/commands/init/Vagrantfile.erb
index d746a71..c06a008 100644
--- a/templates/commands/init/Vagrantfile.erb
+++ b/templates/commands/init/Vagrantfile.erb
@@ -11,7 +11,7 @@ Vagrant.configure("2") do |config|
   # https://docs.vagrantup.com.
 
   # Every Vagrant development environment requires a box. You can search for
-  # boxes at https://atlas.hashicorp.com/search.
+  # boxes at https://vagrantcloud.com/search.
   config.vm.box = "<%= box_name %>"
   <% if box_version -%>
   config.vm.box_version = "<%= box_version %>"
@@ -63,13 +63,6 @@ Vagrant.configure("2") do |config|
   # View the documentation for the provider you are using for more
   # information on available options.
 
-  # Define a Vagrant Push strategy for pushing to Atlas. Other push strategies
-  # such as FTP and Heroku are also available. See the documentation at
-  # https://docs.vagrantup.com/v2/push/atlas.html for more information.
-  # config.push.define "atlas" do |push|
-  #   push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME"
-  # end
-
   # Enable provisioning with a shell script. Additional provisioners such as
   # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
   # documentation for more information about their specific syntax and use.
diff --git a/templates/locales/en.yml b/templates/locales/en.yml
index 1dc1668..b724927 100644
--- a/templates/locales/en.yml
+++ b/templates/locales/en.yml
@@ -380,7 +380,7 @@ en:
         provider. Double-check your requested provider to verify you didn't
         simply misspell it.
 
-        If you're adding a box from HashiCorp's Atlas, make sure the box is
+        If you're adding a box from HashiCorp's Vagrant Cloud, make sure the box is
         released.
 
         Name: %{name}
@@ -399,7 +399,7 @@ en:
       box_add_short_not_found: |-
         The box '%{name}' could not be found or
         could not be accessed in the remote catalog. If this is a private
-        box on HashiCorp's Atlas, please verify you're logged in via
+        box on HashiCorp's Vagrant Cloud, please verify you're logged in via
         `vagrant login`. Also, please double-check the name. The expanded
         URL and error message are shown below:
 
@@ -564,12 +564,12 @@ en:
 
         %{versions}
       box_server_not_set: |-
-        A URL to an Atlas server is not set, so boxes cannot be added with a
+        A URL to a Vagrant Cloud server is not set, so boxes cannot be added with a
         shorthand ("mitchellh/precise64") format. You may also be seeing this
         error if you meant to type in a path to a box file which doesn't exist
         locally on your system.
 
-        To set a URL to an Atlas server, set the `VAGRANT_SERVER_URL`
+        To set a URL to a Vagrant Cloud server, set the `VAGRANT_SERVER_URL`
         environmental variable. Or, if you meant to use a file path, make sure
         the path to the file is valid.
       box_update_multi_provider: |-
diff --git a/test/unit/plugins/commands/login/client_test.rb b/test/unit/plugins/commands/login/client_test.rb
index d8d744e..86c53da 100644
--- a/test/unit/plugins/commands/login/client_test.rb
+++ b/test/unit/plugins/commands/login/client_test.rb
@@ -107,13 +107,13 @@ describe VagrantPlugins::LoginCommand::Client do
     end
 
     it "prefers the environment variable" do
-      stub_env("ATLAS_TOKEN" => "ABCD1234")
+      stub_env("VAGRANT_CLOUD_TOKEN" => "ABCD1234")
       subject.store_token("EFGH5678")
       expect(subject.token).to eq("ABCD1234")
     end
 
     it "prints a warning if the envvar and stored file are both present" do
-      stub_env("ATLAS_TOKEN" => "ABCD1234")
+      stub_env("VAGRANT_CLOUD_TOKEN" => "ABCD1234")
       subject.store_token("EFGH5678")
       expect(env.ui).to receive(:warn).with(/detected both/)
       subject.token
