3rd-party-integrations / github-team-sync

Sync GitHub teams to groups in Active Directory, LDAP, Okta, OneLogin or AzureAD when using any authentication method for GitHub.
MIT License
201 stars 67 forks source link

KeyError: 'APP_ID' #46

Closed kumar0608 closed 3 years ago

kumar0608 commented 4 years ago

[root@eq1vjenbslave13 saml-ldap-team-sync]# python3 app.py Traceback (most recent call last): File "app.py", line 14, in github_app = GitHubApp(app) File "/opt/jenkins/virtualenv/saml-ldap-team-sync/githubapp/core.py", line 32, in init self.init_app(app) File "/opt/jenkins/virtualenv/saml-ldap-team-sync/githubapp/core.py", line 74, in init_app self.load_env(app) File "/opt/jenkins/virtualenv/saml-ldap-team-sync/githubapp/core.py", line 36, in load_env app.config['GITHUBAPP_ID'] = int(os.environ['APP_ID']) File "/usr/lib64/python3.6/os.py", line 669, in getitem raise KeyError(key) from None KeyError: 'APP_ID'

primetheus commented 4 years ago

@kumar0608 have you configured your .env file? This app won't run without first creating the GitHub App and providing the connection info in there

primetheus commented 4 years ago

You can find more information about creating a GitHub App here: https://developer.github.com/apps/building-github-apps/creating-a-github-app/

primetheus commented 4 years ago

@kumar0608

This looks like it could be one of the following:

  1. The .env file is not in the same directory as app.py
  2. The Python environment doesn't have the prerequisites installed (python-dotenv should automatically load the .env file if it's installed)
  3. The .env file doesn't have APP_ID set (i.e. APP_ID=12345)

Can you tell me how you're running this? This issue seems to be running with /usr/lib64/python3.6/, but #44 seems to be running /usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/...

There's a Dockerfile provided that can help ensure the environment is consistent. Or, if you'd prefer to run without Docker you can run with pipenv to ensure you have an environment that isn't affected by outside configurations

pip install pipenv
pipenv install
pipenv run python app.py
kumar0608 commented 4 years ago

[root@eq1vjenbslave13 saml-ldap-team-sync]# docker build . Sending build context to Docker daemon 276kB Step 1/9 : FROM python:3-alpine ---> 8ecf5a48c789 Step 2/9 : LABEL version="2.0" ---> Using cache ---> 63e5ce14fba1 Step 3/9 : LABEL description="LDAP Team Sync for GitHub" ---> Using cache ---> dd9bbc3b1fcb Step 4/9 : MAINTAINER GitHub Services services@github.com ---> Using cache ---> 16c3aa745e0d Step 5/9 : COPY . /opt/github-team-sync ---> e61b254a5f31 Step 6/9 : WORKDIR /opt/github-team-sync ---> Running in c85bd893d1cb Removing intermediate container c85bd893d1cb ---> c03716c6dc5c Step 7/9 : RUN apk add --no-cache libxml2-dev libxslt-dev pipenv python3-dev make gcc libffi-dev build-base ---> Running in d5a69bea6e2d fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/main/x86_64/APKINDEX.tar.gz fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/community/x86_64/APKINDEX.tar.gz ERROR: unsatisfiable constraints: pipenv (missing): required by: world[pipenv] The command '/bin/sh -c apk add --no-cache libxml2-dev libxslt-dev pipenv python3-dev make gcc libffi-dev build-base' returned a non-zero code: 1HI Jaraed,

I "tried docker build . " to build docker image, but getting this error

On Mon, Jul 6, 2020 at 2:27 PM Jared Murrell notifications@github.com wrote:

This looks like it could be one of the following:

  1. The .env file is not in the same directory as app.py
  2. The Python environment doesn't have the prerequisites installed ( python-dotenv should automatically load the .env file if it's installed)
  3. The .env file doesn't have APP_ID set (i.e. APP_ID=12345)

Can you tell me how you're running this? This issue seems to be running with /usr/lib64/python3.6/, but #44 https://github.com/github/saml-ldap-team-sync/issues/44 seems to be running '/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/'...

There's a Dockerfile provided that can help ensure the environment is consistent. Or, if you'd prefer to run without Docker you can run with pipenv to ensure you have an environment that isn't affected by outside configurations

pip install pipenv pipenv install pipenv run python app.py

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/github/saml-ldap-team-sync/issues/46#issuecomment-654474466, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEMZET3LB2FQXDTZZRCXKQDR2I6VPANCNFSM4ORJHECQ .

primetheus commented 4 years ago

@kumar0608 I've pushed a fix for the Dockerfile... seems an upstream dependency is missing. #48 has a working Dockerfile I just tested

FROM python:3-alpine

LABEL version="2.0"
LABEL description="LDAP Team Sync for GitHub"

MAINTAINER GitHub Services <services@github.com>

COPY . /opt/github-team-sync
WORKDIR /opt/github-team-sync

RUN apk add --no-cache \
        libxml2-dev \
        libxslt-dev \
        python3-dev \
        make \
        gcc \
        libffi-dev \
        build-base \
        openssl-dev

RUN pip install --no-cache-dir pipenv

RUN pipenv install

CMD pipenv run flask run
kumar0608 commented 4 years ago

Thanks alot Jarad,

sorry to trouble you multiple times.

Thanks Sridhar

On Mon, Jul 6, 2020 at 9:14 PM Jared Murrell notifications@github.com wrote:

@kumar0608 https://github.com/kumar0608 I've pushed a fix for the Dockerfile... seems an upstream dependency is missing. #48 https://github.com/github/saml-ldap-team-sync/pull/48 has a working Dockerfile I just tested

FROM python:3-alpine LABEL version="2.0"LABEL description="LDAP Team Sync for GitHub" MAINTAINER GitHub Services services@github.com COPY . /opt/github-team-syncWORKDIR /opt/github-team-sync RUN apk add --no-cache \ libxml2-dev \ libxslt-dev \ python3-dev \ make \ gcc \ libffi-dev \ build-base \ openssl-dev RUN pip install --no-cache-dir pipenv RUN pipenv install CMD pipenv run flask run

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/github/saml-ldap-team-sync/issues/46#issuecomment-654588127, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEMZETZX2A4EM3YPMLEUFP3R2KOLTANCNFSM4ORJHECQ .

kumar0608 commented 4 years ago

HI Jarad

one more question.

what is the purpose of "PRIVATE_KEY_PATH" ?

THanks Sridahr

On Mon, Jul 6, 2020 at 9:16 PM Pragnya Ravula ravula06@gmail.com wrote:

Thanks alot Jarad,

sorry to trouble you multiple times.

Thanks Sridhar

On Mon, Jul 6, 2020 at 9:14 PM Jared Murrell notifications@github.com wrote:

@kumar0608 https://github.com/kumar0608 I've pushed a fix for the Dockerfile... seems an upstream dependency is missing. #48 https://github.com/github/saml-ldap-team-sync/pull/48 has a working Dockerfile I just tested

FROM python:3-alpine LABEL version="2.0"LABEL description="LDAP Team Sync for GitHub" MAINTAINER GitHub Services services@github.com COPY . /opt/github-team-syncWORKDIR /opt/github-team-sync RUN apk add --no-cache \ libxml2-dev \ libxslt-dev \ python3-dev \ make \ gcc \ libffi-dev \ build-base \ openssl-dev RUN pip install --no-cache-dir pipenv RUN pipenv install CMD pipenv run flask run

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/github/saml-ldap-team-sync/issues/46#issuecomment-654588127, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEMZETZX2A4EM3YPMLEUFP3R2KOLTANCNFSM4ORJHECQ .

primetheus commented 4 years ago

@kumar0608 the PRIVATE_KEY_PATH is the SSH private key that you generate when creating your GitHub App. You'll also need the App ID for it, and if you're running GHES then specify GHE_HOST in your .env as well

kumar0608 commented 4 years ago

Hi Jarad,

am getting this error

return callback(*args, **kwargs)

File "/root/.local/share/virtualenvs/github-team-sync-2hTjop5Y/lib/python3.8/site-packages/flask/cli.py", line 848, in run_command app = DispatchingApp(info.load_app, use_eager_loading=eager_loading) File "/root/.local/share/virtualenvs/github-team-sync-2hTjop5Y/lib/python3.8/site-packages/flask/cli.py", line 305, in init self._load_unlocked() File "/root/.local/share/virtualenvs/github-team-sync-2hTjop5Y/lib/python3.8/site-packages/flask/cli.py", line 330, in _load_unlocked self._app = rv = self.loader() File "/root/.local/share/virtualenvs/github-team-sync-2hTjop5Y/lib/python3.8/site-packages/flask/cli.py", line 392, in load_app app = locate_app(self, import_name, None, raise_if_not_found=False) File "/root/.local/share/virtualenvs/github-team-sync-2hTjop5Y/lib/python3.8/site-packages/flask/cli.py", line 240, in locate_app import(module_name) File "/opt/github-team-sync/app.py", line 14, in github_app = GitHubApp(app) File "/opt/github-team-sync/githubapp/core.py", line 32, in init self.init_app(app) File "/opt/github-team-sync/githubapp/core.py", line 74, in init_app self.load_env(app) File "/opt/github-team-sync/githubapp/core.py", line 40, in load_env with open(os.environ['PRIVATE_KEY_PATH'], 'rb') as key_file: FileNotFoundError: [Errno 2] No such file or directory: '/Users/sravula/.ssh/sync.2020-07-06.private-key.pem' OSXSRAVUMBP15:saml-ldap-team-sync sravula$

and my env file having this

PRIVATE_KEY_PATH=/Users/sravula/.ssh/sync.2020-07-06.private-key.pem GHE_HOST=github.devltools.rd.elliemae.io

On Mon, Jul 6, 2020 at 9:55 PM Jared Murrell notifications@github.com wrote:

@kumar0608 https://github.com/kumar0608 the PRIVATE_KEY_PATH is the SSH private key that you generate when creating your GitHub App. You'll also need the App ID for it, and if you're running GHES then specify GHE_HOST in your .env as well

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/github/saml-ldap-team-sync/issues/46#issuecomment-654599191, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEMZET4SNKPLGU4JNRXMET3R2KTDLANCNFSM4ORJHECQ .

kumar0608 commented 4 years ago

hi i have few questions this ssh key file are we copying to docker image ? when we run the app in the docker container this pen file should present in the respective location in the container rt?

Thanks sridhar

On Mon, Jul 6, 2020 at 10:20 PM Pragnya Ravula ravula06@gmail.com wrote:

Hi Jarad,

am getting this error

return callback(*args, **kwargs)

File "/root/.local/share/virtualenvs/github-team-sync-2hTjop5Y/lib/python3.8/site-packages/flask/cli.py", line 848, in run_command app = DispatchingApp(info.load_app, use_eager_loading=eager_loading) File "/root/.local/share/virtualenvs/github-team-sync-2hTjop5Y/lib/python3.8/site-packages/flask/cli.py", line 305, in init self._load_unlocked() File "/root/.local/share/virtualenvs/github-team-sync-2hTjop5Y/lib/python3.8/site-packages/flask/cli.py", line 330, in _load_unlocked self._app = rv = self.loader() File "/root/.local/share/virtualenvs/github-team-sync-2hTjop5Y/lib/python3.8/site-packages/flask/cli.py", line 392, in load_app app = locate_app(self, import_name, None, raise_if_not_found=False) File "/root/.local/share/virtualenvs/github-team-sync-2hTjop5Y/lib/python3.8/site-packages/flask/cli.py", line 240, in locate_app import(module_name) File "/opt/github-team-sync/app.py", line 14, in github_app = GitHubApp(app) File "/opt/github-team-sync/githubapp/core.py", line 32, in init self.init_app(app) File "/opt/github-team-sync/githubapp/core.py", line 74, in init_app self.load_env(app) File "/opt/github-team-sync/githubapp/core.py", line 40, in load_env with open(os.environ['PRIVATE_KEY_PATH'], 'rb') as key_file: FileNotFoundError: [Errno 2] No such file or directory: '/Users/sravula/.ssh/sync.2020-07-06.private-key.pem' OSXSRAVUMBP15:saml-ldap-team-sync sravula$

and my env file having this

PRIVATE_KEY_PATH=/Users/sravula/.ssh/sync.2020-07-06.private-key.pem GHE_HOST=github.devltools.rd.elliemae.io

On Mon, Jul 6, 2020 at 9:55 PM Jared Murrell notifications@github.com wrote:

@kumar0608 https://github.com/kumar0608 the PRIVATE_KEY_PATH is the SSH private key that you generate when creating your GitHub App. You'll also need the App ID for it, and if you're running GHES then specify GHE_HOST in your .env as well

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/github/saml-ldap-team-sync/issues/46#issuecomment-654599191, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEMZET4SNKPLGU4JNRXMET3R2KTDLANCNFSM4ORJHECQ .

primetheus commented 4 years ago

@kumar0608 yes, that file will need to be copied into the Docker container

  1. Place the key in the same folder with the source code, inside .ssh
  2. Edit the .env file to reference .ssh/sync.2020-07-06.private-key.pem (not the full path)
  3. Ensure your .env file contains entries for GHE_HOST, APP_ID and WEBHOOK_SECRET (not the defaults from the sample)
  4. Build the Docker container with docker build -t github/teamsync . and the files will all be copied in correctly
  5. Run the container with docker run -ditp 5000:5000 --name teamsync --restart unless-stopped github/teamsync
primetheus commented 4 years ago

@kumar0608 were you able to get this running?

kumar0608 commented 4 years ago

Hi Jarad,

i tried multiple times, stil having issues with docker setup

Thanks Kumar

On Fri, Jul 10, 2020 at 3:03 PM Jared Murrell notifications@github.com wrote:

@kumar0608 https://github.com/kumar0608 were you able to get this running?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/github/saml-ldap-team-sync/issues/46#issuecomment-656912358, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEMZETYEPGT7BGP3OKW2BPTR26F4NANCNFSM4ORJHECQ .

primetheus commented 4 years ago

@kumar0608 what is your time zone? It might be better to sync up and troubleshoot in realtime. I'm unable to replicate these errors

kumar0608 commented 4 years ago

Hi Jarad,

i am in california, PST time zone, please let me know your availability, so that I will be available any time

Thanks Sridhar

On Tue, Jul 28, 2020 at 5:12 AM Jared Murrell notifications@github.com wrote:

@kumar0608 https://github.com/kumar0608 what is your time zone? It might be better to sync up and troubleshoot in realtime.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/github/saml-ldap-team-sync/issues/46#issuecomment-665003449, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEMZET2TZDZYINWM6EJZJGTR526C7ANCNFSM4ORJHECQ .

primetheus commented 3 years ago

I'm unable to reproduce this error. If you still get this please open a new issue

Macasore commented 2 years ago

@primetheus sorry please i'm building a github bot with python and i've followed the necessary documentations but now im getting an error which says: AttributeError: module 'github' has no attribute 'Github'. Did you mean: 'GithubApp'? and when i change it to GithubApp i get this error: TypeError: 'module' object is not callable please help