Skip to content

Commit

Permalink
refactor: rename github integration app configs for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
sgfost committed Oct 18, 2024
1 parent 1b64c51 commit a812066
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ SECRETS_DIR=${BUILD_DIR}/secrets
DB_PASSWORD_PATH=${SECRETS_DIR}/db_password
PGPASS_PATH=${SECRETS_DIR}/.pgpass
SECRET_KEY_PATH=${SECRETS_DIR}/django_secret_key
EXT_SECRETS=hcaptcha_secret github_client_secret orcid_client_secret discourse_api_key discourse_sso_secret mail_api_key github_app_private_key github_app_client_secret
EXT_SECRETS=hcaptcha_secret github_client_secret orcid_client_secret discourse_api_key discourse_sso_secret mail_api_key github_integration_app_private_key github_integration_app_client_secret
GENERATED_SECRETS=$(DB_PASSWORD_PATH) $(PGPASS_PATH) $(SECRET_KEY_PATH)

ENVREPLACE := deploy/scripts/envreplace
Expand Down
12 changes: 6 additions & 6 deletions base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ services:
- django_secret_key
- github_client_secret
- orcid_client_secret
- github_app_private_key
- github_app_client_secret
- github_integration_app_private_key
- github_integration_app_client_secret
- hcaptcha_secret
- mail_api_key
volumes:
Expand Down Expand Up @@ -97,10 +97,10 @@ secrets:
file: ./build/secrets/django_secret_key
github_client_secret:
file: ./build/secrets/github_client_secret
github_app_private_key:
file: ./build/secrets/github_app_private_key
github_app_client_secret:
file: ./build/secrets/github_app_client_secret
github_integration_app_private_key:
file: ./build/secrets/github_integration_app_private_key
github_integration_app_client_secret:
file: ./build/secrets/github_integration_app_client_secret
hcaptcha_secret:
file: ./build/secrets/hcaptcha_secret
mail_api_key:
Expand Down
8 changes: 4 additions & 4 deletions deploy/conf/.env.template
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ SENTRY_DSN=
GITHUB_CLIENT_ID=
ORCID_CLIENT_ID=

# github app
GITHUB_APP_ID=
GITHUB_APP_INSTALLATION_ID=
# github integration app
GITHUB_INTEGRATION_APP_ID=
GITHUB_INTEGRATION_APP_INSTALLATION_ID=
GITHUB_INTEGRATION_APP_CLIENT_ID=
GITHUB_MODEL_LIBRARY_ORG_NAME=
GITHUB_APP_CLIENT_ID=

# test
TEST_USER_ID=10000000
Expand Down
18 changes: 12 additions & 6 deletions django/core/settings/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,12 +510,18 @@ def is_test(self):
GITHUB_CLIENT_ID = os.getenv("GITHUB_CLIENT_ID", "")
GITHUB_CLIENT_SECRET = read_secret("github_client_secret")

GITHUB_APP_ID = int(os.getenv("GITHUB_APP_ID") or 0)
# FIXME: should the main socialauth app be the same as the mirroring app?
GITHUB_APP_CLIENT_ID = os.getenv("GITHUB_APP_ID", "")
GITHUB_APP_CLIENT_SECRET = read_secret("github_app_client_secret")
GITHUB_APP_PRIVATE_KEY = read_secret("github_app_private_key")
GITHUB_APP_INSTALLATION_ID = int(os.getenv("GITHUB_APP_INSTALLATION_ID") or 0)
GITHUB_INTEGRATION_APP_ID = int(os.getenv("GITHUB_INTEGRATION_APP_ID") or 0)
GITHUB_INTEGRATION_APP_PRIVATE_KEY = read_secret("github_integration_app_private_key")
GITHUB_INTEGRATION_APP_INSTALLATION_ID = int(
os.getenv("GITHUB_INTEGRATION_APP_INSTALLATION_ID") or 0
)
# client id and secret are only used for getting user access tokens to be able to push
# to the user's repositories. We are not re-using the regular oauth app in order to
# keep minimal permissions
GITHUB_INTEGRATION_APP_CLIENT_ID = os.getenv("GITHUB_INTEGRATION_APP_ID", "")
GITHUB_INTEGRATION_APP_CLIENT_SECRET = read_secret(
"github_integration_app_client_secret"
)
GITHUB_MODEL_LIBRARY_ORG_NAME = os.getenv("GITHUB_MODEL_LIBRARY_ORG_NAME", "")

TEST_BASIC_AUTH_PASSWORD = os.getenv("TEST_BASIC_AUTH_PASSWORD", "test password")
Expand Down
10 changes: 5 additions & 5 deletions django/library/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,12 @@ def refresh_installation_access_token():
and cache it for future use
"""
auth = Auth.AppAuth(
settings.GITHUB_APP_ID,
settings.GITHUB_APP_PRIVATE_KEY,
settings.GITHUB_INTEGRATION_APP_ID,
settings.GITHUB_INTEGRATION_APP_PRIVATE_KEY,
)
integration = GithubIntegration(auth=auth)
installation_auth = integration.get_access_token(
settings.GITHUB_APP_INSTALLATION_ID
settings.GITHUB_INTEGRATION_APP_INSTALLATION_ID
)
token = installation_auth.token
seconds_until_expiration = (
Expand All @@ -161,8 +161,8 @@ def get_user_access_token(code: str):
"""
github = Github()
app = github.get_oauth_application(
settings.GITHUB_APP_CLIENT_ID,
settings.GITHUB_APP_CLIENT_SECRET,
settings.GITHUB_INTEGRATION_APP_CLIENT_ID,
settings.GITHUB_INTEGRATION_APP_CLIENT_SECRET,
)
return app.get_access_token(code).token

Expand Down

0 comments on commit a812066

Please sign in to comment.