Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Small changes before moving to kilnauth #5

Merged
merged 4 commits into from over 2 years ago

4 participants

Craig Silverstein Chris Klaiber Marcos Ojeda Ben Alpert
Craig Silverstein
Owner

Baby steps...

Ben Alpert spicyj commented on the diff
review.py
((9 lines not shown))
232 242 url_prefix = repo.ui.config('auth', 'kiln.prefix')
233 243 if url_prefix is None:
234 244 ui.warn("In order to work, in your hgrc please set:\n\n")
235 245 ui.warn("[auth]\n")
236   - ui.warn("kiln.prefix = https://<kilnrepo.kilnhg.com>\n")
237   - ui.warn("kiln.username = <username>@<domain>.com\n")
  246 + ui.warn("kiln.prefix = https://<kilnrepo.kilnhg.com> # no trailing /\n")
3
Ben Alpert Owner
spicyj added a note

Does a trailing slash break things?

Craig Silverstein Owner
csilvers added a note

Yes, it did in my previous tests. We could maybe fix it but in my experience it's better to just have a strict format and stick to it.

Craig Silverstein Owner
csilvers added a note

OMG, I just realized that this is showing up as new. I guess I didn't do a pull request for my last set of fixes about a month ago! Based on user feedback of problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Chris Klaiber
Owner

LGTM

Craig Silverstein csilvers Add the ability to use kilnauth to get an authentication token for re…
…view.

It looks like kilnauth is meant to hook into mercurial.url.open, and
while I got that working, it didn't seem to set credentials the way I
wanted: it looks like the kiln API doesn't automatically take the
token from the fbToken header?

So instead I hack into kilnauth internals a bit in order to extract
the fbToken that it would put in the cookie, and adding it to our url
requests (token=<fbToken>).  Kiln is happy with that.

I also moved the authentication error-checking to the auth routines
where it belongs.
d7e1811
Marcos Ojeda
Owner

rad

Marcos Ojeda
Owner
nsfmc commented

lgtm

Craig Silverstein csilvers Explicitly return None when kilnauth_path isn't present.
This is mostly cosmetic, since functions without an explicit return
value implicitly return None in python, but it better shows the
programmer intent.
fc015f9
Craig Silverstein csilvers merged commit 8f60426 into from
Craig Silverstein csilvers closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 4 unique commits by 1 author.

Apr 10, 2012
Craig Silverstein csilvers Print a better error message if we get access-denied from kiln. 108bcbe
Craig Silverstein csilvers Add a .gitignore file for .pyc files. 13d8a72
Craig Silverstein csilvers Add the ability to use kilnauth to get an authentication token for re…
…view.

It looks like kilnauth is meant to hook into mercurial.url.open, and
while I got that working, it didn't seem to set credentials the way I
wanted: it looks like the kiln API doesn't automatically take the
token from the fbToken header?

So instead I hack into kilnauth internals a bit in order to extract
the fbToken that it would put in the cookie, and adding it to our url
requests (token=<fbToken>).  Kiln is happy with that.

I also moved the authentication error-checking to the auth routines
where it belongs.
d7e1811
Craig Silverstein csilvers Explicitly return None when kilnauth_path isn't present.
This is mostly cosmetic, since functions without an explicit return
value implicitly return None in python, but it better shows the
programmer intent.
fc015f9
This page is out of date. Refresh to see the latest.

Showing 2 changed files with 56 additions and 7 deletions. Show diff stats Hide diff stats

  1. +1 0  .gitignore
  2. +55 7 review.py
1  .gitignore
... ... @@ -0,0 +1 @@
  1 +*.pyc
62 review.py
@@ -39,6 +39,8 @@
39 39 import mercurial.scmutil
40 40 import mercurial.ui
41 41 import mercurial.util
  42 +import os
  43 +import sys
42 44 import urllib
43 45 import urllib2
44 46
@@ -74,13 +76,54 @@ def _slurp_from_kiln(command, params, post=False):
74 76 return _slurp(_kiln_url(command), params, post)
75 77
76 78
77   -def _get_authtoken():
  79 +def _get_authtoken_from_kilnauth(ui):
  80 + """Attempts to use kilnauth, if it is installed, to find a kiln token."""
  81 + kilnauth_path = ui.config('extensions', 'kilnauth')
  82 + if kilnauth_path:
  83 + sys.path.append(os.path.dirname(kilnauth_path))
  84 + try:
  85 + import kilnauth
  86 + except ImportError:
  87 + return None
  88 +
  89 + class FakeRepo:
  90 + def local(self): return True
  91 + kilnauth.reposetup(ui, FakeRepo())
  92 +
  93 + hostname = ui.config('auth', 'kiln.prefix')
  94 + if '://' in hostname:
  95 + hostname = hostname[hostname.find('://')+3:]
  96 + if hostname.endswith('/'):
  97 + hostname = hostname[:-1]
  98 +
  99 + for cookie in kilnauth.get_cookiejar(ui):
  100 + if cookie.domain == hostname and cookie.name == 'fbToken':
  101 + return cookie.value
  102 +
  103 + return None
  104 +
  105 +
  106 +def _get_authtoken(ui):
78 107 """Returns credentials for accessing the kilnhg website."""
79   - # TODO(csilvers): just do this once and store the token, not the password
  108 + # If we can, we extract the token from kilnauth, if not we
  109 + # fall back to hard-coded username/password in the config.
  110 + retval = _get_authtoken_from_kilnauth(ui)
  111 + if retval:
  112 + return retval
  113 +
80 114 username = mercurial.ui.ui().config('auth', 'kiln.username')
81 115 password = mercurial.ui.ui().config('auth', 'kiln.password')
82   - return _slurp_from_kiln('Auth/Login',
83   - {'sUser': username, 'sPassword': password})
  116 + retval = _slurp_from_kiln('Auth/Login',
  117 + {'sUser': username, 'sPassword': password})
  118 +
  119 + if 'errors' in retval:
  120 + raise mercurial.util.Abort('Cannot access kiln. Make sure you either'
  121 + ' have kilnauth in your .hgrc and with a'
  122 + ' valid cookie (try running "hg pull"), or'
  123 + ' you have kiln.username and kiln.password'
  124 + ' set in your .hgrc')
  125 +
  126 + return retval
84 127
85 128
86 129 def _get_repo_to_push_to(repo, preferred_repo):
@@ -229,12 +272,17 @@ def push_with_review(origfn, ui, repo, *args, **opts):
229 272 if opts.get('rr') == ['none']:
230 273 return origfn(ui, repo, *args, **opts)
231 274
  275 + # TODO(csilvers): also bypass review if
  276 + # a) this push is a conflict-free merge push
  277 + # b) they have a review number in the commit notes (this means
  278 + # there's already a review for them in kilnhg).
  279 +
232 280 url_prefix = repo.ui.config('auth', 'kiln.prefix')
233 281 if url_prefix is None:
234 282 ui.warn("In order to work, in your hgrc please set:\n\n")
235 283 ui.warn("[auth]\n")
236   - ui.warn("kiln.prefix = https://<kilnrepo.kilnhg.com>\n")
237   - ui.warn("kiln.username = <username>@<domain>.com\n")
  284 + ui.warn("kiln.prefix = https://<kilnrepo.kilnhg.com> # no trailing /\n")
  285 + ui.warn("kiln.username = <username>@<domain.com>\n")
238 286 ui.warn("kiln.password = <password>\n")
239 287 return 0
240 288
@@ -247,7 +295,7 @@ def push_with_review(origfn, ui, repo, *args, **opts):
247 295
248 296 review_params = {}
249 297
250   - auth_token = _get_authtoken()
  298 + auth_token = _get_authtoken(ui)
251 299 review_params['token'] = auth_token
252 300
253 301 # -rtitle: title

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.