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

Use GPG'd netrc secrets when available #84

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 22 additions & 16 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,35 @@ GIT

GIT
remote: https://github.com/CocoaPods/CocoaPods.git
revision: 670952b563febda786895f9df80286a2e683d086
revision: 543cbba059c3873199b6a87695492cca85e3cf68
branch: master
specs:
cocoapods (1.1.0)
cocoapods (1.2.0.beta.2)
activesupport (>= 4.0.2, < 5)
claide (>= 1.0.1, < 2.0)
cocoapods-core (= 1.1.0)
cocoapods-core (= 1.2.0.beta.2)
cocoapods-deintegrate (>= 1.0.1, < 2.0)
cocoapods-downloader (>= 1.1.2, < 2.0)
cocoapods-downloader (>= 1.1.3, < 2.0)
cocoapods-plugins (>= 1.0.0, < 2.0)
cocoapods-search (>= 1.0.0, < 2.0)
cocoapods-stats (>= 1.0.0, < 2.0)
cocoapods-trunk (= 1.1.2)
cocoapods-trunk (>= 1.1.2, < 2.0)
cocoapods-try (>= 1.1.0, < 2.0)
colored (~> 1.2)
escape (~> 0.0.4)
fourflusher (~> 2.0.1)
gh_inspector (~> 1.0)
molinillo (~> 0.5.1)
molinillo (~> 0.5.4)
nap (~> 1.0)
xcodeproj (>= 1.3.2, < 2.0)
ruby-macho (~> 0.2.5)
xcodeproj (>= 1.4.1, < 2.0)

GIT
remote: https://github.com/CocoaPods/Core.git
revision: 92b15bb175facbf57839fa08c44194ab9b8b80b2
revision: 346adb902985092c6c72ef735f15c2f3da89254d
branch: master
specs:
cocoapods-core (1.1.0)
cocoapods-core (1.2.0.beta.2)
activesupport (>= 4.0.2, < 5)
fuzzy_match (~> 2.0.4)
nap (~> 1.0)
Expand All @@ -51,11 +52,12 @@ PATH
specs:
cocoapods-trunk (1.1.2)
nap (>= 0.8, < 2.0)
netrc (= 0.7.8)
netrc (~> 0.10)

GEM
remote: https://rubygems.org/
specs:
CFPropertyList (2.3.4)
activesupport (4.2.7.1)
i18n (~> 0.7)
json (~> 1.7, >= 1.7.7)
Expand All @@ -66,7 +68,7 @@ GEM
ast (2.2.0)
bacon (1.2.0)
cocoapods-deintegrate (1.0.1)
cocoapods-downloader (1.1.2)
cocoapods-downloader (1.1.3)
cocoapods-plugins (1.0.0)
nap
cocoapods-search (1.0.0)
Expand All @@ -92,15 +94,16 @@ GEM
rb-inotify (>= 0.9)
rb-kqueue (>= 0.2)
metaclass (0.0.4)
minitest (5.9.1)
minitest (5.10.1)
mocha (1.1.0)
metaclass (~> 0.0.1)
mocha-on-bacon (0.2.2)
mocha (>= 0.13.0)
molinillo (0.5.1)
molinillo (0.5.4)
multi_json (1.11.2)
nanaimo (0.2.3)
nap (1.1.0)
netrc (0.7.8)
netrc (0.11.0)
notify (0.5.2)
parser (2.3.0.7)
ast (~> 2.2)
Expand All @@ -120,6 +123,7 @@ GEM
rainbow (>= 1.99.1, < 3.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
ruby-macho (0.2.6)
ruby-progressbar (1.7.5)
safe_yaml (1.0.4)
simplecov (0.9.2)
Expand All @@ -134,10 +138,12 @@ GEM
webmock (1.21.0)
addressable (>= 2.3.6)
crack (>= 0.3.2)
xcodeproj (1.3.2)
xcodeproj (1.4.2)
CFPropertyList (~> 2.3.3)
activesupport (>= 3)
claide (>= 1.0.1, < 2.0)
colored (~> 1.2)
nanaimo (~> 0.2.3)

PLATFORMS
ruby
Expand All @@ -160,4 +166,4 @@ DEPENDENCIES
webmock

BUNDLED WITH
1.13.5
1.13.6
2 changes: 1 addition & 1 deletion cocoapods-trunk.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
spec.require_paths = ["lib"]

spec.add_dependency 'nap', '>= 0.8', '< 2.0'
spec.add_dependency 'netrc', '0.7.8'
spec.add_dependency 'netrc', '~> 0.10'
spec.add_development_dependency "bundler", "~> 1.3"
spec.add_development_dependency "rake", '~> 10.0'

Expand Down
13 changes: 12 additions & 1 deletion lib/pod/command/trunk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def json(response)
end

def netrc
@@netrc ||= Netrc.read
@@netrc ||= Netrc.read(netrc_path)
end

def token
Expand Down Expand Up @@ -141,6 +141,17 @@ def time_zone
out, = Executable.capture_command('/bin/date', %w(+%Z), :capture => :out)
out.strip
end

def netrc_path
Copy link
Member

Choose a reason for hiding this comment

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

would this code do better being in the netrcgem itself?

Copy link
Member Author

Choose a reason for hiding this comment

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

~Maybe. It's essentially just an override of Netrc.default_path

Copy link
Member

Choose a reason for hiding this comment

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

it just doesn't feel like a feature that's specific to CocoaPods

Copy link
Member Author

Choose a reason for hiding this comment

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

I tend to agree given that the code for handling GPG exists inside the upstream repo, just not for auto detecting it. I'll see if I can find any reasoning in commits/prs.

Copy link
Member

Choose a reason for hiding this comment

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

this still hasn't been opened as an issue upstream

base_path = ENV['NETRC'] || Dir.home
gpg_path = File.join(base_path, '.netrc.gpg')
plain_path = File.join(base_path, '.netrc')
if File.exist?(gpg_path)
gpg_path
else
plain_path
end
end
end
end
end
27 changes: 27 additions & 0 deletions spec/command/trunk_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,32 @@ module Pod
@command.send(:token).should == 'token'
end
end

describe '#netrc_path' do
it 'uses the user home directory by default' do
ENV.stubs(:[]).with('NETRC').returns(nil)
Dir.stubs(:home).returns('/Users/testuser/')
File.stubs(:exist?).returns(true)
@command.send(:netrc_path).should == '/Users/testuser/.netrc.gpg'
end

it 'respects the NETRC environment variable' do
ENV.stubs(:[]).with('NETRC').returns('/Users/testuser/.config/')
File.stubs(:exist?).returns(true)
@command.send(:netrc_path).should == '/Users/testuser/.config/.netrc.gpg'
end

it 'will use GPG netrc secrets when available' do
ENV.stubs(:[]).with('NETRC').returns('/Users/testuser/')
File.stubs(:exist?).with('/Users/testuser/.netrc.gpg').returns(true)
@command.send(:netrc_path).should == '/Users/testuser/.netrc.gpg'
end

it 'will use plaintext netrc secrets when GPG is not available' do
ENV.stubs(:[]).with('NETRC').returns('/Users/testuser/')
File.stubs(:exist?).with('/Users/testuser/.netrc.gpg').returns(false)
@command.send(:netrc_path).should == '/Users/testuser/.netrc'
end
end
end
end