Class: Puppet::Util::NetworkDevice::Auth0_tenant::Device

Inherits:
Simple::Device
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/puppet/util/network_device/auth0_tenant/device.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Device

Returns a new instance of Device.



12
13
14
15
16
17
18
19
20
# File 'lib/puppet/util/network_device/auth0_tenant/device.rb', line 12

def initialize(*args)
  super
  @connection = Auth0::Client.new(
    client_id: config['client_id'],
    client_secret: config['client_secret'],
    domain: config['domain'],
    api_version: 2,
  )
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



11
12
13
# File 'lib/puppet/util/network_device/auth0_tenant/device.rb', line 11

def connection
  @connection
end

Instance Method Details

#factsObject



22
23
24
25
26
27
# File 'lib/puppet/util/network_device/auth0_tenant/device.rb', line 22

def facts
  { 
    tenant_domain: config['domain'],
    management_client_id: config['client_id'],
  }
end

#patch_resource_server(id, options) ⇒ Object

Raises:

  • (Auth0::MissingClientId)


40
41
42
43
44
45
# File 'lib/puppet/util/network_device/auth0_tenant/device.rb', line 40

def patch_resource_server(id, options)
  raise Auth0::MissingClientId, 'Must specify a resource server id' if id.to_s.empty?
  raise Auth0::MissingParameter, 'Must specify a valid body' if options.to_s.empty?
  path = "#{@connection.send(:resource_servers_path)}/#{id}"
  @connection.patch(path, options)
end

#resource_servers(page: nil, per_page: nil) ⇒ Object Also known as: get_resource_servers

These methods are missing from the Auth0 gem for some reason, a PR is in progress but in the meantime we'll just stick it here.



31
32
33
34
35
36
37
# File 'lib/puppet/util/network_device/auth0_tenant/device.rb', line 31

def resource_servers(page: nil, per_page: nil)
  request_params = {
    page: !page.nil? ? page.to_i : nil,
    per_page: !page.nil? && !per_page.nil? ? per_page.to_i : nil
  }
  @connection.get(@connection.send(:resource_servers_path), request_params)
end