class OnappMarket::Admin::User

Represent a market user and control their whitelist IPs and roles.

Notes

No PRD exists for user requirements. Some initial basic requirements have been created to unblock development

Constants

ADMIN

Admin Role

ID
NONE

No roles

RO_ADMIN

RO Admin role

SUPPLIER

Supplier Role

TRADER

Trader Roles

TYPE

Attributes

api[RW]

API used to manage this resource

contact_email[RW]

Contact e-mail address (for alerts or notifications from the market)

created_at[RW]

Creation time

deleted[RW]

Is this user account deleted?

deleted_at[RW]

Deletion time

enabled[RW]

Is this user account enabled?

ip_whitelist[RW]

IP Addresses from which the user account can be accessed

label[RW]

Label for this user e.g. VPS.Net

local_id[RW]

A local client supplied ID which serves as a reference for this user within a a system external to the market e.g. Client ID from Dashboard

pass[RW]

Password e.g. 128 character random string

pass_hash[RW]

Actual value which will be stored following hash

role[RW]

Roles - one of: User::SUPPLIER, User::TRADER, User::ADMIN or User:RO_ADMIN

salt[RW]

per password salt

user[RW]

User name

user_id[RW]

Market assigned #user_id

Public Class Methods

new(hash = {}) click to toggle source

Create a new user object

# File lib/onapp_market/admin/user.rb, line 63
def initialize(hash = {})
  super(hash, TYPE)
  # Restrictions
  restrict [:local_id, :pass_hash, :pass, :salt], [:admin]
end

Public Instance Methods

add_white_list_addr(ip) click to toggle source

Add a new IP address to the white list

Attributes

  • ip - The IP Address to add

Returns

Roles

admin

# File lib/onapp_market/admin/user.rb, line 77
def add_white_list_addr(ip)
  @api.post("/admin/user/#{self.user_id.url_safe}/whitelist", {:ip => ip})
end
del_all_white_list_addrs() click to toggle source

Delete all white list IP addresses

Returns

Roles

admin

# File lib/onapp_market/admin/user.rb, line 100
def del_all_white_list_addrs
  @api.delete("/admin/user/#{self.user_id.url_safe}/whitelist/delete_all")
end
del_white_list_addr(ip) click to toggle source

Remove an IP address from the white list

Attributes

  • ip - The IP Address to remove

Returns

Roles

admin

# File lib/onapp_market/admin/user.rb, line 89
def del_white_list_addr(ip)
  @api.post("/admin/user/#{self.user_id.url_safe}/whitelist/delete_set", {:ips => ip}) if ip.is_a?(Array)
  @api.delete("/admin/user/#{self.user_id.url_safe}/whitelist/#{URI.escape(ip)}") unless ip.is_a?(Array)
end
delete() click to toggle source

Delete a user from the market

Returns

Roles

admin

# File lib/onapp_market/admin/user.rb, line 152
def delete
  @api.delete("/admin/user/#{self.user_id.url_safe}")
end
enable() click to toggle source

Enable a user account

Returns

Roles

admin

# File lib/onapp_market/admin/user.rb, line 131
def enable
  @enabled = true
  update
end
get_white_list_addrs() click to toggle source

Get a simple array of white list entries

Returns

Roles

admin

# File lib/onapp_market/admin/user.rb, line 110
def get_white_list_addrs
  @api.get("/admin/user/#{self.user_id.url_safe}/whitelist")
end
suspend() click to toggle source

Suspend a user account

Returns

Roles

admin

# File lib/onapp_market/admin/user.rb, line 120
def suspend
  @enabled = false
  update
end
update() click to toggle source

Update a users information

Returns

Roles

admin

# File lib/onapp_market/admin/user.rb, line 142
def update
  @api.put("/admin/user/#{self.user_id.url_safe}", OnappMarket::API::Serialize.to_hash(self))
end