dpl-snap 1.9.7.travis.2853.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 36daa9dbcb7836f6df9dd8c6b6e04ea2d9fe152e49735214f18aea44df745e1b
4
+ data.tar.gz: 6f7c0bf3e2458a2224cde4e910ad92deec94e39a64799971562de3f8713ca8a0
5
+ SHA512:
6
+ metadata.gz: c13b7ea9412188f5a57c2b593878e53aaea97522f332c9464479acb00f0bbe5ad544c72f0ec9f81567964e4008231cc62ad03c75e44313ef4e2e9ad06119e9a3
7
+ data.tar.gz: e5eea1925a2f23471a16b85dcd19eed8b6399b7ce0c98e216c8ce0b6e302917e4b512537e6faa8c6eb6e39dab9898a24266c003ff83df56f783f335acbe29591
data/dpl-snap.gemspec ADDED
@@ -0,0 +1,3 @@
1
+ require './gemspec_helper'
2
+
3
+ gemspec_for 'snap'
@@ -0,0 +1,82 @@
1
+ require 'open3'
2
+
3
+ module DPL
4
+ class Provider
5
+ class Snap < Provider
6
+ # Support installing snaps
7
+ def self.snap(name, command = name, classic: false, channel: nil)
8
+ install_command = "sudo snap install #{name}"
9
+
10
+ if classic
11
+ install_command += " --classic"
12
+ end
13
+
14
+ unless channel.nil?
15
+ install_command += " --channel=#{channel}"
16
+ end
17
+
18
+ context.shell(install_command, retry: true) if `which #{command}`.chop.empty?
19
+ end
20
+
21
+ apt_get 'snapd', 'snap'
22
+ snap 'snapcraft', classic: true
23
+
24
+ def install_deploy_dependencies
25
+ # Snapcraft may already be installed, but in case we installed
26
+ # the snap, we need to add /snap/bin to the PATH.
27
+ ENV["PATH"] += ':/snap/bin'
28
+ end
29
+
30
+ def check_auth
31
+ log "Attemping to login"
32
+ stdout, stderr, status = Open3.capture3(
33
+ "snapcraft login --with -", stdin_data: login_token)
34
+
35
+ if status == 0
36
+ log stdout
37
+ else
38
+ error "Failed to authenticate: #{stderr}"
39
+ end
40
+ end
41
+
42
+ # No SSH keys needed
43
+ def needs_key?
44
+ false
45
+ end
46
+
47
+ # Users must specify the path to the snap they want pushed (globbing is
48
+ # supported).
49
+ def snap
50
+ option(:snap)
51
+ end
52
+
53
+ # Users can specify the channel into which they'd like to release this
54
+ # snap. It defaults to the 'edge' channel.
55
+ def channel
56
+ options.fetch(:channel, 'edge')
57
+ end
58
+
59
+ # Users must specify their login token, either explicitly in the YAML or
60
+ # via the $SNAP_TOKEN enironment variable.
61
+ def login_token
62
+ options[:token] || context.env['SNAP_TOKEN'] || error("Missing token")
63
+ end
64
+
65
+ def push_app
66
+ snaps = Dir.glob(snap)
67
+ case snaps.length
68
+ when 0
69
+ error "No snap found matching '#{snap}'"
70
+ when 1
71
+ snap_path = snaps.first
72
+ context.fold("Pushing snap") do
73
+ context.shell "snapcraft push #{snap_path} --release=#{channel}"
74
+ end
75
+ else
76
+ snap_list = snaps.join(', ')
77
+ error "Multiple snaps found matching '#{snap}': #{snap_list}"
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,114 @@
1
+ require 'spec_helper'
2
+ require 'dpl/provider/snap'
3
+
4
+ describe DPL::Provider::Snap do
5
+ after :each do
6
+ remove_test_snaps
7
+ end
8
+
9
+ subject :provider do
10
+ described_class.new(
11
+ DummyContext.new, :token => 'test-token', :snap => test_snap_name,
12
+ :channel => 'test-channel')
13
+ end
14
+
15
+ describe "#install_deploy_dependencies" do
16
+ example do
17
+ provider.install_deploy_dependencies
18
+ expect(ENV['PATH'].split(':')).to include('/snap/bin')
19
+ end
20
+ end
21
+
22
+ describe "#check_auth" do
23
+ example "success" do
24
+ allow(Open3).to receive(:capture3).with(
25
+ "snapcraft login --with -", stdin_data: 'test-token').and_return(
26
+ ['test-stdout', 'test-stderr', 0])
27
+
28
+ expect(provider).to receive(:log).with("Attemping to login")
29
+ expect(provider).to receive(:log).with("test-stdout")
30
+ provider.check_auth
31
+ end
32
+
33
+ example "failure" do
34
+ allow(Open3).to receive(:capture3).with(
35
+ "snapcraft login --with -", stdin_data: 'test-token').and_return(
36
+ ['test-stdout', 'test-stderr', 1])
37
+
38
+ expect(provider).to receive(:log).with("Attemping to login")
39
+ expect{provider.check_auth}.to raise_error(
40
+ DPL::Error, "Failed to authenticate: test-stderr")
41
+ end
42
+
43
+ example "missing token" do
44
+ allow(Open3).to receive(:capture3).with(
45
+ "snapcraft login --with -", stdin_data: nil).and_return(
46
+ ['test-stdout', 'test-stderr', 1])
47
+
48
+ provider.options.delete(:token)
49
+ expect(provider).to receive(:log).with("Attemping to login")
50
+ expect{provider.check_auth}.to raise_error(DPL::Error, "Missing token")
51
+ end
52
+ end
53
+
54
+ describe "#push_app" do
55
+ example "existing snap" do
56
+ # Create fake snap
57
+ create_test_snap
58
+
59
+ expect(provider.context).to receive(:shell).with(
60
+ "snapcraft push #{test_snap_name} --release=test-channel").and_return(
61
+ true)
62
+
63
+ provider.push_app
64
+ end
65
+
66
+ example "no existing snap should fail" do
67
+ expect{provider.push_app}.to raise_error(
68
+ DPL::Error, "No snap found matching 'test.snap'")
69
+ end
70
+
71
+ example "missing snap" do
72
+ provider.options.delete(:snap)
73
+ expect{provider.push_app}.to raise_error(
74
+ DPL::Error, "missing snap")
75
+ end
76
+
77
+ example "multiple matching snaps should fail" do
78
+ create_test_snap "foo.snap"
79
+ create_test_snap "bar.snap"
80
+ provider.options[:snap] = "*.snap"
81
+ expect{provider.push_app}.to raise_error(
82
+ DPL::Error,
83
+ "Multiple snaps found matching '*.snap': foo.snap, bar.snap")
84
+ end
85
+
86
+ example "missing channel should default to edge" do
87
+ # Create fake snap
88
+ create_test_snap
89
+
90
+ provider.options.delete(:channel)
91
+
92
+ expect(provider.context).to receive(:shell).with(
93
+ "snapcraft push #{test_snap_name} --release=edge").and_return(true)
94
+
95
+ provider.push_app
96
+ end
97
+ end
98
+
99
+ private
100
+
101
+ def test_snap_name
102
+ "test.snap"
103
+ end
104
+
105
+ def create_test_snap(snap_name = test_snap_name)
106
+ File.open snap_name, "w" do | file |
107
+ file.write("test")
108
+ end
109
+ end
110
+
111
+ def remove_test_snaps
112
+ FileUtils.rm_f Dir.glob('*.snap')
113
+ end
114
+ end
metadata ADDED
@@ -0,0 +1,186 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dpl-snap
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.9.7.travis.2853.6
5
+ platform: ruby
6
+ authors:
7
+ - Konstantin Haase
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-04-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: dpl
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 1.9.7.travis.2853.6
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 1.9.7.travis.2853.6
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec-its
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: json_pure
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: tins
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: coveralls
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: highline
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: term-ansicolor
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: faraday
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ description: deploy tool abstraction for clients
154
+ email: konstantin.mailinglists@googlemail.com
155
+ executables: []
156
+ extensions: []
157
+ extra_rdoc_files: []
158
+ files:
159
+ - dpl-snap.gemspec
160
+ - lib/dpl/provider/snap.rb
161
+ - spec/provider/snap_spec.rb
162
+ homepage: https://github.com/travis-ci/dpl
163
+ licenses:
164
+ - MIT
165
+ metadata: {}
166
+ post_install_message:
167
+ rdoc_options: []
168
+ require_paths:
169
+ - lib
170
+ required_ruby_version: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - ">="
173
+ - !ruby/object:Gem::Version
174
+ version: '2.2'
175
+ required_rubygems_version: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - ">"
178
+ - !ruby/object:Gem::Version
179
+ version: 1.3.1
180
+ requirements: []
181
+ rubyforge_project:
182
+ rubygems_version: 2.7.6
183
+ signing_key:
184
+ specification_version: 4
185
+ summary: deploy tool
186
+ test_files: []