==============================
Managing channels and packages
==============================

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

As an administrator, it is your responsibility to monitor and maintain the channels and packages that are available in the internal Workbench repository for your users.

.. warning::

   Do not modify the ``anaconda-enterprise`` channel. Modifications to this channel can cause serious problems for the platform!

Viewing all channels
====================

As an administrator, you are able to view and manage all channels. 

#. Log in to Workbench as a user with administrator permissions.
    
    .. tip::

        The ``anaconda-enterprise`` user has the correct permissions. 

#. Open the |circle-user| **My Account** dropdown menu and select *Admin Console*.
#. Select **Channels** |clone| from the left-hand menu.

    The channels page displays a complete list of channels that exist within the internal Workbench repository. Each channel's owner and when the channel was last updated is displayed for all channels. 

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

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

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

To create a channel in the internal Workbench repository:

#. Log in to Workbench.
#. Select **Channels** |clone| from the left-hand menu.
#. Click **Create** |plus| 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 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.  

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

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 a command on this page to assist you with installing the package 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.


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

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

To add a package to an existing channel:

#. From the channels page, click on a channel name to view its packages.
#. 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.


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

To install a package from an internal Workbench channel:

#. From the 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/install_package_from_channel.png
        :align: center

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

To remove a package from an internal Workbench channel:

#. From the channels page, click on a channel name to view its packages.
#. Open the package's actions |ellipsis-vertical| dropdown menu, then select *Delete*. 
#. Click **Delete**.
   
.. _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 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 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 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 <channels-cli>`. 

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

.. _channels-cli:

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

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

.. _channel-create:

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`` 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, 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>

.. |circle-user| raw:: html
   
   <svg class="inline" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path d="M256 496c-54 0-103.9-17.9-144-48v0c0-61.9 50.1-112 112-112h64c61.9 0 112 50.1 112 112v0c5.3-4 10.4-8.2 15.4-12.6C409.1 370.6 354.5 320 288 320H224c-66.5 0-121.1 50.6-127.4 115.4C47.2 391.5 16 327.4 16 256C16 123.5 123.5 16 256 16s240 107.5 240 240s-107.5 240-240 240zm0 16A256 256 0 1 0 256 0a256 256 0 1 0 0 512zm80-304a80 80 0 1 0 -160 0 80 80 0 1 0 160 0zm-80-64a64 64 0 1 1 0 128 64 64 0 1 1 0-128z"/></svg>

.. |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>