monkey_king 0.1.4 → 0.1.5

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: ba401a00ad2c74b982115b664aa720eddfd385c3
4
- data.tar.gz: f73252403a6856213d29264012d58e213e94afa7
3
+ metadata.gz: beb82abaa898573f203304c24f512196d2188232
4
+ data.tar.gz: b303c14f5e6000d5287456d75db0ca2c39570be9
5
5
  SHA512:
6
- metadata.gz: c096ba127dcf5d3e50329d7be704af6fd7b550e0f150fb9a48673b4def4f7b44ce8f856094790e09f3d30a8919bc3a76d6406e991369b1abbee53938c849b5b8
7
- data.tar.gz: 3430a7109bc73e40eebd7a0adc8225817a7ce655ec250797f7ab6c4b8bca34d31af75375f8b71b6cddbd49a15eb1549d513082c5ea03d0b9e6128fc331ff7646
6
+ metadata.gz: 4a5aabc89c3e9404a0df74936f165f37c3db1c5fcc8dc917a48e18969d6f1b8d163ea3ec249ba43349ed994123a05a3dfadfec84b340ebdd50b1d366d98b7588
7
+ data.tar.gz: 20c4198faa50e4a02a4ec7949ff32f9f19570b1da17ab3fb24f8b17e83cba75014e5011a8e734539e38b1d5b2188084610cf2d04c076eea6403f644cfa350944
data/README.md CHANGED
@@ -1,8 +1,63 @@
1
1
  # MonkeyKing
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/monkey_king`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ Monkey king is a tool which is initially designed for generating deployment manifests for a bosh deployment based on an existing deployment, and it could also be used for other purposes like performing functions on keys/values in yaml files based on yaml tags.
4
+
5
+
6
+ Here is some scenarios about how it works:
7
+ ## Using secret generation
8
+ The `!MK:secret` directive generates a random secret of the same length as the value it replaces.
9
+ BEFORE
10
+ ```
11
+ ---
12
+ meta:
13
+ secret: !MK:secret old_secret
14
+ another_secret: !MK:secret old_secret
15
+ not_secret: not_secret
16
+ ```
17
+
18
+ AFTER
19
+ ```
20
+ ---
21
+ meta:
22
+ secret: !MK:secret new_secret
23
+ another_secret: !MK:secret new_secret
24
+ not_secret: not_secret
25
+ ```
26
+
27
+ ## Using environment variables
28
+ The `!MK:env:<variable_name>` directive pulls values from environment variables and replaces the tagged keys/values
29
+
30
+ Given:
31
+
32
+ ```
33
+ export id1=id1_from_env
34
+ export id2=id2_from_env
35
+ ```
36
+
37
+ Before:
38
+ ```
39
+ ---
40
+ meta1:
41
+ not_secret: not_secret
42
+ layer1:
43
+ - id1: !MK:env:id1 id1_before
44
+ - layer2:
45
+ - id2: !MK:env:id2 id2_before
46
+ - !MK:env:id1 id3: !MK:env:id1 id1_before
47
+ ```
48
+
49
+ After:
50
+ ```
51
+ ---
52
+ meta1:
53
+ not_secret: not_secret
54
+ layer1:
55
+ - id1: !MK:env:id1 id1_from_env
56
+ - layer2:
57
+ - id2: !MK:env:id2 id2_from_env
58
+ - !MK:env:id1 id1_from_env: !MK:env:id1 id1_from_env
59
+ ```
4
60
 
5
- TODO: Delete this and the text above, and describe your gem
6
61
 
7
62
  ## Installation
8
63
 
@@ -21,8 +76,54 @@ Or install it yourself as:
21
76
  $ gem install monkey_king
22
77
 
23
78
  ## Usage
79
+ ```
80
+ $ mk help
81
+ Commands:
82
+ help [COMMAND] Help!
83
+ clone REPO DIR... Clone the repo and replace secret and env annotation
84
+ replace GLOBS... Replace secret and env annotation for existing directory
85
+ ```
86
+ ```
87
+ $ mk help clone
88
+ Clone the repo and replace secret and env annotation
24
89
 
25
- TODO: Write usage instructions here
90
+ Usage: clone REPO DIR...
91
+
92
+ Options:
93
+ --dir DIR
94
+ --repo REPO
95
+ ```
96
+ ```
97
+ $ mk help replace
98
+ Replace secret and env annotation for existing directory
99
+
100
+ Usage: replace GLOBS...
101
+
102
+ Options:
103
+ --globs GLOBS
104
+ ```
105
+
106
+ Example 1: clone the repo and replace all the manifest under bosh-init directory.
107
+
108
+ ```
109
+ $ mk clone --repo git@github.com:[USERNAME]/[DEPLOYMENT].git bosh-init
110
+ Cloning into '[DEPLOYMENT]'...
111
+ remote: Counting objects: 346, done.
112
+ remote: Total 346 (delta 0), reused 0 (delta 0), pack-reused 346
113
+ Receiving objects: 100% (346/346), 179.86 KiB | 0 bytes/s, done.
114
+ Resolving deltas: 100% (157/157), done.
115
+ Checking connectivity... done.
116
+ Transforming [DEPLOYMENT]/bosh-init/bosh-init.yml...
117
+ Done.
118
+ ```
119
+
120
+ Example 2: replace all the manifest under bosh-init directory.
121
+
122
+ ```
123
+ $ mk replace deployment0/bosh-init/*.yml
124
+ Transforming deployment0/bosh-init/bosh-init.yml...
125
+ Done.
126
+ ```
26
127
 
27
128
  ## Development
28
129
 
@@ -6,10 +6,10 @@ module MonkeyKing
6
6
 
7
7
  desc "Clone the repo and replace secret and env annotation"
8
8
  input :repo, :argument => true
9
- input :dir, :argument => :splat
9
+ input :dir, :argument => [:splat, true]
10
10
  def clone
11
11
  repo = input[:repo]
12
- sub_dir = input[:dir]
12
+ sub_dir = Array(input[:dir])
13
13
 
14
14
  directory = repo.split('/').last.split('.').first
15
15
  parser = MonkeyKing::Parser.new
@@ -28,13 +28,17 @@ module MonkeyKing
28
28
  overwrite_file.write transformed_content
29
29
  end
30
30
  end
31
+ puts "Done."
31
32
  end
32
33
 
33
- desc "Clone the repo and replace secret and env annotation"
34
+ desc "Replace secret and env annotation for existing directory"
34
35
  input :globs, :argument => :splat
35
36
  def replace
36
37
  globs = input[:globs]
37
38
  parser = MonkeyKing::Parser.new
39
+ if globs.empty?
40
+ raise 'no globs given in the argument'
41
+ end
38
42
 
39
43
  deployment_yaml_files = []
40
44
  deployment_yaml_files += Dir.glob(globs)
@@ -51,6 +55,7 @@ module MonkeyKing
51
55
  puts "skipping non-yaml file #{file}..."
52
56
  end
53
57
  end
58
+ puts "Done."
54
59
  end
55
60
 
56
61
  end
@@ -1,3 +1,3 @@
1
1
  module MonkeyKing
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: monkey_king
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - cloudops_hosted
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-01 00:00:00.000000000 Z
11
+ date: 2016-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mothership