zillow / battenberg

Providing updates to cookiecutter projects.
Other
13 stars 5 forks source link

Battenberg upgrade error: TypeError: invalid credential type #26

Closed emirot closed 2 years ago

emirot commented 3 years ago

I'm trying to use that tool by running:

battenberg upgrade

I have also have a .cookiecutter.json that I can share.

Python version: Python 3.7.9 Pip freeze:

arrow==1.1.0
battenberg==0.4.1
binaryornot==0.4.4
cached-property==1.5.2
certifi==2020.12.5
cffi==1.14.5
chardet==4.0.0
click==7.1.2
cookiecutter==1.7.2
idna==2.10
Jinja2==2.11.3
jinja2-time==0.2.0
MarkupSafe==1.1.1
poyo==0.5.0
pycparser==2.20
pygit2==1.5.0
python-dateutil==2.8.1
python-slugify==4.0.1
requests==2.25.1
six==1.15.0
text-unidecode==1.3
typing-extensions==3.7.4.3
urllib3==1.26.4

Stacktrace:

\Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/bin/battenberg", line 11, in <module>
    load_entry_point('battenberg==0.4.1', 'console_scripts', 'battenberg')()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/click/decorators.py", line 21, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/battenberg/cli.py", line 112, in upgrade
    battenberg.upgrade(**kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/battenberg/core.py", line 234, in upgrade
    self._fetch_remote_template()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/battenberg/core.py", line 50, in _fetch_remote_template
    callbacks=RemoteCallbacks(credentials=keypair))
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pygit2/remote.py", line 128, in fetch
    payload.check_error(err)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pygit2/callbacks.py", line 91, in check_error
    raise self._stored_exception
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pygit2/callbacks.py", line 331, in wrapper
    return f(*args)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pygit2/callbacks.py", line 376, in _credentials_cb
    ccred = get_credentials(credentials, url, username, allowed)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pygit2/callbacks.py", line 471, in get_credentials
    raise TypeError("invalid credential type")
TypeError: invalid credential type

So I thought something was wrong with my git configuration so I tried:

from pygit2 import Repository
from pygit2 import GIT_SORT_TOPOLOGICAL, GIT_SORT_REVERSE
repo = Repository('.git')
for commit in repo.walk(repo.head.target, GIT_SORT_TOPOLOGICAL):
  print(commit.message)

And it worked fine. Any ideas what I'm doing wrong?

emirot commented 3 years ago

Updating this thread, it's difficult to have similar builds so I would like to use a docker image

Dockerfile

FROM ubuntu

RUN apt update -y
RUN apt install -y build-essential zlib1g-dev libncurses5-dev
RUN apt install -y libgdbm-dev libnss3-dev libssl-dev libsqlite3-dev libreadline-dev libffi-dev curl libbz2-dev
RUN apt install -y python3 python3-pip git
RUN apt install -y gcc libc-dev g++

# https://github.com/libgit2/pygit2/issues/999
RUN pip3 install -U pip
RUN pip3 install --upgrade pip
RUN pip install pygit2

RUN pip install battenberg

COPY .git/ .
COPY . .

I'm running docker build in a project that is using cookie cutter and battenberg. Then I create a ssh-keygen key pair and add it in my gitlab ssh keys in console.

I get

root@000439d4ad86:/# battenberg upgrade 
Traceback (most recent call last):
  File "/usr/local/bin/battenberg", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 1137, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 1062, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 1668, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 763, in invoke
    return __callback(*args, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/click/decorators.py", line 26, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/battenberg/cli.py", line 112, in upgrade
    battenberg.upgrade(**kwargs)
  File "/usr/local/lib/python3.8/dist-packages/battenberg/core.py", line 234, in upgrade
    self._fetch_remote_template()
  File "/usr/local/lib/python3.8/dist-packages/battenberg/core.py", line 49, in _fetch_remote_template
    self.repo.remotes['origin'].fetch([TEMPLATE_BRANCH],
  File "/usr/local/lib/python3.8/dist-packages/pygit2/remote.py", line 147, in fetch
    payload.check_error(err)
  File "/usr/local/lib/python3.8/dist-packages/pygit2/callbacks.py", line 91, in check_error
    raise self._stored_exception
  File "/usr/local/lib/python3.8/dist-packages/pygit2/callbacks.py", line 331, in wrapper
    return f(*args)
  File "/usr/local/lib/python3.8/dist-packages/pygit2/callbacks.py", line 376, in _credentials_cb
    ccred = get_credentials(credentials, url, username, allowed)
  File "/usr/local/lib/python3.8/dist-packages/pygit2/callbacks.py", line 471, in get_credentials
    raise TypeError("invalid credential type")
TypeError: invalid credential type
emirot commented 3 years ago

root@f895e63ffcd6:/# python3 -c "import pygit2; print(bool(pygit2.features & pygit2.GIT_FEATURE_SSH))" True This returns True What really drives me crazy is this:

import pygit2
import getpass
def main():
    keypair = pygit2.KeypairFromMemory( 
        "git", 
        str(Path('~/.ssh/id_rsa.pub').expanduser().read_text()), 
        str(Path('~/.ssh/id_rsa').expanduser().read_text()), 
        "") 
    pygit2.clone_repository(
        'ssh://git@org.net/fastapi.git', 'empty',
        callbacks=pygit2.RemoteCallbacks(credentials=keypair))
if __name__ == '__main__':
    main()

by adding my ssh key it works and I can pull a repo, but battenberg still give me an issue.

emirot commented 3 years ago

Looks like it happens when the template branch is missing.

Your branch is up to date with 'origin/main'.
root@73cdaf79173c:~# battenberg upgrade --checkout demo-to-nolan --no-input
root@73cdaf79173c:~# git branch -D template
Deleted branch template (was f0b9d97).
root@73cdaf79173c:~# battenberg upgrade --checkout demo-to-nolan --no-input
Traceback (most recent call last):
  File "/usr/local/bin/battenberg", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 1137, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 1062, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 1668, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 763, in invoke
    return __callback(*args, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/click/decorators.py", line 26, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/battenberg/cli.py", line 112, in upgrade
    battenberg.upgrade(**kwargs)
  File "/usr/local/lib/python3.8/dist-packages/battenberg/core.py", line 234, in upgrade
    self._fetch_remote_template()
  File "/usr/local/lib/python3.8/dist-packages/battenberg/core.py", line 49, in _fetch_remote_template
    self.repo.remotes['origin'].fetch([TEMPLATE_BRANCH],
  File "/usr/local/lib/python3.8/dist-packages/pygit2/remote.py", line 147, in fetch
    payload.check_error(err)
  File "/usr/local/lib/python3.8/dist-packages/pygit2/callbacks.py", line 91, in check_error
    raise self._stored_exception
  File "/usr/local/lib/python3.8/dist-packages/pygit2/callbacks.py", line 331, in wrapper
    return f(*args)
  File "/usr/local/lib/python3.8/dist-packages/pygit2/callbacks.py", line 376, in _credentials_cb
    ccred = get_credentials(credentials, url, username, allowed)
  File "/usr/local/lib/python3.8/dist-packages/pygit2/callbacks.py", line 471, in get_credentials
    raise TypeError("invalid credential type")
TypeError: invalid credential type