Class: Megam::SshKey

Inherits:
ServerAPI show all
Defined in:
lib/megam/core/sshkey.rb

Instance Attribute Summary

Attributes inherited from ServerAPI

#api_key, #email

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ServerAPI

#megam_rest

Constructor Details

#initialize(email = nil, api_key = nil) ⇒ SshKey

Returns a new instance of SshKey.



19
20
21
22
23
24
25
26
27
# File 'lib/megam/core/sshkey.rb', line 19

def initialize(email=nil, api_key=nil)
  @id = nil
  @name = nil
  @accounts_id = nil      
  @path=nil      
  @created_at = nil
  @some_msg = {}
  super(email, api_key)
end

Class Method Details

.create(o, tmp_email = nil, tmp_api_key = nil) ⇒ Object



145
146
147
148
# File 'lib/megam/core/sshkey.rb', line 145

def self.create(o,tmp_email=nil, tmp_api_key=nil)
  acct = from_hash(o,tmp_email, tmp_api_key)
  acct.create
end

.from_hash(o, tmp_email = nil, tmp_api_key = nil) ⇒ Object



131
132
133
134
135
# File 'lib/megam/core/sshkey.rb', line 131

def self.from_hash(o,tmp_email=nil, tmp_api_key=nil)
  sshKey = self.new(tmp_email, tmp_api_key)
  sshKey.from_hash(o)
  sshKey
end

.json_create(o) ⇒ Object



117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/megam/core/sshkey.rb', line 117

def self.json_create(o)
  sshKey = new
  sshKey.id(o["id"]) if o.has_key?("id")
  sshKey.name(o["name"]) if o.has_key?("name")     
  sshKey.path(o["path"]) if o.has_key?("path")     
  sshKey.created_at(o["created_at"]) if o.has_key?("created_at")
  #success or error
  sshKey.some_msg[:code] = o["code"] if o.has_key?("code")
  sshKey.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
  sshKey.some_msg[:msg]= o["msg"] if o.has_key?("msg")
  sshKey.some_msg[:links] = o["links"] if o.has_key?("links")
  sshKey
end

.list(tmp_email = nil, tmp_api_key = nil) ⇒ Object

Load all sshkeys - returns a sshkeysCollection don’t return self. check if the Megam::SshKeyCollection is returned.



158
159
160
161
# File 'lib/megam/core/sshkey.rb', line 158

def self.list(tmp_email=nil, tmp_api_key=nil)
sshKey = self.new(tmp_email,tmp_api_key)
  sshKey.megam_rest.get_sshkeys
end

.show(p_name, tmp_email = nil, tmp_api_key = nil) ⇒ Object

Show a particular sshKey by name, Megam::SshKey



165
166
167
168
# File 'lib/megam/core/sshkey.rb', line 165

def self.show(p_name,tmp_email=nil, tmp_api_key=nil)
pre = self.new(tmp_email,tmp_api_key)
pre.megam_rest.get_sshkey(p_name)
end

Instance Method Details

#accounts_id(arg = nil) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/megam/core/sshkey.rb', line 50

def accounts_id(arg=nil)
  if arg != nil
    @accounts_id= arg
  else
  @accounts_id
  end
end

#createObject

Create the predef via the REST API



151
152
153
# File 'lib/megam/core/sshkey.rb', line 151

def create
  megam_rest.post_sshkey(to_hash)
end

#created_at(arg = nil) ⇒ Object



67
68
69
70
71
72
73
# File 'lib/megam/core/sshkey.rb', line 67

def created_at(arg=nil)
  if arg != nil
    @created_at = arg
  else
  @created_at
  end
end

#error?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/megam/core/sshkey.rb', line 83

def error?
  crocked  = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
end

#for_jsonObject



105
106
107
108
109
110
111
112
113
114
# File 'lib/megam/core/sshkey.rb', line 105

def for_json
  result = {
    "id" => id,
    "name" => name,
    "accounts_id" => accounts_id,
    "path" => path,        
    "created_at" => created_at
  }
  result
end

#from_hash(o) ⇒ Object



137
138
139
140
141
142
143
# File 'lib/megam/core/sshkey.rb', line 137

def from_hash(o)
  @id        = o[:id] if o.has_key?(:id)
  @name = o[:name] if o.has_key?(:name)      
  @path   = o[:path] if o.has_key?(:path)   
  @created_at   = o[:created_at] if o.has_key?(:created_at)
  self
end

#id(arg = nil) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/megam/core/sshkey.rb', line 34

def id(arg=nil)
  if arg != nil
    @id = arg
  else
  @id
  end
end

#name(arg = nil) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/megam/core/sshkey.rb', line 42

def name(arg=nil)
  if arg != nil
    @name = arg
  else
  @name
  end
end

#path(arg = nil) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/megam/core/sshkey.rb', line 59

def path(arg=nil)
  if arg != nil
    @path= arg
  else
  @path
  end
end

#some_msg(arg = nil) ⇒ Object



75
76
77
78
79
80
81
# File 'lib/megam/core/sshkey.rb', line 75

def some_msg(arg=nil)
  if arg != nil
    @some_msg = arg
  else
  @some_msg
  end
end

#sshkeyObject



29
30
31
# File 'lib/megam/core/sshkey.rb', line 29

def sshkey
  self
end

#to_hashObject

Transform the ruby obj -> to a Hash



88
89
90
91
92
93
94
95
96
97
# File 'lib/megam/core/sshkey.rb', line 88

def to_hash
  index_hash = Hash.new
  index_hash["json_claz"] = self.class.name
  index_hash["id"] = id
  index_hash["name"] = name
  index_hash["accounts_id"] = accounts_id
  index_hash["path"] = path     
  index_hash["created_at"] = created_at
  index_hash
end

#to_json(*a) ⇒ Object

Serialize this object as a hash: called from JsonCompat. Verify if this called from JsonCompat during testing.



101
102
103
# File 'lib/megam/core/sshkey.rb', line 101

def to_json(*a)
  for_json.to_json(*a)
end

#to_sObject



170
171
172
173
# File 'lib/megam/core/sshkey.rb', line 170

def to_s
  Megam::Stuff.styled_hash(to_hash)
#"---> Megam::Account:[error=#{error?}]\n"+
end