Class: LMC::Principal

Inherits:
Object
  • Object
show all
Defined in:
lib/lmc/principal.rb

Constant Summary collapse

PRINCIPAL_URL_BASE =
%w[cloud-service-auth users].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Principal

Returns a new instance of Principal.



14
15
16
# File 'lib/lmc/principal.rb', line 14

def initialize(data)
  apply_data(data)
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



6
7
8
# File 'lib/lmc/principal.rb', line 6

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/lmc/principal.rb', line 6

def name
  @name
end

#passwordObject (readonly)

Returns the value of attribute password.



6
7
8
# File 'lib/lmc/principal.rb', line 6

def password
  @password
end

#typeObject (readonly)

Returns the value of attribute type.



6
7
8
# File 'lib/lmc/principal.rb', line 6

def type
  @type
end

Class Method Details

.get_self(cloud) ⇒ Object

this is actually a bad hack because the lmc api treats users different from principals.



10
11
12
# File 'lib/lmc/principal.rb', line 10

def self.get_self(cloud)
  new(cloud.get([PRINCIPAL_URL_BASE, 'self']))
end

Instance Method Details

#saveObject

returns itself, allows chaining



19
20
21
22
23
24
25
26
27
28
# File 'lib/lmc/principal.rb', line 19

def save
  response = if @id.nil?
               Cloud.instance.post ['cloud-service-auth', 'principals'], self
             else
               raise 'editing principals not supported'
               # @cloud.put ["cloud-service-auth", "principals", @id], self
             end
  apply_data(response)
  self
end

#to_json(*a) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/lmc/principal.rb', line 34

def to_json(*a)
  {
      'name' => @name,
      'type' => @type,
      'password' => @password
  }.to_json(*a)
end

#to_sObject



30
31
32
# File 'lib/lmc/principal.rb', line 30

def to_s
  "#{@name} - #{@id}"
end