rake_circle_ci 0.2.0.pre.7 → 0.2.0.pre.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 06c5333f1bf1e2c377a49a35520cde980f93b73f4f0fd69f1bf1c292554f0f0f
4
- data.tar.gz: f00b9d69ad3a4fac89af31c57e36de1b5ba046d56e5005c21be1626efa69c0ca
3
+ metadata.gz: 4ddef31676c1aeac53eee0f319b772a046a75c346a022011bf7d35251fc14657
4
+ data.tar.gz: f12e78b0eeaaf6054fabbad079e74d8881ffc7525fd2d48fd8e7edd62c769601
5
5
  SHA512:
6
- metadata.gz: b50b611ba364f53074999c14b4fd450d2af47be71655d12427bd31d01f86835e7397383d6cd6a58cb0232b3b178382404bc7dc781af754796be2b6feb756b184
7
- data.tar.gz: 4ec02e53b1e894624e80605df819240b4c4efabcf68941b8808b0a6ed7ac6523449141f9ded5202b934ec2c4db321dd564852d5514fbe621230ea40b1fdb30bd
6
+ metadata.gz: da709e7e9323809215ce1b6732d95336e1538efa03c5f240a533bddcb8d17cb4432ec5d10cff0a1ec8842f1c056b968da66f6fc1a22dba7eae08e9a8b64df1e3
7
+ data.tar.gz: 0e2d3c5794a9e4688f9f0ed15ba1d03209ff3435523dc3a30e459c05be6b4a7d69c9733495cbbb71ca8b0100f0cf01f1cbe9dd707310fbeb55b5fc7e46eb4316
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rake_circle_ci (0.2.0.pre.7)
4
+ rake_circle_ci (0.2.0.pre.8)
5
5
  colored2 (~> 3.1)
6
6
  excon (~> 0.72)
7
7
  rake_factory (~> 0.23)
@@ -35,6 +35,19 @@ module RakeCircleCI
35
35
  end
36
36
  end
37
37
 
38
+ def find_ssh_keys
39
+ response = assert_successful(Excon.get(settings_url, headers: headers))
40
+ body = JSON.parse(response.body)
41
+ ssh_keys = body["ssh_keys"].map do |ssh_key|
42
+ {
43
+ fingerprint: ssh_key["fingerprint"],
44
+ hostname: ssh_key["hostname"]
45
+ }
46
+ end
47
+
48
+ ssh_keys
49
+ end
50
+
38
51
  def create_ssh_key(private_key, opts = {})
39
52
  body = {
40
53
  fingerprint: SSHKey.new(private_key).sha1_fingerprint,
@@ -46,6 +59,27 @@ module RakeCircleCI
46
59
  Excon.post(ssh_keys_url, body: body, headers: headers))
47
60
  end
48
61
 
62
+ def delete_ssh_key(fingerprint, opts = {})
63
+ body = {
64
+ fingerprint: fingerprint
65
+ }
66
+ body = body.merge(hostname: opts[:hostname]) if opts[:hostname]
67
+ body = JSON.dump(body)
68
+ assert_successful(
69
+ Excon.delete(ssh_keys_url, body: body, headers: headers))
70
+ end
71
+
72
+ def delete_ssh_keys
73
+ ssh_keys = find_ssh_keys
74
+ ssh_keys.each do |ssh_key|
75
+ fingerprint = ssh_key[:fingerprint]
76
+ hostname = ssh_key[:hostname]
77
+ options = hostname && {hostname: hostname}
78
+ args = [fingerprint, options].compact
79
+ delete_ssh_key(*args)
80
+ end
81
+ end
82
+
49
83
  private
50
84
 
51
85
  def headers
@@ -75,6 +109,11 @@ module RakeCircleCI
75
109
  "#{@base_url}/v2/project/#{@project_slug}/envvar/#{name}"
76
110
  end
77
111
 
112
+ def settings_url
113
+ "#{@base_url}/v1.1/project/#{@project_slug}/settings?" +
114
+ "circle-token=#{@api_token}"
115
+ end
116
+
78
117
  def ssh_keys_url
79
118
  "#{@base_url}/v1.1/project/#{@project_slug}/ssh-key?" +
80
119
  "circle-token=#{@api_token}"
@@ -4,18 +4,17 @@ require_relative '../../client'
4
4
 
5
5
  module RakeCircleCI
6
6
  module Tasks
7
- module SSHKey
8
- class Provision < RakeFactory::Task
9
- default_name :provision
7
+ module SSHKeys
8
+ class Destroy < RakeFactory::Task
9
+ default_name :destroy
10
10
  default_description RakeFactory::DynamicValue.new { |t|
11
- "Provision SSH key on the #{t.project_slug} project"
11
+ "Destroy SSH keys in the #{t.project_slug} project"
12
12
  }
13
13
 
14
14
  parameter :project_slug, required: true
15
15
  parameter :api_token, required: true
16
16
  parameter :base_url, default: 'https://circleci.com/api'
17
- parameter :private_key, required: true
18
- parameter :hostname
17
+ parameter :ssh_keys, default: {}
19
18
 
20
19
  action do |t|
21
20
  client = Client.new(
@@ -23,10 +22,10 @@ module RakeCircleCI
23
22
  api_token: t.api_token,
24
23
  project_slug: t.project_slug)
25
24
 
26
- print "Provisioning SSH key to the '#{t.project_slug}' project... "
27
- options = t.hostname && {hostname: t.hostname}
28
- args = [t.private_key, options].compact
29
- client.create_ssh_key(*args)
25
+ print "Destroying all SSH keys to the '#{t.project_slug}' " +
26
+ "project... "
27
+ client.delete_ssh_keys
28
+ puts "Done."
30
29
  end
31
30
  end
32
31
  end
@@ -0,0 +1,45 @@
1
+ require 'rake_factory'
2
+
3
+ require_relative '../../client'
4
+
5
+ module RakeCircleCI
6
+ module Tasks
7
+ module SSHKeys
8
+ class Provision < RakeFactory::Task
9
+ default_name :provision
10
+ default_description RakeFactory::DynamicValue.new { |t|
11
+ "Provision SSH keys on the #{t.project_slug} project"
12
+ }
13
+
14
+ parameter :project_slug, required: true
15
+ parameter :api_token, required: true
16
+ parameter :base_url, default: 'https://circleci.com/api'
17
+ parameter :ssh_keys, default: {}
18
+
19
+ action do |t|
20
+ client = Client.new(
21
+ base_url: t.base_url,
22
+ api_token: t.api_token,
23
+ project_slug: t.project_slug)
24
+
25
+ puts "Provisioning all SSH keys to the '#{t.project_slug}' " +
26
+ "project... "
27
+
28
+ t.ssh_keys.each do |ssh_key|
29
+ private_key = ssh_key[:private_key]
30
+ hostname = ssh_key[:hostname]
31
+ fingerprint = SSHKey.new(private_key).sha1_fingerprint
32
+
33
+ print "Adding SSH key with fingerprint: '#{fingerprint}'"
34
+ print " for hostname: '#{hostname}'" if hostname
35
+ print "..."
36
+ options = hostname && {hostname: hostname}
37
+ args = [private_key, options].compact
38
+ client.create_ssh_key(*args)
39
+ puts "Done."
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,9 @@
1
+ require_relative 'ssh_keys/provision'
2
+ require_relative 'ssh_keys/destroy'
3
+
4
+ module RakeCircleCI
5
+ module Tasks
6
+ module SSHKeys
7
+ end
8
+ end
9
+ end
@@ -1,5 +1,5 @@
1
1
  require_relative 'tasks/environment_variables'
2
- require_relative 'tasks/ssh_key'
2
+ require_relative 'tasks/ssh_keys'
3
3
 
4
4
  module RakeCircleCI
5
5
  module Tasks
@@ -1,3 +1,3 @@
1
1
  module RakeCircleCI
2
- VERSION = '0.2.0.pre.7'
2
+ VERSION = '0.2.0.pre.8'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rake_circle_ci
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0.pre.7
4
+ version: 0.2.0.pre.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Toby Clemson
@@ -206,8 +206,9 @@ files:
206
206
  - lib/rake_circle_ci/tasks/environment_variables/destroy.rb
207
207
  - lib/rake_circle_ci/tasks/environment_variables/ensure.rb
208
208
  - lib/rake_circle_ci/tasks/environment_variables/provision.rb
209
- - lib/rake_circle_ci/tasks/ssh_key.rb
210
- - lib/rake_circle_ci/tasks/ssh_key/provision.rb
209
+ - lib/rake_circle_ci/tasks/ssh_keys.rb
210
+ - lib/rake_circle_ci/tasks/ssh_keys/destroy.rb
211
+ - lib/rake_circle_ci/tasks/ssh_keys/provision.rb
211
212
  - lib/rake_circle_ci/version.rb
212
213
  - rake_circle_ci.gemspec
213
214
  - scripts/ci/common/configure-git.sh
@@ -1,8 +0,0 @@
1
- require_relative 'ssh_key/provision'
2
-
3
- module RakeCircleCI
4
- module Tasks
5
- module SSHKey
6
- end
7
- end
8
- end