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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/rake_circle_ci/client.rb +39 -0
- data/lib/rake_circle_ci/tasks/{ssh_key/provision.rb → ssh_keys/destroy.rb} +9 -10
- data/lib/rake_circle_ci/tasks/ssh_keys/provision.rb +45 -0
- data/lib/rake_circle_ci/tasks/ssh_keys.rb +9 -0
- data/lib/rake_circle_ci/tasks.rb +1 -1
- data/lib/rake_circle_ci/version.rb +1 -1
- metadata +4 -3
- data/lib/rake_circle_ci/tasks/ssh_key.rb +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ddef31676c1aeac53eee0f319b772a046a75c346a022011bf7d35251fc14657
|
4
|
+
data.tar.gz: f12e78b0eeaaf6054fabbad079e74d8881ffc7525fd2d48fd8e7edd62c769601
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da709e7e9323809215ce1b6732d95336e1538efa03c5f240a533bddcb8d17cb4432ec5d10cff0a1ec8842f1c056b968da66f6fc1a22dba7eae08e9a8b64df1e3
|
7
|
+
data.tar.gz: 0e2d3c5794a9e4688f9f0ed15ba1d03209ff3435523dc3a30e459c05be6b4a7d69c9733495cbbb71ca8b0100f0cf01f1cbe9dd707310fbeb55b5fc7e46eb4316
|
data/Gemfile.lock
CHANGED
@@ -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
|
8
|
-
class
|
9
|
-
default_name :
|
7
|
+
module SSHKeys
|
8
|
+
class Destroy < RakeFactory::Task
|
9
|
+
default_name :destroy
|
10
10
|
default_description RakeFactory::DynamicValue.new { |t|
|
11
|
-
"
|
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 :
|
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 "
|
27
|
-
|
28
|
-
|
29
|
-
|
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
|
data/lib/rake_circle_ci/tasks.rb
CHANGED
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.
|
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/
|
210
|
-
- lib/rake_circle_ci/tasks/
|
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
|