bosh-gen 0.91.0 → 0.92.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d1dc07f603102568ae5b087023b5dec4b2b9d5f7
4
- data.tar.gz: a8a9f437abf3cdc25cde0b616e959aaa9f2c786f
3
+ metadata.gz: 668c75ea5ea57e96a2d20915d4d4aaecd773e3c0
4
+ data.tar.gz: e9bf3dc769566c2dc6b2d00e153ea76484e2ae87
5
5
  SHA512:
6
- metadata.gz: f0e869917407870d4d9ec67220f47992c88be509d9a1b2145fa748fc39ae95f61a2538611c375948f40740327575357b51c0b9f6c4e14d99b56899f62f84b2aa
7
- data.tar.gz: 780f1dff3a9ca3f19bc63e47e12e272580b957e50163c5f90cc28d49621386106fd3a016fb59ac3b63ac3390a624f67a7f049409ad3a8a791f2b59387a36cbbd
6
+ metadata.gz: 64875d8d16a32845aba49811e9d0f1bb7137cea9ffab4fd58f31a925f951ee2f5c81892107437e1794aa6ff43d585b99f27ecbe17b20af81b60ad8cad24fcd91
7
+ data.tar.gz: 8579d65a33f5450fc5822e4e81c97514a2130388a2071900072c4987da4670a151e4492f6d0b6216ecefd4b623f5965925f90a0d53b634399654e4fcee7a47a2
data/Gemfile CHANGED
@@ -6,7 +6,3 @@ gemspec
6
6
  if File.directory?("../cyoi")
7
7
  gem "cyoi", path: "../cyoi"
8
8
  end
9
-
10
- gem 'bosh_cli', '~> 1.1750'
11
-
12
- gem 'guard-rspec'
data/Rakefile CHANGED
@@ -1,13 +1,2 @@
1
1
  #!/usr/bin/env rake
2
2
  require "bundler/gem_tasks"
3
-
4
- require "rspec/core/rake_task"
5
-
6
-
7
- desc "Run Tests"
8
- RSpec::Core::RakeTask.new(:spec) do |t|
9
- t.pattern = "spec/{generators,models}/**/*_spec.rb"
10
- t.rspec_opts = %w(--format progress --color)
11
- end
12
-
13
- task :default => :spec
data/bosh-gen.gemspec CHANGED
@@ -16,8 +16,6 @@ Gem::Specification.new do |gem|
16
16
  gem.version = Bosh::Gen::VERSION
17
17
 
18
18
  gem.add_dependency "thor"
19
- gem.add_dependency "bosh_cli"
20
- gem.add_dependency "bosh-template"
21
19
  gem.add_dependency "progressbar"
22
20
 
23
21
  gem.add_dependency "cyoi", "~> 0.10"
@@ -28,5 +26,4 @@ Gem::Specification.new do |gem|
28
26
  gem.add_dependency "activesupport", ">= 4.0", "< 5.0"
29
27
 
30
28
  gem.add_development_dependency "rake"
31
- gem.add_development_dependency "rspec-fire"
32
29
  end
@@ -0,0 +1,274 @@
1
+ module Bosh; end
2
+ module Bosh::Cli
3
+ class Config
4
+ VALID_ID = /^[-a-z0-9_.]+$/i
5
+
6
+ class << self
7
+ # @return [Hash<String,Bosh::Cli::CommandDefinition>] Available commands
8
+ attr_reader :commands
9
+
10
+ # @return [Boolean] Should CLI output be colorized?
11
+ attr_accessor :colorize
12
+
13
+ # @return [IO] Where output goes
14
+ attr_accessor :output
15
+
16
+ # @return [Boolean] Is CLI being used interactively?
17
+ attr_accessor :interactive
18
+
19
+ # @return [Integer] CLI polling interval
20
+ attr_accessor :poll_interval
21
+
22
+ # @return [Integer] CLI max parallel downloads
23
+ attr_accessor :max_parallel_downloads
24
+ end
25
+
26
+ @commands = {}
27
+ @colorize = nil
28
+ @output = nil
29
+ @interactive = false
30
+
31
+ # Register command with BOSH CLI
32
+ # @param [Bosh::Cli::CommandDefinition] command
33
+ # @return [void]
34
+ def self.register_command(command)
35
+ if @commands.has_key?(command.usage)
36
+ raise CliError, "Duplicate command '#{command.usage}'"
37
+ end
38
+ @commands[command.usage] = command
39
+ end
40
+
41
+ def self.use_color?
42
+ # colorization explicitly enabled, or output is tty
43
+ return false if Bosh::Cli::Config.colorize == false
44
+
45
+ # colorization explicitly enabled, or output is tty
46
+ Bosh::Cli::Config.colorize || Bosh::Cli::Config.output.tty?
47
+ end
48
+
49
+ def initialize(filename, work_dir = Dir.pwd)
50
+ @filename = File.expand_path(filename || Bosh::Cli::DEFAULT_CONFIG_PATH)
51
+ @work_dir = work_dir
52
+
53
+ unless File.exists?(@filename)
54
+ File.open(@filename, "w") { |f| Psych.dump({}, f) }
55
+ File.chmod(0600, @filename)
56
+ end
57
+
58
+ @config_file = load_yaml_file(@filename, nil)
59
+
60
+ unless @config_file.is_a?(Hash)
61
+ @config_file = {} # Just ignore it if it's malformed
62
+ end
63
+
64
+ rescue SystemCallError => e
65
+ raise ConfigError, "Cannot read config file: #{e.message}"
66
+ end
67
+
68
+ # @return [Hash] Director credentials
69
+ def credentials_for(target)
70
+ if @config_file["auth"].is_a?(Hash) && @config_file["auth"][target]
71
+ @config_file["auth"][target]
72
+ else
73
+ {
74
+ "username" => nil,
75
+ "password" => nil
76
+ }
77
+ end
78
+ end
79
+
80
+ def set_credentials(target, credentials)
81
+ @config_file["auth"] ||= {}
82
+ @config_file["auth"][target] = credentials
83
+ end
84
+
85
+ def set_alias(category, alias_name, value)
86
+ @config_file["aliases"] ||= {}
87
+ @config_file["aliases"][category.to_s] ||= {}
88
+ @config_file["aliases"][category.to_s][alias_name] = value
89
+ end
90
+
91
+ def aliases(category)
92
+ if @config_file.has_key?("aliases") && @config_file["aliases"].is_a?(Hash)
93
+ @config_file["aliases"][category.to_s]
94
+ else
95
+ nil
96
+ end
97
+ end
98
+
99
+ def resolve_alias(category, alias_name)
100
+ category = category.to_s
101
+
102
+ if @config_file.has_key?("aliases") &&
103
+ @config_file["aliases"].is_a?(Hash) &&
104
+ @config_file["aliases"].has_key?(category) &&
105
+ @config_file["aliases"][category].is_a?(Hash) &&
106
+ !@config_file["aliases"][category][alias_name].blank?
107
+ @config_file["aliases"][category][alias_name].to_s
108
+ else
109
+ nil
110
+ end
111
+ end
112
+
113
+ # @param [String] target Target director url
114
+ # @return [String] Username associated with target
115
+ def username(target)
116
+ credentials_for(target)["username"]
117
+ end
118
+
119
+ # @param [String] target Target director url
120
+ # @return [String] Password associated with target
121
+ def password(target)
122
+ credentials_for(target)["password"]
123
+ end
124
+
125
+ # @param [String] target Target director url
126
+ # @return [String] Token associated with target
127
+ def access_token(target)
128
+ credentials_for(target)["access_token"]
129
+ end
130
+
131
+ # @param [String] target Target director url
132
+ # @return [String] Refresh token associated with target
133
+ def refresh_token(target)
134
+ credentials_for(target)["refresh_token"]
135
+ end
136
+
137
+ # Deployment used to be a string that was only stored for your
138
+ # current target. As soon as you switched targets, the deployment
139
+ # was erased. If the user has the old config we convert it to the
140
+ # new config.
141
+ #
142
+ # @return [Boolean] Whether config is using the old deployment format.
143
+ def is_old_deployment_config?
144
+ @config_file["deployment"].is_a?(String)
145
+ end
146
+
147
+ # Read the deployment configuration. Return the deployment for the
148
+ # current target.
149
+ #
150
+ # @return [String?] The deployment path for the current target.
151
+ def deployment
152
+ return nil if target.nil?
153
+ if @config_file.has_key?("deployment")
154
+ if is_old_deployment_config?
155
+ set_deployment(@config_file["deployment"])
156
+ save
157
+ end
158
+ if @config_file["deployment"].is_a?(Hash)
159
+ return @config_file["deployment"][target]
160
+ end
161
+ end
162
+ end
163
+
164
+ # Sets the deployment file for the current target. If the deployment is
165
+ # the old deployment configuration, it will turn it into the format.
166
+ #
167
+ # @raise [MissingTarget] If there is no target set.
168
+ # @param [String] deployment_file_path The string path to the
169
+ # deployment file.
170
+ def set_deployment(deployment_file_path)
171
+ raise MissingTarget, "Must have a target set" if target.nil?
172
+ @config_file["deployment"] = {} if is_old_deployment_config?
173
+ @config_file["deployment"] ||= {}
174
+ @config_file["deployment"][target] = deployment_file_path
175
+ end
176
+
177
+ def target
178
+ read(:target, false)
179
+ end
180
+
181
+ def target=(value)
182
+ write_global(:target, value)
183
+ end
184
+
185
+ def target_name
186
+ read(:target_name, false)
187
+ end
188
+
189
+ def target_name=(value)
190
+ write_global(:target_name, value)
191
+ end
192
+
193
+ def target_version
194
+ read(:target_version, false)
195
+ end
196
+
197
+ def target_version=(value)
198
+ write_global(:target_version, value)
199
+ end
200
+
201
+ def release
202
+ read(:release, false)
203
+ end
204
+
205
+ def release=(value)
206
+ write_global(:release, value)
207
+ end
208
+
209
+ def target_uuid
210
+ read(:target_uuid, false)
211
+ end
212
+
213
+ def target_uuid=(value)
214
+ write_global(:target_uuid, value)
215
+ end
216
+
217
+ def ca_cert(for_target=nil)
218
+ if for_target
219
+ return @config_file.fetch('ca_cert', {}).fetch(for_target, nil)
220
+ end
221
+
222
+ return nil if target.nil?
223
+
224
+ @config_file.fetch('ca_cert', {}).fetch(target, nil)
225
+ end
226
+
227
+
228
+ def save_ca_cert_path(cert_path, for_target=nil)
229
+ expanded_path = cert_path ? File.expand_path(cert_path) : nil
230
+ cert_target = for_target || target
231
+ @config_file['ca_cert'] ||= {}
232
+ @config_file['ca_cert'][cert_target] = expanded_path
233
+
234
+ expanded_path
235
+ end
236
+
237
+ # Read the max parallel downloads configuration.
238
+ #
239
+ # @return [Integer] The maximum number of parallel downloads
240
+ def max_parallel_downloads
241
+ self.class.max_parallel_downloads || @config_file.fetch("max_parallel_downloads", 1)
242
+ end
243
+
244
+ def read(attr, try_local_first = true)
245
+ attr = attr.to_s
246
+ if try_local_first && @config_file[@work_dir].is_a?(Hash) &&
247
+ @config_file[@work_dir].has_key?(attr)
248
+ @config_file[@work_dir][attr]
249
+ else
250
+ @config_file[attr]
251
+ end
252
+ end
253
+
254
+ def write(attr, value)
255
+ @config_file[@work_dir] ||= {}
256
+ @config_file[@work_dir][attr.to_s] = value
257
+ end
258
+
259
+ def write_global(attr, value)
260
+ @config_file[attr.to_s] = value
261
+ end
262
+
263
+ def save
264
+ File.open(@filename, "w") do |f|
265
+ Psych.dump(@config_file, f)
266
+ end
267
+
268
+ rescue SystemCallError => e
269
+ raise ConfigError, e.message
270
+ end
271
+
272
+ attr_reader :filename
273
+ end
274
+ end
data/lib/bosh/gen/cli.rb CHANGED
@@ -1,9 +1,7 @@
1
1
  require "thor"
2
2
 
3
- # bosh_cli libraries
4
- module Bosh; end
5
- require "cli/config"
6
- require "cli/core_ext"
3
+ require "bosh/gen/bosh-config"
4
+ require "bosh/gen/core-ext"
7
5
 
8
6
  module Bosh
9
7
  module Gen
@@ -0,0 +1,185 @@
1
+ module BoshExtensions
2
+
3
+ def say(message, sep = "\n")
4
+ return unless Bosh::Cli::Config.output && message
5
+ message = message.dup.to_s
6
+ sep = "" if message[-1] == sep
7
+ Bosh::Cli::Config.output.print("#{$indent}#{message}#{sep}")
8
+ end
9
+
10
+ def with_indent(indent)
11
+ old_indent, $indent = $indent, old_indent.to_s + indent.to_s
12
+ yield
13
+ ensure
14
+ $indent = old_indent
15
+ end
16
+
17
+ def header(message, filler = '-')
18
+ say("\n")
19
+ say(message)
20
+ say(filler.to_s * message.size)
21
+ end
22
+
23
+ def nl(count = 1)
24
+ say("\n" * count)
25
+ end
26
+
27
+ def err_nl
28
+ warn('')
29
+ end
30
+
31
+ def err(message)
32
+ raise Bosh::Cli::CliError, message
33
+ end
34
+
35
+ def quit(message = nil)
36
+ say(message)
37
+ raise Bosh::Cli::GracefulExit, message
38
+ end
39
+
40
+ def blank?
41
+ self.to_s.blank?
42
+ end
43
+
44
+ def pretty_size(what, prec=1)
45
+ if what.is_a?(String) && File.exists?(what)
46
+ size = File.size(what)
47
+ else
48
+ size = what.to_i
49
+ end
50
+
51
+ return "NA" unless size
52
+ return "#{size}B" if size < 1024
53
+ return sprintf("%.#{prec}fK", size/1024.0) if size < (1024*1024)
54
+ if size < (1024*1024*1024)
55
+ return sprintf("%.#{prec}fM", size/(1024.0*1024.0))
56
+ end
57
+ sprintf("%.#{prec}fG", size/(1024.0*1024.0*1024.0))
58
+ end
59
+
60
+ def pluralize(number, singular, plural = nil)
61
+ plural = plural || "#{singular}s"
62
+ number == 1 ? "1 #{singular}" : "#{number} #{plural}"
63
+ end
64
+
65
+ def format_time(time)
66
+ ts = time.to_i
67
+ sprintf("%02d:%02d:%02d", ts / 3600, (ts / 60) % 60, ts % 60);
68
+ end
69
+
70
+ def load_yaml_file(path, expected_type = Hash)
71
+ yaml_str = read_yaml_file(path)
72
+
73
+ yaml = Psych::load(yaml_str)
74
+ if expected_type && !yaml.is_a?(expected_type)
75
+ err("Incorrect YAML structure in '#{path}': expected #{expected_type} at the root".make_red)
76
+ end
77
+
78
+ yaml
79
+ end
80
+
81
+ def read_yaml_file(path)
82
+ err("Cannot find file '#{path}'".make_red) unless File.exist?(path)
83
+
84
+ begin
85
+ yaml_str = ERB.new(File.read(path)).result
86
+ rescue SystemCallError => e
87
+ err("Cannot load YAML file at '#{path}': #{e}".make_red)
88
+ end
89
+
90
+ begin
91
+ Bosh::Cli::YamlHelper.check_duplicate_keys(yaml_str)
92
+ rescue Exception => e # on ruby 1.9.3 Psych::SyntaxError isn't a StandardError
93
+ err("Incorrect YAML structure in '#{path}': #{e}".make_red)
94
+ end
95
+ yaml_str
96
+ end
97
+
98
+ def write_yaml(manifest, path)
99
+ File.open(path, "w+") do |f|
100
+ f.write(manifest.to_yaml)
101
+ end
102
+ end
103
+
104
+ # @return [Fixnum]
105
+ def terminal_width
106
+ STDIN.tty? ? [HighLine::SystemExtensions.terminal_size[0], 120].min : 80
107
+ end
108
+
109
+ def warning(message)
110
+ warn("[WARNING] #{message}".make_yellow)
111
+ end
112
+ end
113
+
114
+ module BoshStringExtensions
115
+
116
+ COLOR_CODES = {
117
+ :red => "\e[0m\e[31m",
118
+ :green => "\e[0m\e[32m",
119
+ :yellow => "\e[0m\e[33m"
120
+ }
121
+
122
+ def make_red
123
+ make_color(:red)
124
+ end
125
+
126
+ def make_green
127
+ make_color(:green)
128
+ end
129
+
130
+ def make_yellow
131
+ make_color(:yellow)
132
+ end
133
+
134
+ def make_color(color_code)
135
+ # invalid color
136
+ return self if !COLOR_CODES[color_code]
137
+
138
+ # output disabled
139
+ return self if !Bosh::Cli::Config.output
140
+
141
+ if Bosh::Cli::Config.use_color?
142
+ "#{COLOR_CODES[color_code]}#{self}\e[0m"
143
+ else
144
+ self
145
+ end
146
+ end
147
+
148
+ def blank?
149
+ self =~ /^\s*$/
150
+ end
151
+
152
+ def bosh_valid_id?
153
+ !!(self =~ Bosh::Cli::Config::VALID_ID)
154
+ end
155
+
156
+ def truncate(limit = 30)
157
+ return "" if self.blank?
158
+ etc = "..."
159
+ stripped = self.strip[0..limit]
160
+ if stripped.length > limit
161
+ stripped.gsub(/\s+?(\S+)?$/, "") + etc
162
+ else
163
+ stripped
164
+ end
165
+ end
166
+
167
+ def columnize(width = 80, left_margin = 0)
168
+ Bosh::Cli::LineWrap.new(width, left_margin).wrap(self)
169
+ end
170
+
171
+ def indent(margin = 2)
172
+ self.split("\n").map { |line|
173
+ " " * margin + line
174
+ }.join("\n")
175
+ end
176
+
177
+ end
178
+
179
+ class Object
180
+ include BoshExtensions
181
+ end
182
+
183
+ class String
184
+ include BoshStringExtensions
185
+ end
@@ -1,5 +1,5 @@
1
1
  module Bosh
2
2
  module Gen
3
- VERSION = "0.91.0"
3
+ VERSION = "0.92.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bosh-gen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.91.0
4
+ version: 0.92.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dr Nic Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-16 00:00:00.000000000 Z
11
+ date: 2017-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -24,34 +24,6 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: bosh_cli
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: bosh-template
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
27
  - !ruby/object:Gem::Dependency
56
28
  name: progressbar
57
29
  requirement: !ruby/object:Gem::Requirement
@@ -170,20 +142,6 @@ dependencies:
170
142
  - - ">="
171
143
  - !ruby/object:Gem::Version
172
144
  version: '0'
173
- - !ruby/object:Gem::Dependency
174
- name: rspec-fire
175
- requirement: !ruby/object:Gem::Requirement
176
- requirements:
177
- - - ">="
178
- - !ruby/object:Gem::Version
179
- version: '0'
180
- type: :development
181
- prerelease: false
182
- version_requirements: !ruby/object:Gem::Requirement
183
- requirements:
184
- - - ">="
185
- - !ruby/object:Gem::Version
186
- version: '0'
187
145
  description: Generators for creating BOSH releases
188
146
  email:
189
147
  - drnicwilliams@gmail.com
@@ -193,17 +151,17 @@ extensions: []
193
151
  extra_rdoc_files: []
194
152
  files:
195
153
  - ".gitignore"
196
- - ".rspec"
197
154
  - ChangeLog.md
198
155
  - Gemfile
199
- - Guardfile
200
156
  - LICENSE
201
157
  - README.md
202
158
  - Rakefile
203
159
  - bin/bosh-gen
204
160
  - bosh-gen.gemspec
205
161
  - lib/bosh/gen.rb
162
+ - lib/bosh/gen/bosh-config.rb
206
163
  - lib/bosh/gen/cli.rb
164
+ - lib/bosh/gen/core-ext.rb
207
165
  - lib/bosh/gen/generators/blacksmith_forge_generator.rb
208
166
  - lib/bosh/gen/generators/blacksmith_forge_generator/templates/.gitkeep
209
167
  - lib/bosh/gen/generators/blacksmith_forge_generator/templates/jobs/%job_name%/monit.tt
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --format progress
2
- --color
3
- --require spec_helper
data/Guardfile DELETED
@@ -1,5 +0,0 @@
1
- guard 'rspec', spec_paths: ["spec"] do
2
- watch(%r{^spec/(.+_spec)\.rb$})
3
- watch(%r{^lib/bosh/gen/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
4
- watch('spec/spec_helper.rb') { "spec" }
5
- end