Class: Cloudpassage::Accounts

Inherits:
Base
  • Object
show all
Includes:
Collection
Defined in:
lib/cloudpassage/servers.rb

Overview

Accounts on a server

Instance Method Summary collapse

Methods included from Collection

#[], #get, #to_s

Methods inherited from Base

#[], #data, #method_missing, #object_symbol, #post, #reload, #wait_for

Constructor Details

#initialize(server, token, base_resource, data = nil) ⇒ Accounts

Returns a new instance of Accounts.



55
56
57
58
# File 'lib/cloudpassage/servers.rb', line 55

def initialize(server, token, base_resource, data=nil)
  @server = server
  super(token, base_resource, data)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Cloudpassage::Base

Instance Method Details

#allObject



64
65
66
# File 'lib/cloudpassage/servers.rb', line 64

def all
  data.map { |i| get(i[:username], i) }
end

#create(username, groups = '', opts = {}) ⇒ Object

Creates username, in the given group. If opts is specified, that password will be used. Otherwise, password will be generated.



71
72
73
74
75
76
77
78
79
# File 'lib/cloudpassage/servers.rb', line 71

def create(username, groups = '', opts = {})
  payload = {'account' => {
    :username => username,
    :comment  => '',
    :groups   => groups,
    :password => password_opts.merge(opts.fetch(:password, {})),
  }}
  @server.commands.get(post(payload)['command']['id'])
end

#headersObject



90
91
92
# File 'lib/cloudpassage/servers.rb', line 90

def headers
  super.merge({'Content-Type'=>'application/json'})
end

#remove(username) ⇒ Object



86
87
88
# File 'lib/cloudpassage/servers.rb', line 86

def remove(username)
  JSON.parse @base_resource[username].delete(headers)
end

#reset(username, opts = {}) ⇒ Object



81
82
83
84
# File 'lib/cloudpassage/servers.rb', line 81

def reset(username, opts = {})
  payload = {'password' => password_opts.merge(opts)}
  JSON.parse @base_resource[username]['password'].put(payload.to_json, headers)
end

#singleton_classObject



60
61
62
# File 'lib/cloudpassage/servers.rb', line 60

def singleton_class
  Account
end