Skip to content

Commit

Permalink
Fix literal credentials
Browse files Browse the repository at this point in the history
Literal `credentials` lost test coverage (had none to start with) when the pants repo switched to `netrc_credentials`. Add coverage, and fix exposed issues.

Testing Done:
https://travis-ci.org/pantsbuild/pants/builds/119377185

Bugs closed: 3113

Reviewed at https://rbcommons.com/s/twitter/r/3624/
  • Loading branch information
stuhood committed Mar 29, 2016
1 parent acbeb56 commit 38d4c65
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 13 deletions.
16 changes: 6 additions & 10 deletions src/docs/setup_repo.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@ defined in your plugin:
'public': { # must match the name of the `Repository` object that you defined in your plugin.
'resolver': 'maven.example.com', # must match hostname in ~/.netrc and the <url> parameter
# in your custom ivysettings.xml.
'auth': 'build-support:netrc', # Pants spec to a 'credentials()' object.
'auth': 'build-support:netrc', # Pants spec to a 'credentials()' or
# 'netrc_credentials()' object.
'help': 'Configure your ~/.netrc for maven.example.com access.'
},
'testing': {
Expand All @@ -270,12 +271,7 @@ matches the `repos` specified above:
And place the following in a `BUILD` file somewhere in your repository (`build-support/BUILD` is a
good place, and is used in the example above):

netrc = netrc()

credentials(
name = 'netrc',
username=netrc.getusername,
password=netrc.getpassword)
netrc_credentials(name = 'netrc')

Next, tell Ivy how to publish to your repository. Add a new `ivysettings.xml` file to your repo
with the additional information needed to publish artifacts. Here is an example to get you started:
Expand All @@ -285,9 +281,9 @@ with the additional information needed to publish artifacts. Here is an example

<ivysettings>
<settings defaultResolver="chain-repos"/>
<!-- The ${login} and ${password} values come from a credentials() object in a BUILD file,
which is fed by '~/.netrc'. There must be a '~/.netrc' machine entry which matches
a resolver in the "repos" object in 'pants.ini', which also matches the 'host' in
<!-- The ${login} and ${password} values come from a netrc_credentials() object in a BUILD
file, which is fed by '~/.netrc'. There must be a '~/.netrc' machine entry which
matches a resolver in the "repos" object in 'pants.ini', which also matches the 'host' in
this XML block.

machine <hostname>
Expand Down
6 changes: 3 additions & 3 deletions src/python/pants/backend/jvm/targets/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ def __init__(self, username=None, password=None, **kwargs):
"""
super(LiteralCredentials, self).__init__(**kwargs)

deprecated_conditional(callable(username) or callable(password), '0.0.82',
deprecated_conditional(lambda: callable(username) or callable(password), '0.0.82',
'Passing callable arguments to `credentials` is deprecated: '
'use `netrc_credentials` for target {}'.format(
self.address.spec
))

self._username = username if callable(username) else functools.partial(_ignored_repository(username))
self._password = password if callable(password) else functools.partial(_ignored_repository(password))
self._username = username if callable(username) else functools.partial(_ignored_repository, username)
self._password = password if callable(password) else functools.partial(_ignored_repository, password)

def username(self, repository):
return self._username(repository)
Expand Down
9 changes: 9 additions & 0 deletions tests/python/pants_test/backend/jvm/targets/BUILD
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
# Copyright 2015 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

python_tests(
name='credentials',
sources=['test_credentials.py'],
dependencies=[
'src/python/pants/backend/jvm/targets:jvm',
'tests/python/pants_test:base_test',
]
)

python_tests(
name='jar_dependency',
sources=['test_jar_dependency.py'],
Expand Down
20 changes: 20 additions & 0 deletions tests/python/pants_test/backend/jvm/targets/test_credentials.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# coding=utf-8
# Copyright 2016 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

from __future__ import (absolute_import, division, generators, nested_scopes, print_function,
unicode_literals, with_statement)

from pants.backend.jvm.targets.credentials import LiteralCredentials
from pants_test.base_test import BaseTest


class CredentialsTest(BaseTest):

def test_literal_declaration(self):
username = 'please don`t ever do this.'
password = 'seriously, don`t.'
t = self.make_target(':creds', LiteralCredentials, username=username, password=password)

self.assertEquals(t.username('anything'), username)
self.assertEquals(t.password('anything'), password)

0 comments on commit 38d4c65

Please sign in to comment.