megam_api 1.8.1 → 1.8.2
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/megam/api.rb +2 -0
- data/lib/megam/api/license.rb +35 -0
- data/lib/megam/api/version.rb +1 -1
- data/lib/megam/core/json_compat.rb +4 -0
- data/lib/megam/core/license-collection.rb +122 -0
- data/lib/megam/core/license.rb +173 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8fe322a12b43de3a7f578b59e1f3cc468945006a
|
4
|
+
data.tar.gz: 075ccc88dab62d0122caa2b0a2fef03f0ac96e85
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4f91f4b249a4be36fe3d585eecceb0b716786548453cc8487a151c2b71027399cd8fce52e22cfc74c9aac66b674f6a27fd6bf3c7cde669e2c7fc688cd3aa304
|
7
|
+
data.tar.gz: 2bac046921d8cc0efece334d4596a6c55293f57e41af1cc67efe8e1a995918236b2097cf1de8bd15e21f7a7d0b8e71f99436299010c7c17aa51d378f043fddcc
|
data/lib/megam/api.rb
CHANGED
@@ -51,6 +51,8 @@ require 'megam/core/error'
|
|
51
51
|
require 'megam/core/account'
|
52
52
|
require 'megam/core/request'
|
53
53
|
require 'megam/core/request_collection'
|
54
|
+
require 'megam/core/license'
|
55
|
+
require 'megam/core/license_collection'
|
54
56
|
require 'megam/core/sshkey'
|
55
57
|
require 'megam/core/sshkey_collection'
|
56
58
|
require 'megam/core/eventsall'
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Megam
|
2
|
+
class API
|
3
|
+
def get_licenses
|
4
|
+
@options = {:path => '/license',:body => ""}.merge(@options)
|
5
|
+
|
6
|
+
request(
|
7
|
+
:expects => 200,
|
8
|
+
:method => :get,
|
9
|
+
:body => @options[:body]
|
10
|
+
)
|
11
|
+
end
|
12
|
+
|
13
|
+
def get_license(license_name)
|
14
|
+
@options = {:path => "/license/#{license_name}",:body => ""}.merge(@options)
|
15
|
+
|
16
|
+
request(
|
17
|
+
:expects => 200,
|
18
|
+
:method => :get,
|
19
|
+
:body => @options[:body]
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
def post_license(new_license)
|
24
|
+
@options = {:path => '/license/content',
|
25
|
+
:body => Megam::JSONCompat.to_json(new_license)}.merge(@options)
|
26
|
+
|
27
|
+
request(
|
28
|
+
:expects => 201,
|
29
|
+
:method => :post,
|
30
|
+
:body => @options[:body]
|
31
|
+
)
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
data/lib/megam/api/version.rb
CHANGED
@@ -39,6 +39,8 @@ module Megam
|
|
39
39
|
MEGAM_SNAPSHOTSCOLLECTION = 'Megam::SnapshotsCollection'.freeze
|
40
40
|
MEGAM_DISKS = 'Megam::Disks'.freeze
|
41
41
|
MEGAM_DISKSCOLLECTION = 'Megam::DisksCollection'.freeze
|
42
|
+
MEGAM_LICENSE = 'Megam::License'.freeze
|
43
|
+
MEGAM_LICENSECOLLECTION = 'Megam::LicenseCollection'.freeze
|
42
44
|
MEGAM_SSHKEY = 'Megam::SshKey'.freeze
|
43
45
|
MEGAM_SSHKEYCOLLECTION = 'Megam::SshKeyCollection'.freeze
|
44
46
|
MEGAM_EVENTSALL = 'Megam::EventsAll'.freeze
|
@@ -166,6 +168,8 @@ module Megam
|
|
166
168
|
Megam::EventsVm
|
167
169
|
when MEGAM_EVENTSVMCOLLECTION
|
168
170
|
Megam::EventsVmCollection
|
171
|
+
when MEGAM_LICENSECOLLECTION
|
172
|
+
Megam::LicenseCollection
|
169
173
|
when MEGAM_EVENTSALL
|
170
174
|
Megam::EventsAll
|
171
175
|
when MEGAM_EVENTSALLCOLLECTION
|
@@ -0,0 +1,122 @@
|
|
1
|
+
module Megam
|
2
|
+
class LicenseCollection
|
3
|
+
include Enumerable
|
4
|
+
|
5
|
+
attr_reader :iterator
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@license = Array.new
|
9
|
+
@license_by_name = Hash.new
|
10
|
+
@insert_after_idx = nil
|
11
|
+
end
|
12
|
+
|
13
|
+
def all_license
|
14
|
+
@license
|
15
|
+
end
|
16
|
+
|
17
|
+
def [](index)
|
18
|
+
@license[index]
|
19
|
+
end
|
20
|
+
|
21
|
+
def []=(index, arg)
|
22
|
+
is_megam_license(arg)
|
23
|
+
@license[index] = arg
|
24
|
+
@license_by_name[arg.name] = index
|
25
|
+
end
|
26
|
+
|
27
|
+
def <<(*args)
|
28
|
+
args.flatten.each do |a|
|
29
|
+
is_megam_license(a)
|
30
|
+
@license << a
|
31
|
+
@license_by_name[a.name] =@license.length - 1
|
32
|
+
end
|
33
|
+
self
|
34
|
+
end
|
35
|
+
|
36
|
+
# 'push' is an alias method to <<
|
37
|
+
alias_method :push, :<<
|
38
|
+
|
39
|
+
def insert(license)
|
40
|
+
is_megam_license(license)
|
41
|
+
if @insert_after_idx
|
42
|
+
# in the middle of executing a run, so any license inserted now should
|
43
|
+
# be placed after the most recent addition done by the currently executing
|
44
|
+
# license
|
45
|
+
@license.insert(@insert_after_idx + 1, license)
|
46
|
+
# update name -> location mappings and register new license
|
47
|
+
@license_by_name.each_key do |key|
|
48
|
+
@license_by_name[key] += 1 if@license_by_name[key] > @insert_after_idx
|
49
|
+
end
|
50
|
+
@license_by_name[license.name] = @insert_after_idx + 1
|
51
|
+
@insert_after_idx += 1
|
52
|
+
else
|
53
|
+
@license << license
|
54
|
+
@license_by_name[license.name] =@license.length - 1
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def each
|
59
|
+
@license.each do |license|
|
60
|
+
yield license
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def each_index
|
65
|
+
@license.each_index do |i|
|
66
|
+
yield i
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def empty?
|
71
|
+
@license.empty?
|
72
|
+
end
|
73
|
+
|
74
|
+
def lookup(license)
|
75
|
+
lookup_by = nil
|
76
|
+
if license.kind_of?(Megam::License)
|
77
|
+
lookup_by = license.name
|
78
|
+
elsif license.kind_of?(String)
|
79
|
+
lookup_by = license
|
80
|
+
else
|
81
|
+
raise ArgumentError, "Must pass a Megam::license or String to lookup"
|
82
|
+
end
|
83
|
+
res =@license_by_name[lookup_by]
|
84
|
+
unless res
|
85
|
+
raise ArgumentError, "Cannot find a license matching #{lookup_by} (did you define it first?)"
|
86
|
+
end
|
87
|
+
@license[res]
|
88
|
+
end
|
89
|
+
|
90
|
+
def to_s
|
91
|
+
@license.join(", ")
|
92
|
+
end
|
93
|
+
|
94
|
+
def for_json
|
95
|
+
to_a.map { |item| item.to_s }
|
96
|
+
end
|
97
|
+
|
98
|
+
def to_json(*a)
|
99
|
+
Megam::JSONCompat.to_json(for_json, *a)
|
100
|
+
end
|
101
|
+
|
102
|
+
def self.json_create(o)
|
103
|
+
collection = self.new()
|
104
|
+
o["results"].each do |license_list|
|
105
|
+
license_array = license_list.kind_of?(Array) ? license_list : [ license_list ]
|
106
|
+
license_array.each do |license|
|
107
|
+
collection.insert(license)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
collection
|
111
|
+
end
|
112
|
+
|
113
|
+
private
|
114
|
+
|
115
|
+
def is_megam_license(arg)
|
116
|
+
unless arg.kind_of?(Megam::License)
|
117
|
+
raise ArgumentError, "Members must be Megam::License's"
|
118
|
+
end
|
119
|
+
true
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
@@ -0,0 +1,173 @@
|
|
1
|
+
module Megam
|
2
|
+
class License < Megam::RestAdapter
|
3
|
+
def initialize(o)
|
4
|
+
@id = nil
|
5
|
+
@name = nil
|
6
|
+
@org_id = nil
|
7
|
+
@privatekey=nil
|
8
|
+
@publickey=nil
|
9
|
+
@created_at = nil
|
10
|
+
@some_msg = {}
|
11
|
+
super(o)
|
12
|
+
end
|
13
|
+
|
14
|
+
def license
|
15
|
+
self
|
16
|
+
end
|
17
|
+
|
18
|
+
def id(arg=nil)
|
19
|
+
if arg != nil
|
20
|
+
@id = arg
|
21
|
+
else
|
22
|
+
@id
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def name(arg=nil)
|
27
|
+
if arg != nil
|
28
|
+
@name = arg
|
29
|
+
else
|
30
|
+
@name
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def org_id(arg=nil)
|
35
|
+
if arg != nil
|
36
|
+
@org_id= arg
|
37
|
+
else
|
38
|
+
@org_id
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def privatekey(arg=nil)
|
43
|
+
if arg != nil
|
44
|
+
@privatekey = arg
|
45
|
+
else
|
46
|
+
@privatekey
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def publickey(arg=nil)
|
51
|
+
if arg != nil
|
52
|
+
@publickey = arg
|
53
|
+
else
|
54
|
+
@publickey
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
def created_at(arg=nil)
|
60
|
+
if arg != nil
|
61
|
+
@created_at = arg
|
62
|
+
else
|
63
|
+
@created_at
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def some_msg(arg=nil)
|
68
|
+
if arg != nil
|
69
|
+
@some_msg = arg
|
70
|
+
else
|
71
|
+
@some_msg
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def error?
|
76
|
+
crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
|
77
|
+
end
|
78
|
+
|
79
|
+
# Transform the ruby obj -> to a Hash
|
80
|
+
def to_hash
|
81
|
+
index_hash = Hash.new
|
82
|
+
index_hash["json_claz"] = self.class.name
|
83
|
+
index_hash["id"] = id
|
84
|
+
index_hash["name"] = name
|
85
|
+
index_hash["org_id"] = org_id
|
86
|
+
index_hash["privatekey"] = privatekey
|
87
|
+
index_hash["publickey"] = publickey
|
88
|
+
index_hash["created_at"] = created_at
|
89
|
+
index_hash
|
90
|
+
end
|
91
|
+
|
92
|
+
# Serialize this object as a hash: called from JsonCompat.
|
93
|
+
# Verify if this called from JsonCompat during testing.
|
94
|
+
def to_json(*a)
|
95
|
+
for_json.to_json(*a)
|
96
|
+
end
|
97
|
+
|
98
|
+
def for_json
|
99
|
+
result = {
|
100
|
+
"id" => id,
|
101
|
+
"name" => name,
|
102
|
+
"org_id" => org_id,
|
103
|
+
"privatekey" => privatekey,
|
104
|
+
"publickey" => publickey,
|
105
|
+
"created_at" => created_at
|
106
|
+
}
|
107
|
+
result
|
108
|
+
end
|
109
|
+
|
110
|
+
#
|
111
|
+
def self.json_create(o)
|
112
|
+
license = new({})
|
113
|
+
license.id(o["id"]) if o.has_key?("id")
|
114
|
+
license.name(o["name"]) if o.has_key?("name")
|
115
|
+
license.privatekey(o["privatekey"]) if o.has_key?("privatekey")
|
116
|
+
license.publickey(o["publickey"]) if o.has_key?("publickey")
|
117
|
+
license.created_at(o["created_at"]) if o.has_key?("created_at")
|
118
|
+
#success or error
|
119
|
+
license.some_msg[:code] = o["code"] if o.has_key?("code")
|
120
|
+
license.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
|
121
|
+
license.some_msg[:msg]= o["msg"] if o.has_key?("msg")
|
122
|
+
license.some_msg[:links] = o["links"] if o.has_key?("links")
|
123
|
+
license
|
124
|
+
end
|
125
|
+
|
126
|
+
def self.from_hash(o)
|
127
|
+
license = self.new(o)
|
128
|
+
license.from_hash(o)
|
129
|
+
license
|
130
|
+
end
|
131
|
+
|
132
|
+
def from_hash(o)
|
133
|
+
@id = o[:id] if o.has_key?(:id)
|
134
|
+
@name = o[:name] if o.has_key?(:name)
|
135
|
+
@org_id = o[:org_id] if o.has_key?(:org_id)
|
136
|
+
@privatekey = o[:privatekey] if o.has_key?(:privatekey)
|
137
|
+
@publickey = o[:publickey] if o.has_key?(:publickey)
|
138
|
+
@created_at = o[:created_at] if o.has_key?(:created_at)
|
139
|
+
self
|
140
|
+
end
|
141
|
+
|
142
|
+
def self.create(params)
|
143
|
+
acct = from_hash(params)
|
144
|
+
acct.create
|
145
|
+
end
|
146
|
+
|
147
|
+
# Create the predef via the REST API
|
148
|
+
def create
|
149
|
+
megam_rest.post_license(to_hash)
|
150
|
+
end
|
151
|
+
|
152
|
+
# Load all license -
|
153
|
+
# returns a LicensesCollection
|
154
|
+
# don't return self. check if the Megam::LicenseCollection is returned.
|
155
|
+
def self.list(params)
|
156
|
+
license = self.new(params)
|
157
|
+
license.megam_rest.get_license
|
158
|
+
end
|
159
|
+
|
160
|
+
# Show a particular License by name,
|
161
|
+
# Megam::License
|
162
|
+
def self.show(params)
|
163
|
+
pre = self.new(params)
|
164
|
+
pre.megam_rest.get_license(params["name"])
|
165
|
+
end
|
166
|
+
|
167
|
+
def to_s
|
168
|
+
Megam::Stuff.styled_hash(to_hash)
|
169
|
+
#"---> Megam::Account:[error=#{error?}]\n"+
|
170
|
+
end
|
171
|
+
|
172
|
+
end
|
173
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: megam_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.8.
|
4
|
+
version: 1.8.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rajthilak, Kishorekumar Neelamegam, Ranjitha R, Vinodhini V, Rathish VBR, Rajesh
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-10-
|
12
|
+
date: 2016-10-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: excon
|
@@ -153,6 +153,7 @@ files:
|
|
153
153
|
- lib/megam/api/eventscontainer.rb
|
154
154
|
- lib/megam/api/eventsstorage.rb
|
155
155
|
- lib/megam/api/eventsvm.rb
|
156
|
+
- lib/megam/api/license.rb
|
156
157
|
- lib/megam/api/marketplaces.rb
|
157
158
|
- lib/megam/api/organizations.rb
|
158
159
|
- lib/megam/api/promos.rb
|
@@ -194,6 +195,8 @@ files:
|
|
194
195
|
- lib/megam/core/eventsvm_collection.rb
|
195
196
|
- lib/megam/core/json_compat.rb
|
196
197
|
- lib/megam/core/konipai.rb
|
198
|
+
- lib/megam/core/license-collection.rb
|
199
|
+
- lib/megam/core/license.rb
|
197
200
|
- lib/megam/core/log.rb
|
198
201
|
- lib/megam/core/marketplace.rb
|
199
202
|
- lib/megam/core/marketplace_collection.rb
|