How to use the pygit2.UserPass function in pygit2

To help you get started, we’ve selected a few pygit2 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github programa-stic / marvin-django / marvin / frontpage / git_interface.py View on Github external
author    = pygit2.Signature("Alice Author", "alice@authors.tld")
	committer = pygit2.Signature("Alice Author", "alice@authors.tld")
	if master == None:
		myRepo.create_commit('refs/heads/master', author, committer, 
							  version,
							  myTree,
							  [])
	else:
		myRepo.create_commit('refs/heads/master', author, committer, 
							  version,
							  myTree,
							  [master.target])
	myRepo.create_branch(version, myRepo.head.get_object())
	myRemote = myRepo.remotes[0]
	#myRemote.credentials = pygit2.UserPass("marvin",marvin_git_passwd)
	credentials = pygit2.UserPass("marvin",marvin_git_passwd)
	callbacks=pygit2.RemoteCallbacks(credentials=credentials)
	myRemote.push(["refs/heads/master"],callbacks=callbacks)
	myRemote.push(["refs/heads/"+version],callbacks=callbacks)
github MaslowCommunityGarden / Website / createRepo.py View on Github external
repoClone.remotes.set_url("origin", repo.clone_url)
        index = repoClone.index
        print("index")
        index.add_all()
        index.write()
        print("after write")
        author = pygit2.Signature("MaslowCommunityGardenRobot", "info@maslowcnc.com")
        commiter = pygit2.Signature("MaslowCommunityGardenRobot", "info@maslowcnc.com")
        print("setup author")
        tree = index.write_tree()
        print("\nclone\n");
        oid = repoClone.create_commit('refs/heads/master', author, commiter, "init commit",tree,[repoClone.head.target])
        print("clone")
        remote = repoClone.remotes["origin"]
        print("about to login")
        credentials = pygit2.UserPass(userName, password)
        remote.credentials = credentials
        
        callbacks=pygit2.RemoteCallbacks(credentials=credentials)
        print("about to push")
        remote.push(['refs/heads/master'],callbacks=callbacks)
        
        #This section writes the new tracked project name to the tracked projects list in github
        
        trackedProjectsRepo = org.get_repo('Website')
        
        fileName = 'trackedProjects.txt'
        
        print("getting file contents")
        
        #get the tracked projects list and decode it
        fileContents = trackedProjectsRepo.get_file_contents(fileName)
github dpnishant / raptor / backend / raptor / init.py View on Github external
if internal:
        repo_url = '%s/%s.git' % (os.environ['int_git_url'], repo_name)
    else:
        repo_url = '%s/%s.git' % (os.environ['ext_git_url'], repo_name)

    try:
        clone_dir = clone_directory
        if not os.path.isdir(clone_dir):
            os.makedirs(clone_dir)
        repo_path = os.path.join(clone_dir, uniq_path)

        if internal==True:
            username = os.environ['int_git_user']
            password = os.environ['int_git_token']
            login_info = git.UserPass(username, password)
            
            #git_obj = git.clone_repository(repo_url, repo_path, credentials=login_info)
            cb = git.RemoteCallbacks(credentials=login_info)
            git_obj = git.clone_repository(repo_url, repo_path, callbacks=cb)
        else:
            #username = os.environ['ext_git_user']
            #password = os.environ['ext_git_token']
            git_obj = git.clone_repository(repo_url, repo_path)

        return repo_path
    except Exception, e:
        if str(e).find('Unexpected HTTP status code: 404'):
            log.logger.error("repo doesn't exists")
            return "Repo doesn't exists"
        log.logger.error(e)
github dpnishant / raptor / backend / raptor_init.py View on Github external
uniq_path = hashlib.sha224(repo_name).hexdigest()
	if os.path.isdir(os.getcwd() + '/clones/' + uniq_path):
		shutil.rmtree(os.getcwd() + '/clones/' + uniq_path)

	repo_url = 'https://github.com/%s.git' % (repo_name)

	try:
		clone_dir = os.getcwd() + '/clones/'
		if not os.path.isdir(clone_dir):
			os.makedirs(clone_dir)
		repo_path = clone_dir + uniq_path
		login_info = ''
		if internal==True:
			username = 'dpnishant' #your-github-username-here
			password = str(keyring.get_password('github', username))
			login_info = git.UserPass(username, password)
		git_obj = git.clone_repository(repo_url, repo_path, credentials=login_info)			
		return repo_path
	except Exception, e:
		print e
		if str(e).find('Unexpected HTTP status code: 404'):
			print "Repo doesn't exists"
			return "Repo doesn't exists"
		#return str(e)
github ministryofjustice / salt-shaker / misc / convert_formulas.py View on Github external
def http_creds_callback(*args, **kwargs):
    return pygit2.UserPass(GH_TOKEN, 'x-oauth-basic')
github AKSW / QuitStore / quit / git.py View on Github external
# pygit2._pygit2.GitError: Failed to authenticate SSH session:
                # Unable to extract public key from private key file:
                # Method unimplemented in libgcrypt backend
                pubkey = join(ssh, 'id_rsa.pub')
                privkey = join(ssh, 'id_rsa')
                # check if ssh key is available in the directory
                if os.path.isfile(pubkey) and os.path.isfile(privkey):
                    return pygit2.Keypair(username_from_url, pubkey, privkey, "")
                else:
                    raise Exception(
                        "No SSH keys could be found, please specify SSH_AUTH_SOCK or add keys to " +
                        "your ~/.ssh/"
                    )
        elif pygit2.credentials.GIT_CREDTYPE_USERPASS_PLAINTEXT & allowed_types:
            if self.session and "OAUTH_TOKEN" in self.session:
                return pygit2.UserPass(self.session["OAUTH_TOKEN"], 'x-oauth-basic')
            elif "GIT_USERNAME" in os.environ and "GIT_PASSWORD" in os.environ:
                return pygit2.UserPass(os.environ["GIT_USERNAME"], os.environ["GIT_PASSWORD"])
            else:
                raise Exception(
                    "Remote requested plaintext username and password authentication but " +
                    "GIT_USERNAME or GIT_PASSWORD are not set."
                )
        else:
            raise Exception("Only unsupported credential types allowed by remote end")