rake_circle_ci 0.8.0.pre.2 → 0.8.0.pre.3

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: e25f04879cfd54fe6636b6d5e6c02a7e8d4a24e1c4a33b237bd2cef63a6773e6
4
- data.tar.gz: 5809ed4521ee434e801b3a6b0a19e73c2e0e78e59a0bc79ebd09443943f0d07d
3
+ metadata.gz: d1595ba13c3817f5913099d8a144da9e4353ca4eb822d3de130c44580be21c41
4
+ data.tar.gz: 41d4eafae97184eb8ba25ba0a64974e5461b69ee1277e5db900f3935d388a2bb
5
5
  SHA512:
6
- metadata.gz: cdab073fef4a1ebd3a81a4e70a21bf8fb4451c2b9ade3df25eea4471bd6f8c680148ee2c9fb93d807e2f10be12af47c0b483e536fc3abfd17374b46753c1f9f3
7
- data.tar.gz: dcc84945aa915b1f8d2664d683a1640191e5dbd2c4af75ac0e39fe9121ddca67a89162d1ffc5b462298e9f27d139a672ce958e809f18af9aeca6ceacf32e5081
6
+ metadata.gz: 4d3c27ddbe3896dd379cfe06d514bdc4cbab4123513e3ca45f4490eca4979cd92a371dbcca6b0fda7f47629b538352e03c273810a95aad18de96ffc2c2aaa419
7
+ data.tar.gz: 23aa7b246d16daebb9578c6cf11cace268c1a57acf71f7b0bacd4541c282a33d96a49ead98fe60ad2167aad06010f7d7e28f53acb544d4f5811b593968664da8
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rake_circle_ci (0.8.0.pre.2)
4
+ rake_circle_ci (0.8.0.pre.3)
5
5
  colored2 (~> 3.1)
6
6
  excon (~> 0.72)
7
7
  rake_factory (~> 0.23)
@@ -100,4 +100,4 @@ DEPENDENCIES
100
100
  simplecov (~> 0.16)
101
101
 
102
102
  BUNDLED WITH
103
- 2.2.3
103
+ 2.2.4
@@ -41,13 +41,8 @@ module RakeCircleCI
41
41
 
42
42
  def find_ssh_keys
43
43
  response = assert_successful(Excon.get(settings_url, headers: headers))
44
- body = JSON.parse(response.body)
45
- ssh_keys = body["ssh_keys"].map do |ssh_key|
46
- {
47
- fingerprint: ssh_key["fingerprint"],
48
- hostname: ssh_key["hostname"]
49
- }
50
- end
44
+ body = JSON.parse(response.body, symbolize_names: true)
45
+ ssh_keys = body[:ssh_keys]
51
46
 
52
47
  ssh_keys
53
48
  end
@@ -84,6 +79,36 @@ module RakeCircleCI
84
79
  end
85
80
  end
86
81
 
82
+ def find_checkout_keys
83
+ response = assert_successful(
84
+ Excon.get(checkout_keys_url, headers: headers))
85
+ checkout_keys = JSON.parse(response.body, symbolize_names: true)
86
+
87
+ checkout_keys
88
+ end
89
+
90
+ def create_checkout_key(type)
91
+ type_strings = {
92
+ deploy_key: 'deploy-key',
93
+ github_user_key: 'github-user-key'
94
+ }
95
+ body = JSON.dump(type: type_strings[type.to_sym] || type.to_s)
96
+ assert_successful(
97
+ Excon.post(checkout_keys_url, body: body, headers: headers))
98
+ end
99
+
100
+ def delete_checkout_key(fingerprint)
101
+ assert_successful(
102
+ Excon.delete(checkout_key_url(fingerprint), headers: headers))
103
+ end
104
+
105
+ def delete_checkout_keys
106
+ checkout_keys = find_checkout_keys
107
+ checkout_keys.each do |checkout_key|
108
+ delete_checkout_key(checkout_key[:fingerprint])
109
+ end
110
+ end
111
+
87
112
  private
88
113
 
89
114
  def headers
@@ -127,5 +152,13 @@ module RakeCircleCI
127
152
  "#{@base_url}/v1.1/project/#{@project_slug}/ssh-key?" +
128
153
  "circle-token=#{@api_token}"
129
154
  end
155
+
156
+ def checkout_keys_url
157
+ "#{@base_url}/v1.1/project/#{@project_slug}/checkout-key"
158
+ end
159
+
160
+ def checkout_key_url(fingerprint)
161
+ "#{@base_url}/v1.1/project/#{@project_slug}/checkout-key/#{fingerprint}"
162
+ end
130
163
  end
131
- end
164
+ end
@@ -1,6 +1,7 @@
1
1
  require_relative 'tasks/projects'
2
2
  require_relative 'tasks/environment_variables'
3
3
  require_relative 'tasks/ssh_keys'
4
+ require_relative 'tasks/checkout_keys'
4
5
 
5
6
  module RakeCircleCI
6
7
  module Tasks
@@ -0,0 +1,9 @@
1
+ require_relative 'checkout_keys/provision'
2
+ require_relative 'checkout_keys/destroy'
3
+
4
+ module RakeCircleCI
5
+ module Tasks
6
+ module CheckoutKeys
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,32 @@
1
+ require 'rake_factory'
2
+
3
+ require_relative '../../client'
4
+
5
+ module RakeCircleCI
6
+ module Tasks
7
+ module CheckoutKeys
8
+ class Destroy < RakeFactory::Task
9
+ default_name :destroy
10
+ default_description RakeFactory::DynamicValue.new { |t|
11
+ "Destroy checkout keys in 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
+
18
+ action do |t|
19
+ client = Client.new(
20
+ base_url: t.base_url,
21
+ api_token: t.api_token,
22
+ project_slug: t.project_slug)
23
+
24
+ print "Destroying all checkout keys in the '#{t.project_slug}' " +
25
+ "project... "
26
+ client.delete_checkout_keys
27
+ puts "Done."
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,39 @@
1
+ require 'rake_factory'
2
+
3
+ require_relative '../../client'
4
+
5
+ module RakeCircleCI
6
+ module Tasks
7
+ module CheckoutKeys
8
+ class Provision < RakeFactory::Task
9
+ default_name :provision
10
+ default_description RakeFactory::DynamicValue.new { |t|
11
+ "Provision checkout 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 :checkout_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 checkout keys to the '#{t.project_slug}' " +
26
+ "project... "
27
+
28
+ t.checkout_keys.each do |checkout_key|
29
+ type = checkout_key[:type]
30
+
31
+ print "Adding checkout key of type: '#{type}'..."
32
+ client.create_checkout_key(type)
33
+ puts "Done."
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -1,3 +1,3 @@
1
1
  module RakeCircleCI
2
- VERSION = '0.8.0.pre.2'
2
+ VERSION = '0.8.0.pre.3'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rake_circle_ci
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0.pre.2
4
+ version: 0.8.0.pre.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Toby Clemson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-12-30 00:00:00.000000000 Z
11
+ date: 2021-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake_factory
@@ -242,6 +242,9 @@ files:
242
242
  - lib/rake_circle_ci/task_sets/project.rb
243
243
  - lib/rake_circle_ci/task_sets/ssh_keys.rb
244
244
  - lib/rake_circle_ci/tasks.rb
245
+ - lib/rake_circle_ci/tasks/checkout_keys.rb
246
+ - lib/rake_circle_ci/tasks/checkout_keys/destroy.rb
247
+ - lib/rake_circle_ci/tasks/checkout_keys/provision.rb
245
248
  - lib/rake_circle_ci/tasks/environment_variables.rb
246
249
  - lib/rake_circle_ci/tasks/environment_variables/destroy.rb
247
250
  - lib/rake_circle_ci/tasks/environment_variables/ensure.rb