dtk-network-client 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +5 -0
- data/Gemfile +2 -0
- data/LICENSE +201 -0
- data/README.md +2 -0
- data/dtk-network-client.gemspec +24 -0
- data/lib/client/args.rb +19 -0
- data/lib/client/client_args.rb +23 -0
- data/lib/client/command/add_to_group.rb +20 -0
- data/lib/client/command/chmod.rb +21 -0
- data/lib/client/command/create_namespace.rb +19 -0
- data/lib/client/command/delete.rb +25 -0
- data/lib/client/command/delete_namespace.rb +19 -0
- data/lib/client/command/info.rb +32 -0
- data/lib/client/command/install/installer.rb +9 -0
- data/lib/client/command/install.rb +190 -0
- data/lib/client/command/list.rb +13 -0
- data/lib/client/command/list_namespaces.rb +10 -0
- data/lib/client/command/publish.rb +120 -0
- data/lib/client/command/pull.rb +53 -0
- data/lib/client/command/push.rb +63 -0
- data/lib/client/command/remove_from_group.rb +20 -0
- data/lib/client/command/unpublish.rb +27 -0
- data/lib/client/command/update.rb +18 -0
- data/lib/client/command.rb +31 -0
- data/lib/client/config.rb +54 -0
- data/lib/client/conn.rb +132 -0
- data/lib/client/dependency_tree/activated.rb +35 -0
- data/lib/client/dependency_tree/cache.rb +28 -0
- data/lib/client/dependency_tree/candidates.rb +19 -0
- data/lib/client/dependency_tree/resolver.rb +16 -0
- data/lib/client/dependency_tree.rb +272 -0
- data/lib/client/error.rb +22 -0
- data/lib/client/file_helper.rb +8 -0
- data/lib/client/git_adapter/git_gem.rb +246 -0
- data/lib/client/git_client.rb +136 -0
- data/lib/client/git_repo.rb +221 -0
- data/lib/client/module_dir.rb +38 -0
- data/lib/client/module_ref/dependency/local.rb +47 -0
- data/lib/client/module_ref/dependency/remote.rb +18 -0
- data/lib/client/module_ref/dependency.rb +21 -0
- data/lib/client/module_ref/version/source.rb +18 -0
- data/lib/client/module_ref/version.rb +87 -0
- data/lib/client/module_ref.rb +21 -0
- data/lib/client/response/response_types.rb +42 -0
- data/lib/client/response.rb +27 -0
- data/lib/client/rest_wrapper.rb +43 -0
- data/lib/client/s3_helper.rb +23 -0
- data/lib/client/session.rb +54 -0
- data/lib/client/storage/adapters/s3.rb +25 -0
- data/lib/client/storage.rb +29 -0
- data/lib/client/util/os_util.rb +77 -0
- data/lib/client/util/permissions_util.rb +12 -0
- data/lib/client/util/tar.rb +104 -0
- data/lib/client/util.rb +7 -0
- data/lib/client/version.rb +8 -0
- data/lib/dtk_network_client.rb +27 -0
- metadata +183 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4caa7bc4536938be491e6d5f23efcf834f5bb591
|
4
|
+
data.tar.gz: 10c0434499bcbb0c69d585611203c83cf37dd08a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 38a3fda8184fb587d0b2b18d069347ed85ccb1f5dbf296f8f31dc765ee61bb4dceb7d2f8fb2a59472e0088000ee8284b251bcbf3c978d69528e6a496a293e0fd
|
7
|
+
data.tar.gz: 04202674d5df3594fdcd0b9e7cf86dda5245cb1fc5a855aae9f32c2d9a3efdd9f000b7f18dd486ddd80580d840215f2561e9c743c1c685a1855ef5cceee1adab
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,201 @@
|
|
1
|
+
Apache License
|
2
|
+
Version 2.0, January 2004
|
3
|
+
http://www.apache.org/licenses/
|
4
|
+
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6
|
+
|
7
|
+
1. Definitions.
|
8
|
+
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
11
|
+
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
13
|
+
the copyright owner that is granting the License.
|
14
|
+
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
16
|
+
other entities that control, are controlled by, or are under common
|
17
|
+
control with that entity. For the purposes of this definition,
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
19
|
+
direction or management of such entity, whether by contract or
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
22
|
+
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
24
|
+
exercising permissions granted by this License.
|
25
|
+
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
27
|
+
including but not limited to software source code, documentation
|
28
|
+
source, and configuration files.
|
29
|
+
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
31
|
+
transformation or translation of a Source form, including but
|
32
|
+
not limited to compiled object code, generated documentation,
|
33
|
+
and conversions to other media types.
|
34
|
+
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
36
|
+
Object form, made available under the License, as indicated by a
|
37
|
+
copyright notice that is included in or attached to the work
|
38
|
+
(an example is provided in the Appendix below).
|
39
|
+
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
46
|
+
the Work and Derivative Works thereof.
|
47
|
+
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
49
|
+
the original version of the Work and any modifications or additions
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
61
|
+
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
64
|
+
subsequently incorporated within the Work.
|
65
|
+
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
72
|
+
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
78
|
+
where such license applies only to those patent claims licensable
|
79
|
+
by such Contributor that are necessarily infringed by their
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
82
|
+
institute patent litigation against any entity (including a
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
85
|
+
or contributory patent infringement, then any patent licenses
|
86
|
+
granted to You under this License for that Work shall terminate
|
87
|
+
as of the date such litigation is filed.
|
88
|
+
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
91
|
+
modifications, and in Source or Object form, provided that You
|
92
|
+
meet the following conditions:
|
93
|
+
|
94
|
+
(a) You must give any other recipients of the Work or
|
95
|
+
Derivative Works a copy of this License; and
|
96
|
+
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
98
|
+
stating that You changed the files; and
|
99
|
+
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
102
|
+
attribution notices from the Source form of the Work,
|
103
|
+
excluding those notices that do not pertain to any part of
|
104
|
+
the Derivative Works; and
|
105
|
+
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
108
|
+
include a readable copy of the attribution notices contained
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
111
|
+
of the following places: within a NOTICE text file distributed
|
112
|
+
as part of the Derivative Works; within the Source form or
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
114
|
+
within a display generated by the Derivative Works, if and
|
115
|
+
wherever such third-party notices normally appear. The contents
|
116
|
+
of the NOTICE file are for informational purposes only and
|
117
|
+
do not modify the License. You may add Your own attribution
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
120
|
+
that such additional attribution notices cannot be construed
|
121
|
+
as modifying the License.
|
122
|
+
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
124
|
+
may provide additional or different license terms and conditions
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
128
|
+
the conditions stated in this License.
|
129
|
+
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
133
|
+
this License, without any additional terms or conditions.
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
135
|
+
the terms of any separate license agreement you may have executed
|
136
|
+
with Licensor regarding such Contributions.
|
137
|
+
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
140
|
+
except as required for reasonable and customary use in describing the
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
142
|
+
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
152
|
+
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
158
|
+
incidental, or consequential damages of any character arising as a
|
159
|
+
result of this License or out of the use or inability to use the
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
162
|
+
other commercial damages or losses), even if such Contributor
|
163
|
+
has been advised of the possibility of such damages.
|
164
|
+
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
168
|
+
or other liability obligations and/or rights consistent with this
|
169
|
+
License. However, in accepting such obligations, You may act only
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
174
|
+
of your accepting any such warranty or additional liability.
|
175
|
+
|
176
|
+
END OF TERMS AND CONDITIONS
|
177
|
+
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
179
|
+
|
180
|
+
To apply the Apache License to your work, attach the following
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "{}"
|
182
|
+
replaced with your own identifying information. (Don't include
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
184
|
+
comment syntax for the file format. We also recommend that a
|
185
|
+
file or class name and description of purpose be included on the
|
186
|
+
same "printed page" as the copyright notice for easier
|
187
|
+
identification within third-party archives.
|
188
|
+
|
189
|
+
Copyright {yyyy} {name of copyright owner}
|
190
|
+
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
192
|
+
you may not use this file except in compliance with the License.
|
193
|
+
You may obtain a copy of the License at
|
194
|
+
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
196
|
+
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
200
|
+
See the License for the specific language governing permissions and
|
201
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require File.expand_path('../lib/client/version', __FILE__)
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = 'dtk-network-client'
|
5
|
+
spec.version = DTK::Network::Client::VERSION
|
6
|
+
spec.author = 'Reactor8'
|
7
|
+
spec.email = 'support@reactor8.com'
|
8
|
+
spec.description = %q{Library for interaction with dtk network.}
|
9
|
+
spec.summary = %q{Library for interaction with dtk network.}
|
10
|
+
spec.license = 'Apache 2.0'
|
11
|
+
spec.platform = Gem::Platform::RUBY
|
12
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 1.9.3')
|
13
|
+
|
14
|
+
spec.require_paths = ['lib']
|
15
|
+
spec.files = `git ls-files`.split("\n")
|
16
|
+
|
17
|
+
spec.add_dependency 'git', '1.2.9'
|
18
|
+
# spec.add_dependency 'dtk-common-core', '0.11.0'
|
19
|
+
spec.add_dependency 'semverly', '~> 1.0'
|
20
|
+
spec.add_dependency 'rest-client', '1.6.7'
|
21
|
+
spec.add_dependency 'aws-sdk', '~> 3'
|
22
|
+
spec.add_dependency 'dtk-dsl', '~> 1.1.0'
|
23
|
+
spec.add_dependency 'dtk-common-core', '0.11.1'
|
24
|
+
end
|
data/lib/client/args.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module DTK::Network::Client
|
2
|
+
class Args < ::Hash
|
3
|
+
def initialize(hash = {})
|
4
|
+
replace(hash)
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.convert(ruby_hash_or_args)
|
8
|
+
ruby_hash_or_args.kind_of?(Args) ? ruby_hash_or_args : new(ruby_hash_or_args)
|
9
|
+
end
|
10
|
+
|
11
|
+
def required(key)
|
12
|
+
if has_key?(key)
|
13
|
+
self[key]
|
14
|
+
else
|
15
|
+
raise "Args object missing the key '#{key}'"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module DTK::Network
|
2
|
+
module Client
|
3
|
+
class Args < ::Hash
|
4
|
+
def initialize(hash = {})
|
5
|
+
replace(hash)
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.convert(ruby_hash_or_args)
|
9
|
+
ruby_hash_or_args.kind_of?(Args) ? ruby_hash_or_args : new(ruby_hash_or_args)
|
10
|
+
end
|
11
|
+
|
12
|
+
def required(key)
|
13
|
+
if has_key?(key)
|
14
|
+
self[key]
|
15
|
+
else
|
16
|
+
raise "Args object missing the key '#{key}'"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module DTK::Network::Client
|
2
|
+
class Command
|
3
|
+
class AddToGroup < self
|
4
|
+
def initialize(group, user, options = {})
|
5
|
+
@group = group
|
6
|
+
@user = user
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.run(group, user, opts = {})
|
10
|
+
new(group, user, opts).add_to_group
|
11
|
+
end
|
12
|
+
|
13
|
+
def add_to_group
|
14
|
+
rest_post("groups/#{@group}/member", { name: @group, username: @user })
|
15
|
+
nil
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module DTK::Network::Client
|
2
|
+
class Command
|
3
|
+
class Chmod < self
|
4
|
+
def initialize(namespace, permissions, options = {})
|
5
|
+
@namespace = namespace
|
6
|
+
@permissions = permissions
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.run(namespace, permissions, opts = {})
|
10
|
+
new(namespace, permissions, opts).chmod
|
11
|
+
end
|
12
|
+
|
13
|
+
def chmod
|
14
|
+
validate_permissions!(@permissions)
|
15
|
+
rest_post("namespaces/#{@namespace}/chmod", { name: @namespace, permissions: @permissions })
|
16
|
+
nil
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module DTK::Network::Client
|
2
|
+
class Command
|
3
|
+
class CreateNamespace < self
|
4
|
+
def initialize(namespace, options = {})
|
5
|
+
@namespace = namespace
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.run(namespace, opts = {})
|
9
|
+
new(namespace, opts).create_namespace
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_namespace
|
13
|
+
rest_post("groups", { name: @namespace, reference: 'namespace' })
|
14
|
+
nil
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module DTK::Network::Client
|
2
|
+
class Command
|
3
|
+
class Delete < self
|
4
|
+
def initialize(module_ref, options = {})
|
5
|
+
@module_ref = module_ref
|
6
|
+
@options = options
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.run(module_info, opts = {})
|
10
|
+
module_ref = ModuleRef.new(module_info)
|
11
|
+
new(module_ref, opts).delete
|
12
|
+
end
|
13
|
+
|
14
|
+
def delete
|
15
|
+
params = {
|
16
|
+
name: @module_ref.name,
|
17
|
+
namespace: @module_ref.namespace
|
18
|
+
}
|
19
|
+
rest_delete("modules/#{@module_ref.name}", params)
|
20
|
+
|
21
|
+
nil
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module DTK::Network::Client
|
2
|
+
class Command
|
3
|
+
class DeleteNamespace < self
|
4
|
+
def initialize(namespace, options = {})
|
5
|
+
@namespace = namespace
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.run(namespace, opts = {})
|
9
|
+
new(namespace, opts).delete_namespace
|
10
|
+
end
|
11
|
+
|
12
|
+
def delete_namespace
|
13
|
+
rest_delete("groups/#{@namespace}", { name: @namespace, reference: 'namespace' })
|
14
|
+
nil
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module DTK::Network::Client
|
2
|
+
class Command
|
3
|
+
class Info < self
|
4
|
+
def initialize(module_ref, options = {})
|
5
|
+
@module_ref = module_ref
|
6
|
+
@about = options[:about] || :versions
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.run(module_info, opts = {})
|
10
|
+
module_ref = ModuleRef.new(module_info)
|
11
|
+
new(module_ref, opts).info
|
12
|
+
end
|
13
|
+
|
14
|
+
def info
|
15
|
+
case @about.to_sym
|
16
|
+
when :versions
|
17
|
+
versions
|
18
|
+
else
|
19
|
+
module_info
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def versions
|
24
|
+
modules_info = rest_get('modules/get_versions', { name: @module_ref.name, namespace: @module_ref.namespace })
|
25
|
+
modules_info['versions'] || []
|
26
|
+
end
|
27
|
+
|
28
|
+
def module_info
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,190 @@
|
|
1
|
+
module DTK::Network::Client
|
2
|
+
class Command
|
3
|
+
class Install < self
|
4
|
+
include DTK::Network::Client::Util::Tar
|
5
|
+
include DTK::Network::Client::Util::OsUtil
|
6
|
+
|
7
|
+
def initialize(module_ref, dependency_tree, options = {})
|
8
|
+
@module_ref = module_ref
|
9
|
+
@dependency_tree = dependency_tree
|
10
|
+
@module_directory = module_ref.repo_dir
|
11
|
+
@explicit_path = module_ref.explicit_path
|
12
|
+
@options = options
|
13
|
+
@parsed_module = options[:parsed_module]
|
14
|
+
@ret = []
|
15
|
+
@type = options[:type]
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.run(module_info, opts = {})
|
19
|
+
module_ref = ModuleRef.new(module_info)
|
20
|
+
dependency_tree = DependencyTree.get_or_create(module_ref, opts.merge(format: :hash))
|
21
|
+
new(module_ref, dependency_tree, opts).install
|
22
|
+
end
|
23
|
+
|
24
|
+
def install
|
25
|
+
FileUtils.mkdir_p(dtk_modules_gzip_location) unless Dir.exist?(dtk_modules_gzip_location)
|
26
|
+
|
27
|
+
module_list = @dependency_tree.dup
|
28
|
+
module_list << { namespace: @module_ref.namespace, name:@module_ref.name, version: @module_ref.version.str_version }
|
29
|
+
|
30
|
+
modules_info = rest_get('modules/install', { module_list: module_list.to_json })
|
31
|
+
main_module = ret_main_module_install_info(modules_info)
|
32
|
+
|
33
|
+
(modules_info || []).each do |module_info|
|
34
|
+
dep_module_list = module_info['module_list']
|
35
|
+
# credentials = module_info.dig('credentails', 'credentials')
|
36
|
+
credentials = (module_info['credentails']||{})['credentials']
|
37
|
+
|
38
|
+
raise Error.new('Unexpected that repoman did not return any credentials') unless credentials
|
39
|
+
|
40
|
+
s3_args = Args.new({
|
41
|
+
region: 'us-east-1',
|
42
|
+
access_key_id: credentials['access_key_id'],
|
43
|
+
secret_access_key: credentials['secret_access_key'],
|
44
|
+
session_token: credentials['session_token']
|
45
|
+
})
|
46
|
+
storage = Storage.new(:s3, s3_args)
|
47
|
+
|
48
|
+
dep_module_list.each do |module_info|
|
49
|
+
if ModuleRef::Version.is_semantic_version?(module_info['version'])
|
50
|
+
install_semantic_version(module_info, storage)
|
51
|
+
else
|
52
|
+
install_named_version(module_info)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
install_main_module(main_module)
|
58
|
+
@ret
|
59
|
+
end
|
60
|
+
|
61
|
+
def install_main_module(module_info)
|
62
|
+
credentials = module_info['credentials']
|
63
|
+
s3_args = Args.new({
|
64
|
+
region: 'us-east-1',
|
65
|
+
access_key_id: credentials['access_key_id'],
|
66
|
+
secret_access_key: credentials['secret_access_key'],
|
67
|
+
session_token: credentials['session_token']
|
68
|
+
})
|
69
|
+
storage = Storage.new(:s3, s3_args)
|
70
|
+
|
71
|
+
namespace, name = module_info['name'].split('/')
|
72
|
+
module_location = nil
|
73
|
+
|
74
|
+
unless @type == :dependency
|
75
|
+
module_location = @explicit_path || "#{@module_directory}/#{name}"
|
76
|
+
end
|
77
|
+
|
78
|
+
if ModuleRef::Version.is_semantic_version?(module_info['version'])
|
79
|
+
module_location = install_semantic_version(module_info, storage, module_location)
|
80
|
+
else
|
81
|
+
module_location = install_named_version(module_info, module_location)
|
82
|
+
end
|
83
|
+
|
84
|
+
ModuleDir.create_file_with_content("#{module_location}/#{DependencyTree::LOCK_FILE}", YAML.dump(convert_to_module_ref_lock_format(@dependency_tree)))
|
85
|
+
# print "Main module installed in '#{module_location}'.\n"
|
86
|
+
end
|
87
|
+
|
88
|
+
def ret_main_module_install_info(modules_info = [])
|
89
|
+
main_module_info = nil
|
90
|
+
|
91
|
+
modules_info.each do |module_info|
|
92
|
+
break if main_module_info
|
93
|
+
|
94
|
+
module_list = module_info['module_list'] || []
|
95
|
+
main_module_info = module_list.find { |mod_info| mod_info['name'].eql?("#{@module_ref.namespace}/#{@module_ref.name}") && mod_info['version'].eql?(@module_ref.version.str_version) }
|
96
|
+
|
97
|
+
if main_module_info
|
98
|
+
module_list.delete(main_module_info)
|
99
|
+
# credentials = module_info.dig('credentails', 'credentials')
|
100
|
+
credentials = (module_info['credentails']||{})['credentials']
|
101
|
+
main_module_info.merge!('credentials' => credentials)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
main_module_info
|
106
|
+
end
|
107
|
+
|
108
|
+
def install_semantic_version(module_info, storage, target_location = nil)
|
109
|
+
bucket, object_name = ret_s3_bucket_info(module_info)
|
110
|
+
object_name_on_disk = object_name.gsub(/([\/])/,'__')
|
111
|
+
object_location_on_disk = "#{dtk_modules_gzip_location}/#{object_name_on_disk}"
|
112
|
+
download_args = Args.new({
|
113
|
+
response_target: object_location_on_disk,
|
114
|
+
bucket: bucket,
|
115
|
+
key: object_name,
|
116
|
+
response_content_encoding: "gzip"
|
117
|
+
})
|
118
|
+
storage.download(download_args)
|
119
|
+
install_location = target_location || "#{dtk_modules_location}/#{module_info['name']}-#{module_info['version']}"
|
120
|
+
|
121
|
+
FileUtils.rm_rf(install_location) if Dir.exist?(install_location)
|
122
|
+
|
123
|
+
FileUtils.mkdir_p(install_location)
|
124
|
+
`tar xC #{install_location} -f #{object_location_on_disk}`
|
125
|
+
# ModuleDir.ungzip_and_untar(object_location_on_disk, install_location)
|
126
|
+
FileUtils.remove_entry(object_location_on_disk)
|
127
|
+
|
128
|
+
@ret << module_info.merge(location: install_location)
|
129
|
+
print "Module installed in '#{install_location}'.\n"
|
130
|
+
install_location
|
131
|
+
end
|
132
|
+
|
133
|
+
def install_named_version(module_info, target_location = nil)
|
134
|
+
codecommit_uri = construct_clone_url(module_info['codecommit_uri'])#module_info['codecommit_uri']
|
135
|
+
install_location = target_location || "#{dtk_modules_location}/#{module_info['name']}-#{module_info['version']}"
|
136
|
+
|
137
|
+
FileUtils.rm_rf(install_location) if Dir.exist?(install_location)
|
138
|
+
|
139
|
+
GitClient.clone(codecommit_uri, install_location, module_info['version'])
|
140
|
+
|
141
|
+
@ret << module_info.merge(location: install_location)
|
142
|
+
print "Module installed in '#{install_location}'.\n"
|
143
|
+
install_location
|
144
|
+
end
|
145
|
+
|
146
|
+
def ret_s3_bucket_info(module_info)
|
147
|
+
bucket = nil
|
148
|
+
object_name = nil
|
149
|
+
|
150
|
+
# if meta = module_info['meta']
|
151
|
+
if catalog_uri = module_info['uri']
|
152
|
+
if match = catalog_uri.match(/.*amazonaws.com\/([^\/]*)\/(.*.gz)/)
|
153
|
+
bucket = match[1]
|
154
|
+
object_name = match[2]
|
155
|
+
end
|
156
|
+
else
|
157
|
+
raise "Unexpected that publish response does not contain metadata!"
|
158
|
+
end
|
159
|
+
|
160
|
+
raise "Unable to extract bucket and/or object name data from catalog_uri!" if bucket.nil? || object_name.nil?
|
161
|
+
|
162
|
+
return [bucket, object_name]
|
163
|
+
end
|
164
|
+
|
165
|
+
def construct_clone_url(codecommit_uri)
|
166
|
+
require 'open-uri'
|
167
|
+
|
168
|
+
if codecommit_uri # = module_info.dig('meta', 'aws', 'codecommit', 'repository_metadata', 'codecommit_uri')
|
169
|
+
codecommit_data = Session.get_codecommit_data
|
170
|
+
# service_user_name = codecommit_data.dig('service_specific_credential', 'service_user_name')
|
171
|
+
service_user_name = codecommit_data['service_specific_credential']['service_user_name']
|
172
|
+
# service_password = codecommit_data.dig('service_specific_credential', 'service_password')
|
173
|
+
service_password = codecommit_data['service_specific_credential']['service_password']
|
174
|
+
encoded_password = URI.encode_www_form_component(service_password)
|
175
|
+
url = nil
|
176
|
+
if match = codecommit_uri.match(/^(https:\/\/)(.*)$/)
|
177
|
+
url = "#{match[1]}#{service_user_name}:#{encoded_password}@#{match[2]}"
|
178
|
+
end
|
179
|
+
url
|
180
|
+
else
|
181
|
+
raise "Unable to find codecommit https url"
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
def convert_to_module_ref_lock_format(dep_tree)
|
186
|
+
dep_tree.inject({}) { |h, dep| h.merge!({ "#{dep[:namespace]}/#{dep[:name]}" => { 'version' => (dep[:version] || dep['version']) }})}
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module DTK::Network::Client
|
2
|
+
class Command
|
3
|
+
class List < self
|
4
|
+
def self.run(namespace, opts = {})
|
5
|
+
params = namespace ? {namespace: namespace} : {}
|
6
|
+
modules_info = rest_get('modules', params)
|
7
|
+
|
8
|
+
# return format expected by dtk-client, should change this to be more generic
|
9
|
+
{'status' => 'ok', 'datatype' => 'remote_module', 'data' => modules_info}
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|