triton-internal 0.1.3 → 0.2.0
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 +4 -4
- data/lib/triton/api_base.rb +56 -24
- data/lib/triton/imgapi.rb +1 -1
- data/lib/triton/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b16b7be1a4301ff1ce59645470043e7f28aad14d
|
4
|
+
data.tar.gz: 9412ab5e44e030236f71089ae01302ee2f36ac0f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9411f1c5c59af68ae14401e73ccc5fa91bec0472bc9fba707d30662c13f014580d7e05cfe9d440c0bbcadfa43659545096bf942345e56c8fd7a5e62808f4f77c
|
7
|
+
data.tar.gz: fb7c1d776e78832fa0e85a47a47ae31b96b082494901482868abd74862be61ebd6c518940141b9919be70e8bf96443d843fd546dbb0124c4360942c5e8742293
|
data/lib/triton/api_base.rb
CHANGED
@@ -47,12 +47,34 @@ module Triton
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
+
|
51
|
+
attr_reader :path
|
52
|
+
|
50
53
|
def initialize(name, params={})
|
51
54
|
@name = name
|
55
|
+
@params = params.dup || {}
|
52
56
|
@call = DefinedMethods[self.class][name]
|
53
|
-
@params = params
|
54
|
-
|
55
57
|
raise UnknownCall, "#{@name} isn't a known API method." unless @call
|
58
|
+
|
59
|
+
@method = @call.fetch(:method, :get).intern
|
60
|
+
@path = @call[:path]
|
61
|
+
@body_param = @call[:body_param] && @params.delete(@call[:body_param])
|
62
|
+
|
63
|
+
@params.each do |k,v|
|
64
|
+
@path = @path.gsub(":#{k.to_s}") do |_|
|
65
|
+
@params.delete(k)
|
66
|
+
CGI.escape(v.to_s)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
@query_string_params = if @method == :get || !!@body_param
|
71
|
+
@params
|
72
|
+
else
|
73
|
+
[@call.fetch(:querystring, [])].flatten.map do |key|
|
74
|
+
value = @params.delete(key.to_s)
|
75
|
+
[key, value] if value
|
76
|
+
end.compact
|
77
|
+
end
|
56
78
|
end
|
57
79
|
|
58
80
|
def execute
|
@@ -60,7 +82,7 @@ module Triton
|
|
60
82
|
raise Triton::TestModeLeak, "Request '#{@name}' leaked when in test mode\n#{request.method.upcase} #{URI.parse(request.url).path}\n#{JSON.pretty_generate(@params)}"
|
61
83
|
end
|
62
84
|
Triton.logger.debug("#{self.class.name}/#{@name}: #{request.method.upcase} #{URI.parse(request.url).path}\n#{JSON.pretty_generate(@params)}")
|
63
|
-
object =
|
85
|
+
object = parse(request.execute)
|
64
86
|
if object.is_a?(Hash)
|
65
87
|
IndifferentHash.new.merge!(object)
|
66
88
|
else
|
@@ -75,37 +97,47 @@ module Triton
|
|
75
97
|
end
|
76
98
|
end
|
77
99
|
|
78
|
-
def
|
79
|
-
@
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
100
|
+
def parse(body)
|
101
|
+
parser = @call.fetch(:response, :json)
|
102
|
+
if parser.respond_to?(:call)
|
103
|
+
parser.call(body)
|
104
|
+
else
|
105
|
+
case parser
|
106
|
+
when :json_lines
|
107
|
+
body.split("\n").map { |a| JSON.parse(a) }
|
108
|
+
when :json
|
109
|
+
JSON.parse(body)
|
110
|
+
else
|
111
|
+
raise ArgumentError, "Unknown parser '#{parser}'"
|
88
112
|
end
|
113
|
+
end
|
114
|
+
end
|
89
115
|
|
90
|
-
|
116
|
+
def request
|
117
|
+
@request ||= begin
|
91
118
|
|
92
|
-
|
93
|
-
|
94
|
-
|
119
|
+
# Now generate the payload, unless it's a GET
|
120
|
+
payload = if @method == :get
|
121
|
+
nil
|
122
|
+
elsif !!@body_param
|
123
|
+
JSON.generate(@body_param)
|
95
124
|
else
|
96
|
-
|
97
|
-
payload = JSON.dump(@params)
|
125
|
+
JSON.generate(@params)
|
98
126
|
end
|
99
127
|
|
128
|
+
query = @query_string_params.map { |k,v| [CGI.escape(k.to_s), CGI.escape(v.to_s)].join("=")}.join("&")
|
129
|
+
|
100
130
|
url = URI.parse("http://#{self.class.hostname}#{path}")
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
131
|
+
if query.length > 0
|
132
|
+
url.query = if url.query
|
133
|
+
url.query = "#{url.query}&#{query}"
|
134
|
+
else
|
135
|
+
query
|
136
|
+
end
|
105
137
|
end
|
106
138
|
|
107
139
|
RestClient::Request.new({
|
108
|
-
:method =>
|
140
|
+
:method => @method,
|
109
141
|
:url => url.to_s,
|
110
142
|
:headers => {
|
111
143
|
'Accept' => 'application/json',
|
data/lib/triton/imgapi.rb
CHANGED
@@ -26,7 +26,7 @@ module Triton
|
|
26
26
|
call('UpdateImage', :method => :post, :path => '/images/:uuid?action=update')
|
27
27
|
call('AdminImportImage', :method => :post, :path => '/images/:uuid?action=import')
|
28
28
|
call('AdminImportRemoteImage', :method => :post, :path => '/images/:uuid?action=import-remote')
|
29
|
-
call('AdminImportDockerImage', :method => :post, :path => '/images?action=import-docker-image')
|
29
|
+
call('AdminImportDockerImage', :method => :post, :path => '/images?action=import-docker-image', :querystring => ['tag', 'repo', 'digest'], :response => :json_lines)
|
30
30
|
call('AdminChangeImageStor', :method => :post, :path => '/images/:uuid?action=change-stor&stor=:newstor')
|
31
31
|
call('ListImageJobs', :method => :get, :path => '/images/:uuid/jobs')
|
32
32
|
call('ListChannels', :method => :get, :path => '/channels')
|
data/lib/triton/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: triton-internal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Haggett
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-12-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -121,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
121
121
|
version: '0'
|
122
122
|
requirements: []
|
123
123
|
rubyforge_project:
|
124
|
-
rubygems_version: 2.
|
124
|
+
rubygems_version: 2.6.13
|
125
125
|
signing_key:
|
126
126
|
specification_version: 4
|
127
127
|
summary: Library to wrap the Triton internal APIs
|