aptible-cli 0.7.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/aptible-cli.gemspec +1 -1
- data/lib/aptible/cli/agent.rb +18 -4
- data/lib/aptible/cli/version.rb +1 -1
- data/spec/aptible/cli/agent_spec.rb +57 -7
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf860a7c589c2689289068a00ea10b4a2bb8cd10
|
4
|
+
data.tar.gz: 30a8504c9fdeddd33c67a23e775e08eae455cae9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 709bfbf15f9a1988a3bdbd7d6c04d88a7ac748c0f15d4550afdcdf80bdd11536cd1735ed7437c8188d3272e9890a265880b010f546367135d85bb1d956df6a81
|
7
|
+
data.tar.gz: 96ac24c260b42100c57639dcd8ee10e57ccbef49dcbf070ce3509f255b98835df0c2a10d9a99cbfe729c7a195adfac21b6070d622017f8cc55a5f40bf0980718
|
data/.travis.yml
CHANGED
data/aptible-cli.gemspec
CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.require_paths = ['lib']
|
22
22
|
|
23
23
|
spec.add_dependency 'aptible-api', '~> 0.9.7'
|
24
|
-
spec.add_dependency 'aptible-auth', '~> 0.11.
|
24
|
+
spec.add_dependency 'aptible-auth', '~> 0.11.8'
|
25
25
|
spec.add_dependency 'aptible-resource', '~> 0.3.6'
|
26
26
|
spec.add_dependency 'thor', '~> 0.19.1'
|
27
27
|
spec.add_dependency 'git'
|
data/lib/aptible/cli/agent.rb
CHANGED
@@ -24,8 +24,6 @@ require_relative 'subcommands/backup'
|
|
24
24
|
|
25
25
|
module Aptible
|
26
26
|
module CLI
|
27
|
-
TOKEN_EXPIRY_WITH_OTP = 12 * 60 * 60 # 12 hours
|
28
|
-
|
29
27
|
class Agent < Thor
|
30
28
|
include Thor::Actions
|
31
29
|
|
@@ -54,6 +52,8 @@ module Aptible
|
|
54
52
|
desc 'login', 'Log in to Aptible'
|
55
53
|
option :email
|
56
54
|
option :password
|
55
|
+
option :lifetime, desc: 'The duration the token should be valid for ' \
|
56
|
+
'(example usage: 24h, 1d, 600s, etc.)'
|
57
57
|
option :otp_token, desc: 'A token generated by your second-factor app'
|
58
58
|
def login
|
59
59
|
email = options[:email] || ask('Email: ')
|
@@ -66,8 +66,16 @@ module Aptible
|
|
66
66
|
token_options[:otp_token] = otp_token if otp_token
|
67
67
|
|
68
68
|
begin
|
69
|
-
|
70
|
-
|
69
|
+
lifetime = '1w'
|
70
|
+
lifetime = '12h' if token_options[:otp_token]
|
71
|
+
lifetime = options[:lifetime] if options[:lifetime]
|
72
|
+
|
73
|
+
duration = ChronicDuration.parse(lifetime)
|
74
|
+
if duration.nil?
|
75
|
+
fail Thor::Error, "Invalid token lifetime requested: #{lifetime}"
|
76
|
+
end
|
77
|
+
|
78
|
+
token_options[:expires_in] = duration
|
71
79
|
token = Aptible::Auth::Token.create(token_options)
|
72
80
|
rescue OAuth2::Error => e
|
73
81
|
if e.code == 'otp_token_required'
|
@@ -82,6 +90,12 @@ module Aptible
|
|
82
90
|
|
83
91
|
save_token(token.access_token)
|
84
92
|
puts "Token written to #{token_file}"
|
93
|
+
|
94
|
+
lifetime_format = { units: 2, joiner: ', ' }
|
95
|
+
token_lifetime = (token.expires_at - token.created_at).round
|
96
|
+
expires_in = ChronicDuration.output(token_lifetime, lifetime_format)
|
97
|
+
puts "This token will expire after #{expires_in} " \
|
98
|
+
'(use --lifetime to customize)'
|
85
99
|
end
|
86
100
|
|
87
101
|
private
|
data/lib/aptible/cli/version.rb
CHANGED
@@ -3,6 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe Aptible::CLI::Agent do
|
4
4
|
before { subject.stub(:ask) }
|
5
5
|
before { subject.stub(:save_token) }
|
6
|
+
before { allow(subject).to receive(:token_file).and_return 'some.json' }
|
6
7
|
|
7
8
|
describe '#version' do
|
8
9
|
it 'should print the version' do
|
@@ -14,13 +15,18 @@ describe Aptible::CLI::Agent do
|
|
14
15
|
|
15
16
|
describe '#login' do
|
16
17
|
let(:token) { double('Aptible::Auth::Token') }
|
18
|
+
let(:created_at) { Time.now }
|
19
|
+
let(:expires_at) { created_at + 1.week }
|
20
|
+
let(:output) { [] }
|
17
21
|
|
18
22
|
before do
|
19
23
|
m = -> (code) { @code = code }
|
20
24
|
OAuth2::Error.send :define_method, :initialize, m
|
21
25
|
end
|
22
26
|
before { token.stub(:access_token) { 'access_token' } }
|
23
|
-
before {
|
27
|
+
before { token.stub(:created_at) { created_at } }
|
28
|
+
before { token.stub(:expires_at) { expires_at } }
|
29
|
+
before { allow(subject).to receive(:puts) { |m| output << m } }
|
24
30
|
|
25
31
|
it 'should save a token to ~/.aptible/tokens' do
|
26
32
|
Aptible::Auth::Token.stub(:create) { token }
|
@@ -28,6 +34,15 @@ describe Aptible::CLI::Agent do
|
|
28
34
|
subject.login
|
29
35
|
end
|
30
36
|
|
37
|
+
it 'should output the token location and token lifetime' do
|
38
|
+
Aptible::Auth::Token.stub(:create) { token }
|
39
|
+
subject.login
|
40
|
+
expect(output.size).to eq(3)
|
41
|
+
expect(output[0]).to eq('')
|
42
|
+
expect(output[1]).to match(/written to some\.json/)
|
43
|
+
expect(output[2]).to match(/will expire after 7 days/)
|
44
|
+
end
|
45
|
+
|
31
46
|
it 'should raise an error if authentication fails' do
|
32
47
|
Aptible::Auth::Token.stub(:create).and_raise(OAuth2::Error, 'foo')
|
33
48
|
expect do
|
@@ -36,12 +51,31 @@ describe Aptible::CLI::Agent do
|
|
36
51
|
end
|
37
52
|
|
38
53
|
it 'should use command line arguments if passed' do
|
54
|
+
options = { email: 'test@example.com', password: 'password',
|
55
|
+
lifetime: '30 minutes' }
|
56
|
+
subject.stub(:options) { options }
|
57
|
+
args = { email: options[:email], password: options[:password],
|
58
|
+
expires_in: 30.minutes.seconds }
|
59
|
+
expect(Aptible::Auth::Token).to receive(:create).with(args) { token }
|
60
|
+
subject.login
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'should default to 1 week expiry when OTP is disabled' do
|
39
64
|
options = { email: 'test@example.com', password: 'password' }
|
40
65
|
subject.stub(:options) { options }
|
41
|
-
|
66
|
+
args = options.dup.merge(expires_in: 1.week.seconds)
|
67
|
+
expect(Aptible::Auth::Token).to receive(:create).with(args) { token }
|
42
68
|
subject.login
|
43
69
|
end
|
44
70
|
|
71
|
+
it 'should fail if the lifetime is invalid' do
|
72
|
+
options = { email: 'test@example.com', password: 'password',
|
73
|
+
lifetime: 'this is sparta' }
|
74
|
+
subject.stub(:options) { options }
|
75
|
+
|
76
|
+
expect { subject.login }.to raise_error(/Invalid token lifetime/)
|
77
|
+
end
|
78
|
+
|
45
79
|
context 'with OTP' do
|
46
80
|
let(:email) { 'foo@example.org' }
|
47
81
|
let(:password) { 'bar' }
|
@@ -56,7 +90,7 @@ describe Aptible::CLI::Agent do
|
|
56
90
|
it 'should authenticate without otp_token_required feedback' do
|
57
91
|
expect(Aptible::Auth::Token).to receive(:create)
|
58
92
|
.with(email: email, password: password, otp_token: token,
|
59
|
-
expires_in:
|
93
|
+
expires_in: 12.hours.seconds)
|
60
94
|
.once
|
61
95
|
.and_return(token)
|
62
96
|
|
@@ -77,28 +111,44 @@ describe Aptible::CLI::Agent do
|
|
77
111
|
|
78
112
|
it 'should prompt for an OTP token and use it' do
|
79
113
|
expect(Aptible::Auth::Token).to receive(:create)
|
80
|
-
.with(email: email, password: password)
|
114
|
+
.with(email: email, password: password, expires_in: 1.week.seconds)
|
115
|
+
.once
|
116
|
+
.and_raise(OAuth2::Error, 'otp_token_required')
|
117
|
+
|
118
|
+
expect(Aptible::Auth::Token).to receive(:create)
|
119
|
+
.with(email: email, password: password, otp_token: token,
|
120
|
+
expires_in: 12.hours.seconds)
|
121
|
+
.once
|
122
|
+
.and_return(token)
|
123
|
+
|
124
|
+
subject.login
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'should let the user override the default lifetime' do
|
128
|
+
expect(Aptible::Auth::Token).to receive(:create)
|
129
|
+
.with(email: email, password: password, expires_in: 1.day.seconds)
|
81
130
|
.once
|
82
131
|
.and_raise(OAuth2::Error, 'otp_token_required')
|
83
132
|
|
84
133
|
expect(Aptible::Auth::Token).to receive(:create)
|
85
134
|
.with(email: email, password: password, otp_token: token,
|
86
|
-
expires_in:
|
135
|
+
expires_in: 1.day.seconds)
|
87
136
|
.once
|
88
137
|
.and_return(token)
|
89
138
|
|
139
|
+
allow(subject).to receive(:options).and_return(lifetime: '1d')
|
90
140
|
subject.login
|
91
141
|
end
|
92
142
|
|
93
143
|
it 'should not retry non-OTP errors.' do
|
94
144
|
expect(Aptible::Auth::Token).to receive(:create)
|
95
|
-
.with(email: email, password: password)
|
145
|
+
.with(email: email, password: password, expires_in: 1.week.seconds)
|
96
146
|
.once
|
97
147
|
.and_raise(OAuth2::Error, 'otp_token_required')
|
98
148
|
|
99
149
|
expect(Aptible::Auth::Token).to receive(:create)
|
100
150
|
.with(email: email, password: password, otp_token: token,
|
101
|
-
expires_in:
|
151
|
+
expires_in: 12.hours.seconds)
|
102
152
|
.once
|
103
153
|
.and_raise(OAuth2::Error, 'foo')
|
104
154
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aptible-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Frank Macreery
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aptible-api
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.11.
|
33
|
+
version: 0.11.8
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.11.
|
40
|
+
version: 0.11.8
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: aptible-resource
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|