Skip to content

Improve Auth Handling #175

@asergeant01

Description

@asergeant01

I have a case whereby I would like to combine documentation hosted on different git tools (Multiple GitHubs, Bitbucket etc) which given the current sparse_clone.sh script is impossible due to how auth is handled.

if [[ -n  "$AccessToken" ]]; then
    url_to_use="${protocol}://$AccessToken@$url_rest"
    git config http.extraheader "AUTHORIZATION: bearer $AccessToken"
elif [[ -n  "$GithubAccessToken" ]]; then
    url_to_use="${protocol}://x-access-token:$GithubAccessToken@$url_rest"
elif [[ -n  "$GitlabCIJobToken" ]]; then
    url_to_use="${protocol}://gitlab-ci-token:$GitlabCIJobToken@$url_rest"
else
  url_to_use="$url"
fi

If GithubAccessToken is set, it assumes that this token can access every imported repo, which can be the case if they are all on the same Github Instance.

Unfortunately this is not the case in my example, and I need to have different Tokens to access each Github Instance.

A way to solve this could be not to set any of the defined environment variables, but let the user configure this in the config file.
e.g.

- multirepo:
      nav_repos:
        - name: repo1
          import_url: https://x-access-token:${GITHUB_API_TOKEN_INSTANCE_1}@github-1.internal/Org1/Repo1?branch=main
          imports:
            - "/README.md"
         - name: repo2
           import_url: https://x-access-token:${GITHUB_API_TOKEN_INSTANCE_2}@github-2.internal/Org2/Repo2?branch=main
           imports:
             - "/README.md"

Then as long as the user sets the environment variables and the script is modified to evaluate the variables, there is complete flexibility on Auth per Repo.

sparse_clone.sh
eval "url=\"$1\""

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions