forked from pantsbuild/pants
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Squashed commit of the Enabling local publish for pants build. Issue-…
…46: Cherrypick 64b54c04 from twitter/commons
- Loading branch information
Tejal Desai
committed
Apr 11, 2014
1 parent
301e897
commit 67a6dbd
Showing
9 changed files
with
96 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from pants.authentication.netrc_util import Netrc | ||
|
||
netrc = Netrc() | ||
|
||
credentials( | ||
name = 'netrc', | ||
username=netrc.getusername, | ||
password=netrc.getpassword) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Copyright 2014 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Copyright 2014 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
from __future__ import print_function | ||
|
||
import collections | ||
import os | ||
|
||
from netrc import netrc as NetrcDb, NetrcParseError | ||
|
||
from pants.tasks.task_error import TaskError | ||
|
||
|
||
class Netrc(object): | ||
|
||
def __init__(self): | ||
self._login = collections.defaultdict(lambda: None) | ||
self._password = collections.defaultdict(lambda: None) | ||
|
||
def getusername(self, repository): | ||
self._ensure_loaded() | ||
return self._login[repository] | ||
|
||
def getpassword(self, repository): | ||
self._ensure_loaded() | ||
return self._password[repository] | ||
|
||
def _ensure_loaded(self): | ||
if not self._login and not self._password: | ||
db = os.path.expanduser('~/.netrc') | ||
if not os.path.exists(db): | ||
raise TaskError('A ~/.netrc file is required to authenticate') | ||
try: | ||
db = NetrcDb(db) | ||
for host, value in db.hosts.items(): | ||
auth = db.authenticators(host) | ||
if auth: | ||
login, _, password = auth | ||
self._login[host] = login | ||
self._password[host] = password | ||
if len(self._login) == 0: | ||
raise TaskError('Found no usable authentication blocks for twitter in ~/.netrc') | ||
except NetrcParseError as e: | ||
raise TaskError('Problem parsing ~/.netrc: %s' % e) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters