gitpython: How to authenticate as a Github app? - python

When I do
remote = f"https://{username}:{password}#github.com/user/repo"
git.Repo.clone_from(remote, 'repo')
I get to clone the repository with my personal credentials.
But if I try an app credentials
remote = f"https://x-access-token:{token}#github.com/user/repo.git"
git.Repo.clone_from(remote, 'repo')
I get
remote: Invalid username or password. fatal: Authentication failed for
'https://github.com/user/repo'
I have installed the app and added it to the repository integrations. It has content permissions to read and write.
I am using the client secret as the token.

Related

Connect to an gitlab user

i would like to connect to a user in my gitlab server.
i connect to the gitlab server:
import gitlab
gl = gitlab.Gitlab('http://10.0.0.120')
print(gl.users.list())
the connect to the server not getting me any errors but after adding the line:
print(gl.users.list())
i get this error:
raise error(e.error_message, e.response_code, e.response_body) from e
gitlab.exceptions.GitlabListError: 403: 403 Forbidden - Not authorized to access /api/v4/users
how can i fix this?
thanks.
Usually, we use the terminal to connect to gitlab users. You can follow the following steps:
Call the terminal with "ctrl+~" in vscode
Use command git init
Configure user name and mailbox:
git config --global user.name “user.name"
git config --global user.email "user.email"

GCP Authenticate as End User using gcloud auth (not service account)

On my GCP VM (ubuntu) server, if I run:
gcloud init
in the terminal, and log in as my username (NOT A SERVICE ACCOUNT), e.g. my.name#companyname.com, then I can be authenticated as my user self, and am authenticated for all gcp related python functions.
>>> import google.auth
>>> credentials, project = google.auth.default()
UserWarning: Your application has authenticated using end user credentials from Google Cloud SDK without a quota project. You might receive a "quota exceeded" or "API not enabled" error. We recommend you rerun `gcloud auth application-default login` and make sure a quota project is added. Or you can use service accounts instead. For more information about service accounts, see https://cloud.google.com/docs/authentication/
warnings.warn(_CLOUD_SDK_CREDENTIALS_WARNING)
However, when I follow the same process on my local windows machine, I get this error:
>>> import google.auth
>>> credentials, project = google.auth.default()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\ProgramData\Anaconda3\lib\site-packages\google\auth\_default.py", line 354, in default
raise exceptions.DefaultCredentialsError(_HELP_MESSAGE)
google.auth.exceptions.DefaultCredentialsError: Could not automatically determine credentials. Please set GOOGLE_APPLICATION_CREDENTIALS or explicitly create credentials and re-run the
application. For more information, please see https://cloud.google.com/docs/authentication/getting-started
I do not want to use a service account. I want to be authenticated using end user credentials (Without using flow).
Solution:
Run
gcloud auth application-default login
in the windows machine, and login as the user you want.

django ldap auth not working from the app

anyone using django_auth_ldap against an active directory server
I am trying to set up auth through django_auth_ldap and am having an issue.
if i run my auth from the django interactive shell the auth works fine.
example from the shell
>>> from django.contrib.auth import authenticate
>>> authenticate(username='#############',password='*************')
search_s('ou=People, o=hp.com', 2, '(uid=%(user)s)') returned 1 objects: uid=###########,ou=people,o=hp.com
Populating Django ###########
Django user ########## does not have a profile to populate
<User:########## >
but the same code from within a view in the app fails with
Caught LDAPError while authenticating ##########: SERVER_DOWN({'desc': "Can't contact LDAP server"},)
I figured it out. I decided I would set up remote debugging so that I could step through the process and see where it was failing in that process I found that the httpd process was being prevented (by selinux) from making a network connection back to my eclipse IDE fixing this fixed the app. I think selinux was preventing the app from connecting to the ldap server. When I got my debug environment all worked out and stepped through it all worked fine !
the command to allow httpd to make a network connection
as root
setsebool -P httpd_can_network_connect 1

Deploying Code to Heroku (Issues?)

https://devcenter.heroku.com/articles/python
When i'm trying to deploy my code through $ git push heroku master i get an error:
Warning: Permanently added the RSA host key for IP address '50.19.85.132' to the list of known hosts.
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
Next, I was able to add the RSA host key for that IP address by $ heroku keys:add but I still get this error:
Found existing public key: /Users/opalkale/.ssh/github_rsa.pub
Uploading SSH public key /Users/opalkale/.ssh/github_rsa.pub... done
(venv)Opal-Kales-MacBook-Pro:helloflask opalkale$ git push heroku master
Permission denied (publickey).
What am I doing wrong...?
Add your id_rsa.pub SSH key to your Heroku account online: https://dashboard.heroku.com/account
And make sure that the corresponding private key has been added to your identity
$ ssh-add ~/.ssh/id_rsa
E.g.
$ ssh-add ~/.ssh/github_rsa

Heroku Neo4j Issue

I have my neo4j python application using py2neo.
It is working corretly on local but when i deploy it to heroku it is giving error
py2neo.rest.SocketError
SocketError: gaierror(-2, 'Name or service not known')
I am not sure what is the issue.
what should be the correct issue I am using url for db service as
graph_db = neo4j.GraphDatabaseService("http://xyz.hosted.neo4j.org:7480/db/data/")
Configure the authentication as indicated here:
http://packages.python.org/py2neo/neo4j.html#authentication
Use heroku config to note the username and password in the URL.
For example (obviously modified):
$ heroku config
=== secure-caverns-9214 Config Vars
NEO4J_URL: http://username:password#17d0afad4.hosted.neo4j.org:7755
PATH: bin:node_modules/.bin:/usr/local/bin:/usr/bin:/bin

Categories