简体   繁体   中英

Dulwich Remote Repo Authentication

Are there any good examples out there for accessing and fetching a remote repository over HTTPS? I have a Git repository that I can clone from the command line with my username and password, but I want to be able to do this using Dulwich and just provide my username and password when I make my HTTPS client.

Another requirement is that this be done using the MemoryRepo option rather than writing to the file system.

Dulwich 0.16.0 and later support usernames/paswords in URLs.

In older versions, you can do this by specifying a custom HTTP Handler:

    import urllib2

    password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()

    # Add the username and password.
    password_mgr.add_password(realm, top_level_url, username, password)

    handler = urllib2.HTTPBasicAuthHandler(password_mgr)

    opener = urllib2.build_opener([handler])

    client, path = get_transport_and_path(remote_location)
    client.opener = opener
    remote_refs = client.fetch(path, target_repo)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM