Add your Git credentials and repository to IBM Software Hub

After you generate a personal access token for your Git repository, you must register your Git personal access token with IBM Software Hub and create a configuration to store information about your repository.

Who needs to complete this task?

Any users who need to manage assets across instances by using Git must complete this task.

When do you need to complete this task?

Complete this task on each instance of IBM Software Hub where you want to manage asset promotion with Git.

You must complete this task before you can push changes to or pull changes from Git.

In addition, you must complete this task if your access token expires or is revoked.

Before you begin

Before you can register a Git with IBM Software Hub, complete the following tasks:

  1. Generate an IBM Software Hub API key.
  2. Generate a ZenApiKey authorization token.
  3. Generate a Git personal access token
    Important: Ensure that the token has the minimum required permissions.

About this task

In order to manage assets with a remote Git repository, you must provide information about your repository and your credentials to IBM Software Hub. This information is stored in IBM Software Hub so that you can reference it by providing your Git configuration ID.

Procedure

To register your Git personal access token:

  1. Set the INSTANCE_ROUTE environment variable to the URL of IBM Software Hub:
    export INSTANCE_ROUTE=<Software-Hub-route>
    Tip: By default, the route has the following format: <namespace>.apps.<OpenShift-domain>

    You can get the route from the URL of the web client.

  2. Set the AUTH_TOKEN to your ZenApiKey authorization token:
    export AUTH_TOKEN=<ZenApiKey-authorization-token>
  3. Set the GIT_ACCESS_TOKEN environment variable to the value of your personal access token:
    export GIT_ACCESS_TOKEN=<personal-access-token>
  4. Set the TOKEN_NAME environment variable to the name that you want to use to identify your token:
    export TOKEN_NAME=<token-name>
  5. Set the following environment variables based on your Git repository:
    GitHub
    You don't need to set any additional environment variables.
    GitHub Enterprise
    If you are working with a GitHub Enterprise repository, set the GIT_DOMAIN_URL to the base URL of your repository. For example:
    export GIT_DOMAIN_URL=<https://github.example.com>
    GitHub
    If you are working with a repository on gitlab.com, set the GITLAB_USERNAME to your username on gitlab.com:
    export GITLAB_USERNAME=<username>
    GitLab Self-Managed
    If you're working with assets stored in a GitLab Self-Managed repository:
    1. Set the GIT_DOMAIN_URL to the base URL of your repository. For example:
      export GIT_DOMAIN_URL=<https://gitlab.example.com>
    2. Set the GITLAB_USERNAME to your username:
      export GITLAB_USERNAME=<username>
  6. Register your Git token with IBM Software Hub.

    Run the appropriate command based on your Git repository:

    GitHub
    curl -k -X POST \
    'https://${INSTANCE_ROUTE}/zen-gitops/v1/platform/gitops/tokens' \
    -H 'Authorization: Bearer ${AUTH_TOKEN}' \
    -H 'Content-Type: application/json' \
    -d '{
        "access_token": "${GIT_ACCESS_TOKEN}",
        "platform_type": "GITHUB",
        "token_name": "${TOKEN_NAME}"
    }'
    GitHub Enterprise
    curl -k -X POST \
    'https://${INSTANCE_ROUTE}/zen-gitops/v1/platform/gitops/tokens' \
    -H 'Authorization: Bearer ${AUTH_TOKEN}' \
    -H 'Content-Type: application/json' \
    -d '{
        "access_token": "${GIT_ACCESS_TOKEN}",
        "attributes": {
            "domain_url": "${GIT_DOMAIN_URL}"
          },
        "platform_type": "GITHUB_ENT",
        "token_name": "${TOKEN_NAME}"
    }'
    GitLab
    curl -k -X POST \
    'https://${INSTANCE_ROUTE}/zen-gitops/v1/platform/gitops/tokens' \
    -H 'Authorization: Bearer ${AUTH_TOKEN}' \
    -H 'Content-Type: application/json' \
    -d '{
        "access_token": "${GIT_ACCESS_TOKEN}",
        "attributes": {
            "username": "${GITLAB_USERNAME}"
          },
        "platform_type": "GITLAB",
        "token_name": "${TOKEN_NAME}" 
    }'
    GitLab Self-Managed
    curl -k -X POST \
    `https://${INSTANCE_ROUTE}/zen-gitops/v1/platform/gitops/tokens` \
    -H 'Authorization: Bearer ${AUTH_TOKEN}' \
    -H 'Content-Type: application/json' \
    -d '{
        "access_token": "${GIT_ACCESS_TOKEN}",
        "attributes": {
            "domain_url": "${GIT_DOMAIN_URL}",
            "username": "${GITLAB_USERNAME}"
          },
        "platform_type": "GITLAB_SELF_MANAGED",
        "token_name": "${TOKEN_NAME}"
    }'
    The command returns output with the following format:
    {
      "token_id": "123e4567e89b12d3a456426614418000",
      "token_name": "my-token-name"
    }
  7. Set the TOKEN_ID environment variable to the ID returned by the POST zen-gitops/v1/platform/gitops/tokens endpoint:
    export TOKEN_ID=<token-ID>
  8. Set the following environment variables based on your Git repository:
    1. Set the GIT_REPO_URL environment variable to the HTTPS URL of the repository:
      export GIT_REPO_URL=<https://git-host/organization/repo.git>
    2. Set the GIT_BRANCH environment variable to the name of the branch where you are working:
      export GIT_BRANCH=<branch-name>
  9. Set the following environment variables to identify your Git configuration in IBM Software Hub:
    1. Set the GIT_CONFIG_NAME environment variable to the name that you want to use to identify your Git repository:
      export GIT_CONFIG_NAME=<config-name>
    2. Set the GIT_CONFIG_DESCRIPTION environment variable to provide additional information about the configuration.
      export GIT_CONFIG_DESCRIPTION="Extended description of the configuration"

      The description is a string and can contain alphanumeric characters, spaces, dashes, underscores, and periods. Make sure that you surround the description with quotation marks, as shown in the preceding export command.

  10. Register your Git configuration with IBM Software Hub
    curl -k -X POST \
    'https://${INSTANCE_ROUTE}/zen-gitops/v1/platform/gitops/configs' \
    -H 'Authorization: Bearer ${AUTH_TOKEN}' \
    -H 'Content-Type: application/json' \
    -d '{
        "config_name": "${GIT_CONFIG_NAME}",
        "repo_url": "${GIT_REPO_URL}",
        "branch_name": "${GIT_BRANCH}",
        "token_id": "${TOKEN_ID}",
        "description": ${GIT_CONFIG_NAME}
    }' 
  11. If you plan to use this configuration with Data Virtualization, register the configuration with the Data Virtualization service instance where you want to manage assets:
    1. Set the DV_INSTANCE_NAMESPACE environment variable to the project (namespace) where the Data Virtualization service instance is installed:
      export DV_INSTANCE_NAMESPACE
    2. Set the USER_DEFINED_KEY environment variable to the key that you want to use to encrypt sensitive data during export and import.
      export USER_DEFINED_KEY=<encryption-key>
      Important: Ensure that you save this key in a secure location. If you lose this key, you will not be able to decrypt the data when you pull the data from the remote Git repository.
    3. Register the configuration:
      curl -k -X POST \
      'https://${INSTANCE_ROUTE}/icp4data-databases/dv/${DV_INSTANCE_NAMESPACE}/dvapiserver/v1/dv/git/register' \
      -H 'Content-Type: application/json' \
      -H 'Authorization: Bearer ${AUTH_TOKEN}' \
      -d '{
          "gitRepoUrl": "${GIT_REPO_URL}",
          "gitBranch": "${GIT_BRANCH}",
          "gitTokenId": "${TOKEN_ID}",
          "encryptionKey": "${USER_DEFINED_KEY}"
      }'