rezept 0.3.1 → 0.4.0

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
  SHA1:
3
- metadata.gz: 90f6cdd4a9ab9e6d158fce1571ff3ba15a68e15b
4
- data.tar.gz: e00c984f9e574b82c3051b0441a485949c1455df
3
+ metadata.gz: 5c8f3eb27e65563acbbbc617cbc141b5a19de137
4
+ data.tar.gz: e3c70945a590294ec954ea1f9eb4bea2246ee404
5
5
  SHA512:
6
- metadata.gz: 85a8465ae36e3246f571b7ba5942fcbadbe0a49d862a1a2b50679b022dfba112d7e0b11f5f8132f8774868231c2be0eb8a971b3fd9f36d4e00254d735414279b
7
- data.tar.gz: 91b98ae07c7ae2bc829ac406fa90a184f34ec28934f44c0f8072eec4711941ddc0aa3fa98dc2531566c29c86c9d6a3371384bbaf3f5b9fca1a8e2bcec8a40750
6
+ metadata.gz: 7f47d7fc0f2ddee9603e8e109b5a6aaf742efbb50a0419ca03409f3559d6095f2ecf3f6937931d2fb2c446b59ff6a03f3c38577080718f0468ae8b46f23c66cf
7
+ data.tar.gz: dc976d2d4c1403574e6b534fd452aa6e72a1ce83255d3f6479032d3b491d36649ab1341f4f1eee7272da8ff06f8cac307b3865d82772c8eb8287bfa0efbae4c1
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 0.4.0
2
+ - Add `prefix` option to `apply` [#4][]
3
+
1
4
  ## 0.3.1
2
5
  - Bugfix: `Aws::SSM::Errors::ThrottlingException: Rate exceeded` error
3
6
 
data/README.md CHANGED
@@ -22,7 +22,7 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
- #### General
25
+ ### General
26
26
 
27
27
  ```
28
28
  $ rezept
@@ -42,7 +42,7 @@ Options:
42
42
  # Default: true
43
43
  ```
44
44
 
45
- #### apply
45
+ ### apply
46
46
  Apply the documents
47
47
 
48
48
  ```
@@ -51,6 +51,7 @@ Usage:
51
51
  rezept apply
52
52
 
53
53
  Options:
54
+ [--prefix=PREFIX] # The prefix of the documents (All documents are targeted by default)
54
55
  [--dry-run], [--no-dry-run] # Dry run (Only output the difference)
55
56
  -f, [--file=FILE] # Configuration file
56
57
  # Default: Docfile
@@ -61,7 +62,7 @@ Options:
61
62
  # Default: true
62
63
  ```
63
64
 
64
- #### convert
65
+ ### convert
65
66
  Convert the documents to the other format
66
67
 
67
68
  ```
@@ -83,7 +84,7 @@ Options:
83
84
  # Default: true
84
85
  ```
85
86
 
86
- #### export
87
+ ### export
87
88
  Export the documents
88
89
 
89
90
  ```
@@ -103,7 +104,7 @@ Options:
103
104
  # Default: true
104
105
  ```
105
106
 
106
- #### run_command
107
+ ### run_command
107
108
  Run the commands
108
109
 
109
110
  ```
@@ -133,7 +134,7 @@ Options:
133
134
  - If you specify multiple values to `tags` and `parameters`, separate them with commas(`,`).
134
135
  - When you use the `wait` option, the exit code will be `0` if the commands succeed on the all instances, else it will be `1`.
135
136
 
136
- #### put_inventory
137
+ ### put_inventory
137
138
  Put the inventory
138
139
 
139
140
  ```
@@ -158,7 +159,7 @@ Options:
158
159
 
159
160
  ## Advanced methods
160
161
 
161
- #### Script styled commands (__script)
162
+ ### Script styled commands (__script)
162
163
 
163
164
  - Docfile
164
165
 
@@ -212,7 +213,7 @@ Document Type: 'Command'
212
213
  }
213
214
  ```
214
215
 
215
- #### Commands from the other script file (__script_file)
216
+ ### Commands from the other script file (__script_file)
216
217
 
217
218
  - Docfile
218
219
 
@@ -270,7 +271,7 @@ Document Type: 'Command'
270
271
  }
271
272
  ```
272
273
 
273
- #### Templating
274
+ ### Templating
274
275
 
275
276
  - Docfile
276
277
 
@@ -36,7 +36,53 @@ module Rezept
36
36
  @converter.set_options(options)
37
37
  @client.set_options(options)
38
38
  dry_run = options['dry_run'] ? '[Dry run] ' : ''
39
- _apply_docs(@converter.dslfile_to_h(options['file']), @client.get_documents, dry_run)
39
+ local = @converter.dslfile_to_h(options['file'])
40
+ remote = @client.get_documents
41
+
42
+ unless options['prefix'].nil?
43
+ prefix = Regexp.new("^#{Regexp.escape(options['prefix'])}")
44
+ local.reject!{|d| not d['name'] =~ prefix }
45
+ remote.reject!{|d| not d['name'] =~ prefix }
46
+ end
47
+
48
+ _apply_docs(local, remote, dry_run)
49
+ end
50
+
51
+ def _apply_docs(local, remote, dry_run)
52
+ local.each do |l|
53
+ l_ids = l.delete('account_ids')
54
+ r_ids = []
55
+ r = _choice_by_name(remote, l['name'])
56
+
57
+ if r.nil?
58
+ info("#{dry_run}Create the new document #{l['name'].inspect}")
59
+ @client.create_document(l) if dry_run.empty?
60
+ else
61
+ r_ids = r.delete('account_ids')
62
+ diff = Rezept::Utils.diff(@converter, r, l)
63
+
64
+ if diff == "\n"
65
+ info("#{dry_run}No changes '#{l['name']}'")
66
+ else
67
+ warn("#{dry_run}Update the document #{l['name'].inspect}")
68
+ STDERR.puts diff
69
+ @client.version_up_document(l) if dry_run.empty?
70
+ end
71
+ end
72
+
73
+ add_ids = l_ids - r_ids
74
+ del_ids = r_ids - l_ids
75
+ info("#{dry_run}Add permission of #{l['name'].inspect} to #{add_ids.join(', ')}") if add_ids.length > 0
76
+ warn("#{dry_run}Remove permission of #{l['name'].inspect} from #{add_ids.join(', ')}") if del_ids.length > 0
77
+ @client.modify_document_permission(l, add_ids, del_ids) if dry_run.empty?
78
+ end
79
+
80
+ remote.each do |r|
81
+ if _choice_by_name(local, r['name']).nil?
82
+ warn("#{dry_run}Delete the document #{r['name'].inspect}")
83
+ @client.delete_document(r) if dry_run.empty?
84
+ end
85
+ end
40
86
  end
41
87
 
42
88
  def convert(options)
@@ -219,43 +265,6 @@ module Rezept
219
265
  exit(1) if failure
220
266
  end
221
267
 
222
- def _apply_docs(local, remote, dry_run)
223
- local.each do |l|
224
- l_ids = l.delete('account_ids')
225
- r_ids = []
226
- r = _choice_by_name(remote, l['name'])
227
-
228
- if r.nil?
229
- info("#{dry_run}Create the new document #{l['name'].inspect}")
230
- @client.create_document(l) if dry_run.empty?
231
- else
232
- r_ids = r.delete('account_ids')
233
- diff = Rezept::Utils.diff(@converter, r, l)
234
-
235
- if diff == "\n"
236
- info("#{dry_run}No changes '#{l['name']}'")
237
- else
238
- warn("#{dry_run}Update the document #{l['name'].inspect}")
239
- STDERR.puts diff
240
- @client.version_up_document(l) if dry_run.empty?
241
- end
242
- end
243
-
244
- add_ids = l_ids - r_ids
245
- del_ids = r_ids - l_ids
246
- info("#{dry_run}Add permission of #{l['name'].inspect} to #{add_ids.join(', ')}") if add_ids.length > 0
247
- warn("#{dry_run}Remove permission of #{l['name'].inspect} from #{add_ids.join(', ')}") if del_ids.length > 0
248
- @client.modify_document_permission(l, add_ids, del_ids) if dry_run.empty?
249
- end
250
-
251
- remote.each do |r|
252
- if _choice_by_name(local, r['name']).nil?
253
- warn("#{dry_run}Delete the document #{r['name'].inspect}")
254
- @client.delete_document(r) if dry_run.empty?
255
- end
256
- end
257
- end
258
-
259
268
  def _choice_by_name(docs, name)
260
269
  docs.each do |d|
261
270
  return d if d['name'] == name
data/lib/rezept/cli.rb CHANGED
@@ -23,6 +23,7 @@ module Rezept
23
23
  end
24
24
 
25
25
  desc "apply", "Apply the documents"
26
+ option :prefix, desc: 'The prefix of the documents (All documents are targeted by default)', type: :string
26
27
  option :dry_run, desc: 'Dry run (Only output the difference)', type: :boolean, default: false
27
28
  def apply
28
29
  @actions.apply(options)
@@ -1,3 +1,3 @@
1
1
  module Rezept
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rezept
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Serverworks Co.,Ltd.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-03-08 00:00:00.000000000 Z
11
+ date: 2017-03-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk