dtk-network-client 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +5 -0
  3. data/Gemfile +2 -0
  4. data/LICENSE +201 -0
  5. data/README.md +2 -0
  6. data/dtk-network-client.gemspec +24 -0
  7. data/lib/client/args.rb +19 -0
  8. data/lib/client/client_args.rb +23 -0
  9. data/lib/client/command/add_to_group.rb +20 -0
  10. data/lib/client/command/chmod.rb +21 -0
  11. data/lib/client/command/create_namespace.rb +19 -0
  12. data/lib/client/command/delete.rb +25 -0
  13. data/lib/client/command/delete_namespace.rb +19 -0
  14. data/lib/client/command/info.rb +32 -0
  15. data/lib/client/command/install/installer.rb +9 -0
  16. data/lib/client/command/install.rb +190 -0
  17. data/lib/client/command/list.rb +13 -0
  18. data/lib/client/command/list_namespaces.rb +10 -0
  19. data/lib/client/command/publish.rb +120 -0
  20. data/lib/client/command/pull.rb +53 -0
  21. data/lib/client/command/push.rb +63 -0
  22. data/lib/client/command/remove_from_group.rb +20 -0
  23. data/lib/client/command/unpublish.rb +27 -0
  24. data/lib/client/command/update.rb +18 -0
  25. data/lib/client/command.rb +31 -0
  26. data/lib/client/config.rb +54 -0
  27. data/lib/client/conn.rb +132 -0
  28. data/lib/client/dependency_tree/activated.rb +35 -0
  29. data/lib/client/dependency_tree/cache.rb +28 -0
  30. data/lib/client/dependency_tree/candidates.rb +19 -0
  31. data/lib/client/dependency_tree/resolver.rb +16 -0
  32. data/lib/client/dependency_tree.rb +272 -0
  33. data/lib/client/error.rb +22 -0
  34. data/lib/client/file_helper.rb +8 -0
  35. data/lib/client/git_adapter/git_gem.rb +246 -0
  36. data/lib/client/git_client.rb +136 -0
  37. data/lib/client/git_repo.rb +221 -0
  38. data/lib/client/module_dir.rb +38 -0
  39. data/lib/client/module_ref/dependency/local.rb +47 -0
  40. data/lib/client/module_ref/dependency/remote.rb +18 -0
  41. data/lib/client/module_ref/dependency.rb +21 -0
  42. data/lib/client/module_ref/version/source.rb +18 -0
  43. data/lib/client/module_ref/version.rb +87 -0
  44. data/lib/client/module_ref.rb +21 -0
  45. data/lib/client/response/response_types.rb +42 -0
  46. data/lib/client/response.rb +27 -0
  47. data/lib/client/rest_wrapper.rb +43 -0
  48. data/lib/client/s3_helper.rb +23 -0
  49. data/lib/client/session.rb +54 -0
  50. data/lib/client/storage/adapters/s3.rb +25 -0
  51. data/lib/client/storage.rb +29 -0
  52. data/lib/client/util/os_util.rb +77 -0
  53. data/lib/client/util/permissions_util.rb +12 -0
  54. data/lib/client/util/tar.rb +104 -0
  55. data/lib/client/util.rb +7 -0
  56. data/lib/client/version.rb +8 -0
  57. data/lib/dtk_network_client.rb +27 -0
  58. metadata +183 -0
@@ -0,0 +1,221 @@
1
+ module DTK::Network::Client
2
+ class GitRepo
3
+ def self.add_remote_and_publish(git_args)
4
+ Command.wrap_command(git_args) do |git_args|
5
+ repo_dir = git_args.required(:repo_dir)
6
+ remote_url = git_args.required(:remote_url)
7
+ local_branch = git_args[:branch] || 'master'
8
+ remote_branch = git_args[:remote_branch] || local_branch
9
+ remote = git_args[:remote] || 'origin'
10
+
11
+ repo = git_repo.new(repo_dir, :branch => local_branch)
12
+ create_if_missing = local_branch_exist?(repo, local_branch) ? false : true
13
+
14
+ repo.checkout(local_branch, new_branch: create_if_missing)
15
+ repo.add_all
16
+ repo.commit("Publish from dtk client", :allow_empty => true)
17
+ add_remote_and_push(repo, remote, remote_url, remote_branch)
18
+ end
19
+ end
20
+
21
+ def self.push_to_remote(git_args)
22
+ Command.wrap_command(git_args) do |git_args|
23
+ repo_dir = git_args.required(:repo_dir)
24
+ remote_url = git_args.required(:remote_url)
25
+ local_branch = git_args[:branch] || 'master'
26
+ remote_branch = git_args[:remote_branch] || local_branch
27
+ remote = git_args[:remote] || 'origin'
28
+ commit_msg = git_args[:commit_msg] || "Push from dtkn client"
29
+
30
+ repo = git_repo.new(repo_dir, :branch => local_branch)
31
+ create_if_missing = local_branch_exist?(repo, local_branch) ? false : git_args[:create_if_missing]
32
+
33
+ repo.checkout(local_branch, new_branch: create_if_missing)
34
+ repo.add_all
35
+ repo.commit(commit_msg, :allow_empty => true)
36
+
37
+ if repo.is_there_remote?(remote)
38
+ push_when_there_is_remote(repo, remote, remote_url, remote_branch)
39
+ else
40
+ add_remote_and_push(repo, remote, remote_url, remote_branch)
41
+ end
42
+ end
43
+ end
44
+
45
+ def self.pull_from_remote(git_args)
46
+ Command.wrap_command(git_args) do |git_args|
47
+ repo_dir = git_args.required(:repo_dir)
48
+ remote_url = git_args.required(:remote_url)
49
+ local_branch = git_args[:branch] || 'master'
50
+ remote_branch = git_args[:remote_branch] || local_branch
51
+ remote = git_args[:remote] || 'origin'
52
+
53
+ repo = git_repo.new(repo_dir, :branch => local_branch)
54
+ repo.checkout(local_branch)
55
+
56
+ if repo.is_there_remote?(remote)
57
+ pull_when_there_is_remote(repo, remote, remote_url, remote_branch)
58
+ else
59
+ add_remote_and_pull(repo, remote, remote_url, remote_branch)
60
+ end
61
+ end
62
+ end
63
+
64
+ # opts can have keys
65
+ # :branch
66
+ # returns object of type DTK::Client::GitRepo
67
+ def self.create_empty_git_repo?(repo_dir, opts = {})
68
+ git_repo.new(repo_dir, :branch => opts[:branch])
69
+ end
70
+
71
+ # returns head_sha
72
+ def self.empty_commit(repo, commit_msg = nil)
73
+ repo.empty_commit(commit_msg)
74
+ repo.head_commit_sha
75
+ end
76
+
77
+ def self.add_remote(repo, remote_name, remote_url)
78
+ repo.add_remote(remote_name, remote_url)
79
+ remote_name
80
+ end
81
+
82
+ def self.fetch(repo, remote_name)
83
+ repo.fetch(remote_name)
84
+ end
85
+
86
+ def self.push_when_there_is_remote(repo, remote, remote_url, remote_branch)
87
+ repo.remove_remote(remote)
88
+ add_remote_and_push(repo, remote, remote_url, remote_branch)
89
+ end
90
+
91
+ def self.pull_when_there_is_remote(repo, remote, remote_url, remote_branch)
92
+ repo.remove_remote(remote)
93
+ add_remote_and_pull(repo, remote, remote_url, remote_branch)
94
+ end
95
+
96
+ def self.add_remote_and_push(repo, remote, remote_url, remote_branch)
97
+ repo.add_remote(remote, remote_url)
98
+ repo.push(remote, remote_branch)
99
+ end
100
+
101
+ def self.add_remote_and_pull(repo, remote, remote_url, remote_branch)
102
+ repo.add_remote(remote, remote_url)
103
+ repo.pull(remote, remote_branch)
104
+ end
105
+
106
+ def self.local_branch_exist?(repo, branch)
107
+ local_branches = branch.is_a?(String) ? repo.all_branches.local.map { |branch| branch.name } : (repo.all_branches.local || [])
108
+ local_branches.include?(branch)
109
+ end
110
+
111
+ # opts can have keys
112
+ # :no_commit
113
+ def self.merge(repo, merge_from_ref, opts = {})
114
+ base_sha = repo.head_commit_sha
115
+ repo.merge(merge_from_ref, :use_theirs => opts[:use_theirs])
116
+ # the git gem does not take no_commit as merge argument; so doing it with soft reset
117
+ repo.reset_soft(base_sha) if opts[:no_commit]
118
+ repo.head_commit_sha
119
+ end
120
+
121
+ def self.local_ahead?(repo, merge_from_ref, opts = {})
122
+ base_sha = repo.head_commit_sha
123
+ remote_branch = repo.all_branches.remote.find { |r| "#{r.remote}/#{r.name}" == merge_from_ref }
124
+ remote_sha = remote_branch.gcommit.sha
125
+ repo.local_ahead(base_sha, remote_sha)
126
+ end
127
+
128
+ # opts can have keys:
129
+ # :commit_msg
130
+ # returns head_sha
131
+ def self.stage_and_commit(repo_dir,local_branch_type, opts = {})
132
+ local_branch = branch_from_local_branch_type(local_branch_type)
133
+ repo = create_empty_git_repo?(repo_dir, :branch => local_branch)
134
+ repo.stage_and_commit(opts[:commit_msg])
135
+ repo.head_commit_sha
136
+ end
137
+
138
+ # TODO: DTK-2765: see what this does and subsume by create_add_remote_and_push
139
+ # For this and other methods in Internal that use Dtk_Server::GIT_REMOTE
140
+ # put a version in Internal taht takes remote_name as param and then have
141
+ # # method with same name in Dtk, that calss this with appropriate remote name
142
+ # def self.init_and_push_from_existing_repo(repo_dir, repo_url, remote_branch)
143
+ # repo = git_repo.new(repo_dir)
144
+
145
+ # if repo.is_there_remote?(Dtk_Server::GIT_REMOTE)
146
+ # push_when_there_is_dtk_remote(repo, repo_dir, repo_url, remote_branch)
147
+ # else
148
+ # add_remote_and_push(repo, repo_url, remote_branch)
149
+ # end
150
+
151
+ # repo.head_commit_sha
152
+ # end
153
+
154
+ def self.pull_from_remote(args)
155
+ repo_url = args.required(:repo_url)
156
+ remote_branch = args.required(:branch)
157
+ repo_dir = args.required(:repo_dir)
158
+
159
+ repo = git_repo.new(repo_dir, :branch => remote_branch)
160
+ repo.pull(repo.remotes.first, remote_branch)
161
+ end
162
+
163
+ # def self.push_when_there_is_dtk_remote(repo, repo_dir, repo_url, remote_branch)
164
+ # # if there is only one remote and it is dtk-server; remove .git and initialize and push as new repo to dtk-server remote
165
+ # # else if multiple remotes and dtk-server being one of them; remove dtk-server; add new dtk-server remote and push
166
+ # if repo.remotes.size == 1
167
+ # git_repo.unlink_local_clone?(repo_dir)
168
+ # create_repo_from_remote_and_push(repo_dir, repo_url, remote_branch)
169
+ # else
170
+ # repo.remove_remote(Dtk_Server::GIT_REMOTE)
171
+ # add_remote_and_push(repo, repo_url, remote_branch)
172
+ # end
173
+ # end
174
+
175
+ # def self.create_repo_from_server_remote(repo_dir, repo_url, remote_branch)
176
+ # repo = git_repo.new(repo_dir, :branch => Dtkn::LOCAL_BRANCH)
177
+ # repo.checkout(Dtkn::LOCAL_BRANCH, :new_branch => true)
178
+ # repo.add_remote(Dtk_Server::GIT_REMOTE, repo_url)
179
+ # repo
180
+ # end
181
+
182
+ # def self.create_repo_from_remote_and_push(repo_dir, repo_url, remote_branch)
183
+ # repo = create_repo_from_server_remote(repo_dir, repo_url, remote_branch)
184
+ # # repo = git_repo.new(repo_dir, :branch => Dtkn::LOCAL_BRANCH)
185
+ # # repo.checkout(Dtkn::LOCAL_BRANCH, :new_branch => true)
186
+ # # repo.add_remote(Dtk_Server::GIT_REMOTE, repo_url)
187
+ # repo.stage_and_commit
188
+ # repo.push(Dtk_Server::GIT_REMOTE, remote_branch, { :force => true })
189
+ # repo.head_commit_sha
190
+ # end
191
+
192
+ # def self.add_remote_and_push(repo, repo_url, remote_branch)
193
+ # repo.add_remote(Dtk_Server::GIT_REMOTE, repo_url)
194
+ # repo.stage_and_commit
195
+ # repo.push(Dtk_Server::GIT_REMOTE, remote_branch, { :force => true })
196
+ # end
197
+
198
+ def self.all_branches(args)
199
+ repo_url = args.required(:path)
200
+ repo = git_repo.new(repo_url)
201
+ repo.all_branches
202
+ end
203
+
204
+ def self.current_branch(args)
205
+ repo_url = args.required(:path)
206
+ repo = git_repo.new(repo_url)
207
+ repo.current_branch.name
208
+ end
209
+
210
+ def self.git_repo
211
+ GitClient
212
+ end
213
+
214
+ def self.reset_hard(repo, merge_from_ref)
215
+ repo.reset_hard(merge_from_ref)
216
+ repo.head_commit_sha
217
+ end
218
+
219
+ end
220
+ end
221
+
@@ -0,0 +1,38 @@
1
+ require 'fileutils'
2
+
3
+ module DTK::Network::Client
4
+ # Operations for managing module folders
5
+ class ModuleDir
6
+ extend DTK::Network::Client::Util::Tar
7
+
8
+ def self.ret_path_with_current_dir(name)
9
+ "#{Dir.getwd}/#{name.gsub(':','/')}"
10
+ end
11
+
12
+ def self.rm_f(path)
13
+ FileUtils.rm_rf(path)
14
+ end
15
+
16
+ def self.delete_directory_content(path)
17
+ FileUtils.rm_rf(Dir.glob("#{path}/*"))
18
+ end
19
+
20
+ def self.create_file_with_content(file_path, content)
21
+ FileUtils.mkdir_p(File.dirname(file_path))
22
+ File.open(file_path, 'w') { |f| f << content }
23
+ end
24
+
25
+ def self.create_and_ret_tar_gz(source_dir, opts = {})
26
+ raise Error.new("Directory '#{source_dir}' does not exist!") unless Dir.exist?(source_dir)
27
+ gzip(tar(source_dir, opts))
28
+ end
29
+
30
+ def self.ungzip_and_untar(file, target_dir)
31
+ raise Error.new("File '#{file}' does not exist!") unless File.exist?(file)
32
+ FileUtils.mkdir_p(target_dir)
33
+ untar(ungzip(File.open(file, "rb")), target_dir)
34
+ end
35
+
36
+ end
37
+ end
38
+
@@ -0,0 +1,47 @@
1
+ module DTK::Network::Client
2
+ class ModuleRef
3
+ class Dependency
4
+ class Local < self
5
+ MODULE_FILE = 'dtk.module.yaml'
6
+
7
+ attr_reader :version, :source
8
+ def initialize(module_info)
9
+ super(name: module_info[:name] || module_info['module'], namespace: module_info[:namespace] || module_info['namespace'])
10
+ version_hash = module_info[:version] || module_info['version']
11
+ version_str = version_hash[:version] || version_hash['version']
12
+ version_source = version_hash[:source] || version_hash['source']
13
+
14
+ @version = ModuleRef::Version.new(version_str)
15
+ @source = find_source(version_source)
16
+ end
17
+
18
+ def dtkn_versions_with_dependencies
19
+ require 'dtk_dsl'
20
+ file_type = DTK::DSL::FileType::CommonModule::DSLFile::Top
21
+ file_obj = DTK::DSL::FileObj.new(file_type, @source, { content: FileHelper.get_content?("#{@source}/#{MODULE_FILE}") })
22
+ parsed_module = file_obj.parse_content(:common_module_summary)
23
+ dependent_modules = parsed_module.val(:DependentModules) || []
24
+
25
+ dependencies = dependent_modules.map { |dep| { 'namespace' => dep[:namespace], 'module' => dep[:module_name], 'version' => dep[:version] }}
26
+ [
27
+ {
28
+ 'name' => self.version.str_version,
29
+ 'version' => self.version.str_version,
30
+ 'dependencies' => dependencies
31
+ }
32
+ ]
33
+ end
34
+
35
+ private
36
+
37
+ def find_source(version_source)
38
+ if matching_source = version_source.match(/(file:)(.*)/)
39
+ matching_source[2]
40
+ else
41
+ fail "Unsuppored source format: #{version_source}!"
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,18 @@
1
+ module DTK::Network::Client
2
+ class ModuleRef
3
+ class Dependency
4
+ class Remote < self
5
+ def initialize(module_info)
6
+ super(name: module_info[:name] || module_info['module'], namespace: module_info[:namespace] || module_info['namespace'])
7
+ version_str = module_info[:version]||module_info['version']
8
+ @version = ModuleRef::Version.new(version_str)
9
+ end
10
+
11
+ def dtkn_versions_with_dependencies
12
+ response = rest_get("modules/get_versions_with_dependencies", { name: self.name, namespace: self.namespace })
13
+ response['versions']
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,21 @@
1
+ module DTK::Network::Client
2
+ class ModuleRef
3
+ class Dependency < self
4
+ require_relative('dependency/local')
5
+ require_relative('dependency/remote')
6
+
7
+ include RestWrapper
8
+ extend RestWrapper
9
+
10
+ def self.create_local_or_remote(module_info)
11
+ version = module_info[:version] || module_info['version']
12
+ is_local?(version) ? Local.new(module_info) : Remote.new(module_info)
13
+ end
14
+
15
+ def self.is_local?(version)
16
+ return unless version.is_a?(Hash)
17
+ !!(version[:source] || version['source'])
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,18 @@
1
+ module DTK::Network::Client
2
+ class ModuleRef
3
+ class Version
4
+ class Source
5
+ attr_reader :location
6
+ def initialize(source)
7
+ # right now we only support file as source, later we can introduce other sources
8
+ if matching_source = source.match(/(file:)(.*)/)
9
+ @location = matching_source[2]
10
+ else
11
+ fail "Unsuppored source format: #{source}!"
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+
@@ -0,0 +1,87 @@
1
+ module DTK::Network::Client
2
+ class ModuleRef
3
+ class Version
4
+ attr_reader :full_version, :requirement, :semantic_version, :str_version
5
+
6
+ def initialize(version = '')
7
+ @full_version = version.strip
8
+ @str_version = ''
9
+ @requirement = '='
10
+ @semantic_version = nil
11
+ parse
12
+ end
13
+
14
+ def versions_in_range(versions)
15
+ v_in_range = []
16
+ versions = [versions] unless versions.is_a?(Array)
17
+
18
+ versions.each do |version|
19
+ if satisfied_by?(version)
20
+ v_in_range << version
21
+ end
22
+ end
23
+
24
+ v_in_range
25
+ end
26
+
27
+ def satisfied_by?(version = nil)
28
+ return unless version
29
+ match_requirement?(version)
30
+ end
31
+
32
+ def is_semantic_version?
33
+ !!@semantic_version
34
+ end
35
+
36
+ def self.is_semantic_version?(version)
37
+ SemVer.parse(version)
38
+ end
39
+
40
+ private
41
+
42
+ def match_requirement?(version)
43
+ case @requirement
44
+ when '='
45
+ version == @str_version
46
+ when '<'
47
+ version < @str_version
48
+ when '>'
49
+ version > @str_version
50
+ when '<='
51
+ version <= @str_version
52
+ when '>='
53
+ version >= @str_version
54
+ when '~>'
55
+ top_version = nil
56
+
57
+ if patch = @semantic_version.patch
58
+ top_version = "#{@semantic_version.major}.#{@semantic_version.minor + 1}.0"
59
+ elsif minor = @semantic_version.minor
60
+ top_version = "#{@semantic_version.major + 1}.0.0"
61
+ end
62
+
63
+ return false unless top_version
64
+
65
+ (version < top_version) && (version >= @str_version)
66
+ else
67
+ false
68
+ end
69
+ end
70
+
71
+ def parse
72
+ parsed = @full_version.split(' ')
73
+ raise "Invalid version #{@full_version}!" if parsed.empty? || parsed.size > 2
74
+
75
+ if parsed.size == 1
76
+ @str_version = parsed.first
77
+ @semantic_version = SemVer.parse(@str_version)
78
+ else
79
+ @requirement = parsed.first
80
+ @str_version = parsed.last
81
+ @semantic_version = SemVer.parse(@str_version)
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
87
+
@@ -0,0 +1,21 @@
1
+ module DTK::Network
2
+ module Client
3
+ class ModuleRef
4
+ require_relative('module_ref/dependency')
5
+ require_relative('module_ref/version')
6
+
7
+ attr_reader :name, :namespace, :version, :repo_dir, :full_name, :explicit_path
8
+
9
+ def initialize(module_info)
10
+ @name = module_info[:name]
11
+ @namespace = module_info[:namespace]
12
+ mod_info_version = module_info[:version] || module_info['version']
13
+ @version = mod_info_version ? Version.new(mod_info_version) : nil
14
+ @repo_dir = module_info[:repo_dir]
15
+ @explicit_path = module_info[:explicit_path]
16
+ @full_name = "#{@namespace}/#{@name}"
17
+ end
18
+ end
19
+ end
20
+ end
21
+
@@ -0,0 +1,42 @@
1
+ module DTK::Network::Client
2
+ class Response
3
+ class Ok < self
4
+ def initialize(data = {})
5
+ super('data'=> data, 'status' => 'ok')
6
+ end
7
+ end
8
+
9
+ class NotOk < self
10
+ def initialize(data = {})
11
+ super('data'=> data, 'status' => 'notok')
12
+ end
13
+ end
14
+
15
+ class NoOp < self
16
+ def render_data
17
+ end
18
+ end
19
+
20
+ class ErrorResponse < self
21
+ include ::DTK::Common::Response::ErrorMixin
22
+ def initialize(hash = {})
23
+ super('errors' => [hash])
24
+ end
25
+ private :initialize
26
+
27
+ class Usage < self
28
+ def initialize(hash_or_string = {})
29
+ hash = (hash_or_string.kind_of?(String) ? {'message' => hash_or_string} : hash_or_string)
30
+ super({'code' => 'error'}.merge(hash))
31
+ end
32
+ end
33
+
34
+ class Internal < self
35
+ def initialize(hash = {})
36
+ super({'code' => 'error'}.merge(hash).merge('internal' => true))
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+
@@ -0,0 +1,27 @@
1
+ require 'dtk_common_core'
2
+
3
+ module DTK::Network::Client
4
+ class Response < ::DTK::Common::Response
5
+ require_relative('response/response_types')
6
+
7
+ def initialize(hash = {})
8
+ super(hash)
9
+ end
10
+
11
+ def notok?
12
+ kind_of?(NotOk)
13
+ end
14
+
15
+ def self.wrap_as_response(data = {}, &block)
16
+ results = (block ? yield : data)
17
+ if results.nil?
18
+ NoOp.new
19
+ elsif results.kind_of?(Response)
20
+ results
21
+ else
22
+ Ok.new(results)
23
+ end
24
+ end
25
+ end
26
+ end
27
+
@@ -0,0 +1,43 @@
1
+ module DTK::Network::Client
2
+ module RestWrapper
3
+ def rest_get(url, params = {})
4
+ raise_error_if_notok_response do
5
+ Session.rest_get(url, params)
6
+ end
7
+ end
8
+
9
+ def rest_post(url, post_body = {})
10
+ raise_error_if_notok_response do
11
+ Session.rest_post(url, post_body)
12
+ end
13
+ end
14
+
15
+ def rest_delete(url, post_body = {})
16
+ raise_error_if_notok_response do
17
+ Session.rest_delete(url, post_body)
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ def raise_error_if_notok_response(&block)
24
+ response = block.call
25
+ if response
26
+ if response.is_a?(Hash)
27
+ status = response['status']
28
+ if status
29
+ raise Error.new(response) if status.eql?('notok')
30
+ # response
31
+ # else
32
+ # Response::Ok.new(response)
33
+ end
34
+ response
35
+ else
36
+ response
37
+ end
38
+ else
39
+ raise Error.new(response)
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,23 @@
1
+ module DTK::Network::Client
2
+ class S3Helper
3
+ def self.ret_s3_bucket_info(response)
4
+ branch = response['branch'] || {}
5
+ bucket = nil
6
+ object_name = nil
7
+
8
+ if meta = branch['meta']
9
+ catalog_uri = meta['catalog_uri']
10
+ if match = catalog_uri.match(/.*amazonaws.com\/([^\/]*)\/(.*.gz)/)
11
+ bucket = match[1]
12
+ object_name = match[2]
13
+ end
14
+ else
15
+ raise "Unexpected that publish response does not contain branch metadata!"
16
+ end
17
+
18
+ raise "Unable to extract bucket and/or object name data from catalog_uri!" if bucket.nil? || object_name.nil?
19
+
20
+ return [bucket, object_name]
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,54 @@
1
+ require 'singleton'
2
+
3
+ module DTK::Network
4
+ module Client
5
+ class Session
6
+ include Singleton
7
+
8
+ attr_accessor :conn
9
+
10
+ def initialize
11
+ @conn = Conn.new
12
+ end
13
+
14
+ # opts can have keys
15
+ # :reset
16
+ def self.get_connection(opts = {})
17
+ instance.conn = Conn.new if opts[:reset]
18
+ instance.conn
19
+ end
20
+
21
+ # def self.connection_username
22
+ # instance.conn.get_username
23
+ # end
24
+
25
+ def self.re_initialize
26
+ instance.conn = nil
27
+ instance.conn = Conn.new
28
+ instance.conn.cookies
29
+ end
30
+
31
+ def self.logout
32
+ # from this point @conn is not valid, since there are no cookies set
33
+ instance.conn.logout
34
+ end
35
+
36
+ def self.rest_post(route, post_body = {})
37
+ instance.conn.post(route, post_body)
38
+ end
39
+
40
+ def self.rest_get(route, opts = {})
41
+ instance.conn.get(route, opts)
42
+ end
43
+
44
+ def self.rest_delete(route, delete_body = {})
45
+ instance.conn.delete(route, delete_body)
46
+ end
47
+
48
+ def self.get_codecommit_data
49
+ instance.conn.codecommit
50
+ end
51
+
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,25 @@
1
+ module DTK::Network::Client
2
+ class Storage
3
+ module Adapter
4
+ class S3
5
+ require 'aws-sdk'
6
+
7
+ def initialize(data_hash)
8
+ @s3 = Aws::S3::Client.new(data_hash)
9
+ end
10
+
11
+ def upload(data_hash)
12
+ @s3.put_object(data_hash)
13
+ end
14
+
15
+ def download(data_hash, opts = {})
16
+ @s3.get_object(data_hash, opts)
17
+ end
18
+
19
+ def delete(data_hash, opts = {})
20
+ @s3.delete_object(data_hash, opts)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end