==========================================
Connecting Navigator to other repositories
==========================================

.. note::
   
   * Business (Cloud) has recently been renamed to Package Security Manager (Cloud).
   * Anaconda Server (Business On-Prem) has recently been renamed to Package Security Manager (On-prem).

Navigator integrates with Anaconda's free, public repository and premium, curated repository through different connection points. For more information, see our `pricing page <https://www.anaconda.com/pricing/?utm_campaign=pricing&utm_medium=documentation&utm_source=anacondadocs&utm_content=repoconnect>`_.

.. note::

   You can only be signed into one repository service at a time. However, you can be signed into Anaconda Cloud while also signed into a repository service.

How to connect to other repositories
====================================

This guide takes you through the connection setup for Package Security Manager (Cloud and On-prem) and Anaconda Enterprise 4:

.. tab-set::
    
    .. tab-item:: PSM (Cloud)

       .. note::

          The Anaconda Professional sign in is used for both Anaconda Professional and Package Security Manager (Cloud) connections.

       #. Click **Connect** in the top-right corner of the Navigator application.
       #. **Sign in** to *Anaconda Professional*.
       #. Enter your token to log in to your Pro/Package Security Manager instance.

          .. dropdown:: Where is my token?
             :color: primary
             :animate: fade-in

             You can issue yourself a *private* access token from the |key| **Token Access** page of your Anaconda Cloud organization. You must be assigned a seat to issue yourself a token. If you've lost your token, you can re-issue yourself a new token at any time. Re-issuing a token invalidates the previous token.

             For more information, see :ref:`Authenticating to Anaconda <psm-cloud-authenticating-to-anaconda>` in the Package Security Manager (Cloud) quickstart.

       #. Click **Set Token**. If your token is valid, you will be signed in.

          .. thumbnail:: ../img/nav-pro-token.png
             :align: center

         .. note::
            For more information on adding channels from your Package Security Manager (Cloud) repo to Navigator, see :ref:`Adding an organization channel to your .condarc file <psm-cloud-organization-channel>` in the Package Security Manager (Cloud) documentation.

    .. tab-item:: PSM (On-prem)

       .. note::

          The Anaconda Server sign in is the connection for Package Security Manager (On-prem).
       
       #. Click **Connect** in the top-right corner of the Navigator application.
       #. **Sign in** to *Anaconda Server*.
       #. If this is your first time logging in, enter your Anaconda Server domain and click **Set Domain**.
       
          .. thumbnail:: ../img/nav-server-domain.png
             :align: center

       #. Enter the credentials you use to log in to your Anaconda Server instance.
       #. Click **Login**. If all credentials are correct, you will be signed in.

          .. thumbnail:: ../img/nav-server-sign-in.png
             :align: center

       .. dropdown:: (Optional) Add channels from your Server instance to Navigator
          :color: primary
          :animate: fade-in
         
          After signing in, select channels from the repository integration to use with Navigator.

          #. Select **Add to channels** to add each channel to the ``channels:`` list in your ``.condarc`` file. 
          #. Select **Add to default_channels** to add each channel to your default channels.
          #. Click **Add channels** to save your selections.

             .. thumbnail:: ../img/nav-server-channels.png
                :align: center
        
       .. note::

          The Anaconda Server connection also has a **Sign in with SSO** option. For more information on setting up an SSO connection for Package Security Manager (On-prem) using Okta, see `Okta integration using OIDC <https://business-docs.anaconda.com/en/latest/admin/Keycloak_config/okta.html>`_.

    .. tab-item:: AE4

       #. Click **Connect** in the top right corner of the Navigator application.
       #. **Sign in** to *Enterprise 4 Repository*.
       #. If this is your first time logging in, enter your Enterprise 4 domain and click **Set Domain**.

          .. caution::
             The domain must be a full path without a trailing slash. For example: ``http(s)://enterprise-mysite.com``
  
          .. thumbnail:: ../img/nav-enterprise-edition-2.png
             :align: center

       #. Enter the credentials you use to log in to your Enterprise 4 platform.
       #. Click **Login**. If all credentials are correct, you will be signed in.
  
          .. thumbnail:: ../img/nav-enterprise-edition-3.png
             :align: center

       #. A message appears asking you to manually add channels to Navigator.

What happens when you connect to a repository
=============================================

Navigator performs a few actions for you automatically when you connect to your repository:

.. tab-set::

   .. tab-item:: Pro/Package Security Manager

      * The ``conda-token`` tool sets your supplied organization token and automatically manages ``default_channels``.

   .. tab-item:: Server

      * The ``conda-repo-cli`` tool creates a private token for you.
      * Navigator sets the private token in the Navigator config file (``anaconda-navigator.ini``) file. See :ref:`Anaconda Server token authentication <anaconda-server-token-auth>`.
      * Navigator modifies the conda configuration file (``.condarc``):
        
        * ``channels`` is set to an empty list
        * ``default_channels``, if present, is removed
      
      * Navigator asks you to manage your channels and default channels.
   
   .. tab-item:: Enterprise 4

      * Navigator uses a private token managed by ``anaconda-client`` to log in.
      * Navigator modifies the conda configuration file (``.condarc``):
        
        * ``channels`` is set to an empty list so you can set appropriate channels
        * ``default_channels``, if present, is removed

.. note::
   If you have already logged in to your repository using a CLI, Navigator detects that when it opens and shows a connection to that repository automatically. If you log out from your repository connection in Navigator, your CLI session is also affected accordingly.

.. _anaconda-server-token-auth:

Anaconda Server token authentication
====================================

Your access token for Anaconda Server provides you with the ability to access your own private server channel. The access token is stored locally, which gives conda native access to your remote channel and packages.

  .. thumbnail:: ../img/nav-server-token.png
     :align: center

.. note::

   To use other's private channels in Anaconda Server, see `Setting/using a token <https://business-docs.anaconda.com/en/latest/user/auth_token.html#setting-using-a-token>`_ in the Anaconda Server documentation.

The variables ``anaconda_server_token`` and ``anaconda_server_token_id`` in the Navigator config file (``anaconda-navigator.ini``) are also updated when you first connect to Anaconda Server. This is mostly system data to help Navigator integrate with Anaconda Server.

  .. thumbnail:: ../img/nav-server-config.png
     :align: center

  .. caution:: 
     The token and token ID config variable names have been updated from ``team_edition_token`` to ``anaconda_server_token`` and ``team _edition_token_id`` to ``anaconda_server_token_id`` as of Version 2.4.0. If you downgrade your Navigator application to a version older than 2.3.0, you will need to manually change these variable names back to their older versions within your ``anaconda-navigator.ini`` file.

Changing the repository connection domain
=========================================

When you first connect Navigator to a Server or Anaconda Enterprise 4 repository, you enter a domain URL before your login credentials. To change this domain:

.. tab-set::

    .. tab-item:: Anaconda Server

       #. Go to **Preferences**. 
       #. In **Anaconda Server API domain**, enter a valid domain name.

          .. note::
             The domain must be a full path without a trailing slash. For example: ``http(s)://mysite.com``

       #. Click **Apply** to save your changes.

    .. tab-item:: Anaconda Enterprise 4

       #. Go to **Preferences**. 
       #. In **Enterprise 4 Repository API domain**, enter a valid domain name.

          .. note::
             The domain must be a full path without a trailing slash. For example: ``http(s)://mysite.com``

       #. Click **Apply** to save your changes.

How to disconnect from a repository
===================================

You can only be connected to one repository at a time.

To disconnect from a repository:

#. Click **Connect**.
#. Click **Sign out** beside the repository you are signing out of.

Channels that you have added to Navigator from Anaconda.org or a professional (repo.anaconda.cloud) repository are not automatically removed when you disconnect from those repositories. Navigator will still search those channels and install packages from them. If you no longer want those channels to be searched:

#. Open **Preferences** from the **File**, **Anaconda Navigator**, or **python** menus, depending on your setup.
#. Click **Configure Conda**.
#. Delete any channels in the ``channels:`` list that you no longer want to be connected to. Anaconda recommends against deleting ``defaults``.

   For example, let's say you have disconnected from a Package Security Manager repository and have the following ``channels:`` list:

   .. code-block:: none

      channels:
        - https://repo.anaconda.cloud/t/<TOKEN>/repo/business-org-name/channel1
        - https://repo.anaconda.cloud/t/<TOKEN>/repo/business-org-name/channel2
        - defaults

   You would delete the first two lines and leave ``defaults`` in your ``channels:`` list.

   .. code-block:: none

      channels:
        - defaults
      
#. Click **Save and Restart**.

What happens when you disconnect from a repository
==================================================

Navigator performs a few actions for you automatically when you disconnect from your repository:

.. tab-set::

   .. tab-item:: Pro/Business

      * The ``conda-token`` tool removes your supplied organization token.

   .. tab-item:: Server

      * Navigator removes the access token created for you by ``conda-repo-cli``.
      * Navigator sets ``logged_api_url``, ``anaconda_server_token``, and ``anaconda_server_token_id`` to ``None`` in the Navigator config file (``anaconda-navigator.ini``).
      * The conda configuration file (``.condarc``) returns to the state it was in before the login. (Navigator saves a copy of the ``.condarc`` file before a login is attempted.)

   .. tab-item:: Enterprise 4

      * Navigator uses a private token managed by ``anaconda-client`` to log out.
      * The conda configuration file (``.condarc``) returns to the state it was in before the login. (Navigator saves a copy of the ``.condarc`` file before a login is attempted.)

Troubleshooting
===============

If you are having issues logging in to Anaconda Server or know you're logged in but cannot interact with Anaconda Server, see :ref:`Trouble logging in to the Anaconda Server connection in Navigator <business-cloud-integration-issue>`.

.. |key| raw:: html

   <i class="fa-light fa-key"></i>
