config_kit 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,48 @@
1
+ api_version: 'v1.0'
2
+ kind: 'config_kit'
3
+ axle:
4
+ version: '1.0'
5
+ namespace: 'int0'
6
+ database:
7
+ adapter: 'mysql2'
8
+ host: 'localhost'
9
+ port: 3306
10
+ username: 'laxino'
11
+ password: 'password'
12
+ database: 'g2_axle_production'
13
+
14
+ jackpot:
15
+ win_alert:
16
+ mail_recipient: 'lm.cs@laxino.com'
17
+ mail_context:
18
+ serverity: 2
19
+ guide: 'http://faq'
20
+ submit_status:
21
+ exception_mail_recipient: 'lm.cs@laxino.com'
22
+ third_party:
23
+ 1003:
24
+ path: 'http://games.83suncity.local'
25
+ secret_access_key: 'akjlasdfasdfalas;sdkfajs'
26
+ stats_postfix: 'jackpotstats'
27
+ post_with_content_md5: true
28
+ snapshot_report:
29
+ mail_recipient: 'lm.cs@laxino.com'
30
+
31
+ game:
32
+ allow_test_mode: false
33
+ big_win_alert:
34
+ property_ids: '20000'
35
+ mail_context:
36
+ serverity: 2
37
+ guide: 'http://faq'
38
+ stuck_fund:
39
+ mail_recipient: 'lm.cs@laxino.com'
40
+ alert_leave_game_failures:
41
+ mail_recipient: 'lm.cs@laxino.com'
42
+
43
+ service:
44
+ self_schedule_host: 'axle.com'
45
+
46
+ alert:
47
+ mail_sender: 'info@laxino.com'
48
+ mail_receiver: 'axle_admin@laxino.com'
@@ -0,0 +1,31 @@
1
+ api_version: 'v1.0'
2
+ kind: 'config_kit'
3
+ infra:
4
+ version: '1.0'
5
+ namespace: 'int0'
6
+ service:
7
+ ams:
8
+ host: 'ams.hg-int-app01.local'
9
+ url: 'http://ams.hg-int-app01.local'
10
+ rap:
11
+ host: 'rap.hg-int-app01.local'
12
+ url: 'http://rap.hg-int-app01.local'
13
+ fams:
14
+ host: 'fams.hg-int-app01.local'
15
+ url: 'http://fams.hg-int-app01.local'
16
+ axle:
17
+ host: 'axle.hg-int-app01.local'
18
+ url: 'http://axle.hg-int-app01.local'
19
+ anms:
20
+ host: 'anms.hg-int-app01.local'
21
+ url: 'http://anms.hg-int-app01.local'
22
+ js:
23
+ host: 'job_scheduler.com'
24
+ url: 'http://job_scheduler.com'
25
+ mail_server:
26
+ host: 'moexc01.mo.laxino.com'
27
+ broker:
28
+ host: 'hq-int-femb-app01.laxino.local'
29
+ port: 61614
30
+ username: 'laxino_service'
31
+ password: 'laxino_service'
@@ -0,0 +1,48 @@
1
+ api_version: 'v1.0'
2
+ kind: 'config_kit'
3
+ axle:
4
+ version: '1.0'
5
+ namespace: 'stg0'
6
+ database:
7
+ adapter: 'mysql2'
8
+ host: 'localhost'
9
+ port: 3306
10
+ username: 'laxino'
11
+ password: 'password'
12
+ database: 'g2_axle_production'
13
+
14
+ jackpot:
15
+ win_alert:
16
+ mail_recipient: 'lm.cs@laxino.com'
17
+ mail_context:
18
+ serverity: 2
19
+ guide: 'http://faq'
20
+ submit_status:
21
+ exception_mail_recipient: 'lm.cs@laxino.com'
22
+ third_party:
23
+ 1003:
24
+ path: 'http://games.83suncity.local'
25
+ secret_access_key: akjlasdfasdfalas;sdkfajs
26
+ stats_postfix: 'jackpotstats'
27
+ post_with_content_md5: true
28
+ snapshot_report:
29
+ mail_recipient: 'lm.cs@laxino.com'
30
+
31
+ game:
32
+ allow_test_mode: false
33
+ big_win_alert:
34
+ property_ids: '20000'
35
+ mail_context:
36
+ serverity: 2
37
+ guide: 'http://faq'
38
+ stuck_fund:
39
+ mail_recipient: 'lm.cs@laxino.com'
40
+ alert_leave_game_failures:
41
+ mail_recipient: 'lm.cs@laxino.com'
42
+
43
+ service:
44
+ self_schedule_host: 'axle.com'
45
+
46
+ alert:
47
+ mail_sender: 'info@laxino.com'
48
+ mail_receiver: 'axle_admin@laxino.com'
@@ -0,0 +1,31 @@
1
+ api_version: 'v1.0'
2
+ kind: 'config_kit'
3
+ infra:
4
+ version: '1.0'
5
+ namespace: 'stg0'
6
+ service:
7
+ ams:
8
+ host: 'ams.hg-int-app01.local'
9
+ url: 'http://ams.hg-int-app01.local'
10
+ rap:
11
+ host: 'rap.hg-int-app01.local'
12
+ url: 'http://rap.hg-int-app01.local'
13
+ fams:
14
+ host: 'fams.hg-int-app01.local'
15
+ url: 'http://fams.hg-int-app01.local'
16
+ axle:
17
+ host: 'axle.hg-int-app01.local'
18
+ url: 'http://axle.hg-int-app01.local'
19
+ anms:
20
+ host: 'anms.hg-int-app01.local'
21
+ url: 'http://anms.hg-int-app01.local'
22
+ js:
23
+ host: 'job_scheduler.com'
24
+ url: 'http://job_scheduler.com'
25
+ mail_server:
26
+ host: 'moexc01.mo.laxino.com'
27
+ broker:
28
+ host: 'hq-int-femb-app01.laxino.local'
29
+ port: 61614
30
+ username: 'laxino_service'
31
+ password: 'laxino_service'
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'config_kit/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "config_kit"
8
+ spec.version = ConfigKit::VERSION
9
+ spec.authors = ["Ben Wu"]
10
+ spec.email = ["ben.wu@laxino.com"]
11
+
12
+ spec.summary = %q{Write a short summary, because Rubygems requires one.}
13
+ spec.description = %q{Write a longer description or delete this line.}
14
+ spec.homepage = "http://github.com/cheokman"
15
+ spec.licenses = ['MIT', 'Ruby']
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing 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 = ['ck']
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "rspec", "~> 3.0"
31
+
32
+ spec.add_dependency "bundler", "~> 1.12"
33
+ spec.add_dependency "diplomat", "1.4.1"
34
+ spec.add_dependency "git", "1.3.0"
35
+ end
data/lib/config_kit.rb ADDED
@@ -0,0 +1,20 @@
1
+ require 'config_kit/error'
2
+ require 'config_kit/configuration'
3
+ require 'config_kit/client'
4
+ require 'config_kit/config_data'
5
+ require 'config_kit/deploy_data'
6
+ require 'config_kit/manager'
7
+
8
+ module ConfigKit
9
+ def self.config
10
+ @config ||= Configuration.new(ENV.fetch('CK_URL','http://localhost:8500'), debug: ENV.fetch('DEBUG', false))
11
+ end
12
+
13
+ def self.logger
14
+ self.config.logger
15
+ end
16
+
17
+ def self.logger=(log)
18
+ self.config.logger = log
19
+ end
20
+ end
@@ -0,0 +1,77 @@
1
+ require 'optparse'
2
+ require 'config_kit'
3
+ require 'pp'
4
+ require 'config_kit/data/loader'
5
+
6
+ # Run the command given by the first argument. Right
7
+ # now all we have is deployments. We hope to have other
8
+ # kinds of events here later.
9
+ $LOAD_PATH << "#{File.dirname(__FILE__)}/.."
10
+
11
+ module ConfigKit
12
+ module Cli
13
+ class Command
14
+ attr_reader :leftover
15
+ class CommandFailure < StandardError
16
+ attr_reader :options
17
+ def initialize message, opt_parser=nil
18
+ super message
19
+ @options = opt_parser
20
+ end
21
+ end
22
+
23
+ def initialize(args)
24
+ if Hash === args
25
+ args.each do |k, v|
26
+ instance_variable_set "@#{k}", v.to_s if v
27
+ end
28
+ else
29
+
30
+ @options = options do |opts|
31
+ opts.on("-h", "Show this help") { raise CommandFailure, opts.to_s }
32
+ end
33
+ raise CommandFailure, @options.to_s if args.empty?
34
+ @leftover = @options.parse(args)
35
+ end
36
+ rescue OptionParser::ParseError => e
37
+ raise CommandFailure.new(e.message, @options)
38
+ end
39
+
40
+ @commands = []
41
+ def self.inherited(subclass)
42
+ @commands << subclass
43
+ end
44
+
45
+ cmds = cmds = File.expand_path(File.join(File.dirname(__FILE__), 'commands', '*.rb'))
46
+ Dir[cmds].each { |command| require command }
47
+
48
+ def self.run
49
+ @command_names = @commands.map{ |c| c.command}
50
+
51
+ extra = []
52
+
53
+ options = ARGV.options do |opts|
54
+ script_name = File.basename($0)
55
+ opts.banner = "Usage: #{script_name} [ #{ @command_names.join(" | ")} ] [options]"
56
+ opts.separator "use '#{script_name} <command> -h' to see detailed command options"
57
+ opts
58
+ end
59
+ extra = options.order!
60
+ command = extra.shift
61
+
62
+ if command.nil?
63
+ ConfigKit.logger.error "No command provided"
64
+ STDOUT.puts options.to_s
65
+ elsif !@command_names.include?(command)
66
+ ConfigKit.logger.error "Unrecognized command: #{command}"
67
+ ConfigKit.logger.error options
68
+ else
69
+ command_class = @commands.find{ |c| c.command == command}
70
+ command_class.new(extra).run
71
+ end
72
+ rescue OptionParser::InvalidOption => e
73
+ raise CommandFailure.new(e.message)
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,65 @@
1
+ require 'uri'
2
+ module ConfigKit::Cli
3
+ class Bootstrap < Command
4
+ def self.uri_parser(uri)
5
+ URI.parse(uri)
6
+ end
7
+
8
+ def self.command; "bootstrap"; end
9
+
10
+ def initialize(args)
11
+ @uri_string = 'file:///./config'
12
+ @app = 'all'
13
+ super(args)
14
+ @uri_kls = self.class.uri_parser(@uri_string)
15
+ check_args
16
+ end
17
+
18
+ def check_args
19
+ raise ConfigKit::Cli::Command::CommandFailure.new "Wrong bootstrap source from #{@from}, pls use file or git" unless ['git', 'file'].include?(@from)
20
+ raise ConfigKit::Cli::Command::CommandFailure.new "Missmatch source from #{@from} and uri #{@uri_string}" if @from == 'file' && @uri_kls.scheme != 'file'
21
+ raise ConfigKit::Cli::Command::CommandFailure.new "Missmatch source from #{@from} and uri #{@uri_string}" if @from == 'git' && !['git', 'http', 'ssh'].include?(@uri_kls.scheme)
22
+ raise ConfigKit::Cli::Command::CommandFailure.new "Missmatch tag from #{@from} and uri #{@uri_string}" if @from == 'git' && @tag.nil?
23
+ end
24
+
25
+ def run
26
+ begin
27
+ @output = ConfigKit::Manager.bootstrap(@app, @from, @uri_kls, @tag, {})
28
+ pp @output.to_h.to_json
29
+ rescue => e
30
+ ConfigKit.logger.error "Unexpected error attempting to get config data #{@uri_string} in for #{@app.nil? ? 'all' : @app}"
31
+ ConfigKit.logger.debug "#{e}: #{e.backtrace.join("\n ")}"
32
+ raise ConfigKit::Cli::Command::CommandFailure.new(e.to_s)
33
+ end
34
+ end
35
+
36
+ private
37
+
38
+
39
+ def options
40
+ OptionParser.new %Q{Usage: #{$0} #{self.class.command} [OPTIONS] ["description"] }, 40 do |opts|
41
+ opts.separator ''
42
+ opts.separator 'Specific options:'
43
+
44
+ opts.on('-g URI', '--from-git', 'Specify read config from git') do |uri_string|
45
+ @from = 'git'
46
+ @uri_string = uri_string
47
+ end
48
+
49
+ opts.on('-f URI', '--from-file', 'Specify read config from file') do |uri_string|
50
+ @from = 'file'
51
+ @uri_string = uri_string
52
+ end
53
+
54
+ opts.on('-a APP', '--app', 'Specify an app of config to create') do |app|
55
+ @app = app
56
+ end
57
+
58
+ opts.on('-t TAG', '--tag', 'Specify version tag to boostrap(if using git repository for version control)') do |tag|
59
+ @tag = tag
60
+ end
61
+ end
62
+ end
63
+ end
64
+
65
+ end
@@ -0,0 +1,48 @@
1
+ module ConfigKit::Cli
2
+ class Deploy < Command
3
+ def self.command; "deploy"; end
4
+
5
+ def initialize(args)
6
+ @app = nil
7
+ @version = nil
8
+ super(args)
9
+ check_args
10
+ end
11
+
12
+ def check_args
13
+ raise ConfigKit::Cli::Command::CommandFailure.new "Missing app parameters" if @app.nil?
14
+ raise ConfigKit::Cli::Command::CommandFailure.new "Missing version parameters" if @version.nil?
15
+ end
16
+
17
+ def run
18
+ begin
19
+ ConfigKit.logger.debug "Run command #{self.class.command} with options #{@app}:#{@version}"
20
+ @output = ConfigKit::Manager.deploy(@app, @version)
21
+ pp @output.to_h.to_json
22
+ rescue ConfigKit::Cli::Command::CommandFailure
23
+ raise
24
+ rescue => e
25
+ ConfigKit.logger.error "Unexpected error attempting to get config data #{@uri} in env #{@env} for #{@app.nil? ? 'all' : @app}"
26
+ ConfigKit.logger.debug "#{e}: #{e.backtrace.join("\n ")}"
27
+ raise ConfigKit::Cli::Command::CommandFailure.new(e.to_s)
28
+ end
29
+ end
30
+
31
+ private
32
+ def options
33
+ OptionParser.new %Q{Usage: #{$0} #{self.class.command} [OPTIONS] ["description"] }, 40 do |opts|
34
+ opts.separator ''
35
+ opts.separator 'Specific options:'
36
+
37
+ opts.on('-a APP', '--app', 'Specify an app of config to create(default: nil to deploy all apps)') do |app|
38
+ @app = app
39
+ end
40
+
41
+ opts.on('-v VERSION', '--version', 'Specify a version of application to describe') do |version|
42
+ @version = version[0] == 'v' ? version : "v#{version}"
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ end
@@ -0,0 +1,41 @@
1
+ module ConfigKit::Cli
2
+ class Describe < Command
3
+ def self.command; "describe"; end
4
+
5
+ def initialize(args)
6
+ @app = 'idc'
7
+ @output = nil
8
+ args << ['-a', @app] unless args.include?('-a')
9
+ super(args)
10
+ end
11
+
12
+ def run
13
+ begin
14
+ @output = ConfigKit::Manager.describe(@app, @version)
15
+ pp @output
16
+ rescue ConfigKit::Cli::Command::CommandFailure
17
+ raise
18
+ rescue => e
19
+ ConfigKit.logger.error "Unexpected error attempting to get config data #{@uri} in env #{@env} for #{@app.nil? ? 'all' : @app}"
20
+ ConfigKit.logger.debug "#{e}: #{e.backtrace.join("\n ")}"
21
+ raise ConfigKit::Cli::Command::CommandFailure.new(e.to_s)
22
+ end
23
+ end
24
+
25
+ private
26
+ def options
27
+ OptionParser.new %Q{Usage: #{$0} #{self.class.command} [OPTIONS] ["description"] }, 40 do |opts|
28
+ opts.separator ''
29
+ opts.separator 'Specific options:'
30
+
31
+ opts.on('-a APP', '--app', 'Specify an application to describe') do |app|
32
+ @app = app
33
+ end
34
+
35
+ opts.on('-v VERSION', '--version', 'Specify an verion of application to describe') do |version|
36
+ @version = version
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end