dtk-client 0.5.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (120) hide show
  1. checksums.yaml +15 -0
  2. data/Gemfile +5 -0
  3. data/Gemfile_dev +12 -0
  4. data/README.md +78 -0
  5. data/bin/dtk +54 -0
  6. data/bin/dtk-shell +15 -0
  7. data/dtk-client.gemspec +49 -0
  8. data/lib/auxiliary.rb +13 -0
  9. data/lib/bundler_monkey_patch.rb +9 -0
  10. data/lib/client.rb +48 -0
  11. data/lib/command_helper.rb +16 -0
  12. data/lib/command_helpers/git_repo.rb +391 -0
  13. data/lib/command_helpers/jenkins_client/config_xml.rb +271 -0
  14. data/lib/command_helpers/jenkins_client.rb +91 -0
  15. data/lib/command_helpers/service_importer.rb +99 -0
  16. data/lib/command_helpers/service_link.rb +18 -0
  17. data/lib/command_helpers/ssh_processing.rb +43 -0
  18. data/lib/commands/common/thor/assembly_workspace.rb +1089 -0
  19. data/lib/commands/common/thor/clone.rb +39 -0
  20. data/lib/commands/common/thor/common.rb +34 -0
  21. data/lib/commands/common/thor/edit.rb +168 -0
  22. data/lib/commands/common/thor/list_diffs.rb +84 -0
  23. data/lib/commands/common/thor/pull_clone_changes.rb +11 -0
  24. data/lib/commands/common/thor/pull_from_remote.rb +99 -0
  25. data/lib/commands/common/thor/purge_clone.rb +26 -0
  26. data/lib/commands/common/thor/push_clone_changes.rb +45 -0
  27. data/lib/commands/common/thor/push_to_remote.rb +45 -0
  28. data/lib/commands/common/thor/reparse.rb +36 -0
  29. data/lib/commands/common/thor/set_required_params.rb +29 -0
  30. data/lib/commands/common/thor/task_status.rb +81 -0
  31. data/lib/commands/thor/account.rb +213 -0
  32. data/lib/commands/thor/assembly.rb +329 -0
  33. data/lib/commands/thor/attribute.rb +62 -0
  34. data/lib/commands/thor/component.rb +52 -0
  35. data/lib/commands/thor/component_module.rb +829 -0
  36. data/lib/commands/thor/component_template.rb +153 -0
  37. data/lib/commands/thor/dependency.rb +18 -0
  38. data/lib/commands/thor/developer.rb +105 -0
  39. data/lib/commands/thor/dtk.rb +117 -0
  40. data/lib/commands/thor/library.rb +107 -0
  41. data/lib/commands/thor/node.rb +411 -0
  42. data/lib/commands/thor/node_group.rb +211 -0
  43. data/lib/commands/thor/node_template.rb +88 -0
  44. data/lib/commands/thor/project.rb +17 -0
  45. data/lib/commands/thor/provider.rb +155 -0
  46. data/lib/commands/thor/repo.rb +35 -0
  47. data/lib/commands/thor/service.rb +656 -0
  48. data/lib/commands/thor/service_module.rb +806 -0
  49. data/lib/commands/thor/state_change.rb +10 -0
  50. data/lib/commands/thor/target.rb +94 -0
  51. data/lib/commands/thor/task.rb +100 -0
  52. data/lib/commands/thor/utils.rb +4 -0
  53. data/lib/commands/thor/workspace.rb +437 -0
  54. data/lib/commands.rb +40 -0
  55. data/lib/config/cacert.pem +3785 -0
  56. data/lib/config/client.conf.header +18 -0
  57. data/lib/config/configuration.rb +82 -0
  58. data/lib/config/default.conf +14 -0
  59. data/lib/config/disk_cacher.rb +60 -0
  60. data/lib/configurator.rb +92 -0
  61. data/lib/context_router.rb +23 -0
  62. data/lib/core.rb +460 -0
  63. data/lib/domain/git_adapter.rb +221 -0
  64. data/lib/domain/response.rb +234 -0
  65. data/lib/dtk-client/version.rb +3 -0
  66. data/lib/dtk_constants.rb +23 -0
  67. data/lib/dtk_logger.rb +96 -0
  68. data/lib/error.rb +74 -0
  69. data/lib/git-logs/git.log +0 -0
  70. data/lib/parser/adapters/option_parser.rb +53 -0
  71. data/lib/parser/adapters/thor/common_option_defs.rb +12 -0
  72. data/lib/parser/adapters/thor.rb +509 -0
  73. data/lib/require_first.rb +87 -0
  74. data/lib/search_hash.rb +27 -0
  75. data/lib/shell/context.rb +975 -0
  76. data/lib/shell/context_aux.rb +29 -0
  77. data/lib/shell/domain.rb +447 -0
  78. data/lib/shell/header_shell.rb +27 -0
  79. data/lib/shell/help_monkey_patch.rb +221 -0
  80. data/lib/shell/interactive_wizard.rb +233 -0
  81. data/lib/shell/parse_monkey_patch.rb +22 -0
  82. data/lib/shell/status_monitor.rb +105 -0
  83. data/lib/shell.rb +219 -0
  84. data/lib/util/console.rb +143 -0
  85. data/lib/util/dtk_puppet.rb +46 -0
  86. data/lib/util/os_util.rb +265 -0
  87. data/lib/view_processor/augmented_simple_list.rb +27 -0
  88. data/lib/view_processor/hash_pretty_print.rb +106 -0
  89. data/lib/view_processor/simple_list.rb +139 -0
  90. data/lib/view_processor/table_print.rb +277 -0
  91. data/lib/view_processor.rb +112 -0
  92. data/puppet/manifests/init.pp +72 -0
  93. data/puppet/manifests/params.pp +16 -0
  94. data/puppet/r8meta.puppet.yml +18 -0
  95. data/puppet/templates/bash_profile.erb +2 -0
  96. data/puppet/templates/client.conf.erb +1 -0
  97. data/puppet/templates/dtkclient.erb +2 -0
  98. data/spec/assembly_spec.rb +50 -0
  99. data/spec/assembly_template_spec.rb +51 -0
  100. data/spec/component_template_spec.rb +40 -0
  101. data/spec/dependency_spec.rb +6 -0
  102. data/spec/dtk_shell_spec.rb +13 -0
  103. data/spec/dtk_spec.rb +33 -0
  104. data/spec/lib/spec_helper.rb +10 -0
  105. data/spec/lib/spec_thor.rb +105 -0
  106. data/spec/module_spec.rb +35 -0
  107. data/spec/node_spec.rb +43 -0
  108. data/spec/node_template_spec.rb +25 -0
  109. data/spec/project_spec.rb +6 -0
  110. data/spec/repo_spec.rb +7 -0
  111. data/spec/response_spec.rb +52 -0
  112. data/spec/service_spec.rb +41 -0
  113. data/spec/state_change_spec.rb +7 -0
  114. data/spec/table_print_spec.rb +48 -0
  115. data/spec/target_spec.rb +57 -0
  116. data/spec/task_spec.rb +28 -0
  117. data/views/assembly/augmented_simple_list.rb +12 -0
  118. data/views/assembly_template/augmented_simple_list.rb +12 -0
  119. data/views/list_task/augmented_simple_list.rb +12 -0
  120. metadata +351 -0
@@ -0,0 +1,18 @@
1
+ development_mode=false
2
+ meta_table_ttl=7200000 # time to live (ms)
3
+ meta_constants_ttl=7200000 # time to live (ms)
4
+ meta_pretty_print_ttl=7200000 # time to live (ms)
5
+ task_check_frequency=60 # check frequency for task status threads (seconds)
6
+ tail_log_frequency=2 # assembly - frequency between requests (seconds)
7
+ debug_task_frequency=5 # assembly - frequency between requests (seconds)
8
+ auto_commit_changes=false # autocommit for modules
9
+ verbose_rest_calls=false # logging of REST calls
10
+
11
+ # if relative path is used we will use HOME + relative path, apsoluth path will override this
12
+ module_location=component_modules
13
+ service_location=service_modules
14
+
15
+ # server connection details
16
+ server_port=80
17
+ secure_connection_server_port=443
18
+ secure_connection=true
@@ -0,0 +1,82 @@
1
+ #
2
+ # Singleton patern to hold configuration for dtk client.
3
+ #
4
+ # DEFAULT: Configuration
5
+ # DEVELOPMENT: Can add lib/config/local.conf, this is git ignored
6
+ #
7
+ # NOTE: Singleton here is not necessery since it will not persist in memory due
8
+ # to nature of DTK Client, but it is right approach for possible re-use
9
+ #
10
+ # Pririoty of load
11
+ # 1) LOCAL
12
+ # 2) EXTERNAL
13
+ # 3) DEFAULT
14
+ #
15
+ # NOTE: Default will be used if there some parameters missing in other configuration
16
+ #
17
+ require 'singleton'
18
+
19
+ dtk_require_from_base('util/os_util')
20
+
21
+ module DTK
22
+ class Configuration
23
+ include Singleton
24
+
25
+ EXTERNAL_APP_CONF = "client.conf"
26
+ DEVELOPMENT_CONF = 'local.conf'
27
+ DEFAULT_CONF = 'default.conf'
28
+
29
+ def self.get(name, default=nil)
30
+ Configuration.instance.get(name, default)
31
+ end
32
+
33
+ def self.[](k)
34
+ Configuration.instance.get(k)
35
+ end
36
+
37
+ def initialize
38
+ # default configuration
39
+ @cache = load_configuration_to_hash(File.expand_path("../#{DEFAULT_CONF}",__FILE__))
40
+
41
+ # we will not use local.conf from gemfile because client.conf is required so this is deprecated
42
+ if File.exist?(File.expand_path("../#{DEVELOPMENT_CONF}",__FILE__))
43
+ local_configuration = load_configuration_to_hash(File.expand_path("../#{DEVELOPMENT_CONF}",__FILE__))
44
+ # we override only values from local configuration
45
+ # that way developer does not have updates its local configuration all the time
46
+ @cache.merge!(local_configuration)
47
+ # if we have loaded local configuration we will not check external
48
+ return
49
+ end
50
+
51
+ # We load this if there is no local configuration
52
+ external_file_location = File.join(::DTK::Client::OsUtil.dtk_local_folder(), "#{EXTERNAL_APP_CONF}")
53
+
54
+ if File.exist?(external_file_location)
55
+ external_configuration = load_configuration_to_hash(external_file_location)
56
+ @cache.merge!(external_configuration)
57
+ end
58
+ end
59
+
60
+ def get(name, default=nil)
61
+ return @cache[name.to_s] || default
62
+ end
63
+
64
+ private
65
+
66
+ def load_configuration_to_hash(path_to_file)
67
+ configuration = Hash[*File.read(path_to_file).gsub(/#.+/,'').strip().gsub(/( |\t)+$/,'').split(/[=\n\r\r\n]+/)]
68
+
69
+ # check for types
70
+ return configuration.each do |k,v|
71
+ case v
72
+ when /^(true|false)$/
73
+ configuration[k] = v.eql?('true') ? true : false
74
+ when /^[0-9]+$/
75
+ configuration[k] = v.to_i
76
+ when /^[0-9\.]+$/
77
+ configuration[k] = v.to_f
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,14 @@
1
+ development_mode=false
2
+ debug_grit=false
3
+ meta_table_ttl=7200000 # time to live (ms)
4
+ meta_constants_ttl=7200000 # time to live (ms)
5
+ meta_pretty_print_ttl=7200000 # time to live (ms)
6
+ task_check_frequency=60 # check frequency for task status threads (seconds)
7
+ tail_log_frequency=2 # assembly - frequency between requests (seconds)
8
+ debug_task_frequency=5 # assembly - frequency between requests (seconds)
9
+ auto_commit_changes=false # autocommit for modules
10
+ verbose_rest_calls=false # logging of REST calls
11
+
12
+ # if relative path is used we will use HOME + relative path, apsoluth path will override this
13
+ module_location=component_modules
14
+ service_location=service_modules
@@ -0,0 +1,60 @@
1
+ require 'net/http'
2
+ #require 'md5' => Ruby 1.8.7 specific
3
+ require File.expand_path('../util/os_util', File.dirname(__FILE__))
4
+ dtk_require("../commands")
5
+
6
+
7
+ #
8
+ # Class dedicated for caching data on local system as well as for cookie management
9
+ #
10
+ class DiskCacher
11
+ include DTK::Client::CommandBase
12
+ extend DTK::Client::CommandBase
13
+
14
+ # file name to hold cookies
15
+ COOKIE_HOLDER_NAME = 'tempdtkstore'
16
+
17
+ def initialize(cache_dir=DTK::Client::OsUtil.get_temp_location())
18
+ @cache_dir = cache_dir
19
+ end
20
+
21
+ def fetch(file_name, max_age=0, use_mock_up=true)
22
+ file = Digest::MD5.hexdigest(file_name)
23
+ file_path = File.join(@cache_dir, file)
24
+
25
+ # we check if the file -- a MD5 hexdigest of the URL -- exists
26
+ # in the dir. If it does and the data is fresh, we just read
27
+ # data from the file and return
28
+ if File.exists? file_path
29
+ return File.new(file_path).read if Time.now-File.mtime(file_path)<max_age
30
+ end
31
+
32
+ # if the file does not exist (or if the data is not fresh), we
33
+ # make an get request and save it to a file
34
+ response_string = ""
35
+ @response = get rest_url("metadata/get_metadata/#{file_name}")
36
+
37
+ if (@response["status"] == "ok")
38
+ file = File.open(file_path, "w") do |data|
39
+ data << response_string = @response["data"]
40
+ end
41
+ end
42
+
43
+ return response_string
44
+ end
45
+
46
+ def save_cookie(cookie_content)
47
+ file_path = File.join(@cache_dir, COOKIE_HOLDER_NAME)
48
+ File.open(file_path, "w") do |file|
49
+ #data << cookie_content
50
+ Marshal.dump(cookie_content, file)
51
+ end
52
+ end
53
+
54
+ def load_cookie()
55
+ file_path = File.join(@cache_dir, COOKIE_HOLDER_NAME)
56
+ cookie_content = File.exists?(file_path) ? File.open(file_path) {|f| Marshal.load(f)} : nil
57
+ cookie_content
58
+ end
59
+
60
+ end
@@ -0,0 +1,92 @@
1
+ require 'rubygems'
2
+
3
+ dtk_require_from_base('util/os_util')
4
+
5
+ module DTK
6
+ module Client
7
+ class Configurator
8
+
9
+ CONFIG_FILE = File.join(OsUtil.dtk_local_folder, "client.conf")
10
+ CRED_FILE = File.join(OsUtil.dtk_local_folder, ".connection")
11
+ DIRECT_ACCESS = File.join(OsUtil.dtk_local_folder, ".add_direct_access")
12
+
13
+ require 'fileutils'
14
+ FileUtils.mkdir(OsUtil.dtk_local_folder) unless File.directory?(OsUtil.dtk_local_folder)
15
+
16
+ def self.CONFIG_FILE
17
+ CONFIG_FILE
18
+ end
19
+
20
+ def self.CRED_FILE
21
+ CRED_FILE
22
+ end
23
+
24
+ def self.check_config_exists
25
+ if !File.exists?(CONFIG_FILE)
26
+ puts "", "Please enter the DTK server address (example: dtk.r8network.com)"
27
+ header = File.read(File.expand_path('../lib/config/client.conf.header', File.dirname(__FILE__)))
28
+ generate_conf_file(CONFIG_FILE, [['server_host', 'Server address']], header)
29
+ end
30
+ if !File.exists?(CRED_FILE)
31
+ puts "", "Please enter your DTK login details"
32
+ generate_conf_file(CRED_FILE, [['username', 'Username'], ['password', 'Password']], '')
33
+ end
34
+ end
35
+
36
+ def self.check_git
37
+ if OsUtil.which('git') == nil
38
+ OsUtil.put_warning "[WARNING]", "Can't find the 'git' command in you path. Please make sure git is installed in order to use all features of DTK Client.", :yellow
39
+ else
40
+ OsUtil.put_warning "[WARNING]", 'Git username not set. This can cause issues while using DTK Client. To set it, run `git config --global user.name "User Name"`', :yellow if `git config --get user.name` == ""
41
+ OsUtil.put_warning "[WARNING]", 'Git email not set. This can cause issues while using DTK Client. To set it, run `git config --global user.email "me@here.com"`', :yellow if `git config --get user.email` == ""
42
+ end
43
+ end
44
+
45
+ # return true/false, .add_direct_access file location and ssk key file location
46
+ def self.check_direct_access
47
+ file_exists = File.exists?(DIRECT_ACCESS)
48
+ ssh_key_path = SshProcessing.default_rsa_pub_key_path()
49
+
50
+ {:file_exists => file_exists, :file_path => DIRECT_ACCESS, :ssh_key_path => ssh_key_path}
51
+ end
52
+
53
+ def self.generate_conf_file(file_path, properties, header)
54
+ require 'highline/import'
55
+ property_template = []
56
+
57
+ properties.each do |p,d|
58
+ begin
59
+ trap("INT") {
60
+ puts "", "Exiting..."
61
+ abort
62
+ }
63
+ end
64
+ value = ask("#{d}: ") { |q| q.echo = false if p == 'password'}
65
+ property_template << [p,value]
66
+ end
67
+
68
+ File.open(file_path, 'w') do |f|
69
+ f.puts(header)
70
+ property_template.each do |prop|
71
+ f.puts("#{prop[0]}=#{prop[1]}")
72
+ end
73
+ end
74
+ end
75
+
76
+ def self.regenerate_conf_file(file_path, properties, header)
77
+ File.open(file_path, 'w') do |f|
78
+ f.puts(header)
79
+ properties.each do |prop|
80
+ f.puts("#{prop[0]}=#{prop[1]}")
81
+ end
82
+ end
83
+ end
84
+
85
+ def self.create_missing_clone_dirs
86
+ FileUtils.mkdir(OsUtil.module_clone_location) unless File.directory?(OsUtil.module_clone_location)
87
+ FileUtils.mkdir(OsUtil.service_clone_location) unless File.directory?(OsUtil.service_clone_location)
88
+ end
89
+ end
90
+ end
91
+ end
92
+
@@ -0,0 +1,23 @@
1
+ module DTK
2
+ module Client
3
+
4
+ #
5
+ # This class is used to reroute commands/tasks (Method invocations) from one context (Class) to another
6
+ #
7
+ class ContextRouter
8
+
9
+ # This method invokes target context task
10
+ def self.routeTask(target_context, target_method, target_context_params, conn)
11
+
12
+ # Initing required params and invoking target_context.target_method
13
+ load_command(target_context)
14
+ target_context_class = DTK::Client.const_get "#{cap_form(target_context)}"
15
+
16
+ ret = target_context_class.execute_from_cli(conn, target_method, target_context_params, [], false)
17
+ ret.kind_of?(Response::NoOp) ? Response::Ok.new() : ret
18
+ end
19
+
20
+ end
21
+
22
+ end
23
+ end