Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Github Enterprise Support #3853

Closed
wants to merge 3 commits into from
Closed

Conversation

gaborbernat
Copy link
Contributor

@gaborbernat gaborbernat commented Mar 26, 2018

support

This solves #2194.


This change is Reviewable

@gaborbernat gaborbernat force-pushed the master branch 6 times, most recently from 888a0b0 to 38ee82a Compare March 27, 2018 08:46
@ericholscher ericholscher requested a review from a team March 28, 2018 10:42
Copy link
Member

@humitos humitos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution! This seems to be a good addition.

Although, I'm not sure to fully understand the problem itself. The only difference between GH and GHE is the URL that we hit? I mean, instead of github.com we need to hit whatever you defined in {{github_url}}?

It seems that it's needed to update a django setting to match the github provider name to the enterprise URL as pointed here: http://django-allauth.readthedocs.io/en/latest/providers.html#enterprise-support

I did that change and it worked. So, I think we need to mention that at some point.

In [1]: from allauth.socialaccount.providers.github.views import GitHubOAuth2Adapter

In [2]: GitHubOAuth2Adapter.profile_url
Out[2]: 'http://localhost:8000/api/v3/user'

In [3]: 

Finally, is there a way to co-exist both connections here: GH and GHE?

I'm requesting these changes before merging, but I think it's pretty close.

To swap out this connection with an enterprise edition of Github you need to:

1. Create an OAuth Github Application by following the `official guide <https://developer.github.com/apps/building-oauth-apps/creating-an-oauth-app/>`_. Note here you must provide the address of the readthedocs
instance you're setting up. This will give you a Github application ``client id`` and ``secret``.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this line be indented at the same level than Create word?

@@ -36,6 +38,8 @@

DEFAULT_VERSION_PRIVACY_LEVEL = getattr(
settings, 'DEFAULT_VERSION_PRIVACY_LEVEL', 'public')
ARGS = '/{user}/{repo}/{action}/{version}{docroot}{path}{source_suffix}'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe a name like _GITHUB_URL_ARS instead?

site, _ = Site.objects.update_or_create(id=SITE_ID, defaults=dict(name=PRODUCTION_DOMAIN, domain=PRODUCTION_DOMAIN))

# change the github social account provider to link to the enterprise Github
GITHUB = "{{github_url}}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem to be used at all.

@gaborbernat
Copy link
Contributor Author

@humitos yes you need to change that, however in some places the github.com was hard coded into the code, I've replaced in these cases to instead read it from from allauth.socialaccount.providers.github.provider import GitHubProvider (also I've already mention you need to do the change in there at: https://github.com/gaborbernat/readthedocs.org/blame/38ee82afe90b2a0af455f93b7baa699db4b8cf50/docs/custom_installs/github_enterprise.rst#L32 - this is a config change)
We could expose a main level variable in config if you guys think it would make it easier.

To have the connect account feature work you need to setup the site setting correctly (e.g. point to your domain and not example.com as it's by default - which is the first change in the script).

As for having both exists do we have a strong need for that, as would probably complicate the implementation.

@gaborbernat
Copy link
Contributor Author

@humitos made the requested changes, ready to discuss supporting an enterprise instance with github.com in parallel.

@@ -5,6 +5,8 @@
absolute_import, division, print_function, unicode_literals)

import logging

from allauth.socialaccount.providers.github.views import GitHubOAuth2Adapter
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from should go after import, and third party import should go after stdlib import and before local imports

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for import sorting, you can run isort command which does the trick automatically following our rules.

@@ -37,17 +40,12 @@ def handle(self, *args, **options):
return

for project in Project.objects.filter(
programming_language__in=['none', '', 'words']
programming_language__in=['none', '', 'words']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4 spaces was fine

tox.ini Outdated
@@ -15,6 +15,7 @@ setenv =
DJANGO_SETTINGS_MODULE=readthedocs.settings.test
LANG=C
DJANGO_SETTINGS_SKIP_LOCAL=True
passenv = https_proxy http_proxy no_proxy
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks unrelated

@@ -11,13 +11,16 @@
from __future__ import absolute_import
from __future__ import print_function
import os

from allauth.socialaccount.providers.github.views import GitHubOAuth2Adapter
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as before

@RichardLitt RichardLitt added the Improvement Minor improvement to code label Mar 28, 2018
@gaborbernat
Copy link
Contributor Author

Made the requested changes. By the way running isort would modify a lot of existing source files 🤔 are we sure it's configured correctly?

Copy link
Member

@humitos humitos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some minor comments


.. code-block:: python

SOCIALACCOUNT_PROVIDERS = {'github': {'SCOPE': ['user:email', 'read:org',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, if you modify local_settings.py like this, you override the setting and loose the gitlab feature, for example.

I've been using somethin like this:

from .dev import CommunityDevSettings

INSTALLED_APPS = CommunityDevSettings().INSTALLED_APPS + [
    'debug_toolbar',
]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay I can do; my approach was that people in an enterprise env usually just want one VCS, hence why removing gitlab is not needed anymore

re.compile('github.com/(.+)/(.+)'),
re.compile('github.com:(.+)/(.+)\.git$'),
GITHUB_REGEX_BASES = [
'{}/(.+)/(.+)(?:\.git){{1}}$',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this was on purpose, but it was {1} and now it's {{1}}. I suppose the original was correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no this change is needed, because now we'll format the string to get the regex, hence the double quotation actually keeps it as it was beforehand (aka literal {)

@humitos
Copy link
Member

humitos commented Mar 29, 2018

Made the requested changes. By the way running isort would modify a lot of existing source files thinking are we sure it's configured correctly?

Yes. It's correctly configured but it's something new and we didn't run to the entire project yet. We were running it only the files that we modify on each PR.

So, you could run it only on those files.

At a higher level, we have pre-commit configured (which will run only on your modified fields) but we are not forcing the community PR to run this command yet.

@humitos
Copy link
Member

humitos commented Mar 29, 2018

As for having both exists do we have a strong need for that, as would probably complicate the implementation.

We don't really need this for the community site since we don't support GHE in .org but I was asking you to know if this could be applicable in the readthedocs.com site. There, we will need to support:

  • multiples GHE accounts
  • GHE and regular GH connections living together
  • accessing to a private network of GHE instace

Anyway, I was checking if we could advance in one of those point in this PR but it seems that we won't be able to do this yet.

Currently, this is only useful for private installations of RTD source code.

@humitos humitos dismissed their stale review March 29, 2018 16:26

Changes I requested were already done

@gaborbernat
Copy link
Contributor Author

gaborbernat commented Mar 29, 2018

@humitos tox organization has a fix-lint target to setup and run automatically the pre-commit maybe we should have it here too, but that's part of a different PR/issue

Indeed this PR is useful for private installations of RTD. We can look into supporting more part of further subsequent PRs. I don't have access to multiple instances of these, hence why was not focusing on taking a look at it. But most likely it's something that can be done.

Additionally made the required change (this way we keep previous settings - gitlab included, only upgrade the github URL):

from .dev import CommunityDevSettings
_SETTINGS = CommunityDevSettings()

SOCIALACCOUNT_PROVIDERS = _SETTINGS.SOCIALACCOUNT_PROVIDERS
SOCIALACCOUNT_PROVIDERS['github']['GITHUB_URL'] == '{{github_url}}'

Part of a future PR we may want to make the GITHUB_URL a root level settings, and the CommunityDevSettings use that to construct it's own SOCIALACCOUNT_PROVIDERS.

PS. Also did rebase on current master, hence the change in commit hash here.

@@ -28,7 +28,7 @@ class GitHubService(Service):

adapter = GitHubOAuth2Adapter
# TODO replace this with a less naive check
url_pattern = re.compile(r'github\.com')
url_pattern = re.compile(re.escape(GitHubOAuth2Adapter.web_url))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realized that we can simply use self.adapter in all this class.

(it's the common usage for all the services implemented in RTD)

@gaborbernat
Copy link
Contributor Author

@humitos done

@humitos
Copy link
Member

humitos commented Apr 5, 2018

@gaborbernat nice! Thanks. There is a linting error, could you check it?

To me, this PR is ready for merge. Let's wait for another core team member to review it -- @agjohnson was interested on these changes also.

Signed-off-by: Bernat Gabor <bgabor8@bloomberg.net>
@gaborbernat
Copy link
Contributor Author

@humitos fixed 😄

@gaborbernat
Copy link
Contributor Author

@core ping 👍

@RichardLitt
Copy link
Member

You're heard, @gaborbernat. Four days (and over the weekend) isn't a lot of time for us - we'll get to this when we can.

@agjohnson
Copy link
Contributor

I'm happy that someone is able to take this on. Thanks for the contribution @gaborbernat !

I'll have more feedback when I can focus on this more, but for starters: this is touching a lot of important code and has no tests. So, fixing that is a good place to continue this work.

I'm going to target a future release, as this isn't quite on our roadmap. I think this is mostly close though. Apologies for any delays responding, off-roadmap PRs have lower priority for us.

@agjohnson agjohnson added Needed: tests Tests are required PR: work in progress Pull request is not ready for full review and removed PR: ready for review labels Apr 17, 2018
@agjohnson agjohnson added this to the 2.5 milestone Apr 17, 2018
@gaborbernat
Copy link
Contributor Author

Just an update. I definitely plan to continue to work on this. Just other things have come up. The fact that the actual code has not tests at the moment means I first need to figure out how this part is intended to be tested. Which makes picking up this non-trivial.

@gaborbernat
Copy link
Contributor Author

Due to lack of resource for working on this, I'll need to retract this PR. Thanks for the collaboration guys.

@gaborbernat gaborbernat closed this Jan 9, 2019
@RichardLitt
Copy link
Member

@gaborbernat Thanks for letting us know, and for your work, even if it wasn't merged in the end. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Improvement Minor improvement to code Needed: tests Tests are required PR: work in progress Pull request is not ready for full review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants