Repository: conda/conda

Issue:
Bug: Authenticated channels broken when using conda_env create.
<!--
Hi!

This is an issue tracker for conda -- the package manager.  File feature requests
for conda here, as well as bug reports about something conda has messed up.

If your issue is a bug report or feature request for:
  * a specific conda package from Anaconda ('defaults' channel):
      ==> file at https://github.com/ContinuumIO/anaconda-issues
  * a specific conda package from conda-forge:
      ==> file at the corresponding feedstock under https://github.com/conda-forge
  * repo.continuum.io access and service:
      ==> file at https://github.com/ContinuumIO/anaconda-issues
  * anaconda.org access and service:
      ==> file at https://anaconda.org/contact/report
  * commands under 'conda build':
      ==> file at https://github.com/conda/conda-build
  * commands under 'conda env':
      ==> please file it here!
  * all other conda commands that start with 'conda':
      ==> please file it here!

-->

**I'm submitting a...**
  - [x] bug report
  - [ ] feature request


### Current Behavior
Found two issues in Conda 4.4.x, which I believe are related so I've included them in the same ticket:
* `conda env create` ignores the authentication component of channels (as well as other components).
    * When `conda env create` is run, the authentication component is skipped, causing `PackageNotFound` errors to be generated for private packages.
* `conda env create` does not respect the channel priority flag available in the context (based off of expected behavior defined here: https://conda.io/docs/user-guide/tasks/manage-channels.html#after-conda-4-1-0)
    * When `conda env create` is run, channels with the same name are truncated before they reach the `Solver`; the `Solver` only receives the highest priority channel. This is not consistent with the channel priority behavior outlined above.

The problem appears to be happening with these 3 lines of code in the `conda` installer in the `conda_env`package: https://github.com/conda/conda/blob/master/conda_env/installers/conda.py#L31-L33

In that code, all of the channels retrieved from the `_channel_priority_map` are instantiated to `Channel` classes and then immediately truncated based on canonical name (for authed channels, this is only the channel name, with the token excluded). 

### Steps to Reproduce
For the first issue, using this environment file (`authed.yaml`, NOTE: that you will need to replace the channel with a private channel you control):
```yaml
name: authed_env
channels:
  - https://conda.anaconda.org/t/<TOKEN>/<CHANNEL>
dependencies:
  - private_package
```
Run the following command and get:
```bash
$ conda env create -n authed_env -f authed.yaml
Solving environment: failed

ResolvePackageNotFound:
  - private_package
```

For the second issue, using this environment file (`priority.yaml`)
```yaml
name: priority_env
channels:
  - nextdoor
  - https://conda.anaconda.org/t/<TOKEN>/<CHANNEL>
dependencies:
  - private_package
```
And this `.condarc`
```yaml
channel_priority: false
```
Run this command and get.
```bash
$ conda env create -n priority_env -f priority.yaml
Solving environment: failed

ResolvePackageNotFound:
  - private_package
```
This second is a little hidden because of the authenticated channel issue, but it's again caused by the `canonical_name` truncation.


### Expected Behavior
<!-- What do you think should happen? -->
* `conda env create` should allow environment files and `condarc` files to use authenticated channels (by respecting the full URL). 
* The command should also not truncate channels that it passes to the `Solver`. This is not behavior that is exhibited in other areas where `Solver` is instantiated.

As a note, the expected behavior did successfully occur in the latest 4.3.x release.

##### `conda info`
<!-- between the ticks below, paste the output of 'conda info' -->
```
     active environment : nextdoor
    active env location : /var/lib/conda/envs/nextdoor
            shell level : 1
       user config file : /home/vagrant/.condarc
 populated config files : /home/vagrant/.condarc
          conda version : 4.4.7
    conda-build version : not installed
         python version : 3.6.3.final.0
       base environment : /var/lib/conda  (writable)
           channel URLs : https://repo.continuum.io/pkgs/main/linux-64
                          https://repo.continuum.io/pkgs/main/noarch
                          https://repo.continuum.io/pkgs/free/linux-64
                          https://repo.continuum.io/pkgs/free/noarch
                          https://repo.continuum.io/pkgs/r/linux-64
                          https://repo.continuum.io/pkgs/r/noarch
                          https://repo.continuum.io/pkgs/pro/linux-64
                          https://repo.continuum.io/pkgs/pro/noarch
          package cache : /var/lib/conda/pkgs
                          /home/vagrant/.conda/pkgs
       envs directories : /var/lib/conda/envs
                          /home/vagrant/.conda/envs
               platform : linux-64
             user-agent : conda/4.4.7 requests/2.18.4 CPython/3.6.3 Linux/3.8.0-44-generic ubuntu/12.04 glibc/2.19
                UID:GID : 1000:1000
             netrc file : None
           offline mode : False
```


##### `conda config --show-sources`
<!-- between the ticks below, paste the output of 'conda config --show-sources' -->
```
==> /home/vagrant/.condarc <==
channel_priority: False
channels:
  - defaults
```


##### `conda list --show-channel-urls`
<!-- between the ticks below, paste the output of 'conda list --show-channel-urls' -->
```
# packages in environment at /var/lib/conda:
#
asn1crypto                0.23.0           py36h4639342_0    defaults
ca-certificates           2017.08.26           h1d4fec5_0    defaults
certifi                   2017.11.5        py36hf29ccca_0    defaults
cffi                      1.11.2           py36h2825082_0    defaults
chardet                   3.0.4            py36h0f667ec_1    defaults
conda                     4.4.7                    py36_0    defaults
conda-env                 2.6.0                h36134e3_1    defaults
cryptography              2.1.4            py36hd09be54_0    defaults
idna                      2.6              py36h82fb2a8_1    defaults
libedit                   3.1                  heed3624_0    defaults
libffi                    3.2.1                hd88cf55_4    defaults
libgcc-ng                 7.2.0                h7cc24e2_2    defaults
libstdcxx-ng              7.2.0                h7a57d05_2    defaults
ncurses                   6.0                  h9df7e31_2    defaults
openssl                   1.0.2n               hb7f436b_0    defaults
pip                       9.0.1            py36h6c6f9ce_4    defaults
pycosat                   0.6.3            py36h0a5515d_0    defaults
pycparser                 2.18             py36hf9f622e_1    defaults
pyopenssl                 17.5.0           py36h20ba746_0    defaults
pysocks                   1.6.7            py36hd97a5b1_1    defaults
python                    3.6.3                h6c0c0dc_5    defaults
readline                  7.0                  ha6073c6_4    defaults
requests                  2.18.4           py36he2e5f8d_1    defaults
ruamel_yaml               0.11.14          py36ha2fb22d_2    defaults
setuptools                36.5.0           py36he42e2e1_0    defaults
six                       1.11.0           py36h372c433_1    defaults
sqlite                    3.20.1               hb898158_2    defaults
tk                        8.6.7                hc745277_3    defaults
urllib3                   1.22             py36hbe7ace6_0    defaults
wheel                     0.30.0           py36hfd4bba0_1    defaults
xz                        5.2.3                h55aa19d_2    defaults
yaml                      0.1.7                had09818_2    defaults
zlib                      1.2.11               ha838bed_2    defaults
```



Discussion:

Resolving patch:
diff --git a/conda_env/installers/conda.py b/conda_env/installers/conda.py
--- a/conda_env/installers/conda.py
+++ b/conda_env/installers/conda.py
@@ -28,8 +28,7 @@ def install(prefix, specs, args, env, *_, **kwargs):
         channel_urls.extend(context.channels)
     _channel_priority_map = prioritize_channels(channel_urls)
 
-    channel_names = IndexedSet(Channel(url).canonical_name for url in _channel_priority_map)
-    channels = IndexedSet(Channel(cn) for cn in channel_names)
+    channels = IndexedSet(Channel(url) for url in _channel_priority_map)
     subdirs = IndexedSet(basename(url) for url in _channel_priority_map)
 
     solver = Solver(prefix, channels, subdirs, specs_to_add=specs)


Test patch: