ky 0.5.1 → 0.5.2.pre1

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: 666a1f9df164ebe18972f49effbeddcbbb3faec9
4
- data.tar.gz: 518729830dd9260892cf782ade1fc58aae77fa7f
3
+ metadata.gz: 79b89255c18ce526eae627c708a5bc265777ff53
4
+ data.tar.gz: 90ec88c86756ae65599f3005b4480e4312bce855
5
5
  SHA512:
6
- metadata.gz: 45f7949edf594ffb2345567b3b25588b5332c89c471636ae9514e91fd5017f9d2e9cea00045592b5233eb760bc0d742abb0393ddc729275e8edd22f300e25a0a
7
- data.tar.gz: 5823a7f1ef34db3ac32b5a2335e6ba7d9d02989602139320e1eb305c6592e5d481c91169993a58640db6943e9ab51da04e2a100fccec2510c91e89999e8eb53f
6
+ metadata.gz: 7a059e29f0cfc7b31c5873bf662e427abd8f676a697c5a15f3332efc2c9cf01c487b39b5f9eeb3063475975589b8eda2da69464d69b0558345e0335cecacdea5
7
+ data.tar.gz: 83d2f6d350fec0028d7d3a8804ef316621bb2939eb968a50fc63f9abc607696ca9254d69233dcbbdec19592a51babf811ee7f64f5331a1d41cb4f59ccb17eec6
data/lib/ky.rb CHANGED
@@ -4,6 +4,7 @@ require 'open-uri'
4
4
  require 'fileutils'
5
5
  require 'pathname'
6
6
  require 'random_username'
7
+ require_relative 'ky/api'
7
8
  require_relative 'ky/configuration'
8
9
  require_relative 'ky/compilation'
9
10
  require_relative 'ky/manipulation'
@@ -0,0 +1,62 @@
1
+ module KY
2
+ module API
3
+ MissingParametersError = Class.new(StandardError)
4
+
5
+ def self.encode(input_source, output_source)
6
+ input_output(input_source, output_source) do |input_object, output_object|
7
+ Manipulation.encode(output_object, input_object)
8
+ end
9
+ end
10
+
11
+ def self.decode(input_source, output_source)
12
+ input_output(input_source, output_source) do |input_object, output_object|
13
+ Manipulation.decode(output_object, input_object)
14
+ end
15
+ end
16
+
17
+
18
+ def self.merge(input_source1, input_source2, output_source)
19
+ input_output(input_source1, output_source) do |input_object1, output_object|
20
+ with(input_source2, 'r') {|input_object2| Manipulation.merge(output_object, input_object1, input_object2) }
21
+ end
22
+ end
23
+
24
+ def self.env(input_source1, input_source2, output_source)
25
+ input_output(input_source1, output_source) do |input_object1, output_object|
26
+ with(input_source2, 'r') {|input_object2| EnvGeneration.env(output_object, input_object1, input_object2) }
27
+ end
28
+ end
29
+
30
+ def self.compile(config_or_secrets_path, secrets_or_config_path, output_dir, options={})
31
+ Compilation.new(options.with_indifferent_access).tap do |instance|
32
+ config_or_secrets_path ||= instance.configuration['config_path'] || instance.configuration['secret_path']
33
+ secrets_or_config_path ||= instance.configuration['secret_path'] || instance.configuration['config_path']
34
+ output_dir ||= instance.configuration['output_dir']
35
+ raise MissingParametersError unless config_or_secrets_path && secrets_or_config_path && output_dir && instance.configuration['procfile_path']
36
+ input_input(config_or_secrets_path, secrets_or_config_path) do |input1, input2|
37
+ instance.compile(input1, input2, output_dir)
38
+ end
39
+ end
40
+ end
41
+
42
+ private
43
+
44
+ def self.input_output(input1, output1)
45
+ with(input1, 'r') {|input_object| with(output1, 'w+') { |output_object| yield(input_object, output_object) } }
46
+ end
47
+
48
+ def self.input_input(input1, input2)
49
+ with(input1, 'r') {|input_object1| with(input2, 'r') { |input_object2| yield(input_object1, input_object2) } }
50
+ end
51
+
52
+ def self.with(output, mode)
53
+ if output.kind_of?(IO)
54
+ yield output
55
+ else
56
+ open(output, mode) do |f|
57
+ yield f
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -2,33 +2,24 @@ require_relative '../ky'
2
2
  require 'thor'
3
3
  module KY
4
4
  class Cli < Thor
5
- MissingParametersError = Class.new(StandardError)
6
5
  desc "encode secrets.yml", "base64 encoded yaml version of data attributes in secrets.yml"
7
6
  def encode(input_source=$stdin, output_source=$stdout)
8
- input_output(input_source, output_source) do |input_object, output_object|
9
- Manipulation.encode(output_object, input_object)
10
- end
7
+ API.encode(input_source, output_source)
11
8
  end
12
9
 
13
10
  desc "decode secrets.yml", "decoded yaml version of secrets.yml with base64 encoded data attributes"
14
11
  def decode(input_source=$stdin, output_source=$stdout)
15
- input_output(input_source, output_source) do |input_object, output_object|
16
- Manipulation.decode(output_object, input_object)
17
- end
12
+ API.decode(input_source, output_source)
18
13
  end
19
14
 
20
15
  desc "merge base.yml env.yml", "deep merged/combined yaml of two seperate files"
21
16
  def merge(input_source1, input_source2=$stdin, output_source=$stdout)
22
- input_output(input_source1, output_source) do |input_object1, output_object|
23
- with(input_source2, 'r') {|input_object2| Manipulation.merge(output_object, input_object1, input_object2) }
24
- end
17
+ API.merge(input_source1, input_source2, output_source)
25
18
  end
26
19
 
27
20
  desc "env config.yml secrets.yml", "generate env variables section of a deployment from a config and a secrets file"
28
21
  def env(input_source1, input_source2=$stdin, output_source=$stdout)
29
- input_output(input_source1, output_source) do |input_object1, output_object|
30
- with(input_source2, 'r') {|input_object2| EnvGeneration.env(output_object, input_object1, input_object2) }
31
- end
22
+ API.env(input_source1, input_source2, output_source)
32
23
  end
33
24
 
34
25
  desc "compile (config.yml secrets.yml output)", <<-DOC.strip_heredoc
@@ -46,14 +37,7 @@ module KY
46
37
  method_option :procfile_path, type: :string, aliases: "-p"
47
38
  method_option :ky_config_path, type: :string, aliases: "-k"
48
39
  def compile(config_or_secrets_path=nil, secrets_or_config_path=nil, output_dir=nil)
49
- instance = Compilation.new(options.with_indifferent_access)
50
- config_or_secrets_path ||= instance.configuration['config_path'] || instance.configuration['secret_path']
51
- secrets_or_config_path ||= instance.configuration['secret_path'] || instance.configuration['config_path']
52
- output_dir ||= instance.configuration['output_dir']
53
- raise MissingParametersError unless config_or_secrets_path && secrets_or_config_path && output_dir && instance.configuration['procfile_path']
54
- input_input(config_or_secrets_path, secrets_or_config_path) do |input1, input2|
55
- instance.compile(input1, input2, output_dir)
56
- end
40
+ API.compile(config_or_secrets_path, secrets_or_config_path, output_dir, options)
57
41
  end
58
42
 
59
43
  desc "example", "copy example configuration and environment override file to current directory"
@@ -68,25 +52,5 @@ module KY
68
52
  `cp #{__dir__}/../../examples/dev.deployment.yml .`
69
53
  end
70
54
 
71
- private
72
-
73
- def input_output(input1, output1)
74
- with(input1, 'r') {|input_object| with(output1, 'w+') { |output_object| yield(input_object, output_object) } }
75
- end
76
-
77
- def input_input(input1, input2)
78
- with(input1, 'r') {|input_object1| with(input2, 'r') { |input_object2| yield(input_object1, input_object2) } }
79
- end
80
-
81
- def with(output, mode)
82
- if output.kind_of?(IO)
83
- yield output
84
- else
85
- open(output, mode) do |f|
86
- yield f
87
- end
88
- end
89
- end
90
-
91
55
  end
92
56
  end
@@ -1,6 +1,6 @@
1
1
  module KY
2
2
  class Compilation
3
- attr_reader :configuration
3
+ attr_reader :configuration, :deploy_generation
4
4
 
5
5
  def initialize(opts={})
6
6
  @configuration = Configuration.new(opts)
@@ -10,7 +10,8 @@ module KY
10
10
  full_output_dir = Pathname.new(base_output_dir).join(configuration[:environment].to_s).to_s
11
11
  FileUtils.mkdir_p(full_output_dir)
12
12
  env_obj = EnvGeneration.new(env1path, env2path, configuration)
13
- deploys_hash = DeployGeneration.new(full_output_dir, env_obj.immutable_project_name, configuration).to_h
13
+ @deploy_generation = DeployGeneration.new(full_output_dir, env_obj.immutable_project_name, configuration)
14
+ deploys_hash = deploy_generation.to_h
14
15
  deploys_hash.each do |file_path, deploy_hash|
15
16
  File.write(file_path, Manipulation.merge_hash(deploy_hash, env_obj.to_h).to_plain_yaml)
16
17
  end
@@ -23,9 +23,10 @@ module KY
23
23
  end.to_h
24
24
  end
25
25
 
26
- private
27
26
  attr_reader :proc_commands, :full_output_dir, :project_name, :deployment_yaml, :configuration
28
27
 
28
+ private
29
+
29
30
  def read_deployment_yaml
30
31
  if configuration['deployment']
31
32
  File.read(configuration['deployment'])
@@ -1,3 +1,3 @@
1
1
  module KY
2
- VERSION = "0.5.1"
2
+ VERSION = "0.5.2.pre1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ky
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2.pre1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Glusman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-07 00:00:00.000000000 Z
11
+ date: 2017-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -130,6 +130,7 @@ files:
130
130
  - examples/dev.yml
131
131
  - ky.gemspec
132
132
  - lib/ky.rb
133
+ - lib/ky/api.rb
133
134
  - lib/ky/cli.rb
134
135
  - lib/ky/compilation.rb
135
136
  - lib/ky/configuration.rb
@@ -166,9 +167,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
166
167
  version: '0'
167
168
  required_rubygems_version: !ruby/object:Gem::Requirement
168
169
  requirements:
169
- - - ">="
170
+ - - ">"
170
171
  - !ruby/object:Gem::Version
171
- version: '0'
172
+ version: 1.3.1
172
173
  requirements: []
173
174
  rubyforge_project: ky
174
175
  rubygems_version: 2.6.8
@@ -176,3 +177,4 @@ signing_key:
176
177
  specification_version: 4
177
178
  summary: Kubernetes Yaml utilities and lubricant
178
179
  test_files: []
180
+ has_rdoc: