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

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

Constant Summary collapse

PAGINATED_METHODS =
%i{
  clients get_clients client_grants get_all_client_grants rules get_rules
  connections get_connections resource_servers get_resource_servers
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Device

Returns a new instance of Device.



26
27
28
29
30
31
32
33
34
# File 'lib/puppet/util/network_device/auth0_tenant/device.rb', line 26

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.



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

def connection
  @connection
end

Instance Method Details

#factsObject



36
37
38
39
40
41
# File 'lib/puppet/util/network_device/auth0_tenant/device.rb', line 36

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

#handling_rate_limitObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/puppet/util/network_device/auth0_tenant/device.rb', line 43

def handling_rate_limit
  begin
    yield
  rescue Auth0::RateLimitEncountered => rle
    retry_after = Time.now - rle.reset
    if retry_after > 0
      Puppet.warning("Encountered rate limit, will delay #{retry_after} seconds and try again.")
      sleep(retry_after)
      yield
    else
      Puppet.warning("Encountered rate limit but rate-limit-reset has already occurred, trying again immediately.")
      yield
    end
  end
end

#paginate_request(method, *args, **kwargs) ⇒ Object



59
60
61
62
63
64
65
66
67
68
# File 'lib/puppet/util/network_device/auth0_tenant/device.rb', line 59

def paginate_request(method, *args, **kwargs)
  results = []
  0.step do |page|
    real_kwargs = kwargs.merge(page: page, per_page: 50)
    result = @connection.send(method, *args, **real_kwargs)
    break if result.empty?
    results.concat(result)
  end
  results
end