Class: Printos::AaaService

Inherits:
BaseService show all
Extended by:
AaaOrganization, AaaOrganizationAddress, AaaOrganizationSite
Defined in:
lib/printos/aaa_service.rb

Constant Summary

Constants included from AaaOrganization

Printos::AaaOrganization::ORGANIZATIONS_PATH

Constants included from AaaOrganizationSite

Printos::AaaOrganizationSite::ORGANIZATION_SITES_PATH

Constants included from AaaOrganizationAddress

Printos::AaaOrganizationAddress::ORGANIZATION_ADDRESSES_PATH

Class Method Summary collapse

Methods included from AaaOrganization

organization, update_organization

Methods included from AaaOrganizationSite

create_site, site, sites, update_site

Methods included from AaaOrganizationAddress

address, addresses, create_address, update_address

Methods inherited from BaseService

get_resource, parse, post_resource, put_resource

Class Method Details

.admin_contextObject



80
81
82
# File 'lib/printos/aaa_service.rb', line 80

def self.admin_context
  get_resource("#{API_BASE_PATH}/admin/context")
end

.admin_device(resource_id) ⇒ Object



84
85
86
# File 'lib/printos/aaa_service.rb', line 84

def self.admin_device(resource_id)
  get_resource("#{API_BASE_PATH}/admin/devices/#{resource_id}")
end

.admin_device_gbu_organizations(offset, limit, device_gbu_filter, device_type_filter) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
# File 'lib/printos/aaa_service.rb', line 88

def self.admin_device_gbu_organizations(offset, limit, device_gbu_filter, device_type_filter)
  uri = URI.join("#{API_BASE_PATH}/admin/devicegbu/organizations", org_id)
  query_params = URI.decode_www_form(uri.query || '')
  query_params << ['offset', offset] unless offset.blank?
  query_params << ['limit', limit] unless limit.blank?
  query_params << ['deviceType', device_type_filter] unless device_type_filter.blank?
  query_params << ['deviceGBU', device_gbu_filter] unless device_gbu_filter.blank?
  uri.query = URI.encode_www_form(query_params)

  get_resource(uri.to_s)
end

.admin_organization(org_id) ⇒ Object



100
101
102
# File 'lib/printos/aaa_service.rb', line 100

def self.admin_organization(org_id)
  get_resource("#{API_BASE_PATH}/admin/organizations/#{org_id}")
end

.admin_organizations(offset, limit, name_filter, gbu_filter) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
# File 'lib/printos/aaa_service.rb', line 104

def self.admin_organizations(offset, limit, name_filter, gbu_filter)
  uri = URI.parse("#{API_BASE_PATH}/admin/organizations")
  query_params = URI.decode_www_form(uri.query || '')
  query_params << ['offset', offset] unless offset.blank?
  query_params << ['limit', limit] unless limit.blank?
  query_params << ['name', name_filter] unless name_filter.blank?
  query_params << ['gbu', gbu_filter] unless gbu_filter.blank?
  uri.query = URI.encode_www_form(query_params)

  get_resource(uri.to_s)
end

.admin_site(org_id, resource_id) ⇒ Object



116
117
118
119
120
121
122
# File 'lib/printos/aaa_service.rb', line 116

def self.admin_site(org_id, resource_id)
  # AAA v3 does not have a method to directly retrieve a site by resource id
  # so we have to get all sites for the organization and select it
  sites = get_resource("#{API_BASE_PATH}/admin/organizations/#{org_id}/sites")

  sites[:sites].select { |site| site[:siteId] == resource_id }.first
end

.authorize(payload, as_service = false) ⇒ Object



124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/printos/aaa_service.rb', line 124

def self.authorize(payload, as_service=false)
  # The authorization API implementation is odd in that a response code of 412 is returned to indicate
  # that the service token has expired (normally 401 would be used)
  service_token_expired_code = 412

  begin
    parse PrintosRestClient.post("#{API_BASE_PATH}/authorize", payload, as_service, service_token_expired_code)
  rescue RestClient::Unauthorized
    Printos.config.logger.error('User token is invalid.')
    {}
  end
end

.device(resource_id) ⇒ Object



72
73
74
# File 'lib/printos/aaa_service.rb', line 72

def self.device(resource_id)
  get_resource("#{API_BASE_PATH}/organizations/devices/#{resource_id}")
end

.devicesObject



76
77
78
# File 'lib/printos/aaa_service.rb', line 76

def self.devices
  get_resource("#{API_BASE_PATH}/organizations/devices/v2")
end

.system_role_users(org_id, role_id) ⇒ Object



141
142
143
# File 'lib/printos/aaa_service.rb', line 141

def self.system_role_users(org_id, role_id)
  get_resource("#{API_BASE_PATH}/admin/organizations/#{org_id}/users/systemroles/#{role_id}", true)
end

.system_roles(as_service = false) ⇒ Object



137
138
139
# File 'lib/printos/aaa_service.rb', line 137

def self.system_roles(as_service=false)
  get_resource("#{API_BASE_PATH}/systemroles", as_service)
end

.userObject



68
69
70
# File 'lib/printos/aaa_service.rb', line 68

def self.user
  get_resource("#{API_BASE_PATH}/users")
end