class Fog::Identity::Proxmox::Domains
class Domains collection authentication
Public Instance Methods
all(_options = {})
click to toggle source
# File lib/fog/identity/proxmox/models/domains.rb, line 40 def all(_options = {}) load_response(service.list_domains, 'domains') end
create(attributes = {})
click to toggle source
# File lib/fog/identity/proxmox/models/domains.rb, line 58 def create(attributes = {}) domain = new(realm: attributes[:realm]) type_s = attributes[:type] tfa_s = attributes[:tfa] attr = attributes.reject { |k, _v| %i[realm type tfa].include? k } domain.type = to_type(type_s, attr) tfa = to_tfa(tfa_s) domain.type.tfa = tfa if tfa domain.create end
destroy(id)
click to toggle source
# File lib/fog/identity/proxmox/models/domains.rb, line 53 def destroy(id) domain = find_by_id(id) domain.destroy end
find_by_id(id)
click to toggle source
# File lib/fog/identity/proxmox/models/domains.rb, line 44 def find_by_id(id) response = service.get_domain(id) body = JSON.decode(response.body) data = body['data'] data.store('realm', id) data.delete_if { |k, _v| k == 'digest' } to_domain(data) end
tfa_class(tfa)
click to toggle source
# File lib/fog/identity/proxmox/models/domains.rb, line 101 def tfa_class(tfa) if tfa == 'oath' tfa_class = Fog::Identity::Proxmox::Oath elsif tfa == 'yubico' tfa_class = Fog::Identity::Proxmox::Yubico else raise Fog::Proxmox::Errors::NotFound, 'domain tfa unknown' end tfa_class end
to_domain(hash)
click to toggle source
# File lib/fog/identity/proxmox/models/domains.rb, line 29 def to_domain(hash) realm = hash['realm'] type_value = hash['type'] tfa_value = hash['tfa'] type_hash = hash.reject { |k, _v| %w[realm type tfa].include? k } type = to_type(type_value, type_hash) tfa = to_tfa(tfa_value) type.tfa = tfa if tfa new(realm: realm, type: type) end
to_tfa(tfa_s)
click to toggle source
# File lib/fog/identity/proxmox/models/domains.rb, line 73 def to_tfa(tfa_s) oath_rxp = /type=oath,step=(?<step>\d+),digits=(?<digits>\d+)/ yubico_rxp = /type=yubico,id=(?<id>\w+),key=(?<key>\w+),url=(?<url>.+)/ if oath_rxp.match(tfa_s) attributes = oath_rxp.named_captures type = 'oath' elsif yubico_rxp.match(tfa_s) attributes = yubico_rxp.named_captures type = 'yubico' end tfa_class(type).new(attributes) if type && attributes end
to_type(type, attributes)
click to toggle source
# File lib/fog/identity/proxmox/models/domains.rb, line 69 def to_type(type, attributes) type_class(type).new(attributes) end
type_class(type)
click to toggle source
# File lib/fog/identity/proxmox/models/domains.rb, line 86 def type_class(type) if type == 'pam' type_class = Fog::Identity::Proxmox::Pam elsif type == 'pve' type_class = Fog::Identity::Proxmox::Pve elsif type == 'ldap' type_class = Fog::Identity::Proxmox::Ldap elsif type == 'ad' type_class = Fog::Identity::Proxmox::Activedirectory else raise Fog::Proxmox::Errors::NotFound, 'domain type unknown' end type_class end