avisi-cloud / structurizr-site-generatr

Static site generator for architecture models created with Structurizr DSL
https://avisi-cloud.github.io/structurizr-site-generatr/
Apache License 2.0
224 stars 34 forks source link

git-url option returns error; Authentication is required but no CredentialsProvider has been registered #621

Closed Vinedine closed 4 days ago

Vinedine commented 5 days ago

Hi,

First of all congratulations on creating such a great tool. It makes viewing complex C4 architectures a lot more pleasurable.

I am trying to get the git integration to work to be able to see multiple branches. However I always get an error about no CredentialsProvider being registered.

I am using Azure DevOps and have the following step in my pipeline;

- task: AzureCLI@2
  displayName: 'Create build folder'
  inputs:
    azureSubscription: $(ServiceConnection.Name)
    scriptType: 'bash'
    scriptLocation: 'inlineScript'
    inlineScript: |
      docker run --user root --rm -v $(WORKSPACE_PATH):/var/model ghcr.io/avisi-cloud/structurizr-site-generatr generate-site \
        --git-url https://$(PersonalAccessToke)@$(GitRepository).git \
        --workspace-file workspace.dsl \
        --assets-dir assets \
        --all-branches \
        --default-branch master

This gives me the following error;

Exception in thread "main" org.eclipse.jgit.api.errors.TransportException: https://PAT@GIT_REPO.git: Authentication is required but no CredentialsProvider has been registered
    at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:249)
    at org.eclipse.jgit.api.CloneCommand.fetch(CloneCommand.java:319)
    at org.eclipse.jgit.api.CloneCommand.call(CloneCommand.java:189)
    at nl.avisi.structurizr.site.generatr.ClonedRepository.refreshLocalClone(ClonedRepository.kt:35)
    at nl.avisi.structurizr.site.generatr.GenerateSiteCommand.generateSiteForModelInGitRepository(GenerateSiteCommand.kt:79)
    at nl.avisi.structurizr.site.generatr.GenerateSiteCommand.execute(GenerateSiteCommand.kt:71)
    at kotlinx.cli.ArgParser.parse(ArgParser.kt:657)
    at kotlinx.cli.ArgParser.parse(ArgParser.kt:530)
    at nl.avisi.structurizr.site.generatr.AppKt.main(App.kt:13)
Caused by: org.eclipse.jgit.errors.TransportException: https://PAT@GIT_REPO.git: Authentication is required but no CredentialsProvider has been registered
    at org.eclipse.jgit.transport.TransportHttp.connect(TransportHttp.java:687)
    at org.eclipse.jgit.transport.TransportHttp.openFetch(TransportHttp.java:465)
    at org.eclipse.jgit.transport.FetchProcess.executeImp(FetchProcess.java:153)
    at org.eclipse.jgit.transport.FetchProcess.execute(FetchProcess.java:105)
    at org.eclipse.jgit.transport.Transport.fetch(Transport.java:1480)
    at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:238)

When I test the URL https://PAT@GIT_REPO.git via postman I also get an error (401).

However when I include the PAT via an authorization header it works.

As detailed here; https://learn.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=azure-devops&tabs=Windows#use-a-pat

I also tried this below but it did not work;

- task: AzureCLI@2
  displayName: 'Create build folder'
  inputs:
    azureSubscription: $(ServiceConnection.Name)
    scriptType: 'bash'
    scriptLocation: 'inlineScript'
    inlineScript: |
      # Create the Authorization header in Base64
      PAT_ENCODED=$(echo -n ":${GitPersonalAccessToken}" | base64)
      export GIT_AUTH_HEADER="Authorization: Basic $PAT_ENCODED"

      # Set the Git configuration to use the Authorization header
      git config --global http.extraheader "$GIT_AUTH_HEADER"

      docker run --user root --rm -v $(WORKSPACE_PATH):/var/model ghcr.io/avisi-cloud/structurizr-site-generatr generate-site \
        --git-url https://$(GitRepository).git \
        --workspace-file workspace.dsl \
        --assets-dir assets \
        --all-branches \
        --default-branch master

How can I therefore access a git repository that requires authentication?

Vinedine commented 4 days ago

Just noticed I can use --git-username and --git-password and that seems to have solved the issue.

jenspav commented 4 days ago

ah nice, thanks for sharing your solution!