Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add a uri_scheme option #247

Closed
wants to merge 3 commits into from

5 participants

@mmrobins

This allows github enterprise installations that don't use https to use the
hub gem.

I think all installations should use https, but I don't control my company's
install, and their argument for not using https is that the install is only
available over VPN, so traffic is already encrypted, and using https means
they'd need to buy another https cert.

So until I can convince them otherwise, I'd still like to be able to make
pull-requests from the command line.

The cucumber tests don't run for me

undefined method `posix_spawn=' for ChildProcess:Module (NoMethodError)

so I haven't updated them. If I comment out that line in
features/support/env.rb there's already failures in the master branch, so it's
hard to tell if my changes could have broken anything.

@mmrobins mmrobins referenced this pull request
Closed

Http support #234

@mislav mislav referenced this pull request from a commit
@mislav mislav ChildProcess.posix_spawn= isn't always available
References #257, references #247
3b4f2d8
@gvaughn

I'm in the same boat: http only for our GH:Ent install. However, there seems to be a chicken and egg problem here. I can't get hub to generate the ~/.config/hub file containing an auth token in the first place. But I need that file to tell hub I want to use http instead of https. Is there a workaround?

@mmrobins

@gvaughn When I run something like hub fork for a project on github enterpirse and don't have a ~/.config/hub, it generates a ~/.config/hub entry for my github enterprise with uri_scheme set to https as soon as I enter my username. Then when I enter my password, it fails with "Errno::ECONNREFUSED" because of the uri_scheme issue. Then I just change the uri_scheme in the ~/.config/hub, and rerun hub fork, and this time when I enter my password it works and puts the oauth_token in.

Does it not generate the ~/.config/hub with an entry for your github enterprise url when you enter your username at the prompt? If so, maybe you didn't follow the instructions to whitelist your github enterprise?

git config --global --add hub.host my.example.org
Matt Robinson added some commits
Matt Robinson Add a uri_scheme option
This allows github enterprise installations that don't use https to use
the hub gem.

I think all installations should use https, but I don't control my
company's install, and their argument for not using https is that the
install is only available over VPN, so traffic is already encrypted, and
using https means they'd need to buy another https cert.

So until I can convince them otherwise, I'd still like to be able to
make pull-requests from the command line.
ee1c871
Matt Robinson fix `hub browse` with http 396b834
Matt Robinson Fix hub browse to work without a ~/.config/hub entry 5543fe7
@mislav
Owner

Hey guys. The current process for adding an enterprise host is convoluted and too manual, even more so if I merge this pull request. This is evident by your current problems. I need to improve this.

The code in this pull request is solid and I will work with that. However you don't need to contribute to this pull request further. I'm in the process of restructuring things a little, and will report back when done.

@mmrobins

@mislav I just noticed that the cucumbers were passing in master, so I was working a bit on fixing those with my PR.

I realized that with my "fix" to hub browse I made it so it didn't work without there being a ~/.config/hub entry, which shouldn't be necessary and caused lots of cuc failures, so I fixed that and force pushed to get it based off master with the new code. It's still a little awkward to need to load the ~/.config/hub in lib/hub/context.rb, but I think a little better.

I also noticed that one of the remaining cucumber failures says that the ~/.config/hub shouldn't be present if the authentication step fails, and that's no longer the case. I was going to work on fixing that, but I'll hold off if you're restructuring.

Let me know if I can help with the restructuring or any further improvements to this branch and thanks again.

@gvaughn

Just got back to this. Thanks for the replies. I hadn't pulled down this PR yet and figured out how to override my brew-installed hub. It is the 1.10.12 code that won't create the ~/.config/hub if there's an auth error. So I'm not really reporting anything knew.

@mislav will you follow up here with your progress or is there somewhere else I should sign up to stay in the loop?

@mmrobins

@gvaughn, I'm a little confused how you expect to be able to change the scheme to http from https if you haven't pulled down this PR yet. The currently released code for hub won't let you do that, but if you're running the code in this PR, then the steps I describe above should work for you until @mislav finishes restructuring, merging and releasing some form of this PR.

@gvaughn

@mmrobins Sorry for the confusion. I didn't have a lot of time to devote to this. I was going to quickly set up my config file, then figure out how to get your branch to mask the brew'd hub (and be easy to undo) as a second step. I now understand that ordering doesn't work. I'll try to find time to do it right this evening.

@gvaughn

@mmrobins I got it working. I just had to read the docs. I moved my old hub script and then ran "rake install prefix=/usr/local" from a clone of your branch. I got ~/.config/hub setup with 'http' and my initial experiments with 'hub browse' is working great. Thanks.

I'll still keep an eye on @mislav 's long term solution, but this is a great step forward for the time being.

@mmrobins

@mislav just remembered this PR since I had a coworker ask about using hub. Any word on the restructuring of enterprise auth? I'll haven't checked the code in master in a while, but I can try to rebase or something if it would help get this in.

@mislav
Owner

I didn't yet get around to improving that. I definitely want to have an enterprise command that configures your enterprise host (optionally with plain http) and saves everything to ~/.config/hub instead of hub.host in your gitconfig. However, the new solution would have to be backwards compatible with people who are currently using Enterprise.

It's a tricky problem. You're welcome to take a stab.

@mislav mislav referenced this pull request in git-merge/hack-day
Closed

Improving `pull-request` and other features of hub CLI tool #1

@Yeraze

So it's been almost a year.. Any progress on this?

@mmrobins

I've just been using my branch to run hub commands, feel free to use it as well. I haven't tried to merge any of master back in or anything, but may try. I didn't really want to take a stab at and enterprise command either.

@gvaughn

I can confirm that. I've been running @mmrobins branch this entire time. No complaints. However, I did have a co-worker ask me the other day how 'git browse' was working for me. When I pointed them to this thread, they declined spending the time to set it up and be off mainline hub.

@mislav
Owner

No progress. I'm sorry. I wanted to cover this while making a specialized hub subcommand that handles authentication and Enterprise configuration, but I never got around to actually writing it.

I'll think about merging parts of this PR and have people edit their hub config file manually if they really want this. The PR is good stuff; I just want the diff to be smaller and I have an idea how to achieve that.

@Yeraze

So, I loaded up the @mmrobins fork and that gets me the basics.. But browse, compare, etc (the various webpage loading functions) still try to load an https url (and fail). How do I override that?

@msabramo

@Yeraze: Did you set:

uri_scheme: http

in ~/.config/hub? That's what made browse work for me.

@msabramo

#485 is #247 (this PR) but updated for the latest code on master.

@msabramo

or for a smaller change that only makes browse work, see #484 ("Allow browse to work with Enterprise server with only HTTP"), but it probably makes more sense to look at #485, since that is more comprehensive and is derived from this PR, which has been tested for a while by @mmrobins and @gvaughn.

@Yeraze

Ah.. got it figured out, thanks :)

@msabramo

@Yeraze: Cool! You might want to try #484 #485, as this has the changes here and the latest stuff on master. If it works, you could give it a thumbs up (:+1:), which would maybe help with getting it merged.

@Yeraze

I went straight for #485 actually, but I'll do that :)

@msabramo

Oops, I meant #485 actually :smile: Sorry. Mixing up PRs.

@mislav
Owner

Thanks for the feature idea. This is now possible in master via the protocol option (instead of uri_scheme)

@mislav mislav closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 11, 2012
  1. Add a uri_scheme option

    Matt Robinson authored
    This allows github enterprise installations that don't use https to use
    the hub gem.
    
    I think all installations should use https, but I don't control my
    company's install, and their argument for not using https is that the
    install is only available over VPN, so traffic is already encrypted, and
    using https means they'd need to buy another https cert.
    
    So until I can convince them otherwise, I'd still like to be able to
    make pull-requests from the command line.
  2. fix `hub browse` with http

    Matt Robinson authored
  3. Fix hub browse to work without a ~/.config/hub entry

    Matt Robinson authored
This page is out of date. Refresh to see the latest.
View
16 README.md
@@ -330,6 +330,22 @@ $ git clone defunkt/repl
< https clone >
~~~
+### GitHub Enterprise
+
+To use the hub gem with your GitHub Enterprise installation, first whitelist
+your hostname
+
+ $ git config --global --add hub.host my.example.org
+
+If for some reason your GitHub Enterprise installation only runs over http (not
+https), first see if you can't fix it to run over https. If you can't, you'll
+need to modify your $HOME/.config/hub to set the uri_scheme to http for the
+Enterprise hostname
+
+ my.example.org:
+ - user: myuser
+ oauth_token: mytoken
+ uri_scheme: http
Contributing
------------
View
16 lib/hub/context.rb
@@ -257,7 +257,7 @@ def web_url(path = nil)
path = '/wiki' + path
end
end
- "https://#{host}/" + project_name + path.to_s
+ "#{scheme}://#{host}/" + project_name + path.to_s
end
def git_url(options = {})
@@ -266,6 +266,20 @@ def git_url(options = {})
else "git://#{host}/"
end + name_with_owner + '.git'
end
+
+ private
+
+ def scheme
+ config_file = ENV['HUB_CONFIG'] || '~/.config/hub'
+
+ if File.exist? File.expand_path(config_file)
+ file_store = GitHubAPI::FileStore.new File.expand_path(config_file)
+ config = GitHubAPI::Configuration.new file_store
+ config.uri_scheme(host)
+ else
+ 'https'
+ end
+ end
end
class GithubURL < URI::HTTPS
View
36 lib/hub/github_api.rb
@@ -28,6 +28,7 @@ class GitHubAPI
# - api_token(host, user)
# - password(host, user)
# - oauth_token(host, user)
+ # - uri_scheme(host)
def initialize config, options
@config = config
@oauth_app_url = options.fetch(:app_url)
@@ -48,8 +49,8 @@ def api_host host
# Public: Fetch data for a specific repo.
def repo_info project
- get "https://%s/repos/%s/%s" %
- [api_host(project.host), project.owner, project.name]
+ get "%s://%s/repos/%s/%s" %
+ [config.uri_scheme(project.host), api_host(project.host), project.owner, project.name]
end
# Public: Determine whether a specific repo exists.
@@ -59,8 +60,8 @@ def repo_exists? project
# Public: Fork the specified repo.
def fork_repo project
- res = post "https://%s/repos/%s/%s/forks" %
- [api_host(project.host), project.owner, project.name]
+ res = post "%s://%s/repos/%s/%s/forks" %
+ [config.uri_scheme(project.host), api_host(project.host), project.owner, project.name]
res.error! unless res.success?
end
@@ -71,18 +72,21 @@ def create_repo project, options = {}
params[:description] = options[:description] if options[:description]
params[:homepage] = options[:homepage] if options[:homepage]
+ uri_scheme = config.uri_scheme(project.host)
if is_org
- res = post "https://%s/orgs/%s/repos" % [api_host(project.host), project.owner], params
+ res = post "%s://%s/orgs/%s/repos" %
+ [uri_scheme, api_host(project.host), project.owner], params
else
- res = post "https://%s/user/repos" % api_host(project.host), params
+ res = post "%s://%s/user/repos" %
+ [uri_scheme, api_host(project.host)], params
end
res.error! unless res.success?
end
# Public: Fetch info about a pull request.
def pullrequest_info project, pull_id
- res = get "https://%s/repos/%s/%s/pulls/%d" %
- [api_host(project.host), project.owner, project.name, pull_id]
+ res = get "%s://%s/repos/%s/%s/pulls/%d" %
+ [config.uri_scheme(project.host), api_host(project.host), project.owner, project.name, pull_id]
res.error! unless res.success?
res.data
end
@@ -102,8 +106,8 @@ def create_pullrequest options
params[:body] = options[:body] if options[:body]
end
- res = post "https://%s/repos/%s/%s/pulls" %
- [api_host(project.host), project.owner, project.name], params
+ res = post "%s://%s/repos/%s/%s/pulls" %
+ [config.uri_scheme(project.host), api_host(project.host), project.owner, project.name], params
res.error! unless res.success?
res.data
@@ -239,15 +243,16 @@ def apply_authentication req, url
end
def obtain_oauth_token host, user
+ uri_scheme = config.uri_scheme(host)
# first try to fetch existing authorization
- res = get "https://#{user}@#{host}/authorizations"
+ res = get "#{uri_scheme}://#{user}@#{host}/authorizations"
res.error! unless res.success?
if found = res.data.find {|auth| auth['app']['url'] == oauth_app_url }
found['token']
else
# create a new authorization
- res = post "https://#{user}@#{host}/authorizations",
+ res = post "#{uri_scheme}://#{user}@#{host}/authorizations",
:scopes => %w[repo], :note => 'hub', :note_url => oauth_app_url
res.error! unless res.success?
res.data['token']
@@ -396,6 +401,13 @@ def proxy_uri(with_ssl)
URI.parse proxy
end
end
+
+ def uri_scheme host
+ user = @data.fetch_user normalize_host(host)
+ @data.fetch_value normalize_host(host), user, :uri_scheme do
+ 'https'
+ end
+ end
end
end
end
View
22 test/hub_test.rb
@@ -336,6 +336,24 @@ def test_pullrequest_enterprise_no_tracking
assert_output expected, "pull-request hereyougo -f"
end
+ def test_pullrequest_enterprise_no_tracking_http
+ stub_hub_host('git.my.org')
+ stub_repo_url('git@git.my.org:defunkt/hub.git')
+ stub_branch('refs/heads/feature')
+ stub_tracking_nothing('feature')
+ stub_command_output "rev-list --cherry-pick --right-only --no-merges origin/feature...", nil
+ edit_hub_config do |data|
+ data['git.my.org'] = [{'user'=>'myfiname', 'oauth_token' => 'FITOKEN', 'uri_scheme' => 'http'}]
+ end
+
+ stub_request(:post, "http://git.my.org/api/v3/repos/defunkt/hub/pulls").
+ with(:body => {'base' => "master", 'head' => "myfiname:feature", 'title' => "hereyougo" }).
+ to_return(:body => mock_pullreq_response(1, 'api/v3/defunkt/hub', 'git.my.org', 'http'))
+
+ expected = "http://git.my.org/api/v3/defunkt/hub/pull/1\n"
+ assert_output expected, "pull-request hereyougo -f"
+ end
+
def test_pullrequest_explicit_head
stub_request(:post, "https://api.github.com/repos/defunkt/hub/pulls").
with(:body => {'base' => "master", 'head' => "tpw:yay-feature", 'title' => "hereyougo" }).
@@ -748,8 +766,8 @@ def with_host_os(value)
end
end
- def mock_pullreq_response(id, name_with_owner = 'defunkt/hub', host = 'github.com')
- Hub::JSON.generate :html_url => "https://#{host}/#{name_with_owner}/pull/#{id}"
+ def mock_pullreq_response(id, name_with_owner = 'defunkt/hub', host = 'github.com', uri_scheme = 'https')
+ Hub::JSON.generate :html_url => "#{uri_scheme}://#{host}/#{name_with_owner}/pull/#{id}"
end
def mock_pull_response(label, priv = false)
Something went wrong with that request. Please try again.