monkey_king 0.1.2

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8ff695582cc29fa310eb02dc8bc5d8dc9518c62c
4
+ data.tar.gz: 2a2beb9d73d6ca7a9edb9d75ca7f0cc7e06bf5ad
5
+ SHA512:
6
+ metadata.gz: 9a104e25f735889136e69d302db996b6fe1fde7dd6df47c56dfb0ce39e89a8e16e37676ecc6c3f75ebc1351c47f0ab326654b582dfb5b47224a27e95c7e8e1e3
7
+ data.tar.gz: 849b6f2cda8bd03030fc3180cd39e68873fb2594123295fce400b6bdd362edc6a53dad9f88db4d5fb5d33ece79422a8cf29b85ac3d99b62c61e8e876770d9d69
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ before_install: gem install bundler -v 1.11.2
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at pivotal@pivotal.io. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in monkey_king.gemspec
4
+ gemspec
5
+
6
+ gem 'guard-rspec', require: false
7
+ gem 'climate_control'
8
+ gem 'pry-byebug'
9
+ gem 'mothership'
10
+ gem 'highline'
11
+
data/Guardfile ADDED
@@ -0,0 +1,74 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ ## Uncomment and set this to only include directories you want to watch
5
+ # directories %w(app lib config test spec features) \
6
+ # .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
7
+
8
+ ## Note: if you are using the `directories` clause above and you are not
9
+ ## watching the project directory ('.'), then you will want to move
10
+ ## the Guardfile to a watched dir and symlink it back, e.g.
11
+ #
12
+ # $ mkdir config
13
+ # $ mv Guardfile config/
14
+ # $ ln -s config/Guardfile .
15
+ #
16
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
17
+
18
+ # Note: The cmd option is now required due to the increasing number of ways
19
+ # rspec may be run, below are examples of the most common uses.
20
+ # * bundler: 'bundle exec rspec'
21
+ # * bundler binstubs: 'bin/rspec'
22
+ # * spring: 'bin/rspec' (This will use spring if running and you have
23
+ # installed the spring binstubs per the docs)
24
+ # * zeus: 'zeus rspec' (requires the server to be started separately)
25
+ # * 'just' rspec: 'rspec'
26
+
27
+ guard :rspec, cmd: "bundle exec rspec" do
28
+ require "guard/rspec/dsl"
29
+ dsl = Guard::RSpec::Dsl.new(self)
30
+
31
+ # Feel free to open issues for suggestions and improvements
32
+
33
+ watch('./**.rb')
34
+
35
+ # RSpec files
36
+ rspec = dsl.rspec
37
+ watch(rspec.spec_helper) { rspec.spec_dir }
38
+ watch(rspec.spec_support) { rspec.spec_dir }
39
+ watch(rspec.spec_files)
40
+ watch(%r{^lib/.*/(.+)\.rb}) { rspec.spec_dir }
41
+
42
+
43
+ # Ruby files
44
+ ruby = dsl.ruby
45
+ dsl.watch_spec_files_for(ruby.lib_files)
46
+
47
+ # Rails files
48
+ rails = dsl.rails(view_extensions: %w(erb haml slim))
49
+ dsl.watch_spec_files_for(rails.app_files)
50
+ dsl.watch_spec_files_for(rails.views)
51
+
52
+ watch(rails.controllers) do |m|
53
+ [
54
+ rspec.spec.("routing/#{m[1]}_routing"),
55
+ rspec.spec.("controllers/#{m[1]}_controller"),
56
+ rspec.spec.("acceptance/#{m[1]}")
57
+ ]
58
+ end
59
+
60
+ # Rails config changes
61
+ watch(rails.spec_helper) { rspec.spec_dir }
62
+ watch(rails.routes) { "#{rspec.spec_dir}/routing" }
63
+ watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
64
+
65
+ # Capybara features specs
66
+ watch(rails.view_dirs) { |m| rspec.spec.("features/#{m[1]}") }
67
+ watch(rails.layouts) { |m| rspec.spec.("features/#{m[1]}") }
68
+
69
+ # Turnip features and steps
70
+ watch(%r{^spec/acceptance/(.+)\.feature$})
71
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
72
+ Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
73
+ end
74
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 clay richardson
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # MonkeyKing
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.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'monkey_king'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install monkey_king
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/monkey_king. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/mk ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ libdir = File.expand_path(File.join(File.dirname(__FILE__), "../lib"))
4
+ $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
5
+
6
+ require 'rubygems'
7
+ require 'monkey_king'
8
+
9
+ $stdout.sync = true
10
+
11
+ if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new("1.9.3")
12
+ warn "ERROR: \033[31mRuby version #{RUBY_VERSION} is not supported.\033[0m Please install 1.9.3 or later. (See http://docs.cloudfoundry.com/docs/common/install_ruby.html for more information)"
13
+ exit 1
14
+ end
15
+
16
+ MonkeyKing::CloneCommand.start(ARGV)
@@ -0,0 +1,45 @@
1
+ require 'mothership'
2
+ require 'highline/import'
3
+
4
+ module MonkeyKing
5
+ class CloneCommand < Mothership
6
+ option :help, :desc => "Show command usage", :alias => "-h",
7
+ :default => false
8
+
9
+ desc "Show Help"
10
+ input :command, :argument => :optional
11
+ def help
12
+ if name = input[:command]
13
+ if cmd = @@commands[name.gsub("-", "_").to_sym]
14
+ Mothership::Help.command_help(cmd)
15
+ else
16
+ unknown_command(name)
17
+ end
18
+ else
19
+ Mothership::Help.basic_help(@@commands, @@global)
20
+ end
21
+ end
22
+
23
+ desc "Clone the repo and replace secret and env annotation"
24
+ input(:repo) { ask("Input the github repo of a existing deployment") }
25
+ def clone
26
+ repo = input[:repo]
27
+ directory = repo.split('/').last.split('.').first
28
+ parser = MonkeyKing::Parser.new
29
+
30
+ raise 'Failed to clone' unless system("git clone #{repo} #{directory}")
31
+ deployment_yaml_files = []
32
+
33
+ deployment_yaml_files += Dir.glob("#{directory}/deployments/*.yml")
34
+ deployment_yaml_files += Dir.glob("#{directory}/bosh-init/*.yml")
35
+
36
+ deployment_yaml_files.each do |file|
37
+ puts "Transforming #{file}..."
38
+ transformed_content = parser.transform(file)
39
+ File.open(file, "w") do |overwrite_file|
40
+ overwrite_file.write transformed_content
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,101 @@
1
+ require 'yaml'
2
+
3
+ module MonkeyKing
4
+ class SecretTag
5
+ yaml_tag '!MK:secret'
6
+
7
+ attr_reader :secret
8
+
9
+ def initialize( *secret )
10
+ self.secret = *secret
11
+ end
12
+
13
+ def init_with( coder )
14
+ case coder.type
15
+ when :scalar
16
+ self.secret = coder.scalar
17
+ else
18
+ raise "Dunno how to handle #{coder.type} for #{coder.inspect}"
19
+ end
20
+ end
21
+
22
+ def encode_with( coder )
23
+ coder.style = Psych::Nodes::Mapping::FLOW
24
+ coder.scalar = gen_secret(@secret.length)
25
+ end
26
+
27
+ protected def secret=( str )
28
+ @secret= str
29
+ end
30
+
31
+ def gen_secret(length)
32
+ [*('a'..'z'),*('0'..'9'),*('A'..'Z')].shuffle[0,length].join
33
+ end
34
+ end
35
+
36
+ class EnvTag
37
+ attr_reader :env_tag
38
+
39
+ def register(tag)
40
+ if tag.split(':')[1] == 'env'
41
+ self.class.send(:yaml_tag, tag)
42
+ end
43
+ end
44
+
45
+ def init_with( coder )
46
+ unless coder.type == :scalar
47
+ raise "Dunno how to handle #{coder.type} for #{coder.inspect}"
48
+ end
49
+ end
50
+
51
+ def encode_with(coder)
52
+ coder.style = Psych::Nodes::Mapping::FLOW
53
+ tag=coder.tag.split(':')[2]
54
+ if ENV[tag].nil?
55
+ raise "#{tag} not found in env"
56
+ end
57
+ coder.scalar = ENV[tag]
58
+ end
59
+ end
60
+
61
+ class Parser
62
+ def transform(yaml_file)
63
+ tags = get_tags(yaml_file)
64
+ env_tag_instances={}
65
+ tags.each do |tag|
66
+ command = tag.split(':')[1]
67
+ unless command.nil? or command != 'env'
68
+ class_name = tag.split(':')[2]
69
+ unless class_name.nil?
70
+ tag_class = Class.new(EnvTag)
71
+
72
+ # Hacky way to give each class a global uniq name
73
+ random_string = [*('a'..'z')].shuffle[0,32].join
74
+ Object.const_set("EnvTag#{class_name}#{random_string}", tag_class)
75
+
76
+ tag_instance = tag_class.new
77
+ tag_instance.register(tag)
78
+ env_tag_instances[tag] = tag_instance
79
+ end
80
+ end
81
+ end
82
+ yaml = YAML.load_file(yaml_file)
83
+ yaml.to_yaml
84
+ end
85
+
86
+ def get_tags(yaml_file)
87
+ tags = []
88
+ nodes = Psych.parse_file(yaml_file)
89
+ # traverse the tree and return
90
+ nodes.each do |n|
91
+ if n.class == Psych::Nodes::Scalar
92
+ unless n.tag.nil?
93
+ tags << n.tag
94
+ end
95
+ end
96
+ end
97
+ tags.uniq
98
+ end
99
+ end
100
+
101
+ end
@@ -0,0 +1,3 @@
1
+ module MonkeyKing
2
+ VERSION = "0.1.2"
3
+ end
@@ -0,0 +1,7 @@
1
+ require "monkey_king/version"
2
+ require "monkey_king/parser"
3
+ require "monkey_king/clone_command"
4
+
5
+ module MonkeyKing
6
+ # Your code goes here...
7
+ end
@@ -0,0 +1,36 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'monkey_king/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "monkey_king"
8
+ spec.version = MonkeyKing::VERSION
9
+ spec.authors = ["cloudops_hosted"]
10
+ spec.email = ["cloudops+hosted@pivotal.io"]
11
+
12
+ spec.summary = %q{Creates new BOSH deployments from existing deployments}
13
+ spec.description = %q{It clones the existing BOSH deployments manifest and replaces the annotated fields}
14
+ spec.homepage = "https://github.com/pivotal-cloudops/monkey_king"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "bin"
27
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_runtime_dependency "mothership", '~> 0.5.1'
31
+ spec.add_runtime_dependency 'highline', '~> 1.7', '>= 1.7.8'
32
+
33
+ spec.add_development_dependency "bundler", "~> 1.11"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ spec.add_development_dependency "rspec", "~> 3.0"
36
+ end
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: monkey_king
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - cloudops_hosted
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-02-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: mothership
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.5.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.5.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: highline
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 1.7.8
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '1.7'
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 1.7.8
47
+ - !ruby/object:Gem::Dependency
48
+ name: bundler
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '1.11'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '1.11'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rake
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '10.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '10.0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rspec
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '3.0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '3.0'
89
+ description: It clones the existing BOSH deployments manifest and replaces the annotated
90
+ fields
91
+ email:
92
+ - cloudops+hosted@pivotal.io
93
+ executables:
94
+ - mk
95
+ extensions: []
96
+ extra_rdoc_files: []
97
+ files:
98
+ - ".gitignore"
99
+ - ".rspec"
100
+ - ".travis.yml"
101
+ - CODE_OF_CONDUCT.md
102
+ - Gemfile
103
+ - Guardfile
104
+ - LICENSE.txt
105
+ - README.md
106
+ - Rakefile
107
+ - bin/mk
108
+ - lib/monkey_king.rb
109
+ - lib/monkey_king/clone_command.rb
110
+ - lib/monkey_king/parser.rb
111
+ - lib/monkey_king/version.rb
112
+ - monkey_king.gemspec
113
+ homepage: https://github.com/pivotal-cloudops/monkey_king
114
+ licenses:
115
+ - MIT
116
+ metadata:
117
+ allowed_push_host: https://rubygems.org
118
+ post_install_message:
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ requirements: []
133
+ rubyforge_project:
134
+ rubygems_version: 2.4.5
135
+ signing_key:
136
+ specification_version: 4
137
+ summary: Creates new BOSH deployments from existing deployments
138
+ test_files: []