=====================
Channels and packages
=====================

A channel is a repository location for storing software packages. Users with access to a given channel can download and install the software packages available within the channel. 

If you've :doc:`built a conda package <build>`, you can upload it to a channel to make it available for others to use. 

Data Science & AI Workbench allows all users to create channels in the internal Workbench repository, and allows users with the ``ae-uploader`` role to upload packages to channels that they have read-write permissions for. 

.. note::

    * For more information about user permissions, see :ref:`roles <roles>`.
    * For more information about channel permissions, see :ref:`sharing channels <user_sharing_channels>`.
    * For more information about how Workbench manages channels, see :doc:`configuring conda in Workbench <../../admin/chan-pkg/conda-config>`.

Viewing channels
================

To view channels you have access to:

#. Log in to Workbench.
#. Select |clone| **Channels** from the left-hand menu.

    .. note::
        
        Channels that display a |lock| lock beside their name are private. For more information about private channels, see :ref:`sharing channels <user_sharing_channels>`.

Creating a channel
==================

To create a channel in the internal Workbench repository:

#. Select |clone| **Channels** from the left-hand menu.
#. Click |plus| **Create** in the upper right corner.
#. Set the channel to public or private access. 
#. Enter a name for the channel, then click **Create**.

Viewing channel packages
========================

From the |clone| **Channels** page, click on a channel name to view its packages. You can see the supported platforms, latest versions, when each package in the channel was last modified, and the number of times each package has been downloaded.  

Viewing package details
=======================

Each package in Workbench presents valuable information pertaining to the package, such as its platform architecture, version, license, number of downloads, and the last time the package was updated. You can also find :ref:`a command on this page to assist you with installing the package <install_pkg>` in your environment.

From the channel packages page, select any package to view the package details page.

.. tip:: 
    
    You can search |magnifying-glass| for packages by name to locate them more efficiently.

.. _user-upload-package:

Uploading a package to a channel
================================

To add a package to an existing channel:


#. Select |clone| **Channels** from the left-hand menu.
#. Click |upload| **Upload**. 
#. Click **Browse** and locate the package in your file system.
#. Click **Upload**.
   
.. note::

   * There is a 1GB file size limit for package file uploads.
   * If the **Upload** option is not available, you don't have permission to upload packages to the channel.

You can :ref:`share the channel <user_sharing_channels>` with others to provide them with access to the packages it contains. 

.. _install_pkg:

Installing a package from a channel
===================================

To install a package from an internal Workbench channel:

#. From the |clone| **Channels** page, click on a channel name to view its packages.
#. Select any package to view the package details page.
#. Copy the installation command provided.
#. Run the copied command in the environment you want to install the package in.

    .. thumbnail:: ../../images/user_install_package_from_channel.png
        :align: center

Removing a package from a channel
=================================

To remove a package from an internal Workbench channel:

#. From the |clone| **Channels** page, click on a channel name to view its packages.
#. Open the package's |ellipsis-vertical| actions dropdown menu, then select *Delete*. 
#. Click **Delete**.

.. note::

   If the **Delete** option is not available, you don't have permission to remove packages from the channel.

.. _user_sharing_channels:

Sharing channels
================

There are two types of channels within the internal Workbench repository, public and private. Channels are set to public access by default.

Sharing public channels
-----------------------

Public channels are accessible by non-authenticated users. In other words, people that do not have access to Workbench can still access packages in the internal Workbench repository channels. 

To share a public channel: 

#. From the |clone| **Channels** page, click on a channel name to view its details.
#. Select |share-nodes| **Share** from the left-hand navigation. 
#. Copy the channel address and distribute it to individuals who need access to the channel. 

Sharing private channels
------------------------

Private channels are accessible only to other Workbench users that you have added as collaborators to the channel. 

To mark a channel as private:

#. From the |clone| **Channels** page, click on a channel name to view its details.
#. Select |share-nodes| **Share** from the left-hand navigation. 
#. Set the **Sharing** toggle to **Private**.

To share a private channel with other workbench users:

#. From the |clone| **Channels** page, click on a channel name to view its details.
#. Select |share-nodes| **Share** from the left-hand navigation. 
#. Begin typing a user or group name in the **Add New Collaborator** dropdown to search for matches. Select the correct entry, then click **Add**.

.. note:: 
    
    By default, collaborators are granted read-write access to your shared channel. If you want to prevent collaborators from adding or removing packages in your channel, you'll need to :ref:`restrict them to read-only access using the CLI <user-channels-cli>`. 

.. _user-channels-cli:

Managing channels using the CLI
===============================

:ref:`Log in to the CLI <cli-log-in>` before you begin attempting to manage channels. 

Creating a channel
------------------

Create a new channel in the internal Workbench repository by running the following command:

.. code-block:: none

    # Replace <CHANNEL_NAME> with the name of the channel you want to create
    anaconda-enterprise-cli channels create <CHANNEL_NAME>

Uploading a package to a channel
--------------------------------

Upload a conda package to a channel by running the following command:

.. code-block:: none

    anaconda-enterprise-cli upload --channel <path/to/package>

Listing all channels
--------------------

Get a list of all the channels on the platform with the ``channels list`` command:

.. code-block:: none
    
    anaconda-enterprise-cli channels list

Sharing channels
----------------

Share and manage permissions for channels with the ``share`` command:

.. tab-set:: 

    .. tab-item:: Share with user

        .. code-block:: none
            
            # Replace <CHANNEL_NAME> with the name of the channel you want to share
            # Replace <USERNAME> with the username of the user you want to share the channel with
            anaconda-enterprise-cli channels share --user <USERNAME> <CHANNEL_NAME>

    .. tab-item:: Share with group
    
        .. code-block:: none
            
            # Replace <CHANNEL_NAME> with the name of the channel you want to share
            # Replace <GROUP_NAME> with the name of group you want to share with
            anaconda-enterprise-cli channels share --group <GROUP_NAME> <CHANNEL_NAME>

.. note::

    By default, sharing a channel with a user or group provides them with read-write access to the channel. Restrict access to the channel to read-only by including ``--level r`` to before the ``<CHANNEL_NAME>``. 

    For example: 

    .. code-block:: none

        anaconda-enterprise-cli channels share --group <GROUP_NAME> --level r <CHANNEL_NAME>
   

Revoking channel access
-----------------------

Revoke a user's or a group's access to a channel by running one of the following commands:


.. tab-set:: 

    .. tab-item:: Revoke user access
        
        .. code-block:: none

            # Replace <CHANNEL_NAME> with the name of the channel you want to revoke access to
            # Replace <USERNAME> with the username of the user whose access you want to revoke 
            anaconda-enterprise-cli channels share --user <USERNAME> --remove <CHANNEL_NAME>

    .. tab-item:: Revoke group access

        .. code-block:: none
    
            # Replace <CHANNEL_NAME> with the name of the channel you want to revoke access to
            # Replace <GROUP_NAME> with the name of the group whose access you want to revoke 
            anaconda-enterprise-cli channels share --group <GROUP_NAME> --remove <CHANNEL_NAME>

Setting a default channel
-------------------------

The ``default_channel`` value is not set when ``anaconda-enterprise-cli`` is installed. This means every time you run an ``upload`` command, you need to supply a specific channel name.

If you don't want to include the ``--channel`` option with each command, you can set a default channel by running the following command:

    .. code-block:: none

        # Replace <CHANNEL_NAME> with the name of the channel you want to upload to by default
        anaconda-enterprise-cli config set default_channel <CHANNEL_NAME>

View your current default channel by running the following command:

    .. code-block:: none
        
        # Replace <CHANNEL_NAME> with the name of the channel you want to upload to by default
        anaconda-enterprise-cli config get default_channel '<CHANNEL_NAME>'

.. note:: 
    
    For more information about actions you can take with channels in the CLI, run the following command:

    .. code-block:: none
        
        anaconda-enterprise-cli channels --help

.. |clone| raw:: html

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

.. |lock| raw:: html

    <i class="fa-solid fa-lock"></i>

.. |upload| raw:: html

    <svg class="inline" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path d="M272 54.6V368c0 8.8-7.2 16-16 16s-16-7.2-16-16V54.6L139.3 155.3c-6.2 6.2-16.4 6.2-22.6 0s-6.2-16.4 0-22.6l128-128c6.2-6.2 16.4-6.2 22.6 0l128 128c6.2 6.2 6.2 16.4 0 22.6s-16.4 6.2-22.6 0L272 54.6zM208 352H64c-17.7 0-32 14.3-32 32v64c0 17.7 14.3 32 32 32H448c17.7 0 32-14.3 32-32V384c0-17.7-14.3-32-32-32H304V320H448c35.3 0 64 28.7 64 64v64c0 35.3-28.7 64-64 64H64c-35.3 0-64-28.7-64-64V384c0-35.3 28.7-64 64-64H208v32zm176 64a24 24 0 1 1 48 0 24 24 0 1 1 -48 0z"/></svg>

.. |ellipsis-vertical| raw:: html

   <svg class="inline" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 128 512"><path d="M64 360a56 56 0 1 0 0 112 56 56 0 1 0 0-112zm0-160a56 56 0 1 0 0 112 56 56 0 1 0 0-112zM120 96A56 56 0 1 0 8 96a56 56 0 1 0 112 0z"/></svg>

.. |share-nodes| raw:: html

   <svg class="inline" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><path d="M448 112c0 44.2-35.8 80-80 80c-22.9 0-43.6-9.6-58.1-25l-151 75.5c.8 4.4 1.1 8.9 1.1 13.5s-.4 9.1-1.1 13.5l151 75.5c14.6-15.4 35.2-25 58.1-25c44.2 0 80 35.8 80 80s-35.8 80-80 80s-80-35.8-80-80c0-9.7 1.7-19 4.9-27.7L147.2 299.5c-14.3 22-39 36.5-67.2 36.5c-44.2 0-80-35.8-80-80s35.8-80 80-80c28.2 0 52.9 14.5 67.2 36.5l145.7-72.9c-3.2-8.6-4.9-17.9-4.9-27.7c0-44.2 35.8-80 80-80s80 35.8 80 80zM80 304a48 48 0 1 0 0-96 48 48 0 1 0 0 96zM416 112a48 48 0 1 0 -96 0 48 48 0 1 0 96 0zM368 448a48 48 0 1 0 0-96 48 48 0 1 0 0 96z"/></svg>

.. |plus| raw:: html

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

.. |magnifying-glass| raw:: html

    <svg class="inline" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path d="M368 208A160 160 0 1 0 48 208a160 160 0 1 0 320 0zM337.1 371.1C301.7 399.2 256.8 416 208 416C93.1 416 0 322.9 0 208S93.1 0 208 0S416 93.1 416 208c0 48.8-16.8 93.7-44.9 129.1L505 471c9.4 9.4 9.4 24.6 0 33.9s-24.6 9.4-33.9 0L337.1 371.1z"/></svg>
