Class: Puppet::Util::NetworkDevice::Auth0_tenant::Device
- Inherits:
-
Simple::Device
- Object
- Simple::Device
- Puppet::Util::NetworkDevice::Auth0_tenant::Device
- 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
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
Instance Method Summary collapse
- #facts ⇒ Object
- #handling_rate_limit ⇒ Object
-
#initialize(*args) ⇒ Device
constructor
A new instance of Device.
- #paginate_request(method, *args, **kwargs) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Device
Returns a new instance of Device.
39 40 41 42 43 44 45 46 47 |
# File 'lib/puppet/util/network_device/auth0_tenant/device.rb', line 39 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
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
38 39 40 |
# File 'lib/puppet/util/network_device/auth0_tenant/device.rb', line 38 def connection @connection end |
Instance Method Details
#facts ⇒ Object
49 50 51 52 53 54 |
# File 'lib/puppet/util/network_device/auth0_tenant/device.rb', line 49 def facts { tenant_domain: config['domain'], management_client_id: config['client_id'], } end |
#handling_rate_limit ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/puppet/util/network_device/auth0_tenant/device.rb', line 56 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
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/puppet/util/network_device/auth0_tenant/device.rb', line 72 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 |